BxBaseModProfileGridAdministration.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. return $isChecked ? $oProfile->activate($iAction) : $oProfile->suspend($iAction);
  90. }
  91. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  92. {
  93. if(strpos($sFilter, $this->_sParamsDivider) !== false)
  94. list($this->_sFilter1Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  95. if(!empty($this->_sFilter1Value))
  96. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepare(" AND `tp`.`status`=?", $this->_sFilter1Value);
  97. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  98. }
  99. //--- Layout methods ---//
  100. protected function _getFilterControls()
  101. {
  102. parent::_getFilterControls();
  103. return $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
  104. }
  105. protected function _getCellFullname($mixedValue, $sKey, $aField, $aRow)
  106. {
  107. $oProfile = $this->_getProfileObject($aRow['id']);
  108. $mixedValue = $this->_oTemplate->parseHtmlByName('name_link.html', array(
  109. 'href' => $oProfile->getUrl(),
  110. 'title' => $mixedValue,
  111. 'content' => $mixedValue
  112. ));
  113. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  114. }
  115. protected function _getCellLastOnline($mixedValue, $sKey, $aField, $aRow)
  116. {
  117. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  118. }
  119. protected function _getCellAccount($mixedValue, $sKey, $aField, $aRow)
  120. {
  121. $sManageAccountUrl = $this->_getManageAccountUrl($aRow[$sKey]);
  122. if(!empty($sManageAccountUrl)) {
  123. $mixedValue = $this->_oTemplate->parseHtmlByName('account_link.html', array(
  124. 'href' => $sManageAccountUrl,
  125. 'title' => _t($this->_oModule->_oConfig->CNF['T']['grid_txt_account_manager']),
  126. 'content' => $mixedValue,
  127. ));
  128. }
  129. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  130. }
  131. protected function _getProfileObject($iId)
  132. {
  133. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iId, $this->_oModule->_oConfig->getName());
  134. if (!$oProfile)
  135. $oProfile = BxDolProfileUndefined::getInstance();
  136. return $oProfile;
  137. }
  138. protected function _getProfileId($iId)
  139. {
  140. return $this->_getProfileObject($iId)->id();
  141. }
  142. protected function _doDelete($iId, $aParams = array())
  143. {
  144. if($this->_oModule->checkMyself($iId))
  145. return false;
  146. if(isset($aParams['with_content']) && $aParams['with_content'] === true) {
  147. $oProfile = $this->_getProfileObject($iId);
  148. if($oProfile instanceof BxDolProfileUndefined)
  149. return false;
  150. return $oProfile->delete($oProfile->id(), true);
  151. }
  152. return parent::_doDelete($iId, $aParams);
  153. }
  154. }
  155. /** @} */