BxBaseStudioGrid.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 BxBaseStudioGrid extends BxDolStudioGrid
  11. {
  12. function __construct($aOptions, $oTemplate = false)
  13. {
  14. parent::__construct($aOptions, $oTemplate);
  15. }
  16. function getJsObject()
  17. {
  18. return '';
  19. }
  20. public function getModulesSelectOneArray($sGetItemsMethod, $bShowCustom = true, $bShowSystem = true)
  21. {
  22. if(empty($sGetItemsMethod))
  23. return '';
  24. $aInputModules = array(
  25. 'type' => 'select',
  26. 'name' => 'module',
  27. 'attrs' => array(
  28. 'id' => 'bx-grid-module-' . $this->_sObject,
  29. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeModule()'
  30. ),
  31. 'value' => $this->sModule,
  32. 'values' => $this->getModules($bShowCustom, $bShowSystem)
  33. );
  34. $aCounter = array();
  35. $this->oDb->$sGetItemsMethod(array('type' => 'counter_by_modules'), $aCounter, false);
  36. foreach($aInputModules['values'] as $sKey => $sValue)
  37. $aInputModules['values'][$sKey] = $aInputModules['values'][$sKey] . " (" . (isset($aCounter[$sKey]) ? $aCounter[$sKey] : "0") . ")";
  38. return $aInputModules;
  39. }
  40. public function getModulesSelectOne($sGetItemsMethod, $bShowCustom = true, $bShowSystem = true)
  41. {
  42. $aInputModules = $this->getModulesSelectOneArray($sGetItemsMethod, $bShowCustom, $bShowSystem);
  43. $aInputModules['values'] = array_merge(array('' => _t('_adm_txt_select_module')), $aInputModules['values']);
  44. $oForm = new BxTemplStudioFormView(array());
  45. return $oForm->genRow($aInputModules);
  46. }
  47. protected function _getItem($sDbMethod = '')
  48. {
  49. $aIds = bx_get('ids');
  50. if(!$aIds || !is_array($aIds)) {
  51. $iId = (int)bx_get('id');
  52. if(!$iId)
  53. return false;
  54. $aIds = array($iId);
  55. }
  56. $iId = $aIds[0];
  57. $aItem = array();
  58. $this->oDb->$sDbMethod(array('type' => 'by_id', 'value' => $iId), $aItem, false);
  59. if(!is_array($aItem) || empty($aItem))
  60. return false;
  61. return $aItem;
  62. }
  63. protected function _getIconPreview($iId, $sIconImage = '', $sIcon = '')
  64. {
  65. $bIconImage = !empty($sIconImage);
  66. $aIcons = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIcon($sIcon);
  67. $sIconHtml = $aIcons[2] . $aIcons[3] . $aIcons[4];
  68. $bIconHtml = !empty($sIconHtml) && !$bIconImage;
  69. return $this->_oTemplate->parseHtmlByName('item_icon_preview.html', [
  70. 'id' => $iId,
  71. 'bx_if:show_icon_empty' => [
  72. 'condition' => !$bIconImage && !$bIconHtml,
  73. 'content' => []
  74. ],
  75. 'bx_if:show_icon_image' => [
  76. 'condition' => $bIconImage,
  77. 'content' => [
  78. 'js_object' => $this->getJsObject(),
  79. 'url' => $sIconImage,
  80. 'id' => $iId
  81. ]
  82. ],
  83. 'bx_if:show_icon_html' => [
  84. 'condition' => $bIconHtml,
  85. 'content' => [
  86. 'icon' => $sIconHtml
  87. ]
  88. ]
  89. ]);
  90. }
  91. }
  92. /** @} */