1
0

BxBaseStudioNavigationImport.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  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 DolphinView Dolphin Studio Representation classes
  7. * @ingroup DolphinStudio
  8. * @{
  9. */
  10. defined('BX_DOL') or die('hack attempt');
  11. bx_import('BxDolStudioNavigationImport');
  12. class BxBaseStudioNavigationImport extends BxDolStudioNavigationImport {
  13. function __construct($aOptions, $oTemplate = false) {
  14. parent::__construct($aOptions, $oTemplate);
  15. $this->_aOptions['actions_single']['import']['attr']['title'] = _t('_adm_nav_btn_items_import');
  16. }
  17. public function performActionImport() {
  18. $iAffected = 0;
  19. $aIds = bx_get('ids');
  20. if(!$aIds || !is_array($aIds)) {
  21. $this->_echoResultJson(array());
  22. exit;
  23. }
  24. $aIdsAffected = array ();
  25. foreach($aIds as $iId) {
  26. $aItem = array();
  27. $iItem = $this->oDb->getItems(array('type' => 'by_id', 'value' => (int)$iId), $aItem);
  28. if($iItem != 1 || empty($aItem))
  29. continue;
  30. $mixedIcon = 0;
  31. if(is_numeric($aItem['icon']) && (int)$aItem['icon'] != 0) {
  32. bx_import('BxDolStorage');
  33. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  34. if(($mixedIcon = $oStorage->storeFileFromStorage(array('id' => (int)$aItem['icon']), false, 0)) === false) {
  35. $this->_echoResultJson(array('msg' => _t('_adm_nav_err_items_icon_copy') . $oStorage->getErrorString()), true);
  36. return;
  37. }
  38. $oStorage->afterUploadCleanup($mixedIcon, 0);
  39. }
  40. $iIdImported = (int)$aItem['id'];
  41. $sTitleKey = $aItem['title'];
  42. unset($aItem['id']);
  43. $aItem['set_name'] = $this->sSet;
  44. $aItem['module'] = BX_DOL_STUDIO_MODULE_CUSTOM;
  45. $aItem['title'] .= '_' . time();
  46. $aItem['icon'] = $mixedIcon != 0 ? $mixedIcon : '';
  47. $aItem['active'] = 1;
  48. $aItem['order'] = $this->oDb->getItemOrderMax($this->sSet) + 1;
  49. if(($iIdAdded = (int)$this->oDb->addItem($aItem)) == 0)
  50. continue;
  51. bx_import('BxDolStudioLanguagesUtils');
  52. BxDolStudioLanguagesUtils::getInstance()->addLanguageString($aItem['title'], _t($sTitleKey));
  53. $aIdsImported[] = $iIdImported;
  54. $aIdsAdded[] = $iIdAdded;
  55. $iAffected++;
  56. }
  57. $aResult = array('msg' => _t('_adm_nav_err_items_import'));
  58. if($iAffected) {
  59. $oGrid = BxDolGrid::getObjectInstance('sys_studio_nav_items');
  60. if($oGrid !== false)
  61. $aResult = array(
  62. 'parent_grid' => $oGrid->getCode(false),
  63. 'parent_blink' => $aIdsAdded,
  64. 'disable' => $aIdsImported,
  65. 'eval' => $this->getJsObject() . '.onImport(oData)'
  66. );
  67. }
  68. $this->_echoResultJson($aResult);
  69. }
  70. function getJsObject() {
  71. return 'oBxDolStudioNavigationImport';
  72. }
  73. function getCode($isDisplayHeader = true) {
  74. return $this->_oTemplate->parseHtmlByName('nav_import.html', array(
  75. 'content' => parent::getCode($isDisplayHeader),
  76. 'js_object' => $this->getJsObject(),
  77. 'grid_object' => $this->_sObject,
  78. 'params_divider' => $this->sParamsDivider
  79. ));
  80. }
  81. protected function _getCellIcon ($mixedValue, $sKey, $aField, $aRow) {
  82. $mixedValue = $this->_oTemplate->getIcon($mixedValue, array('class' => 'bx-nav-item-icon bx-def-border'));
  83. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  84. }
  85. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow) {
  86. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  87. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  88. }
  89. protected function _getActionDone ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array()) {
  90. $a['attr']['onclick'] = "$('.bx-popup-applied:visible').dolPopupHide()";
  91. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  92. }
  93. protected function _getFilterControls () {
  94. parent::_getFilterControls();
  95. $sContent = "";
  96. bx_import('BxTemplStudioFormView');
  97. $oForm = new BxTemplStudioFormView(array());
  98. $aInputSets = array(
  99. 'type' => 'select',
  100. 'name' => 'set',
  101. 'attrs' => array(
  102. 'id' => 'bx-grid-set-' . $this->_sObject,
  103. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeFilter()'
  104. ),
  105. 'value' => '',
  106. 'values' => array()
  107. );
  108. $aSets = $aCounter = array();
  109. $this->oDb->getSets(array('type' => 'all', 'except' => $this->sSet), $aSets, false);
  110. $this->oDb->getItems(array('type' => 'counter_by_sets'), $aCounter, false);
  111. foreach($aSets as $aSet)
  112. $aInputSets['values'][$aSet['name']] = _t($aSet['title']) . " (" . (isset($aCounter[$aSet['name']]) ? $aCounter[$aSet['name']] : "0") . ")";
  113. asort($aInputSets['values']);
  114. $aInputSets['values'] = array_merge(array('' => _t('_adm_nav_txt_select_set')), $aInputSets['values']);
  115. $sContent .= $oForm->genRow($aInputSets);
  116. $aInputModules = array(
  117. 'type' => 'select',
  118. 'name' => 'module',
  119. 'attrs' => array(
  120. 'id' => 'bx-grid-module-' . $this->_sObject,
  121. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeFilter()'
  122. ),
  123. 'value' => '',
  124. 'values' => $this->getModules()
  125. );
  126. $aCounter = array();
  127. $this->oDb->getItems(array('type' => 'counter_by_modules'), $aCounter, false);
  128. foreach($aInputModules['values'] as $sKey => $sValue)
  129. $aInputModules['values'][$sKey] = $aInputModules['values'][$sKey] . " (" . (isset($aCounter[$sKey]) ? $aCounter[$sKey] : "0") . ")";
  130. $aInputModules['values'] = array_merge(array('' => _t('_adm_nav_txt_all_modules')), $aInputModules['values']);
  131. $sContent .= $oForm->genRow($aInputModules);
  132. $aInputSearch = array(
  133. 'type' => 'text',
  134. 'name' => 'keyword',
  135. 'attrs' => array(
  136. 'id' => 'bx-grid-search-' . $this->_sObject,
  137. 'onKeyup' => 'javascript:$(this).off(\'keyup\'); ' . $this->getJsObject() . '.onChangeFilter()'
  138. )
  139. );
  140. $sContent .= $oForm->genRow($aInputSearch);
  141. return $sContent;
  142. }
  143. }
  144. /** @} */