BxBaseModProfileGridAdministration.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 BaseGeneral Base classes for 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. exit;
  32. }
  33. foreach($aIds as $iKey => $iId)
  34. $aIds[$iKey] = $this->_getProfileId($iId);
  35. if(count($aIds) == 1)
  36. $aIds = $aIds[0];
  37. $sContent = $this->_oTemplate->parseHtmlByName('bx_div.html', array(
  38. 'bx_repeat:attrs' => array(
  39. array('key' => 'class', 'value' => 'bx-def-padding')
  40. ),
  41. 'content' => $oMenu->getCode($aIds)
  42. ));
  43. bx_import('BxTemplFunctions');
  44. $sContent = BxTemplFunctions::getInstance()->transBox($this->_oModule->_oConfig->getName() . 'set_acl_level_popup', $sContent);
  45. $this->_echoResultJson(array('popup' => $sContent), true);
  46. }
  47. public function performActionDelete($bWithContent = false)
  48. {
  49. if($bWithContent) {
  50. $this->_echoResultJson(array('msg' => 'TODO: delete with content'));
  51. return;
  52. }
  53. $iAffected = 0;
  54. $aIds = bx_get('ids');
  55. if(!$aIds || !is_array($aIds)) {
  56. $this->_echoResultJson(array());
  57. exit;
  58. }
  59. $aIdsAffected = array ();
  60. foreach($aIds as $iId) {
  61. $oProfile = $this->_getProfileObject(iId);
  62. if((int)$this->_delete($iId) == 0)
  63. continue;
  64. if(!$oProfile->delete())
  65. continue;
  66. if($bWithContent) {
  67. //TODO: delete content after profile deletion
  68. }
  69. $aIdsAffected[] = $iId;
  70. $iAffected++;
  71. }
  72. $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_nav_err_menus_delete')));
  73. }
  74. public function performActionDeleteWithContent()
  75. {
  76. $this->performActionDelete(true);
  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. $iAction = BX_PROFILE_ACTION_MANUAL;
  89. $oProfile = $this->_getProfileObject($mixedId);
  90. return $isChecked ? $oProfile->activate($iAction) : $oProfile->suspend($iAction);
  91. }
  92. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  93. {
  94. if(strpos($sFilter, $this->_sParamsDivider) !== false)
  95. list($this->_sFilter1, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  96. if(!empty($this->_sFilter1))
  97. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepare(" AND `tp`.`status`=?", $this->_sFilter1);
  98. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  99. }
  100. //--- Layout methods ---//
  101. protected function _getFilterControls()
  102. {
  103. parent::_getFilterControls();
  104. $sFilterName = 'filter1';
  105. $aFilterValues = array(
  106. 'active' => '_bx_persons_grid_filter_item_title_adm_active',
  107. 'pending' => '_bx_persons_grid_filter_item_title_adm_pending',
  108. 'suspended' => '_bx_persons_grid_filter_item_title_adm_suspended',
  109. );
  110. return $this->_getFilterSelectOne($sFilterName, $aFilterValues) . $this->_getSearchInput();
  111. }
  112. protected function _getCellFullname($mixedValue, $sKey, $aField, $aRow)
  113. {
  114. $oProfile = $this->_getProfileObject($aRow['id']);
  115. $mixedValue = $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  116. 'href' => $oProfile->getUrl(),
  117. 'title' => $mixedValue,
  118. 'bx_repeat:attrs' => array(),
  119. 'content' => $mixedValue
  120. ));
  121. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  122. }
  123. protected function _getActionSettings($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  124. {
  125. $sName = $this->_oModule->_oConfig->getName() . "_menu_manage_tools";
  126. $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
  127. bx_import('BxDolMenu');
  128. $sMenu = BxDolMenu::getObjectInstance($sName)->getCode();
  129. if(empty($sMenu))
  130. return '';
  131. $a['attr'] = array_merge($a['attr'], array(
  132. "bx-popup-id" => $sName . "-" . $aRow['id'],
  133. "onclick" => "$(this).off('click'); " . $sJsObject . ".onClickSettings('" . $sName . "', this);"
  134. ));
  135. return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  136. }
  137. protected function _getCellLastOnline($mixedValue, $sKey, $aField, $aRow)
  138. {
  139. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  140. }
  141. protected function _getProfileObject($iId)
  142. {
  143. bx_import('BxDolProfile');
  144. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iId, $this->_oModule->_oConfig->getName());
  145. if (!$oProfile) {
  146. bx_import('BxDolProfileUndefined');
  147. $oProfile = BxDolProfileUndefined::getInstance();
  148. }
  149. return $oProfile;
  150. }
  151. protected function _getProfileId($iId)
  152. {
  153. return $this->_getProfileObject($iId)->id();
  154. }
  155. }
  156. /** @} */