BxBaseStudioRolesActions.php 3.9 KB

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