1
0

BxBaseStudioNavigationImport.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 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. $iAffected = 0;
  20. $aIds = bx_get('ids');
  21. if(!$aIds || !is_array($aIds)) {
  22. $this->_echoResultJson(array());
  23. exit;
  24. }
  25. $aIdsAffected = array ();
  26. foreach($aIds as $iId) {
  27. $aItem = array();
  28. $iItem = $this->oDb->getItems(array('type' => 'by_id', 'value' => (int)$iId), $aItem);
  29. if($iItem != 1 || empty($aItem))
  30. continue;
  31. $mixedIcon = 0;
  32. if(is_numeric($aItem['icon']) && (int)$aItem['icon'] != 0) {
  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. BxDolStudioLanguagesUtils::getInstance()->addLanguageString($aItem['title'], _t($sTitleKey));
  52. $aIdsImported[] = $iIdImported;
  53. $aIdsAdded[] = $iIdAdded;
  54. $iAffected++;
  55. }
  56. $aResult = array('msg' => _t('_adm_nav_err_items_import'));
  57. if($iAffected) {
  58. $oGrid = BxDolGrid::getObjectInstance('sys_studio_nav_items');
  59. if($oGrid !== false)
  60. $aResult = array(
  61. 'parent_grid' => $oGrid->getCode(false),
  62. 'parent_blink' => $aIdsAdded,
  63. 'disable' => $aIdsImported,
  64. 'eval' => $this->getJsObject() . '.onImport(oData)'
  65. );
  66. }
  67. $this->_echoResultJson($aResult);
  68. }
  69. function getJsObject()
  70. {
  71. return 'oBxDolStudioNavigationImport';
  72. }
  73. function getCode($isDisplayHeader = true)
  74. {
  75. return $this->_oTemplate->parseHtmlByName('nav_import.html', array(
  76. 'content' => parent::getCode($isDisplayHeader),
  77. 'js_object' => $this->getJsObject(),
  78. 'grid_object' => $this->_sObject,
  79. 'params_divider' => $this->sParamsDivider
  80. ));
  81. }
  82. protected function _getCellIcon ($mixedValue, $sKey, $aField, $aRow)
  83. {
  84. $mixedValue = $this->_oTemplate->getIcon($mixedValue, array('class' => 'bx-nav-item-icon bx-def-border'));
  85. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  86. }
  87. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow)
  88. {
  89. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  90. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  91. }
  92. protected function _getActionDone ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  93. {
  94. $a['attr']['onclick'] = "$('.bx-popup-applied:visible').dolPopupHide()";
  95. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  96. }
  97. protected function _getFilterControls ()
  98. {
  99. parent::_getFilterControls();
  100. $oForm = new BxTemplStudioFormView(array());
  101. $aInputSets = array(
  102. 'type' => 'select',
  103. 'name' => 'set',
  104. 'attrs' => array(
  105. 'id' => 'bx-grid-set-' . $this->_sObject,
  106. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeFilter()'
  107. ),
  108. 'value' => '',
  109. 'values' => array()
  110. );
  111. $aSets = $aCounter = array();
  112. $this->oDb->getSets(array('type' => 'all', 'except' => $this->sSet), $aSets, false);
  113. $this->oDb->getItems(array('type' => 'counter_by_sets'), $aCounter, false);
  114. foreach($aSets as $aSet)
  115. $aInputSets['values'][$aSet['name']] = _t($aSet['title']) . " (" . (isset($aCounter[$aSet['name']]) ? $aCounter[$aSet['name']] : "0") . ")";
  116. asort($aInputSets['values']);
  117. $aInputSets['values'] = array_merge(array('' => _t('_adm_nav_txt_select_set')), $aInputSets['values']);
  118. return $oForm->genRow($aInputSets) . $this->getModulesSelectAll('getItems') . $this->getSearchInput();
  119. }
  120. }
  121. /** @} */