BxCreditsGridBundles.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 Credits Credits
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxCreditsGridBundles extends BxTemplGrid
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. public function __construct ($aOptions, $oTemplate = false)
  16. {
  17. parent::__construct ($aOptions, $oTemplate);
  18. $this->_sModule = 'bx_credits';
  19. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  20. }
  21. public function performActionAdd()
  22. {
  23. $CNF = &$this->_oModule->_oConfig->CNF;
  24. $sAction = 'add';
  25. $oForm = $this->_getFormObject($sAction);
  26. $oForm->initChecker();
  27. if($oForm->isSubmittedAndValid()) {
  28. $aValsToAdd = array(
  29. 'active' => 1,
  30. 'order' => $this->_oModule->_oDb->getBundle(array('type' => 'order_max')) + 1
  31. );
  32. $iId = (int)$oForm->insert($aValsToAdd);
  33. if($iId != 0)
  34. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  35. else
  36. $aRes = array('msg' => _t('_bx_credits_err_cannot_perform_action'));
  37. echoJson($aRes);
  38. }
  39. else {
  40. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('add_bundle_popup'), _t('_bx_credits_grid_popup_title_add_bundle'), $this->_oModule->_oTemplate->parseHtmlByName('bundle_form.html', array(
  41. 'form_id' => $oForm->aFormAttrs['id'],
  42. 'form' => $oForm->getCode(true),
  43. 'object' => $this->_sObject,
  44. 'action' => $sAction
  45. )));
  46. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false, 'removeOnClose' => true))));
  47. }
  48. }
  49. public function performActionEdit()
  50. {
  51. $CNF = &$this->_oModule->_oConfig->CNF;
  52. $sAction = 'edit';
  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. $aBundle = $this->_oModule->_oDb->getBundle(array('type' => 'id', 'id' => $iId));
  62. if(empty($aBundle) || !is_array($aBundle))
  63. return echoJson(array());
  64. $oForm = $this->_getFormObject($sAction, $aBundle);
  65. $oForm->initChecker($aBundle);
  66. if($oForm->isSubmittedAndValid()) {
  67. if($oForm->update($iId) !== false)
  68. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  69. else
  70. $aRes = array('msg' => _t('_bx_credits_txt_err_cannot_perform_action'));
  71. echoJson($aRes);
  72. }
  73. else {
  74. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('edit_bundle_popup'), _t('_bx_credits_grid_popup_title_edit_bundle', _t($aBundle['title'])), $this->_oModule->_oTemplate->parseHtmlByName('bundle_form.html', array(
  75. 'form_id' => $oForm->aFormAttrs['id'],
  76. 'form' => $oForm->getCode(true),
  77. 'object' => $this->_sObject,
  78. 'action' => $sAction
  79. )));
  80. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false, 'removeOnClose' => true))));
  81. }
  82. }
  83. protected function _getFormObject($sAction, $aBundle = array())
  84. {
  85. $CNF = &$this->_oModule->_oConfig->CNF;
  86. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_BUNDLE'], $CNF['OBJECT_FORM_BUNDLE_DISPLAY_' . strtoupper($sAction)]);
  87. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction;
  88. if(!empty($aBundle['id']))
  89. $oForm->aFormAttrs['action'] .= '&id=' . $aBundle['id'];
  90. return $oForm;
  91. }
  92. protected function _getCellPrice ($mixedValue, $sKey, $aField, $aRow)
  93. {
  94. return parent::_getCellDefault(_t_format_currency($mixedValue), $sKey, $aField, $aRow);
  95. }
  96. protected function _addJsCss()
  97. {
  98. parent::_addJsCss();
  99. $this->_oModule->_oTemplate->addStudioJs(array('jquery.form.min.js', 'studio.js'));
  100. $oForm = new BxTemplStudioFormView(array());
  101. $oForm->addCssJs();
  102. }
  103. protected function _isVisibleGrid ($a)
  104. {
  105. return isAdmin();
  106. }
  107. protected function _delete ($mixedId)
  108. {
  109. $aBundle = $this->_oModule->_oDb->getBundle(array('type' => 'id', 'id' => $mixedId));
  110. if(!empty($aBundle['title']))
  111. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBundle['title']);
  112. return parent::_delete($mixedId);
  113. }
  114. }
  115. /** @} */