BxFilesFormsEntryHelper.php 3.0 KB

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