BxBaseModProfileGridAdministration.php 6.6 KB

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