BxBaseStudioRolesActions.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  8. * @{
  9. */
  10. class BxBaseStudioRolesActions extends BxDolStudioRolesActions
  11. {
  12. protected $sUrlPage;
  13. function __construct($aOptions, $oTemplate = false)
  14. {
  15. parent::__construct($aOptions, $oTemplate);
  16. $this->sUrlPage = BX_DOL_URL_STUDIO . 'builder_roles.php?page=ractions';
  17. }
  18. public function performActionEnable($mixedChecked = null)
  19. {
  20. if($this->iRole == BX_DOL_STUDIO_ROLE_MASTER)
  21. return echoJson([]);
  22. $aIds = bx_get('ids');
  23. $bEnable = (int)bx_get('checked');
  24. if(!$aIds || !is_array($aIds))
  25. return echoJson([]);
  26. $aResultIds = [];
  27. foreach($aIds as $mixedId) {
  28. if(strpos($mixedId, $this->sParamsDivider) !== false)
  29. list($this->iRole, $iId) = explode($this->sParamsDivider, urldecode($mixedId));
  30. if($this->oDb->switchAction($this->iRole, $iId, $bEnable))
  31. $aResultIds[] = $iId;
  32. }
  33. $sAction = $bEnable ? 'enable' : 'disable';
  34. return echoJson([
  35. $sAction => $aResultIds,
  36. ]);
  37. }
  38. function getJsObject()
  39. {
  40. return 'oBxDolStudioRolesActions';
  41. }
  42. function getCode($isDisplayHeader = true)
  43. {
  44. return $this->_oTemplate->parseHtmlByName('rl_roles_actions.html', array(
  45. 'content' => parent::getCode($isDisplayHeader),
  46. 'js_object' => $this->getJsObject(),
  47. 'page_url' => $this->sUrlPage,
  48. 'grid_object' => $this->_sObject,
  49. 'params_divider' => $this->sParamsDivider
  50. ));
  51. }
  52. protected function _addJsCss()
  53. {
  54. parent::_addJsCss();
  55. $this->_oTemplate->addJs(array('jquery.form.min.js', 'roles_actions.js'));
  56. $oForm = new BxTemplStudioFormView(array());
  57. $oForm->addCssJs();
  58. }
  59. protected function _getCellSwitcher($mixedValue, $sKey, $aField, $aRow)
  60. {
  61. if(in_array($this->iRole, [0, BX_DOL_STUDIO_ROLE_MASTER]))
  62. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  63. $aRow[$this->_aOptions['field_id']] = urlencode($this->iRole . $this->sParamsDivider . $aRow[$this->_aOptions['field_id']]);
  64. return parent::_getCellSwitcher($mixedValue, $sKey, $aField, $aRow);
  65. }
  66. protected function _getFilterControls ()
  67. {
  68. parent::_getFilterControls();
  69. $sContent = "";
  70. $sJsObject = $this->getJsObject();
  71. $oForm = new BxTemplStudioFormView(array());
  72. $aInputRoles = array(
  73. 'type' => 'select',
  74. 'name' => 'role',
  75. 'attrs' => array(
  76. 'id' => 'bx-grid-role-' . $this->_sObject,
  77. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeRole()'
  78. ),
  79. 'value' => 'id-' . $this->iRole,
  80. 'values' => array()
  81. );
  82. $aRoles = $this->oDb->getRoles(array('type' => 'all'));
  83. $aCounter = $this->oDb->getActions(array('type' => 'counter_by_roles'));
  84. foreach($aRoles as $aRole)
  85. $aInputRoles['values']['id-' . $aRole['id']] = _t($aRole['title']) . " (" . (isset($aCounter[$aRole['id']]) ? $aCounter[$aRole['id']] : "0") . ")";
  86. asort($aInputRoles['values']);
  87. $aInputRoles['values'] = array_merge(array('id-0' => _t('_adm_rl_txt_select_role')), $aInputRoles['values']);
  88. $sContent .= $oForm->genRow($aInputRoles);
  89. if($this->iRole == 0)
  90. return $sContent;
  91. $aInputSearch = array(
  92. 'type' => 'text',
  93. 'name' => 'keyword',
  94. 'attrs' => array(
  95. 'id' => 'bx-grid-search-' . $this->_sObject,
  96. 'aria-label' => _t('_adm_grid_lbl_search'),
  97. 'onKeyup' => 'javascript:$(this).off(\'keyup\'); ' . $this->getJsObject() . '.onChangeFilter()'
  98. )
  99. );
  100. $sContent .= $oForm->genRow($aInputSearch);
  101. return $sContent;
  102. }
  103. }
  104. /** @} */