BxForumFormEntry.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 Forum Forum
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Create/Edit entry form
  13. */
  14. class BxForumFormEntry extends BxBaseModTextFormEntry
  15. {
  16. public function __construct($aInfo, $oTemplate = false)
  17. {
  18. $this->MODULE = 'bx_forum';
  19. parent::__construct($aInfo, $oTemplate);
  20. $oTemplate = BxDolTemplate::getInstance();
  21. $oTemplate->addJs(array('jquery.form.min.js'));
  22. $oTemplate->addJsTranslation(array(
  23. '_bx_forum_draft_saving_error',
  24. '_bx_forum_draft_saved_success',
  25. ));
  26. }
  27. public function insert($aValsToAdd = array(), $isIgnore = false)
  28. {
  29. $CNF = $this->_oModule->_oConfig->CNF;
  30. $aValsToAdd['lr_timestamp'] = time();
  31. $aValsToAdd['lr_profile_id'] = bx_get_logged_profile_id();
  32. $iDraftId = (int)bx_get('draft_id');
  33. $bDraftSave = (int)bx_get('draft_save') == 1; //--- draft is saved via ajax call only, upon successfull draft saving content id is returned
  34. $bDraft = false;
  35. if($iDraftId) {
  36. $aDraftInfo = $this->_oModule->_oDb->getContentInfoById($iDraftId);
  37. if(!empty($aDraftInfo[$CNF['FIELD_STATUS']]) && $aDraftInfo[$CNF['FIELD_STATUS']] == 'draft')
  38. $bDraft = true;
  39. if(!$bDraft)
  40. return 0;
  41. if(!$bDraftSave)
  42. $aValsToAdd[$CNF['FIELD_STATUS']] = 'active';
  43. if(!parent::update($iDraftId, $aValsToAdd, $isIgnore))
  44. return 0;
  45. }
  46. else {
  47. if($bDraftSave)
  48. $aValsToAdd[$CNF['FIELD_STATUS']] = 'draft';
  49. $iDraftId = parent::insert($aValsToAdd, $isIgnore);
  50. if(!$iDraftId)
  51. return 0;
  52. }
  53. if($bDraftSave) {
  54. echo $iDraftId;
  55. exit;
  56. }
  57. return $iDraftId;
  58. }
  59. protected function genCustomInputSubmitText ($aInput)
  60. {
  61. $aVars = array();
  62. return $this->_oModule->_oTemplate->parseHtmlByName('form_submit_text.html', $aVars);
  63. }
  64. function initChecker ($aValues = array (), $aSpecificValues = array())
  65. {
  66. $iContentId = bx_get('draft_id');
  67. if($iContentId) { // if adding from draft, fill in existing fields info
  68. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  69. if($aContentInfo)
  70. $aValues = array_merge($aContentInfo, $aValues);
  71. }
  72. return parent::initChecker ($aValues, $aSpecificValues);
  73. }
  74. function isValid ()
  75. {
  76. if(bx_get('draft_save')) // form is always valid when saving to drafts
  77. return true;
  78. return parent::isValid ();
  79. }
  80. public function processFiles ($sFieldFile, $iContentId = 0, $isAssociateWithContent = false)
  81. {
  82. if (!$isAssociateWithContent && bx_get('draft_id')) // when draft is already saved then db update is called but we still need to do association since it's draft
  83. $isAssociateWithContent = true; // TODO: if edit mode will be added, then this functionality maybe reconsidered
  84. return parent::processFiles ($sFieldFile, $iContentId, $isAssociateWithContent);
  85. }
  86. }
  87. /** @} */