BxBaseModProfileGridAdministration.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModProfileGridAdministration extends BxBaseModGeneralGridAdministration
  12. {
  13. protected $_sFilter1Name;
  14. protected $_sFilter1Value;
  15. protected $_aFilter1Values;
  16. public function __construct ($aOptions, $oTemplate = false)
  17. {
  18. parent::__construct ($aOptions, $oTemplate);
  19. $CNF = &$this->_oModule->_oConfig->CNF;
  20. $this->_aQueryReset = array('order_field', 'order_dir', $this->_aOptions['paginate_get_start'], $this->_aOptions['paginate_get_per_page']);
  21. $this->_sFilter1Name = 'filter1';
  22. $this->_aFilter1Values = array(
  23. 'active' => $CNF['T']['filter_item_active'],
  24. 'pending' => $CNF['T']['filter_item_pending'],
  25. 'suspended' => $CNF['T']['filter_item_suspended'],
  26. );
  27. $sFilter1 = bx_get($this->_sFilter1Name);
  28. if(!empty($sFilter1)) {
  29. $this->_sFilter1Value = bx_process_input($sFilter1);
  30. $this->_aQueryAppend[$this->_sFilter1Name] = $this->_sFilter1Value;
  31. }
  32. }
  33. public function performActionSetAclLevel()
  34. {
  35. $oMenu = BxDolMenu::getObjectInstance('sys_set_acl_level');
  36. $aIds = bx_get('ids');
  37. if(!$aIds || !is_array($aIds) || !$oMenu) {
  38. echoJson(array());
  39. return;
  40. }
  41. $aIdsResult = array();
  42. foreach($aIds as $iId) {
  43. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iId);
  44. if($this->_oModule->checkAllowedSetMembership($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
  45. continue;
  46. $aIdsResult[] = $this->_getProfileId($iId);
  47. }
  48. if(empty($aIdsResult)) {
  49. echoJson(array());
  50. return;
  51. }
  52. if(count($aIdsResult) == 1)
  53. $aIdsResult = $aIdsResult[0];
  54. $sContent = $this->_oTemplate->parseHtmlByName('set_acl_popup.html', array(
  55. 'content' => $oMenu->getCode($aIdsResult)
  56. ));
  57. $sContent = BxTemplFunctions::getInstance()->transBox($this->_oModule->_oConfig->getName() . 'set_acl_level_popup', $sContent);
  58. echoJson(array('popup' => $sContent));
  59. }
  60. public function performActionDeleteWithContent()
  61. {
  62. $this->performActionDelete(array('with_content' => true));
  63. }
  64. protected function _getActionSetAclLevel($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  65. {
  66. if($this->_sManageType == BX_DOL_MANAGE_TOOLS_ADMINISTRATION && $this->_oModule->checkAllowedSetMembership($aRow) !== CHECK_ACTION_RESULT_ALLOWED)
  67. return '';
  68. return $this->_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  69. }
  70. protected function _getActionDeleteWithContent($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  71. {
  72. if($this->_sManageType == BX_DOL_MANAGE_TOOLS_ADMINISTRATION && $this->_oModule->checkAllowedEditAnyEntry() !== CHECK_ACTION_RESULT_ALLOWED)
  73. return '';
  74. return $this->_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  75. }
  76. protected function _switcherChecked2State($isChecked)
  77. {
  78. return $isChecked ? 'active' : 'suspended';
  79. }
  80. protected function _switcherState2Checked($mixedState)
  81. {
  82. return 'active' == $mixedState ? true : false;
  83. }
  84. protected function _enable ($mixedId, $isChecked)
  85. {
  86. $oProfile = $this->_getProfileObject($mixedId);
  87. if($oProfile instanceof BxDolProfileUndefined)
  88. return false;
  89. $iAction = BX_PROFILE_ACTION_MANUAL;
  90. $bSendEmailNotification = $this->_oModule->serviceActAsProfile();
  91. return $isChecked ? $oProfile->activate($iAction, 0, $bSendEmailNotification) : $oProfile->suspend($iAction, 0, $bSendEmailNotification);
  92. }
  93. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  94. {
  95. if(strpos($sFilter, $this->_sParamsDivider) !== false)
  96. list($this->_sFilter1Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  97. if(!empty($this->_sFilter1Value))
  98. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `tp`.`status`=?", $this->_sFilter1Value);
  99. return $this->_getDataSqlInner($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  100. }
  101. protected function _getDataSqlInner($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  102. {
  103. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  104. }
  105. //--- Layout methods ---//
  106. protected function _getFilterControls()
  107. {
  108. parent::_getFilterControls();
  109. return $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
  110. }
  111. protected function _getCellFullname($mixedValue, $sKey, $aField, $aRow)
  112. {
  113. $oProfile = $this->_getProfileObject($aRow['id']);
  114. $mixedValue = $this->_oTemplate->parseHtmlByName('name_link.html', array(
  115. 'href' => $oProfile->getUrl(),
  116. 'title' => $mixedValue,
  117. 'content' => $mixedValue
  118. ));
  119. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  120. }
  121. protected function _getCellLastOnline($mixedValue, $sKey, $aField, $aRow)
  122. {
  123. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  124. }
  125. protected function _getCellAddedTs($mixedValue, $sKey, $aField, $aRow)
  126. {
  127. return $this->_getCellLastOnline($mixedValue, $sKey, $aField, $aRow);
  128. }
  129. protected function _getCellAccount($mixedValue, $sKey, $aField, $aRow)
  130. {
  131. $sManageAccountUrl = $this->_getManageAccountUrl($aRow[$sKey]);
  132. if(!empty($sManageAccountUrl)) {
  133. $mixedValue = $this->_oTemplate->parseHtmlByName('account_link.html', array(
  134. 'href' => $sManageAccountUrl,
  135. 'title' => _t($this->_oModule->_oConfig->CNF['T']['grid_txt_account_manager']),
  136. 'content' => $mixedValue,
  137. ));
  138. }
  139. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  140. }
  141. protected function _getProfileObject($iId)
  142. {
  143. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iId, $this->_oModule->_oConfig->getName());
  144. if (!$oProfile)
  145. $oProfile = BxDolProfileUndefined::getInstance();
  146. return $oProfile;
  147. }
  148. protected function _getProfileId($iId)
  149. {
  150. return $this->_getProfileObject($iId)->id();
  151. }
  152. protected function _doDelete($iId, $aParams = array())
  153. {
  154. if($this->_oModule->checkMyself($iId))
  155. return false;
  156. if(isset($aParams['with_content']) && $aParams['with_content'] === true) {
  157. $oProfile = $this->_getProfileObject($iId);
  158. if($oProfile instanceof BxDolProfileUndefined)
  159. return false;
  160. return $oProfile->delete($oProfile->id(), true);
  161. }
  162. return parent::_doDelete($iId, $aParams);
  163. }
  164. }
  165. /** @} */