BxBaseModProfileGridAdministration.php 5.4 KB

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