BxBaseStudioNavigationImport.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. $aIdsAffected = array ();
  27. foreach($aIds as $iId) {
  28. $aItem = array();
  29. $iItem = $this->oDb->getItems(array('type' => 'by_id', 'value' => (int)$iId), $aItem);
  30. if($iItem != 1 || empty($aItem))
  31. continue;
  32. $mixedIcon = 0;
  33. if(is_numeric($aItem['icon']) && (int)$aItem['icon'] != 0) {
  34. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  35. if(($mixedIcon = $oStorage->storeFileFromStorage(array('id' => (int)$aItem['icon']), false, 0)) === false) {
  36. echoJson(array('msg' => _t('_adm_nav_err_items_icon_copy') . $oStorage->getErrorString()));
  37. return;
  38. }
  39. $oStorage->afterUploadCleanup($mixedIcon, 0);
  40. }
  41. $iIdImported = (int)$aItem['id'];
  42. $sTitleKey = $aItem['title'];
  43. unset($aItem['id']);
  44. $aItem['set_name'] = $this->sSet;
  45. $aItem['module'] = BX_DOL_STUDIO_MODULE_CUSTOM;
  46. $aItem['title'] .= '_' . time();
  47. $aItem['icon'] = $mixedIcon != 0 ? $mixedIcon : '';
  48. $aItem['active'] = 1;
  49. $aItem['order'] = $this->oDb->getItemOrderMax($this->sSet) + 1;
  50. if(($iIdAdded = (int)$this->oDb->addItem($aItem)) == 0)
  51. continue;
  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. echoJson($aResult);
  69. }
  70. function getJsObject()
  71. {
  72. return 'oBxDolStudioNavigationImport';
  73. }
  74. function getCode($isDisplayHeader = true)
  75. {
  76. return $this->_oTemplate->parseHtmlByName('nav_import.html', array(
  77. 'content' => parent::getCode($isDisplayHeader),
  78. 'js_object' => $this->getJsObject(),
  79. 'grid_object' => $this->_sObject,
  80. 'params_divider' => $this->sParamsDivider
  81. ));
  82. }
  83. protected function _getCellIcon ($mixedValue, $sKey, $aField, $aRow)
  84. {
  85. $mixedValue = $this->_oTemplate->getIcon($mixedValue, array('class' => 'bx-nav-item-icon bx-def-border'));
  86. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  87. }
  88. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow)
  89. {
  90. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  91. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  92. }
  93. protected function _getActionDone ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  94. {
  95. $a['attr']['onclick'] = "$('.bx-popup-applied:visible').dolPopupHide()";
  96. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  97. }
  98. protected function _getFilterControls ()
  99. {
  100. parent::_getFilterControls();
  101. $sJsObject = $this->getJsObject();
  102. $oForm = new BxTemplStudioFormView(array());
  103. $aInputSets = array(
  104. 'type' => 'select',
  105. 'name' => 'set',
  106. 'attrs' => array(
  107. 'id' => 'bx-grid-set-' . $this->_sObject,
  108. 'onChange' => 'javascript:$(this).off(\'keyup focusout\'); javascript:' . $sJsObject . '.onChangeFilter()',
  109. 'onBlur' => 'javascript:' . $sJsObject . '.onChangeFilter()',
  110. ),
  111. 'value' => '',
  112. 'values' => array()
  113. );
  114. $aSets = $aCounter = array();
  115. $this->oDb->getSets(array('type' => 'all', 'except' => $this->sSet), $aSets, false);
  116. $this->oDb->getItems(array('type' => 'counter_by_sets'), $aCounter, false);
  117. foreach($aSets as $aSet)
  118. $aInputSets['values'][$aSet['name']] = _t($aSet['title']) . " (" . (isset($aCounter[$aSet['name']]) ? $aCounter[$aSet['name']] : "0") . ")";
  119. asort($aInputSets['values']);
  120. $aInputSets['values'] = array_merge(array('' => _t('_adm_nav_txt_select_set')), $aInputSets['values']);
  121. return $oForm->genRow($aInputSets) . $this->getModulesSelectAll('getItems') . $this->getSearchInput();
  122. }
  123. }
  124. /** @} */