1
0

BxBaseModFilesFormsEntryHelper.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 BaseFile Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Entry forms helper functions
  13. */
  14. class BxBaseModFilesFormsEntryHelper extends BxBaseModTextFormsEntryHelper
  15. {
  16. protected $_sDisplayForFormAdd;
  17. protected $_sObjectNameForFormAdd;
  18. public function __construct($oModule)
  19. {
  20. parent::__construct($oModule);
  21. }
  22. public function getObjectFormAdd ($sDisplay = false)
  23. {
  24. if (false === $sDisplay)
  25. $sDisplay = $this->_sDisplayForFormAdd;
  26. $oForm = BxDolForm::getObjectInstance($this->_sObjectNameForFormAdd, $sDisplay, $this->_oModule->_oTemplate);
  27. if($this->_bAjaxMode)
  28. $oForm->setAjaxMode($this->_bAjaxMode);
  29. if($this->_bAbsoluteActionUrl)
  30. $this->_setAbsoluteActionUrl('add', $oForm);
  31. return $oForm;
  32. }
  33. protected function addDataFormAction ($sDisplay = false, $sCheckFunction = false)
  34. {
  35. $CNF = &$this->_oModule->_oConfig->CNF;
  36. $bAsJson = false;
  37. // get form object
  38. $oForm = $this->getObjectFormAdd();
  39. if (!$oForm)
  40. return $this->prepareResponse(MsgBox(_t('_sys_txt_error_occured')), $bAsJson, 'msg');
  41. $bAsJson = $this->_bAjaxMode && $oForm->isSubmitted();
  42. // check access
  43. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedAdd()))
  44. return $this->prepareResponse(MsgBox($sMsg), $bAsJson, 'msg');
  45. // check and display form
  46. $oForm->initChecker();
  47. if (!$oForm->isSubmittedAndValid())
  48. return $this->prepareResponse($oForm->getCode($this->_bDynamicMode), $bAsJson, 'form', array(
  49. 'form_id' => $oForm->getId()
  50. ));
  51. // insert data into database
  52. $aValsToAdd = array ();
  53. $aContentIds = $oForm->insert ($aValsToAdd);
  54. if (false === $aContentIds || !is_array($aContentIds)) {
  55. if (!$oForm->isValid() || !is_array($aContentIds))
  56. return $this->prepareResponse($oForm->getCode($this->_bDynamicMode), $bAsJson, 'form', array(
  57. 'form_id' => $oForm->getId()
  58. ));
  59. else
  60. return $this->prepareResponse(MsgBox(_t('_sys_txt_error_entry_creation')), $bAsJson, 'msg');
  61. }
  62. foreach ($aContentIds as $iContentId) {
  63. $sResult = $this->onDataAddAfter (getLoggedId(), $iContentId);
  64. if ($sResult)
  65. return $sResult;
  66. }
  67. return array('need_redirect_after_action' => true, 'content_ids_array' => $aContentIds);
  68. }
  69. }
  70. /** @} */