1
0

BxBaseModFilesFormsEntryHelper.php 2.5 KB

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