BxBaseModGroupsFormEntry.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseGroups Base classes for groups modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Create/Edit Group Form.
  13. */
  14. class BxBaseModGroupsFormEntry extends BxBaseModProfileFormEntry
  15. {
  16. protected $_bDisplayInvite;
  17. public function __construct($aInfo, $oTemplate = false)
  18. {
  19. if (!isset($this->_bAllowChangeUserForAdmins))
  20. $this->_bAllowChangeUserForAdmins = true;
  21. parent::__construct($aInfo, $oTemplate);
  22. $CNF = &$this->_oModule->_oConfig->CNF;
  23. $this->_bDisplayInvite = isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_INVITE']) && $CNF['OBJECT_FORM_ENTRY_DISPLAY_INVITE'] == $this->aParams['display'];
  24. if (isset($this->aInputs['initial_members'])) {
  25. if(!isset($this->aInputs['initial_members']['value']))
  26. $this->aInputs['initial_members']['value'] = $this->_bDisplayInvite ? [] : [bx_get_logged_profile_id()];
  27. if($this->_bDisplayInvite)
  28. $this->aInputs['initial_members'] = array_merge($this->aInputs['initial_members'], [
  29. 'required' => 1,
  30. 'checker' => [
  31. 'func' => 'Avail',
  32. 'params' => [],
  33. 'error' => _t('_Enter_value_here'),
  34. ]
  35. ]);
  36. }
  37. }
  38. function initChecker ($aValues = array (), $aSpecificValues = array())
  39. {
  40. $CNF = &$this->_oModule->_oConfig->CNF;
  41. $bValues = $aValues && !empty($aValues['id']);
  42. $aContentInfo = $bValues ? $this->_oModule->_oDb->getContentInfoById($aValues['id']) : false;
  43. if(isset($CNF['FIELD_PUBLISHED']) && $this->aParams['display'] == $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'] && isset($this->aInputs[$CNF['FIELD_PUBLISHED']]))
  44. if($bValues && in_array($aValues[$CNF['FIELD_STATUS']], array('active', 'hidden')))
  45. unset($this->aInputs[$CNF['FIELD_PUBLISHED']]);
  46. parent::initChecker ($aValues, $aSpecificValues);
  47. }
  48. public function insert ($aValsToAdd = array(), $isIgnore = false)
  49. {
  50. $CNF = &$this->_oModule->_oConfig->CNF;
  51. if(isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']])) {
  52. $iAdded = 0;
  53. if(isset($this->aInputs[$CNF['FIELD_ADDED']]))
  54. $iAdded = $this->getCleanValue($CNF['FIELD_ADDED']);
  55. if(empty($iAdded))
  56. $iAdded = time();
  57. $aValsToAdd[$CNF['FIELD_ADDED']] = $iAdded;
  58. }
  59. if(isset($CNF['FIELD_PUBLISHED']) && empty($aValsToAdd[$CNF['FIELD_PUBLISHED']])) {
  60. $iPublished = 0;
  61. if(isset($this->aInputs[$CNF['FIELD_PUBLISHED']]))
  62. $iPublished = $this->getCleanValue($CNF['FIELD_PUBLISHED']);
  63. if(empty($iPublished))
  64. $iPublished = time();
  65. $aValsToAdd[$CNF['FIELD_PUBLISHED']] = $iPublished;
  66. }
  67. if(!empty($CNF['FIELD_STATUS']) && empty($aValsToAdd[$CNF['FIELD_STATUS']]))
  68. $aValsToAdd[$CNF['FIELD_STATUS']] = (isset($CNF['FIELD_PUBLISHED']) && ($aValsToAdd[$CNF['FIELD_PUBLISHED']] > $aValsToAdd[$CNF['FIELD_ADDED']])) ? 'awaiting' : 'active';
  69. return parent::insert ($aValsToAdd, $isIgnore);
  70. }
  71. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  72. {
  73. $CNF = &$this->_oModule->_oConfig->CNF;
  74. if(isset($CNF['FIELD_PUBLISHED'])) {
  75. if(empty($aValsToAdd[$CNF['FIELD_PUBLISHED']]) && isset($this->aInputs[$CNF['FIELD_PUBLISHED']])) {
  76. $iPublished = $this->getCleanValue($CNF['FIELD_PUBLISHED']);
  77. if(empty($iPublished))
  78. $iPublished = time();
  79. $aValsToAdd[$CNF['FIELD_PUBLISHED']] = $iPublished;
  80. }
  81. }
  82. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  83. $mixedResult = parent::update($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  84. if($mixedResult && ($iAuthorId = (int)$this->getCleanValue($CNF['FIELD_AUTHOR'])) && (int)$aContentInfo[$CNF['FIELD_AUTHOR']] != $iAuthorId) {
  85. $oProfileAuthor = BxDolProfile::getInstance($iAuthorId);
  86. $oProfileContent = BxDolProfile::getInstanceByContentAndType($iContentId, $this->MODULE);
  87. if($oProfileAuthor !== false && $oProfileContent !== false)
  88. $oProfileContent->move($oProfileAuthor->getAccountId());
  89. }
  90. return $mixedResult;
  91. }
  92. protected function genCustomInputInitialMembers ($aInput)
  93. {
  94. $aInput['ajax_get_suggestions'] = BX_DOL_URL_ROOT . "modules/?r=" . $this->_oModule->_oConfig->getUri() . "/ajax_get_initial_members";
  95. if(bx_is_api()) {
  96. $aInput['ajax_get_suggestions'] = $this->_oModule->_oConfig->getName() . "/get_initial_members&params[]=";
  97. $aInput['value_data'] = [];
  98. if(!empty($aInput['value']) && is_array($aInput['value']))
  99. foreach($aInput['value'] as $iProfileId)
  100. if(($oProfile = BxDolProfile::getInstance($iProfileId)) !== false) {
  101. $aProfile = $oProfile->getUnitAPI();
  102. $aInput['value_data'][] = $aProfile['author_data'];
  103. }
  104. }
  105. return $this->genCustomInputUsernamesSuggestions($aInput);
  106. }
  107. }
  108. /** @} */