BxDolStudioPermissionsActions.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaStudio UNA Studio
  7. * @{
  8. */
  9. class BxDolStudioPermissionsActions extends BxTemplStudioGrid
  10. {
  11. protected $iLevel;
  12. protected $sModule;
  13. public function __construct ($aOptions, $oTemplate = false)
  14. {
  15. parent::__construct ($aOptions, $oTemplate);
  16. $this->oDb = new BxDolStudioPermissionsQuery();
  17. $this->iLevel = 0;
  18. if(($iLevel = bx_get('level')) !== false) {
  19. $this->iLevel = (int)$iLevel;
  20. $this->_aQueryAppend['level'] = $this->iLevel;
  21. }
  22. $this->sModule = '';
  23. if(($sModule = bx_get('module')) !== false) {
  24. $this->sModule = bx_process_input($sModule);
  25. $this->_aQueryAppend['module'] = $this->sModule;
  26. }
  27. if(($sFilter = bx_get('filter')) !== false)
  28. $this->_processFilter($sFilter);
  29. }
  30. protected function _processFilter($sFilter)
  31. {
  32. if(strpos($sFilter, $this->sParamsDivider) !== false)
  33. list($this->sModule, $sFilter) = explode($this->sParamsDivider, $sFilter);
  34. return $sFilter;
  35. }
  36. protected function _isRowDisabled($aRow)
  37. {
  38. return $aRow['Active'] == 0;
  39. }
  40. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  41. {
  42. if(empty($this->iLevel))
  43. return [];
  44. $sFilter = $this->_processFilter($sFilter);
  45. if($this->sModule != '')
  46. $this->_aOptions['source'] .= $this->oDb->prepareAsString(" AND `Module`=?", $this->sModule);
  47. $this->_aOptions['source'] .= $this->oDb->prepareAsString(" AND (`DisabledForLevels`='0' OR `DisabledForLevels`&?=0)", pow(2, ($this->iLevel - 1)));
  48. $aActions = parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  49. $aActionsActive = [];
  50. $iActionsActive = $this->oDb->getActions(array('type' => 'by_level_id_key_id', 'value' => $this->iLevel), $aActionsActive);
  51. foreach($aActions as $iKey => $aAction)
  52. $aActions[$iKey]['Active'] = array_key_exists($aAction['ID'], $aActionsActive) ? 1 : 0;
  53. return $aActions;
  54. }
  55. }
  56. /** @} */