BxBaseStudioNavigationImport.php 6.1 KB

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