BxBaseModFilesFormsEntryHelper.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. return BxDolForm::getObjectInstance($this->_sObjectNameForFormAdd, $sDisplay, $this->_oModule->_oTemplate);
  27. }
  28. protected function addDataFormAction ($sDisplay = false, $sCheckFunction = false)
  29. {
  30. $CNF = &$this->_oModule->_oConfig->CNF;
  31. $bAsJson = false;
  32. // get form object
  33. $oForm = $this->getObjectFormAdd();
  34. if (!$oForm)
  35. return $this->prepareResponse(MsgBox(_t('_sys_txt_error_occured')), $bAsJson, 'msg');
  36. $bAsJson = $this->_bAjaxMode && $oForm->isSubmitted();
  37. // check access
  38. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedAdd()))
  39. return $this->prepareResponse(MsgBox($sMsg), $bAsJson, 'msg');
  40. // check and display form
  41. $oForm->initChecker();
  42. if (!$oForm->isSubmittedAndValid())
  43. return $this->prepareResponse($oForm->getCode($this->_bDynamicMode), $bAsJson, 'form', array(
  44. 'form_id' => $oForm->getId()
  45. ));
  46. // insert data into database
  47. $aValsToAdd = array ();
  48. $aContentIds = $oForm->insert ($aValsToAdd);
  49. if (false === $aContentIds || !is_array($aContentIds)) {
  50. if (!$oForm->isValid() || !is_array($aContentIds))
  51. return $this->prepareResponse($oForm->getCode($this->_bDynamicMode), $bAsJson, 'form', array(
  52. 'form_id' => $oForm->getId()
  53. ));
  54. else
  55. return $this->prepareResponse(MsgBox(_t('_sys_txt_error_entry_creation')), $bAsJson, 'msg');
  56. }
  57. foreach ($aContentIds as $iContentId) {
  58. $sResult = $this->onDataAddAfter (getLoggedId(), $iContentId);
  59. if ($sResult)
  60. return $sResult;
  61. }
  62. return array('need_redirect_after_action' => true, 'content_ids_array' => $aContentIds);
  63. }
  64. }
  65. /** @} */