BxForumFormEntry.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. protected $_sGhostTemplateCover = 'form_ghost_template_cover.html';
  17. public function __construct($aInfo, $oTemplate = false)
  18. {
  19. $this->MODULE = 'bx_forum';
  20. parent::__construct($aInfo, $oTemplate);
  21. }
  22. function initChecker ($aValues = array (), $aSpecificValues = array())
  23. {
  24. $CNF = &$this->_oModule->_oConfig->CNF;
  25. $bValues = $aValues && !empty($aValues['id']);
  26. $aContentInfo = $bValues ? $this->_oModule->_oDb->getContentInfoById($aValues['id']) : false;
  27. if (isset($CNF['FIELD_COVER']) && isset($this->aInputs[$CNF['FIELD_COVER']])) {
  28. if($bValues)
  29. $this->aInputs[$CNF['FIELD_COVER']]['content_id'] = $aValues['id'];
  30. $this->aInputs[$CNF['FIELD_COVER']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateCover, $this->_getCoverGhostTmplVars($aContentInfo));
  31. }
  32. parent::initChecker ($aValues, $aSpecificValues);
  33. }
  34. public function insert($aValsToAdd = array(), $isIgnore = false)
  35. {
  36. $CNF = $this->_oModule->_oConfig->CNF;
  37. $aValsToAdd['lr_timestamp'] = time();
  38. $aValsToAdd['lr_profile_id'] = (isset($CNF['FIELD_ANONYMOUS']) && isset($this->aInputs[$CNF['FIELD_ANONYMOUS']]) && $this->getCleanValue($CNF['FIELD_ANONYMOUS']) ? -1 : 1) * bx_get_logged_profile_id();
  39. $iContentId = parent::insert($aValsToAdd, $isIgnore);
  40. if(!empty($iContentId)){
  41. $this->processFiles($CNF['FIELD_COVER'], $iContentId, true);
  42. }
  43. return $iContentId;
  44. }
  45. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  46. {
  47. $CNF = $this->_oModule->_oConfig->CNF;
  48. $aContentInfo = $this->_oModule->_oDb->getContentInfoById ($iContentId);
  49. if (isset($CNF['FIELD_ANONYMOUS']) && isset($this->aInputs[$CNF['FIELD_ANONYMOUS']]) && !$aContentInfo['lr_comment_id'])
  50. $aValsToAdd['lr_profile_id'] = ($this->getCleanValue($CNF['FIELD_ANONYMOUS']) ? -1 : 1) * abs($aContentInfo['lr_profile_id']);
  51. $iResult = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  52. $this->processFiles($CNF['FIELD_COVER'], $iContentId, false);
  53. return $iResult;
  54. }
  55. public function delete ($iContentId, $aContentInfo = array())
  56. {
  57. $CNF = &$this->_oModule->_oConfig->CNF;
  58. $mixedResult = parent::delete($iContentId, $aContentInfo);
  59. if($mixedResult !== false) {
  60. if(!empty($CNF['OBJECT_CONNECTION_SUBSCRIBERS']))
  61. BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION_SUBSCRIBERS'])->onDeleteContent($iContentId);
  62. }
  63. return $mixedResult;
  64. }
  65. protected function _getCoverGhostTmplVars($aContentInfo = array())
  66. {
  67. $CNF = &$this->_oModule->_oConfig->CNF;
  68. return array (
  69. 'name' => $this->aInputs[$CNF['FIELD_COVER']]['name'],
  70. 'content_id' => $this->aInputs[$CNF['FIELD_COVER']]['content_id'],
  71. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
  72. 'thumb_id' => isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : 0,
  73. 'name_thumb' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : ''
  74. );
  75. }
  76. protected function _getPhotoGhostTmplVars($aContentInfo = array())
  77. {
  78. $CNF = &$this->_oModule->_oConfig->CNF;
  79. return array (
  80. 'name' => $this->aInputs[$CNF['FIELD_PHOTO']]['name'],
  81. 'content_id' => (int)$this->aInputs[$CNF['FIELD_PHOTO']]['content_id'],
  82. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
  83. 'bx_if:set_thumb' => [
  84. 'condition' => false,
  85. 'content' => []
  86. ],
  87. );
  88. }
  89. }
  90. /** @} */