BxBaseModProfileGridAdministration.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 DolphinModules
  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('bx_div.html', array(
  56. 'bx_repeat:attrs' => array(
  57. array('key' => 'class', 'value' => 'bx-def-padding')
  58. ),
  59. 'content' => $oMenu->getCode($aIdsResult)
  60. ));
  61. bx_import('BxTemplFunctions');
  62. $sContent = BxTemplFunctions::getInstance()->transBox($this->_oModule->_oConfig->getName() . 'set_acl_level_popup', $sContent);
  63. $this->_echoResultJson(array('popup' => $sContent), true);
  64. }
  65. public function performActionDeleteWithContent()
  66. {
  67. $this->performActionDelete(array('with_content' => true));
  68. }
  69. protected function _switcherChecked2State($isChecked)
  70. {
  71. return $isChecked ? 'active' : 'suspended';
  72. }
  73. protected function _switcherState2Checked($mixedState)
  74. {
  75. return 'active' == $mixedState ? true : false;
  76. }
  77. protected function _enable ($mixedId, $isChecked)
  78. {
  79. $iAction = BX_PROFILE_ACTION_MANUAL;
  80. $oProfile = $this->_getProfileObject($mixedId);
  81. return $isChecked ? $oProfile->activate($iAction) : $oProfile->suspend($iAction);
  82. }
  83. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  84. {
  85. if(strpos($sFilter, $this->_sParamsDivider) !== false)
  86. list($this->_sFilter1Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  87. if(!empty($this->_sFilter1Value))
  88. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepare(" AND `tp`.`status`=?", $this->_sFilter1Value);
  89. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  90. }
  91. //--- Layout methods ---//
  92. protected function _getFilterControls()
  93. {
  94. parent::_getFilterControls();
  95. return $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
  96. }
  97. protected function _getCellFullname($mixedValue, $sKey, $aField, $aRow)
  98. {
  99. $oProfile = $this->_getProfileObject($aRow['id']);
  100. $mixedValue = $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  101. 'href' => $oProfile->getUrl(),
  102. 'title' => $mixedValue,
  103. 'bx_repeat:attrs' => array(),
  104. 'content' => $mixedValue
  105. ));
  106. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  107. }
  108. protected function _getCellLastOnline($mixedValue, $sKey, $aField, $aRow)
  109. {
  110. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  111. }
  112. protected function _getProfileObject($iId)
  113. {
  114. bx_import('BxDolProfile');
  115. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iId, $this->_oModule->_oConfig->getName());
  116. if (!$oProfile) {
  117. bx_import('BxDolProfileUndefined');
  118. $oProfile = BxDolProfileUndefined::getInstance();
  119. }
  120. return $oProfile;
  121. }
  122. protected function _getProfileId($iId)
  123. {
  124. return $this->_getProfileObject($iId)->id();
  125. }
  126. protected function _onDelete($iId, $aParams = array())
  127. {
  128. if(isset($aParams['with_content']) && $aParams['with_content'] === true) {
  129. //TODO: delete content after profile deletion
  130. }
  131. return parent::_onDelete($iId, $aParams);
  132. }
  133. }
  134. /** @} */