BxBaseStudioNavigationSets.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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 BxBaseStudioNavigationSets extends BxDolStudioNavigationSets
  11. {
  12. protected $sUrlViewItems;
  13. function __construct($aOptions, $oTemplate = false)
  14. {
  15. parent::__construct($aOptions, $oTemplate);
  16. $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_adm_nav_btn_sets_edit');
  17. $this->_aOptions['actions_single']['delete']['attr']['title'] = _t('_adm_nav_btn_sets_delete');
  18. $this->sUrlViewItems = BX_DOL_URL_STUDIO . 'builder_menu.php?page=items&module=%s&set=%s';
  19. }
  20. public function performActionAdd()
  21. {
  22. $sAction = 'add';
  23. bx_import('BxTemplStudioFormView');
  24. $aForm = array(
  25. 'form_attrs' => array(
  26. 'id' => 'adm-nav-set-create',
  27. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  28. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  29. ),
  30. 'params' => array (
  31. 'db' => array(
  32. 'table' => 'sys_menu_sets',
  33. 'key' => 'set_name',
  34. 'uri' => '',
  35. 'uri_title' => '',
  36. 'submit_name' => 'do_submit'
  37. ),
  38. ),
  39. 'inputs' => array (
  40. 'title' => array(
  41. 'type' => 'text_translatable',
  42. 'name' => 'title',
  43. 'caption' => _t('_adm_nav_txt_sets_title'),
  44. 'info' => _t('_adm_nav_dsc_sets_title'),
  45. 'value' => '_adm_nav_txt_set',
  46. 'required' => '1',
  47. 'db' => array (
  48. 'pass' => 'Xss',
  49. ),
  50. 'checker' => array (
  51. 'func' => 'LengthTranslatable',
  52. 'params' => array(3, 100, 'title'),
  53. 'error' => _t('_adm_nav_err_sets_title'),
  54. ),
  55. ),
  56. 'deletable' => array(
  57. 'type' => 'hidden',
  58. 'name' => 'deletable',
  59. 'value' => 1,
  60. 'db' => array (
  61. 'pass' => 'Int',
  62. ),
  63. ),
  64. 'controls' => array(
  65. 'name' => 'controls',
  66. 'type' => 'input_set',
  67. array(
  68. 'type' => 'submit',
  69. 'name' => 'do_submit',
  70. 'value' => _t('_adm_nav_btn_sets_add'),
  71. ),
  72. array (
  73. 'type' => 'reset',
  74. 'name' => 'close',
  75. 'value' => _t('_adm_nav_btn_sets_cancel'),
  76. 'attrs' => array(
  77. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  78. 'class' => 'bx-def-margin-sec-left',
  79. ),
  80. )
  81. )
  82. )
  83. );
  84. $oForm = new BxTemplStudioFormView($aForm);
  85. $oForm->initChecker();
  86. if($oForm->isSubmittedAndValid()) {
  87. bx_import('BxDolStudioUtils');
  88. $sLanguage = BxDolStudioLanguagesUtils::getInstance()->getCurrentLangName(false);
  89. $sName = BxDolForm::getSubmittedValue('title-' . $sLanguage, $aForm['form_attrs']['method']);
  90. $sName = uriGenerate($sName, 'sys_menu_sets', 'set_name', 'set');
  91. if($oForm->insert(array('set_name' => $sName, 'module' => BX_DOL_STUDIO_MODULE_CUSTOM)) !== false)
  92. $aRes = array('grid' => $this->getCode(false), 'blink' => $sName);
  93. else
  94. $aRes = array('msg' => _t('_adm_nav_err_sets_create'));
  95. echoJson($aRes);
  96. }
  97. else {
  98. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-nav-set-create-popup', _t('_adm_nav_txt_sets_create_popup'), $this->_oTemplate->parseHtmlByName('nav_add_set.html', array(
  99. 'form_id' => $aForm['form_attrs']['id'],
  100. 'form' => $oForm->getCode(true),
  101. 'object' => $this->_sObject,
  102. 'action' => $sAction
  103. )));
  104. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  105. }
  106. }
  107. public function performActionEdit()
  108. {
  109. $sAction = 'edit';
  110. $aIds = bx_get('ids');
  111. if(!$aIds || !is_array($aIds)) {
  112. $sId = bx_get('set_name');
  113. if(!$sId) {
  114. echoJson(array());
  115. exit;
  116. }
  117. $aIds = array($sId);
  118. }
  119. $sId = bx_process_input($aIds[0]);
  120. $aSet = array();
  121. $iSet = $this->oDb->getSets(array('type' => 'by_name', 'value' => $sId), $aSet);
  122. if($iSet != 1 || empty($aSet)) {
  123. echoJson(array());
  124. exit;
  125. }
  126. bx_import('BxTemplStudioFormView');
  127. $aForm = array(
  128. 'form_attrs' => array(
  129. 'id' => 'adm-nav-set-edit',
  130. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  131. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  132. ),
  133. 'params' => array (
  134. 'db' => array(
  135. 'table' => 'sys_menu_sets',
  136. 'key' => 'set_name',
  137. 'uri' => '',
  138. 'uri_title' => '',
  139. 'submit_name' => 'do_submit'
  140. ),
  141. ),
  142. 'inputs' => array (
  143. 'set_name' => array(
  144. 'type' => 'hidden',
  145. 'name' => 'set_name',
  146. 'value' => $sId,
  147. 'db' => array (
  148. 'pass' => 'Xss',
  149. ),
  150. ),
  151. 'title' => array(
  152. 'type' => 'text_translatable',
  153. 'name' => 'title',
  154. 'caption' => _t('_adm_nav_txt_sets_title'),
  155. 'info' => _t('_adm_nav_dsc_sets_title'),
  156. 'value' => $aSet['title'],
  157. 'required' => '1',
  158. 'db' => array (
  159. 'pass' => 'Xss',
  160. ),
  161. 'checker' => array (
  162. 'func' => 'LengthTranslatable',
  163. 'params' => array(3, 100, 'title'),
  164. 'error' => _t('_adm_nav_err_sets_title'),
  165. ),
  166. ),
  167. 'controls' => array(
  168. 'name' => 'controls',
  169. 'type' => 'input_set',
  170. array(
  171. 'type' => 'submit',
  172. 'name' => 'do_submit',
  173. 'value' => _t('_adm_nav_btn_menus_save'),
  174. ),
  175. array (
  176. 'type' => 'reset',
  177. 'name' => 'close',
  178. 'value' => _t('_adm_nav_btn_menus_cancel'),
  179. 'attrs' => array(
  180. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  181. 'class' => 'bx-def-margin-sec-left',
  182. ),
  183. )
  184. )
  185. )
  186. );
  187. $oForm = new BxTemplStudioFormView($aForm);
  188. $oForm->initChecker();
  189. if($oForm->isSubmittedAndValid()) {
  190. if($oForm->update($sId) !== false)
  191. $aRes = array('grid' => $this->getCode(false), 'blink' => $sId);
  192. else
  193. $aRes = array('msg' => _t('_adm_nav_err_sets_edit'));
  194. echoJson($aRes);
  195. }
  196. else {
  197. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-nav-set-edit-popup', _t('_adm_nav_txt_sets_edit_popup', _t($aSet['title'])), $this->_oTemplate->parseHtmlByName('nav_add_set.html', array(
  198. 'form_id' => $aForm['form_attrs']['id'],
  199. 'form' => $oForm->getCode(true),
  200. 'object' => $this->_sObject,
  201. 'action' => $sAction
  202. )));
  203. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  204. }
  205. }
  206. public function performActionDelete()
  207. {
  208. $iAffected = 0;
  209. $aIds = bx_get('ids');
  210. if(!$aIds || !is_array($aIds)) {
  211. echoJson(array());
  212. exit;
  213. }
  214. $oGridItems = BxDolGrid::getObjectInstance('sys_studio_nav_items');
  215. if(!$oGridItems) {
  216. echoJson(array());
  217. exit;
  218. }
  219. $aIdsAffected = array ();
  220. foreach($aIds as $sId) {
  221. $sId = bx_process_input($sId);
  222. $aSet = array();
  223. $this->oDb->getSets(array('type' => 'by_name', 'value' => $sId), $aSet, false);
  224. if(!is_array($aSet) || empty($aSet))
  225. continue;
  226. $aMenus = array();
  227. $this->oDb->getMenus(array('type' => 'by_set_name', 'value' => $sId), $aMenus, false);
  228. if(is_array($aMenus) && count($aMenus) > 0) {
  229. echoJson(array('msg' => _t('_adm_nav_err_sets_delete_used')));
  230. exit;
  231. }
  232. if((int)$this->_delete($sId) <= 0)
  233. continue;
  234. $aItems = array();
  235. $this->oDb->getItems(array('type' => 'by_set_name', 'value' => $aSet['name']), $aItems, false);
  236. if(is_array($aItems) && !empty($aItems))
  237. foreach($aItems as $aItem)
  238. $oGridItems->deleteByItem($aItem);
  239. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aSet['title']);
  240. $aIdsAffected[] = $sId;
  241. $iAffected++;
  242. }
  243. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_nav_err_sets_delete')));
  244. }
  245. function getJsObject()
  246. {
  247. return 'oBxDolStudioNavigationSets';
  248. }
  249. function getCode($isDisplayHeader = true)
  250. {
  251. return $this->_oTemplate->parseHtmlByName('nav_sets.html', array(
  252. 'content' => parent::getCode($isDisplayHeader),
  253. 'js_object' => $this->getJsObject(),
  254. 'grid_object' => $this->_sObject,
  255. 'params_divider' => $this->sParamsDivider
  256. ));
  257. }
  258. protected function _addJsCss()
  259. {
  260. parent::_addJsCss();
  261. $this->_oTemplate->addJs(array('jquery.form.min.js', 'navigation_sets.js'));
  262. $oForm = new BxTemplStudioFormView(array());
  263. $oForm->addCssJs();
  264. }
  265. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow)
  266. {
  267. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  268. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  269. }
  270. protected function _getCellItems ($mixedValue, $sKey, $aField, $aRow)
  271. {
  272. $aSets = array();
  273. $this->oDb->getSets(array('type' => 'by_name', 'value' => $aRow['set_name']), $aSets, false);
  274. $sLink = sprintf($this->sUrlViewItems, $aRow['module'], $aRow['set_name']);
  275. $mixedValue = $this->_oTemplate->parseLink($sLink, _t('_adm_nav_txt_n_items', $aSets['items_count']), array(
  276. 'title' => _t('_adm_nav_txt_manage_items')
  277. ));
  278. return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
  279. }
  280. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  281. {
  282. if ($sType == 'single' && (int)$aRow['deletable'] != 1)
  283. return '';
  284. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  285. }
  286. protected function _getFilterControls ()
  287. {
  288. parent::_getFilterControls();
  289. return $this->getModulesSelectAll('getSets') . $this->getSearchInput();
  290. }
  291. }
  292. /** @} */