BxBaseModProfileGridAdministration.php 6.6 KB

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