BxBaseStudioGrid.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. if (isset($aCounter[$sKey]) && $aCounter[$sKey] > 0)
  38. $aInputModules['values'][$sKey] = $aInputModules['values'][$sKey] . " (" . (isset($aCounter[$sKey]) ? $aCounter[$sKey] : "0") . ")";
  39. else
  40. unset($aInputModules['values'][$sKey]);
  41. }
  42. return $aInputModules;
  43. }
  44. public function getModulesSelectOne($sGetItemsMethod, $bShowCustom = true, $bShowSystem = true)
  45. {
  46. $aInputModules = $this->getModulesSelectOneArray($sGetItemsMethod, $bShowCustom, $bShowSystem);
  47. $aInputModules['values'] = array_merge(array('' => _t('_adm_txt_select_module')), $aInputModules['values']);
  48. $oForm = new BxTemplStudioFormView(array());
  49. return $oForm->genRow($aInputModules);
  50. }
  51. protected function _getItem($sDbMethod = '')
  52. {
  53. $aIds = bx_get('ids');
  54. if(!$aIds || !is_array($aIds)) {
  55. $iId = (int)bx_get('id');
  56. if(!$iId)
  57. return false;
  58. $aIds = array($iId);
  59. }
  60. $iId = $aIds[0];
  61. $aItem = array();
  62. $this->oDb->$sDbMethod(array('type' => 'by_id', 'value' => $iId), $aItem, false);
  63. if(!is_array($aItem) || empty($aItem))
  64. return false;
  65. return $aItem;
  66. }
  67. }
  68. /** @} */