BxBaseStudioNavigationSets.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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 TridentView Trident Studio Representation classes
  7. * @ingroup TridentStudio
  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. $sLanguage = BxDolStudioLanguagesUtils::getInstance()->getCurrentLangName(false);
  88. $sName = BxDolForm::getSubmittedValue('title-' . $sLanguage, $aForm['form_attrs']['method']);
  89. $sName = uriGenerate($sName, 'sys_menu_sets', 'set_name', 'set');
  90. if($oForm->insert(array('set_name' => $sName, 'module' => BX_DOL_STUDIO_MODULE_CUSTOM)) !== false)
  91. $aRes = array('grid' => $this->getCode(false), 'blink' => $sName);
  92. else
  93. $aRes = array('msg' => _t('_adm_nav_err_sets_create'));
  94. $this->_echoResultJson($aRes, true);
  95. }
  96. else {
  97. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-nav-set-create-popup', _t('_adm_nav_txt_sets_create_popup'), $this->_oTemplate->parseHtmlByName('nav_add_set.html', array(
  98. 'form_id' => $aForm['form_attrs']['id'],
  99. 'form' => $oForm->getCode(true),
  100. 'object' => $this->_sObject,
  101. 'action' => $sAction
  102. )));
  103. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  104. }
  105. }
  106. public function performActionEdit()
  107. {
  108. $sAction = 'edit';
  109. $aIds = bx_get('ids');
  110. if(!$aIds || !is_array($aIds)) {
  111. $sId = bx_get('set_name');
  112. if(!$sId) {
  113. $this->_echoResultJson(array());
  114. exit;
  115. }
  116. $aIds = array($sId);
  117. }
  118. $sId = bx_process_input($aIds[0]);
  119. $aSet = array();
  120. $iSet = $this->oDb->getSets(array('type' => 'by_name', 'value' => $sId), $aSet);
  121. if($iSet != 1 || empty($aSet)) {
  122. $this->_echoResultJson(array());
  123. exit;
  124. }
  125. bx_import('BxTemplStudioFormView');
  126. $aForm = array(
  127. 'form_attrs' => array(
  128. 'id' => 'adm-nav-set-edit',
  129. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  130. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  131. ),
  132. 'params' => array (
  133. 'db' => array(
  134. 'table' => 'sys_menu_sets',
  135. 'key' => 'set_name',
  136. 'uri' => '',
  137. 'uri_title' => '',
  138. 'submit_name' => 'do_submit'
  139. ),
  140. ),
  141. 'inputs' => array (
  142. 'set_name' => array(
  143. 'type' => 'hidden',
  144. 'name' => 'set_name',
  145. 'value' => $sId,
  146. 'db' => array (
  147. 'pass' => 'Xss',
  148. ),
  149. ),
  150. 'title' => array(
  151. 'type' => 'text_translatable',
  152. 'name' => 'title',
  153. 'caption' => _t('_adm_nav_txt_sets_title'),
  154. 'info' => _t('_adm_nav_dsc_sets_title'),
  155. 'value' => $aSet['title'],
  156. 'required' => '1',
  157. 'db' => array (
  158. 'pass' => 'Xss',
  159. ),
  160. 'checker' => array (
  161. 'func' => 'LengthTranslatable',
  162. 'params' => array(3, 100, 'title'),
  163. 'error' => _t('_adm_nav_err_sets_title'),
  164. ),
  165. ),
  166. 'controls' => array(
  167. 'name' => 'controls',
  168. 'type' => 'input_set',
  169. array(
  170. 'type' => 'submit',
  171. 'name' => 'do_submit',
  172. 'value' => _t('_adm_nav_btn_menus_save'),
  173. ),
  174. array (
  175. 'type' => 'reset',
  176. 'name' => 'close',
  177. 'value' => _t('_adm_nav_btn_menus_cancel'),
  178. 'attrs' => array(
  179. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  180. 'class' => 'bx-def-margin-sec-left',
  181. ),
  182. )
  183. )
  184. )
  185. );
  186. $oForm = new BxTemplStudioFormView($aForm);
  187. $oForm->initChecker();
  188. if($oForm->isSubmittedAndValid()) {
  189. if($oForm->update($sId) !== false)
  190. $aRes = array('grid' => $this->getCode(false), 'blink' => $sId);
  191. else
  192. $aRes = array('msg' => _t('_adm_nav_err_sets_edit'));
  193. $this->_echoResultJson($aRes, true);
  194. }
  195. else {
  196. $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(
  197. 'form_id' => $aForm['form_attrs']['id'],
  198. 'form' => $oForm->getCode(true),
  199. 'object' => $this->_sObject,
  200. 'action' => $sAction
  201. )));
  202. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  203. }
  204. }
  205. public function performActionDelete()
  206. {
  207. $iAffected = 0;
  208. $aIds = bx_get('ids');
  209. if(!$aIds || !is_array($aIds)) {
  210. $this->_echoResultJson(array());
  211. exit;
  212. }
  213. $oGridItems = BxDolGrid::getObjectInstance('sys_studio_nav_items');
  214. if(!$oGridItems) {
  215. $this->_echoResultJson(array());
  216. exit;
  217. }
  218. $aIdsAffected = array ();
  219. foreach($aIds as $sId) {
  220. $sId = bx_process_input($sId);
  221. $aSet = array();
  222. $this->oDb->getSets(array('type' => 'by_name', 'value' => $sId), $aSet, false);
  223. if(!is_array($aSet) || empty($aSet))
  224. continue;
  225. $aMenus = array();
  226. $this->oDb->getMenus(array('type' => 'by_set_name', 'value' => $sId), $aMenus, false);
  227. if(is_array($aMenus) && count($aMenus) > 0) {
  228. $this->_echoResultJson(array('msg' => _t('_adm_nav_err_sets_delete_used')));
  229. exit;
  230. }
  231. if((int)$this->_delete($sId) <= 0)
  232. continue;
  233. $aItems = array();
  234. $this->oDb->getItems(array('type' => 'by_set_name', 'value' => $aSet['name']), $aItems, false);
  235. if(is_array($aItems) && !empty($aItems))
  236. foreach($aItems as $aItem)
  237. $oGridItems->deleteByItem($aItem);
  238. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aSet['title']);
  239. $aIdsAffected[] = $sId;
  240. $iAffected++;
  241. }
  242. $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_nav_err_sets_delete')));
  243. }
  244. function getJsObject()
  245. {
  246. return 'oBxDolStudioNavigationSets';
  247. }
  248. function getCode($isDisplayHeader = true)
  249. {
  250. return $this->_oTemplate->parseHtmlByName('nav_sets.html', array(
  251. 'content' => parent::getCode($isDisplayHeader),
  252. 'js_object' => $this->getJsObject(),
  253. 'grid_object' => $this->_sObject,
  254. 'params_divider' => $this->sParamsDivider
  255. ));
  256. }
  257. protected function _addJsCss()
  258. {
  259. parent::_addJsCss();
  260. $this->_oTemplate->addJs(array('jquery.form.min.js', 'navigation_sets.js'));
  261. $oForm = new BxTemplStudioFormView(array());
  262. $oForm->addCssJs();
  263. }
  264. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow)
  265. {
  266. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  267. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  268. }
  269. protected function _getCellItems ($mixedValue, $sKey, $aField, $aRow)
  270. {
  271. $aSets = array();
  272. $this->oDb->getSets(array('type' => 'by_name', 'value' => $aRow['set_name']), $aSets, false);
  273. $mixedValue = $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  274. 'href' => sprintf($this->sUrlViewItems, $aRow['module'], $aRow['set_name']),
  275. 'title' => _t('_adm_nav_txt_manage_items'),
  276. 'bx_repeat:attrs' => array(),
  277. 'content' => _t('_adm_nav_txt_n_items', $aSets['items_count'])
  278. ));
  279. return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
  280. }
  281. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  282. {
  283. if ($sType == 'single' && (int)$aRow['deletable'] != 1)
  284. return '';
  285. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  286. }
  287. protected function _getFilterControls ()
  288. {
  289. parent::_getFilterControls();
  290. return $this->getModulesSelectAll('getSets') . $this->getSearchInput();
  291. }
  292. }
  293. /** @} */