BxBaseModProfileGridAdministration.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 $_sFilter1;
  15. public function __construct ($aOptions, $oTemplate = false)
  16. {
  17. parent::__construct ($aOptions, $oTemplate);
  18. $sFilter1 = bx_get('filter1');
  19. if(!empty($sFilter1)) {
  20. $this->_sFilter1 = bx_process_input($sFilter1);
  21. $this->_aQueryAppend['filter1'] = $this->_sFilter1;
  22. }
  23. }
  24. public function performActionSetAclLevel()
  25. {
  26. bx_import('BxDolMenu');
  27. $oMenu = BxDolMenu::getObjectInstance('sys_set_acl_level');
  28. $aIds = bx_get('ids');
  29. if(!$aIds || !is_array($aIds) || !$oMenu) {
  30. $this->_echoResultJson(array());
  31. return;
  32. }
  33. $aIdsResult = array();
  34. foreach($aIds as $iId) {
  35. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iId);
  36. if($this->_oModule->checkAllowedSetMembership($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
  37. continue;
  38. $aIdsResult[] = $this->_getProfileId($iId);
  39. }
  40. if(empty($aIdsResult)) {
  41. $this->_echoResultJson(array());
  42. return;
  43. }
  44. if(count($aIdsResult) == 1)
  45. $aIdsResult = $aIdsResult[0];
  46. $sContent = $this->_oTemplate->parseHtmlByName('bx_div.html', array(
  47. 'bx_repeat:attrs' => array(
  48. array('key' => 'class', 'value' => 'bx-def-padding')
  49. ),
  50. 'content' => $oMenu->getCode($aIdsResult)
  51. ));
  52. bx_import('BxTemplFunctions');
  53. $sContent = BxTemplFunctions::getInstance()->transBox($this->_oModule->_oConfig->getName() . 'set_acl_level_popup', $sContent);
  54. $this->_echoResultJson(array('popup' => $sContent), true);
  55. }
  56. public function performActionDeleteWithContent()
  57. {
  58. $this->performActionDelete(array('with_content' => true));
  59. }
  60. protected function _switcherChecked2State($isChecked)
  61. {
  62. return $isChecked ? 'active' : 'suspended';
  63. }
  64. protected function _switcherState2Checked($mixedState)
  65. {
  66. return 'active' == $mixedState ? true : false;
  67. }
  68. protected function _enable ($mixedId, $isChecked)
  69. {
  70. $iAction = BX_PROFILE_ACTION_MANUAL;
  71. $oProfile = $this->_getProfileObject($mixedId);
  72. return $isChecked ? $oProfile->activate($iAction) : $oProfile->suspend($iAction);
  73. }
  74. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  75. {
  76. if(strpos($sFilter, $this->_sParamsDivider) !== false)
  77. list($this->_sFilter1, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  78. if(!empty($this->_sFilter1))
  79. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepare(" AND `tp`.`status`=?", $this->_sFilter1);
  80. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  81. }
  82. //--- Layout methods ---//
  83. protected function _getFilterControls()
  84. {
  85. parent::_getFilterControls();
  86. $sPrefixLang = $this->_oModule->_oConfig->getPrefix('lang');
  87. $sFilterName = 'filter1';
  88. $aFilterValues = array(
  89. 'active' => $sPrefixLang . '_grid_filter_item_title_adm_active',
  90. 'pending' => $sPrefixLang . '_grid_filter_item_title_adm_pending',
  91. 'suspended' => $sPrefixLang . '_grid_filter_item_title_adm_suspended',
  92. );
  93. return $this->_getFilterSelectOne($sFilterName, $aFilterValues) . $this->_getSearchInput();
  94. }
  95. protected function _getCellFullname($mixedValue, $sKey, $aField, $aRow)
  96. {
  97. $oProfile = $this->_getProfileObject($aRow['id']);
  98. $mixedValue = $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  99. 'href' => $oProfile->getUrl(),
  100. 'title' => $mixedValue,
  101. 'bx_repeat:attrs' => array(),
  102. 'content' => $mixedValue
  103. ));
  104. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  105. }
  106. protected function _getCellLastOnline($mixedValue, $sKey, $aField, $aRow)
  107. {
  108. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  109. }
  110. protected function _getProfileObject($iId)
  111. {
  112. bx_import('BxDolProfile');
  113. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iId, $this->_oModule->_oConfig->getName());
  114. if (!$oProfile) {
  115. bx_import('BxDolProfileUndefined');
  116. $oProfile = BxDolProfileUndefined::getInstance();
  117. }
  118. return $oProfile;
  119. }
  120. protected function _getProfileId($iId)
  121. {
  122. return $this->_getProfileObject($iId)->id();
  123. }
  124. protected function _onDelete($iId, $aParams = array())
  125. {
  126. if(isset($aParams['with_content']) && $aParams['with_content'] === true) {
  127. //TODO: delete content after profile deletion
  128. }
  129. return parent::_onDelete($iId, $aParams);
  130. }
  131. }
  132. /** @} */