BxFilesFormsEntryHelper.php 2.8 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 Files Files
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Entry forms helper functions
  13. */
  14. class BxFilesFormsEntryHelper extends BxBaseModTextFormsEntryHelper
  15. {
  16. public function __construct($oModule)
  17. {
  18. parent::__construct($oModule);
  19. }
  20. public function getObjectFormAdd ()
  21. {
  22. return BxDolForm::getObjectInstance('bx_files_upload', 'bx_files_entry_upload', $this->_oModule->_oTemplate);
  23. }
  24. public function addDataForm ()
  25. {
  26. $CNF = &$this->_oModule->_oConfig->CNF;
  27. // check access
  28. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedAdd()))
  29. return MsgBox($sMsg);
  30. // check and display form
  31. $oForm = $this->getObjectFormAdd();
  32. if (!$oForm)
  33. return MsgBox(_t('_sys_txt_error_occured'));
  34. $oForm->initChecker();
  35. if (!$oForm->isSubmittedAndValid())
  36. return $oForm->getCode();
  37. // insert data into database
  38. $aValsToAdd = array ();
  39. $aContentIds = $oForm->insert ($aValsToAdd);
  40. if (false === $aContentIds || !is_array($aContentIds)) {
  41. if (!$oForm->isValid() || !is_array($aContentIds))
  42. return $oForm->getCode();
  43. else
  44. return MsgBox(_t('_sys_txt_error_entry_creation'));
  45. }
  46. foreach ($aContentIds as $iContentId) {
  47. $sResult = $this->onDataAddAfter (getLoggedId(), $iContentId);
  48. if ($sResult)
  49. return $sResult;
  50. // perform action
  51. $this->_oModule->checkAllowedAdd(true);
  52. }
  53. // redirect
  54. $iContentId = array_pop($aContentIds);
  55. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  56. $oProfile = BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]);
  57. $sUri = BxDolService::call($oProfile->getModule(), 'is_group_profile') ? $CNF['URI_GROUP_ENTRIES'] . '&profile_id=' . $oProfile->id() : $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id=' . bx_get_logged_profile_id();
  58. $this->_redirectAndExit('page.php?i=' . $sUri);
  59. }
  60. protected function redirectAfterDelete($aContentInfo)
  61. {
  62. $CNF = &$this->_oModule->_oConfig->CNF;
  63. $oProfile = BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]);
  64. if (BxDolService::call($oProfile->getModule(), 'is_group_profile'))
  65. $this->_redirectAndExit('page.php?i=' . $CNF['URI_GROUP_ENTRIES'] . '&profile_id=' . $oProfile->id());
  66. else
  67. $this->_redirectAndExit($CNF['URL_HOME'], true, array(
  68. 'account_id' => getLoggedId(),
  69. 'profile_id' => bx_get_logged_profile_id(),
  70. ));
  71. }
  72. }
  73. /** @} */