BxBaseStudioNavigationImport.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 DolphinView Dolphin Studio Representation classes
  7. * @ingroup DolphinStudio
  8. * @{
  9. */
  10. bx_import('BxDolStudioNavigationImport');
  11. class BxBaseStudioNavigationImport extends BxDolStudioNavigationImport {
  12. function __construct($aOptions, $oTemplate = false) {
  13. parent::__construct($aOptions, $oTemplate);
  14. $this->_aOptions['actions_single']['import']['attr']['title'] = _t('_adm_nav_btn_items_import');
  15. }
  16. public function performActionImport() {
  17. $iAffected = 0;
  18. $aIds = bx_get('ids');
  19. if(!$aIds || !is_array($aIds)) {
  20. $this->_echoResultJson(array());
  21. exit;
  22. }
  23. $aIdsAffected = array ();
  24. foreach($aIds as $iId) {
  25. $aItem = array();
  26. $iItem = $this->oDb->getItems(array('type' => 'by_id', 'value' => (int)$iId), $aItem);
  27. if($iItem != 1 || empty($aItem))
  28. continue;
  29. $mixedIcon = 0;
  30. if(is_numeric($aItem['icon']) && (int)$aItem['icon'] != 0) {
  31. bx_import('BxDolStorage');
  32. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  33. if(($mixedIcon = $oStorage->storeFileFromStorage(array('id' => (int)$aItem['icon']), false, 0)) === false) {
  34. $this->_echoResultJson(array('msg' => _t('_adm_nav_err_items_icon_copy') . $oStorage->getErrorString()), true);
  35. return;
  36. }
  37. $oStorage->afterUploadCleanup($mixedIcon, 0);
  38. }
  39. $iIdImported = (int)$aItem['id'];
  40. $sTitleKey = $aItem['title'];
  41. unset($aItem['id']);
  42. $aItem['set_name'] = $this->sSet;
  43. $aItem['module'] = BX_DOL_STUDIO_MODULE_CUSTOM;
  44. $aItem['title'] .= '_' . time();
  45. $aItem['icon'] = $mixedIcon != 0 ? $mixedIcon : '';
  46. $aItem['active'] = 1;
  47. $aItem['order'] = $this->oDb->getItemOrderMax($this->sSet) + 1;
  48. if(($iIdAdded = (int)$this->oDb->addItem($aItem)) == 0)
  49. continue;
  50. bx_import('BxDolStudioLanguagesUtils');
  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. return 'oBxDolStudioNavigationImport';
  71. }
  72. function getCode($isDisplayHeader = true) {
  73. return $this->_oTemplate->parseHtmlByName('nav_import.html', array(
  74. 'content' => parent::getCode($isDisplayHeader),
  75. 'js_object' => $this->getJsObject(),
  76. 'grid_object' => $this->_sObject,
  77. 'params_divider' => $this->sParamsDivider
  78. ));
  79. }
  80. protected function _getCellIcon ($mixedValue, $sKey, $aField, $aRow) {
  81. $mixedValue = $this->_oTemplate->getIcon($mixedValue, array('class' => 'bx-nav-item-icon bx-def-border'));
  82. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  83. }
  84. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow) {
  85. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  86. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  87. }
  88. protected function _getActionDone ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array()) {
  89. $a['attr']['onclick'] = "$('.bx-popup-applied:visible').dolPopupHide()";
  90. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  91. }
  92. protected function _getFilterControls () {
  93. parent::_getFilterControls();
  94. bx_import('BxTemplStudioFormView');
  95. $oForm = new BxTemplStudioFormView(array());
  96. $aInputSets = array(
  97. 'type' => 'select',
  98. 'name' => 'set',
  99. 'attrs' => array(
  100. 'id' => 'bx-grid-set-' . $this->_sObject,
  101. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeFilter()'
  102. ),
  103. 'value' => '',
  104. 'values' => array()
  105. );
  106. $aSets = $aCounter = array();
  107. $this->oDb->getSets(array('type' => 'all', 'except' => $this->sSet), $aSets, false);
  108. $this->oDb->getItems(array('type' => 'counter_by_sets'), $aCounter, false);
  109. foreach($aSets as $aSet)
  110. $aInputSets['values'][$aSet['name']] = _t($aSet['title']) . " (" . (isset($aCounter[$aSet['name']]) ? $aCounter[$aSet['name']] : "0") . ")";
  111. asort($aInputSets['values']);
  112. $aInputSets['values'] = array_merge(array('' => _t('_adm_nav_txt_select_set')), $aInputSets['values']);
  113. return $oForm->genRow($aInputSets) . $this->getModulesSelectAll('getItems') . $this->getSearchInput();
  114. }
  115. }
  116. /** @} */