BxBaseStudioGrid.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. public function getSearchInput()
  48. {
  49. return parent::_getSearchInput();
  50. }
  51. protected function _getFilterOnChange()
  52. {
  53. return $this->getJsObject() . '.onChangeFilter()';
  54. }
  55. protected function _getItem($sDbMethod = '')
  56. {
  57. $aIds = bx_get('ids');
  58. if(!$aIds || !is_array($aIds)) {
  59. $iId = (int)bx_get('id');
  60. if(!$iId)
  61. return false;
  62. $aIds = array($iId);
  63. }
  64. $iId = $aIds[0];
  65. $aItem = array();
  66. $this->oDb->$sDbMethod(array('type' => 'by_id', 'value' => $iId), $aItem, false);
  67. if(!is_array($aItem) || empty($aItem))
  68. return false;
  69. return $aItem;
  70. }
  71. protected function _getIconPreview($iId, $sIconImage = '', $sIcon = '')
  72. {
  73. $bIconImage = !empty($sIconImage);
  74. $aIcons = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIcon($sIcon);
  75. $sIconHtml = $aIcons[2] . $aIcons[3] . $aIcons[4];
  76. $bIconHtml = !empty($sIconHtml) && !$bIconImage;
  77. return $this->_oTemplate->parseHtmlByName('item_icon_preview.html', [
  78. 'id' => $iId,
  79. 'bx_if:show_icon_empty' => [
  80. 'condition' => !$bIconImage && !$bIconHtml,
  81. 'content' => []
  82. ],
  83. 'bx_if:show_icon_image' => [
  84. 'condition' => $bIconImage,
  85. 'content' => [
  86. 'js_object' => $this->getJsObject(),
  87. 'url' => $sIconImage,
  88. 'id' => $iId
  89. ]
  90. ],
  91. 'bx_if:show_icon_html' => [
  92. 'condition' => $bIconHtml,
  93. 'content' => [
  94. 'icon' => $sIconHtml
  95. ]
  96. ]
  97. ]);
  98. }
  99. protected function _getIds()
  100. {
  101. if(($aIds = bx_get('ids')) && is_array($aIds))
  102. return reset($aIds);
  103. if(($iId = bx_get('id')) !== false)
  104. return (int)$iId;
  105. return false;
  106. }
  107. }
  108. /** @} */