BxBaseModGeneralFormEntry.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Create/edit entry form
  13. */
  14. class BxBaseModGeneralFormEntry extends BxTemplFormView
  15. {
  16. protected $MODULE;
  17. protected $_oModule;
  18. protected $_aMetatagsFieldsWithKeywords = array();
  19. protected $_oMetatagsObject = null;
  20. protected $_oMetatagsContentId = 0;
  21. public function __construct($aInfo, $oTemplate = false)
  22. {
  23. parent::__construct($aInfo, $oTemplate);
  24. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  25. $CNF = &$this->_oModule->_oConfig->CNF;
  26. if (isset($CNF['FIELD_ADDED']) && isset($this->aInputs[$CNF['FIELD_ADDED']])) {
  27. $this->aInputs[$CNF['FIELD_ADDED']]['date_filter'] = BX_DATA_INT;
  28. $this->aInputs[$CNF['FIELD_ADDED']]['date_format'] = BX_FORMAT_DATE;
  29. }
  30. if (isset($CNF['FIELD_CHANGED']) && isset($this->aInputs[$CNF['FIELD_CHANGED']])) {
  31. $this->aInputs[$CNF['FIELD_CHANGED']]['date_filter'] = BX_DATA_INT;
  32. $this->aInputs[$CNF['FIELD_CHANGED']]['date_format'] = BX_FORMAT_DATE;
  33. }
  34. if (isset($CNF['FIELD_LOCATION_PREFIX']) && isset($this->aInputs[$CNF['FIELD_LOCATION_PREFIX']])) {
  35. $this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]['manual_input'] = true;
  36. }
  37. }
  38. function initChecker ($aValues = array (), $aSpecificValues = array())
  39. {
  40. $CNF = &$this->_oModule->_oConfig->CNF;
  41. if (!empty($CNF['FIELD_LOCATION_PREFIX']) && isset($this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]) && isset($aValues[$CNF['FIELD_ID']]) && !empty($CNF['OBJECT_METATAGS']) && ($oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])) && $oMetatags->locationsIsEnabled())
  42. $this->aInputs[$CNF['FIELD_LOCATION_PREFIX']]['value'] = $oMetatags->locationsString($aValues[$CNF['FIELD_ID']], false);
  43. parent::initChecker ($aValues, $aSpecificValues);
  44. }
  45. public function insert ($aValsToAdd = array(), $isIgnore = false)
  46. {
  47. $CNF = &$this->_oModule->_oConfig->CNF;
  48. if (isset($CNF['FIELD_AUTHOR']) && empty($aValsToAdd[$CNF['FIELD_AUTHOR']]))
  49. $aValsToAdd[$CNF['FIELD_AUTHOR']] = bx_get_logged_profile_id ();
  50. if (isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']]))
  51. $aValsToAdd[$CNF['FIELD_ADDED']] = time();
  52. if (isset($CNF['FIELD_CHANGED']) && empty($aValsToAdd[$CNF['FIELD_CHANGED']]))
  53. $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
  54. return parent::insert ($aValsToAdd, $isIgnore);
  55. }
  56. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  57. {
  58. $CNF = &$this->_oModule->_oConfig->CNF;
  59. if (isset($CNF['FIELD_CHANGED']))
  60. $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
  61. return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  62. }
  63. function delete ($iContentId, $aContentInfo = array())
  64. {
  65. $CNF = &$this->_oModule->_oConfig->CNF;
  66. // delete associated files
  67. if (!empty($CNF['OBJECT_STORAGE'])) {
  68. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  69. if ($oStorage)
  70. $oStorage->queueFilesForDeletionFromGhosts($aContentInfo[$CNF['FIELD_AUTHOR']], $iContentId);
  71. }
  72. // delete associated objects data
  73. if (!empty($CNF['OBJECT_VIEWS'])) {
  74. $o = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $iContentId);
  75. if ($o) $o->onObjectDelete();
  76. }
  77. if (!empty($CNF['OBJECT_VOTES'])) {
  78. $o = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  79. if ($o) $o->onObjectDelete();
  80. }
  81. if (!empty($CNF['OBJECT_COMMENTS'])) {
  82. $o = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  83. if ($o) $o->onObjectDelete();
  84. }
  85. if (!empty($CNF['OBJECT_METATAGS'])) {
  86. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  87. $oMetatags->onDeleteContent($iContentId);
  88. }
  89. // delete db record
  90. return parent::delete($iContentId);
  91. }
  92. public function processFiles ($sFieldFile, $iContentId = 0, $isAssociateWithContent = false)
  93. {
  94. $CNF = &$this->_oModule->_oConfig->CNF;
  95. if (!isset($this->aInputs[$sFieldFile]))
  96. return true;
  97. $mixedFileIds = $this->getCleanValue($sFieldFile);
  98. if(!$mixedFileIds)
  99. return true;
  100. $oStorage = BxDolStorage::getObjectInstance($this->aInputs[$sFieldFile]['storage_object']);
  101. if (!$oStorage)
  102. return false;
  103. $iProfileId = $this->getContentOwnerProfileId($iContentId);
  104. $aGhostFiles = $oStorage->getGhosts ($iProfileId, $isAssociateWithContent ? 0 : $iContentId, true);
  105. if (!$aGhostFiles)
  106. return true;
  107. foreach ($aGhostFiles as $aFile) {
  108. if (is_array($mixedFileIds) && !in_array($aFile['id'], $mixedFileIds))
  109. continue;
  110. if ($aFile['private'])
  111. $oStorage->setFilePrivate ($aFile['id'], 0);
  112. if ($iContentId)
  113. $this->_associalFileWithContent($oStorage, $aFile['id'], $iProfileId, $iContentId, $sFieldFile);
  114. }
  115. return true;
  116. }
  117. function addCssJs ()
  118. {
  119. if (!isset($this->aParams['view_mode']) || !$this->aParams['view_mode']) {
  120. if (self::$_isCssJsAdded)
  121. return;
  122. $this->_oModule->_oTemplate->addCss('forms.css');
  123. $this->_oModule->_oTemplate->addJs('modules/base/general/js/|forms.js');
  124. }
  125. return parent::addCssJs ();
  126. }
  127. function genViewRowValue(&$aInput)
  128. {
  129. $s = parent::genViewRowValue($aInput);
  130. if ($this->_oMetatagsObject && in_array($aInput['name'], $this->_aMetatagsFieldsWithKeywords) && $s)
  131. $s = $this->_oMetatagsObject->keywordsParse($this->_oMetatagsContentId, $s);
  132. return $s;
  133. }
  134. function setMetatagsKeywordsData($iId, $a, $o)
  135. {
  136. $this->_oMetatagsContentId = $iId;
  137. $this->_aMetatagsFieldsWithKeywords = $a;
  138. $this->_oMetatagsObject = $o;
  139. }
  140. function getContentOwnerProfileId ($iContentId)
  141. {
  142. $CNF = &$this->_oModule->_oConfig->CNF;
  143. // file owner must be author of the content or profile itself in case of profile based module
  144. if ($iContentId) {
  145. if ($this->_oModule instanceof iBxDolProfileService) {
  146. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->MODULE);
  147. }
  148. else {
  149. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  150. $oProfile = $aContentInfo ? BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]) : null;
  151. }
  152. $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
  153. }
  154. else {
  155. $iProfileId = bx_get_logged_profile_id();
  156. }
  157. return $iProfileId;
  158. }
  159. }
  160. /** @} */