1
0

BxBaseStudioNavigationImport.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. {
  13. function __construct($aOptions, $oTemplate = false)
  14. {
  15. parent::__construct($aOptions, $oTemplate);
  16. $this->_aOptions['actions_single']['import']['attr']['title'] = _t('_adm_nav_btn_items_import');
  17. }
  18. public function performActionImport()
  19. {
  20. $iAffected = 0;
  21. $aIds = bx_get('ids');
  22. if(!$aIds || !is_array($aIds)) {
  23. $this->_echoResultJson(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. bx_import('BxDolStorage');
  35. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  36. if(($mixedIcon = $oStorage->storeFileFromStorage(array('id' => (int)$aItem['icon']), false, 0)) === false) {
  37. $this->_echoResultJson(array('msg' => _t('_adm_nav_err_items_icon_copy') . $oStorage->getErrorString()), true);
  38. return;
  39. }
  40. $oStorage->afterUploadCleanup($mixedIcon, 0);
  41. }
  42. $iIdImported = (int)$aItem['id'];
  43. $sTitleKey = $aItem['title'];
  44. unset($aItem['id']);
  45. $aItem['set_name'] = $this->sSet;
  46. $aItem['module'] = BX_DOL_STUDIO_MODULE_CUSTOM;
  47. $aItem['title'] .= '_' . time();
  48. $aItem['icon'] = $mixedIcon != 0 ? $mixedIcon : '';
  49. $aItem['active'] = 1;
  50. $aItem['order'] = $this->oDb->getItemOrderMax($this->sSet) + 1;
  51. if(($iIdAdded = (int)$this->oDb->addItem($aItem)) == 0)
  52. continue;
  53. bx_import('BxDolStudioLanguagesUtils');
  54. BxDolStudioLanguagesUtils::getInstance()->addLanguageString($aItem['title'], _t($sTitleKey));
  55. $aIdsImported[] = $iIdImported;
  56. $aIdsAdded[] = $iIdAdded;
  57. $iAffected++;
  58. }
  59. $aResult = array('msg' => _t('_adm_nav_err_items_import'));
  60. if($iAffected) {
  61. $oGrid = BxDolGrid::getObjectInstance('sys_studio_nav_items');
  62. if($oGrid !== false)
  63. $aResult = array(
  64. 'parent_grid' => $oGrid->getCode(false),
  65. 'parent_blink' => $aIdsAdded,
  66. 'disable' => $aIdsImported,
  67. 'eval' => $this->getJsObject() . '.onImport(oData)'
  68. );
  69. }
  70. $this->_echoResultJson($aResult);
  71. }
  72. function getJsObject()
  73. {
  74. return 'oBxDolStudioNavigationImport';
  75. }
  76. function getCode($isDisplayHeader = true)
  77. {
  78. return $this->_oTemplate->parseHtmlByName('nav_import.html', array(
  79. 'content' => parent::getCode($isDisplayHeader),
  80. 'js_object' => $this->getJsObject(),
  81. 'grid_object' => $this->_sObject,
  82. 'params_divider' => $this->sParamsDivider
  83. ));
  84. }
  85. protected function _getCellIcon ($mixedValue, $sKey, $aField, $aRow)
  86. {
  87. $mixedValue = $this->_oTemplate->getIcon($mixedValue, array('class' => 'bx-nav-item-icon bx-def-border'));
  88. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  89. }
  90. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow)
  91. {
  92. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  93. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  94. }
  95. protected function _getActionDone ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  96. {
  97. $a['attr']['onclick'] = "$('.bx-popup-applied:visible').dolPopupHide()";
  98. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  99. }
  100. protected function _getFilterControls ()
  101. {
  102. parent::_getFilterControls();
  103. bx_import('BxTemplStudioFormView');
  104. $oForm = new BxTemplStudioFormView(array());
  105. $aInputSets = array(
  106. 'type' => 'select',
  107. 'name' => 'set',
  108. 'attrs' => array(
  109. 'id' => 'bx-grid-set-' . $this->_sObject,
  110. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeFilter()'
  111. ),
  112. 'value' => '',
  113. 'values' => array()
  114. );
  115. $aSets = $aCounter = array();
  116. $this->oDb->getSets(array('type' => 'all', 'except' => $this->sSet), $aSets, false);
  117. $this->oDb->getItems(array('type' => 'counter_by_sets'), $aCounter, false);
  118. foreach($aSets as $aSet)
  119. $aInputSets['values'][$aSet['name']] = _t($aSet['title']) . " (" . (isset($aCounter[$aSet['name']]) ? $aCounter[$aSet['name']] : "0") . ")";
  120. asort($aInputSets['values']);
  121. $aInputSets['values'] = array_merge(array('' => _t('_adm_nav_txt_select_set')), $aInputSets['values']);
  122. return $oForm->genRow($aInputSets) . $this->getModulesSelectAll('getItems') . $this->getSearchInput();
  123. }
  124. }
  125. /** @} */