1
0

BxNotesFormNote.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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('BxTemplFormView');
  12. /**
  13. * Create/Edit Note Form.
  14. */
  15. class BxNotesFormNote extends BxTemplFormView {
  16. protected $_oModule;
  17. public function __construct($aInfo, $oTemplate = false) {
  18. parent::__construct($aInfo, $oTemplate);
  19. $this->_oModule = BxDolModule::getInstance('bx_notes');
  20. if (isset($this->aInputs[BxNotesConfig::$FIELD_TEXT])) {
  21. $this->aInputs[BxNotesConfig::$FIELD_TEXT]['attrs'] = array_merge (
  22. array ('id' => BxNotesConfig::$FIELD_TEXT_ID),
  23. is_array($this->aInputs[BxNotesConfig::$FIELD_TEXT]['attrs']) ? $this->aInputs[BxNotesConfig::$FIELD_TEXT]['attrs'] : array ()
  24. );
  25. }
  26. if (isset($this->aInputs[BxNotesConfig::$FIELD_SUMMARY])) {
  27. $this->aInputs[BxNotesConfig::$FIELD_SUMMARY]['attrs'] = array_merge (
  28. array ('id' => BxNotesConfig::$FIELD_SUMMARY_ID),
  29. is_array($this->aInputs[BxNotesConfig::$FIELD_SUMMARY]['attrs']) ? $this->aInputs[BxNotesConfig::$FIELD_SUMMARY]['attrs'] : array ()
  30. );
  31. }
  32. if (isset($this->aInputs[BxNotesConfig::$FIELD_PHOTO])) {
  33. $this->aInputs[BxNotesConfig::$FIELD_PHOTO]['storage_object'] = BxNotesConfig::$OBJECT_STORAGE;
  34. $this->aInputs[BxNotesConfig::$FIELD_PHOTO]['uploaders'] = array('sys_simple', 'sys_html5');
  35. $this->aInputs[BxNotesConfig::$FIELD_PHOTO]['images_transcoder'] = BxNotesConfig::$OBJECT_IMAGES_TRANSCODER_PREVIEW;
  36. $this->aInputs[BxNotesConfig::$FIELD_PHOTO]['multiple'] = true;
  37. $this->aInputs[BxNotesConfig::$FIELD_PHOTO]['content_id'] = 0;
  38. //$this->aInputs[BxNotesConfig::$FIELD_PHOTO]['upload_buttons_titles'] = _t('_bx_notes_form_note_input_photo_btn_upload');
  39. $this->aInputs[BxNotesConfig::$FIELD_PHOTO]['ghost_template'] = '';
  40. }
  41. if (isset($this->aInputs[BxNotesConfig::$FIELD_ALLOW_VIEW_TO])) {
  42. bx_import('BxDolPrivacy');
  43. $this->aInputs[BxNotesConfig::$FIELD_ALLOW_VIEW_TO] = BxDolPrivacy::getGroupChooser(BxNotesConfig::$OBJECT_PRIVACY_VIEW);
  44. }
  45. }
  46. function initChecker ($aValues = array (), $aSpecificValues = array()) {
  47. if (isset($this->aInputs[BxNotesConfig::$FIELD_PHOTO])) {
  48. $aContentInfo = false;
  49. if ($aValues && !empty($aValues['id'])) {
  50. $aContentInfo = $this->_oModule->_oDb->getContentInfoById ($aValues['id']);
  51. $this->aInputs[BxNotesConfig::$FIELD_PHOTO]['content_id'] = $aValues['id'];
  52. }
  53. $aVars = array (
  54. 'name' => $this->aInputs[BxNotesConfig::$FIELD_PHOTO]['name'],
  55. 'content_id' => $this->aInputs[BxNotesConfig::$FIELD_PHOTO]['content_id'],
  56. 'editor_id' => BxNotesConfig::$FIELD_TEXT_ID,
  57. 'summary_id' => BxNotesConfig::$FIELD_SUMMARY_ID,
  58. 'thumb_id' => $aContentInfo[BxNotesConfig::$FIELD_THUMB],
  59. 'bx_if:set_thumb' => array (
  60. 'condition' => CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->isAllowedSetThumb(),
  61. 'content' => array (
  62. 'name_thumb' => BxNotesConfig::$FIELD_THUMB,
  63. ),
  64. ),
  65. );
  66. $this->aInputs[BxNotesConfig::$FIELD_PHOTO]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName('form_ghost_template.html', $aVars);
  67. }
  68. return parent::initChecker($aValues, $aSpecificValues);
  69. }
  70. public function insert ($aValsToAdd = array(), $isIgnore = false) {
  71. $aValsToAdd[BxNotesConfig::$FIELD_AUTHOR] = bx_get_logged_profile_id ();
  72. $aValsToAdd[BxNotesConfig::$FIELD_ADDED] = time();
  73. $aValsToAdd[BxNotesConfig::$FIELD_CHANGED] = time();
  74. if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->isAllowedSetThumb()) {
  75. $aThumb = isset($_POST[BxNotesConfig::$FIELD_THUMB]) ? bx_process_input ($_POST[BxNotesConfig::$FIELD_THUMB], BX_DATA_INT) : false;
  76. $aValsToAdd[BxNotesConfig::$FIELD_THUMB] = 0;
  77. if (!empty($aThumb) && is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
  78. $aValsToAdd[BxNotesConfig::$FIELD_THUMB] = $iFileThumb;
  79. }
  80. if ($iContentId = parent::insert ($aValsToAdd, $isIgnore))
  81. $this->_processFiles ($this->getCleanValue(BxNotesConfig::$FIELD_PHOTO), $iContentId, true);
  82. return $iContentId;
  83. }
  84. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null) {
  85. $aValsToAdd[BxNotesConfig::$FIELD_CHANGED] = time();
  86. if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->isAllowedSetThumb()) {
  87. $aThumb = bx_process_input ($_POST[BxNotesConfig::$FIELD_THUMB], BX_DATA_INT);
  88. $aValsToAdd[BxNotesConfig::$FIELD_THUMB] = 0;
  89. if (!empty($aThumb) && is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
  90. $aValsToAdd[BxNotesConfig::$FIELD_THUMB] = $iFileThumb;
  91. }
  92. if ($iRet = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges))
  93. $this->_processFiles ($this->getCleanValue(BxNotesConfig::$FIELD_PHOTO), $iContentId, false);
  94. return $iRet;
  95. }
  96. function delete ($iContentId) {
  97. // delete associated files
  98. bx_import('BxDolStorage');
  99. $oStorage = BxDolStorage::getObjectInstance(BxNotesConfig::$OBJECT_STORAGE);
  100. if (!$oStorage)
  101. return false;
  102. $aGhostFiles = $oStorage->getGhosts (bx_get_logged_profile_id(), $iContentId);
  103. if ($aGhostFiles)
  104. foreach ($aGhostFiles as $aFile)
  105. $this->_deleteFile($aFile['id']);
  106. // delete db record
  107. bx_import('BxDolView');
  108. BxDolView::getObjectInstance(BxNotesConfig::$OBJECT_VIEWS, $iContentId)->onObjectDelete();
  109. bx_import('BxDolVote');
  110. BxDolVote::getObjectInstance(BxNotesConfig::$OBJECT_VOTES, $iContentId)->onObjectDelete();
  111. bx_import('BxDolCmts');
  112. BxDolCmts::getObjectInstance(BxNotesConfig::$OBJECT_COMMENTS, $iContentId)->onObjectDelete();
  113. return parent::delete($iContentId);
  114. }
  115. function _processFiles ($mixedFileIds, $iContentId = 0, $isAssociateWithContent = false) {
  116. if (!$mixedFileIds)
  117. return true;
  118. bx_import('BxDolStorage');
  119. $oStorage = BxDolStorage::getObjectInstance(BxNotesConfig::$OBJECT_STORAGE);
  120. if (!$oStorage)
  121. return false;
  122. $iProfileId = bx_get_logged_profile_id();
  123. $aGhostFiles = $oStorage->getGhosts ($iProfileId, $isAssociateWithContent ? 0 : $iContentId);
  124. if (!$aGhostFiles)
  125. return true;
  126. foreach ($aGhostFiles as $aFile) {
  127. if ($aFile['private'])
  128. $oStorage->setFilePrivate ($aFile['id'], 0);
  129. if ($isAssociateWithContent && $iContentId)
  130. $oStorage->updateGhostsContentId ($aFile['id'], $iProfileId, $iContentId);
  131. }
  132. return true;
  133. }
  134. function _deleteFile ($iFileId) {
  135. if (!$iFileId)
  136. return true;
  137. bx_import('BxDolStorage');
  138. if (!($oStorage = BxDolStorage::getObjectInstance(BxNotesConfig::$OBJECT_STORAGE)))
  139. return false;
  140. if (!$oStorage->getFile($iFileId))
  141. return true;
  142. $iProfileId = bx_get_logged_profile_id();
  143. return $oStorage->deleteFile($iFileId, $iProfileId);
  144. }
  145. function addCssJs () {
  146. if (!isset($this->aParams['view_mode']) || !$this->aParams['view_mode']) {
  147. if (self::$_isCssJsAdded)
  148. return;
  149. $this->_oModule->_oTemplate->addJs('forms.js');
  150. $this->_oModule->_oTemplate->addCss('forms.css');
  151. }
  152. return parent::addCssJs ();
  153. }
  154. }
  155. /** @} */