1
0

BxBaseModGeneralFormsEntryHelper.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup BaseGeneral Base classes for modules
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolProfileForms');
  12. bx_import('BxDolForm');
  13. /**
  14. * Entry forms helper functions
  15. */
  16. class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
  17. {
  18. protected $_oModule;
  19. public function __construct($oModule)
  20. {
  21. parent::__construct();
  22. $this->_oModule = $oModule;
  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 = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
  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. $iContentId = $oForm->insert ($aValsToAdd);
  40. if (!$iContentId) {
  41. if (!$oForm->isValid())
  42. return $oForm->getCode();
  43. else
  44. return MsgBox(_t('_sys_txt_error_entry_creation'));
  45. }
  46. $sResult = $this->onDataAddAfter ($iContentId);
  47. if ($sResult)
  48. return $sResult;
  49. // perform action
  50. $this->_oModule->checkAllowedAdd(true);
  51. // redirect
  52. $this->_redirectAndExit('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
  53. }
  54. public function editDataForm ($iContentId, $sDisplay = false)
  55. {
  56. $CNF = &$this->_oModule->_oConfig->CNF;
  57. if (false === $sDisplay)
  58. $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'];
  59. // get content data and profile info
  60. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  61. if (!$aContentInfo)
  62. return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
  63. // check access
  64. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedEdit($aContentInfo)))
  65. return MsgBox($sMsg);
  66. // check and display form
  67. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay);
  68. if (!$oForm)
  69. return MsgBox(_t('_sys_txt_error_occured'));
  70. $oForm->initChecker($aContentInfo);
  71. if (!$oForm->isSubmittedAndValid())
  72. return $oForm->getCode();
  73. // update data in the DB
  74. $aTrackTextFieldsChanges = null;
  75. $this->onDataEditBefore ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $aTrackTextFieldsChanges);
  76. if (!$oForm->update ($aContentInfo[$CNF['FIELD_ID']], array(), $aTrackTextFieldsChanges)) {
  77. if (!$oForm->isValid())
  78. return $oForm->getCode();
  79. else
  80. return MsgBox(_t('_sys_txt_error_entry_update'));
  81. }
  82. $sResult = $this->onDataEditAfter ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $aTrackTextFieldsChanges, $oProfile);
  83. if ($sResult)
  84. return $sResult;
  85. // perform action
  86. $this->_oModule->checkAllowedEdit($aContentInfo, true);
  87. // redirect
  88. $this->_redirectAndExit('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  89. }
  90. public function deleteDataForm ($iContentId, $sDisplay = false)
  91. {
  92. $CNF = &$this->_oModule->_oConfig->CNF;
  93. if (false === $sDisplay)
  94. $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_DELETE'];
  95. // get content data and profile info
  96. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  97. if (!$aContentInfo)
  98. return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
  99. // check access
  100. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedDelete($aContentInfo)))
  101. return MsgBox($sMsg);
  102. // check and display form
  103. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay);
  104. if (!$oForm)
  105. return MsgBox(_t('_sys_txt_error_occured'));
  106. $oForm->initChecker($aContentInfo);
  107. if (!$oForm->isSubmittedAndValid())
  108. return $oForm->getCode();
  109. if (!$oForm->delete ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo))
  110. return MsgBox(_t('_sys_txt_error_entry_delete'));
  111. $sResult = $this->onDataDeleteAfter ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $oProfile);
  112. if ($sResult)
  113. return $sResult;
  114. // perform action
  115. $this->_oModule->checkAllowedDelete($aContentInfo, true);
  116. // create an alert
  117. bx_alert($this->_oModule->getName(), 'deleted', $aContentInfo[$CNF['FIELD_ID']]);
  118. // redirect
  119. bx_import('BxDolPermalinks');
  120. $this->_redirectAndExit(BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']));
  121. }
  122. public function viewDataForm ($iContentId, $sDisplay = false)
  123. {
  124. $CNF = &$this->_oModule->_oConfig->CNF;
  125. if (false === $sDisplay)
  126. $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_VIEW'];
  127. // get content data and profile info
  128. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  129. if (!$aContentInfo)
  130. return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
  131. // check access
  132. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($aContentInfo)))
  133. return MsgBox($sMsg);
  134. // get form
  135. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay);
  136. if (!$oForm)
  137. return MsgBox(_t('_sys_txt_error_occured'));
  138. // display profile
  139. $oForm->initChecker($aContentInfo);
  140. return $oForm->getCode();
  141. }
  142. }
  143. /** @} */