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