BxNotesFormsEntryHelper.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 Notes Notes
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolProfileForms');
  12. bx_import('BxDolProfile');
  13. bx_import('BxDolForm');
  14. /**
  15. * Note forms functions
  16. */
  17. class BxNotesFormsEntryHelper extends BxDolProfileForms
  18. {
  19. protected $_oModule;
  20. public function __construct($oModule)
  21. {
  22. parent::__construct();
  23. $this->_oModule = $oModule;
  24. }
  25. /**
  26. * @return add data html
  27. */
  28. public function addDataForm ()
  29. {
  30. $CNF = &$this->_oModule->_oConfig->CNF;
  31. // check access
  32. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->isAllowedAdd()))
  33. return MsgBox($sMsg);
  34. // check and display form
  35. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
  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. $iContentId = $oForm->insert ($aValsToAdd);
  44. if (!$iContentId) {
  45. if (!$oForm->isValid())
  46. return $oForm->getCode();
  47. else
  48. return MsgBox(_t('_bx_notes_txt_error_entry_creation'));
  49. }
  50. // perform action
  51. $this->_oModule->isAllowedAdd(true);
  52. // alert
  53. //TODO: Pass a valid entry privacy view group.
  54. bx_import('BxDolPrivacy');
  55. bx_alert($this->_oModule->getName(), 'added', $iContentId, false, array('privacy_view' => BX_DOL_PG_ALL));
  56. // redirect
  57. $this->_redirectAndExit('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
  58. }
  59. /**
  60. * @return edit data html
  61. */
  62. public function editDataForm ($iContentId, $sDisplay = false)
  63. {
  64. $CNF = &$this->_oModule->_oConfig->CNF;
  65. if (false === $sDisplay)
  66. $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'];
  67. // get content data and profile info
  68. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  69. if (!$aContentInfo)
  70. return MsgBox(_t('_bx_notes_txt_error_entry_is_not_defined'));
  71. // check access
  72. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->isAllowedEdit($aContentInfo)))
  73. return MsgBox($sMsg);
  74. // check and display form
  75. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay);
  76. if (!$oForm)
  77. return MsgBox(_t('_sys_txt_error_occured'));
  78. $oForm->initChecker($aContentInfo);
  79. if (!$oForm->isSubmittedAndValid())
  80. return $oForm->getCode();
  81. // update data in the DB
  82. $aTrackTextFieldsChanges = null;
  83. if (!$oForm->update ($aContentInfo['id'], array(), $aTrackTextFieldsChanges)) {
  84. if (!$oForm->isValid())
  85. return $oForm->getCode();
  86. else
  87. return MsgBox(_t('_bx_notes_txt_error_entry_update'));
  88. }
  89. // change profile to 'pending' only if profile is 'active'
  90. if ($oProfile->isActive() && !empty($aTrackTextFieldsChanges['changed_fields']))
  91. $oProfile->disapprove(BX_PROFILE_ACTION_AUTO);
  92. // perform action
  93. $this->_oModule->isAllowedEdit($aContentInfo, true);
  94. // create an alert
  95. //TODO: Pass a valid entry privacy view group.
  96. bx_import('BxDolPrivacy');
  97. bx_alert($this->_oModule->getName(), 'edited', $aContentInfo['id'], false, array('privacy_view' => BX_DOL_PG_MEMBERS));
  98. // redirect
  99. $this->_redirectAndExit('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo['id']);
  100. }
  101. /**
  102. * @return delete data html
  103. */
  104. public function deleteDataForm ($iContentId, $sDisplay = false)
  105. {
  106. $CNF = &$this->_oModule->_oConfig->CNF;
  107. if (false === $sDisplay)
  108. $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_DELETE'];
  109. // get content data and profile info
  110. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  111. if (!$aContentInfo)
  112. return MsgBox(_t('_bx_notes_txt_error_entry_is_not_defined'));
  113. // check access
  114. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->isAllowedDelete($aContentInfo)))
  115. return MsgBox($sMsg);
  116. // check and display form
  117. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay);
  118. if (!$oForm)
  119. return MsgBox(_t('_sys_txt_error_occured'));
  120. $oForm->initChecker($aContentInfo);
  121. if (!$oForm->isSubmittedAndValid())
  122. return $oForm->getCode();
  123. if (!$oForm->delete ($aContentInfo['id'])) {
  124. if (!$oForm->isValid())
  125. return $oForm->getCode();
  126. else
  127. return MsgBox(_t('_bx_notes_txt_error_entry_delete'));
  128. }
  129. // perform action
  130. $this->_oModule->isAllowedDelete($aContentInfo, true);
  131. // create an alert
  132. bx_alert($this->_oModule->getName(), 'deleted', $aContentInfo['id']);
  133. // redirect
  134. $this->_redirectAndExit('page.php?i=' . $CNF['URI_HOME']);
  135. }
  136. /**
  137. * @return view data html
  138. */
  139. public function viewDataForm ($iContentId)
  140. {
  141. $CNF = &$this->_oModule->_oConfig->CNF;
  142. // get content data and profile info
  143. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  144. if (!$aContentInfo)
  145. return MsgBox(_t('_bx_notes_txt_error_entry_is_not_defined'));
  146. // check access
  147. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->isAllowedView($aContentInfo)))
  148. return MsgBox($sMsg);
  149. // get form
  150. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_VIEW']);
  151. if (!$oForm)
  152. return MsgBox(_t('_sys_txt_error_occured'));
  153. // perform action
  154. $this->_oModule->isAllowedView($aContentInfo);
  155. // display profile
  156. $oForm->initChecker($aContentInfo);
  157. return $oForm->getCode();
  158. }
  159. /**
  160. * @return main content text
  161. */
  162. public function viewDataText ($iContentId)
  163. {
  164. $CNF = &$this->_oModule->_oConfig->CNF;
  165. // get content data and profile info
  166. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  167. if (!$aContentInfo)
  168. return MsgBox(_t('_bx_notes_txt_error_entry_is_not_defined'));
  169. // check access
  170. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->isAllowedView($aContentInfo)))
  171. return MsgBox($sMsg);
  172. return $aContentInfo[$CNF['FIELD_TEXT']];
  173. }
  174. /**
  175. * @return main content text
  176. */
  177. public function viewDataEntry ($iContentId)
  178. {
  179. // get content data and profile info
  180. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  181. if (!$aContentInfo)
  182. return MsgBox(_t('_bx_notes_txt_error_entry_is_not_defined'));
  183. // check access
  184. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->isAllowedView($aContentInfo)))
  185. return MsgBox($sMsg);
  186. return $this->_oModule->_oTemplate->entryText($aContentInfo);
  187. }
  188. /**
  189. * @return array of profile object, profile info and content info
  190. */
  191. protected function _getProfileAndContentData ($iContentId)
  192. {
  193. $CNF = &$this->_oModule->_oConfig->CNF;
  194. $aContentInfo = array();
  195. $oProfile = false;
  196. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  197. if (!$aContentInfo)
  198. return array (false, false, false);
  199. $oProfile = BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]);
  200. if (!$oProfile) {
  201. bx_import('BxDolProfileUndefined');
  202. $oProfile = BxDolProfileUndefined::getInstance();
  203. }
  204. return array ($oProfile, $aContentInfo);
  205. }
  206. }
  207. /** @} */