BxBaseModProfileGridAdministration.php 5.5 KB

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