BxBaseModGeneralFormEntry.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 BaseGeneral Base classes for modules
  7. * @ingroup TridentModules
  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. }
  26. public function insert ($aValsToAdd = array(), $isIgnore = false)
  27. {
  28. $CNF = &$this->_oModule->_oConfig->CNF;
  29. if (isset($CNF['FIELD_AUTHOR']) && empty($aValsToAdd[$CNF['FIELD_AUTHOR']]))
  30. $aValsToAdd[$CNF['FIELD_AUTHOR']] = bx_get_logged_profile_id ();
  31. if (isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']]))
  32. $aValsToAdd[$CNF['FIELD_ADDED']] = time();
  33. if (isset($CNF['FIELD_CHANGED']) && empty($aValsToAdd[$CNF['FIELD_CHANGED']]))
  34. $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
  35. return parent::insert ($aValsToAdd, $isIgnore);
  36. }
  37. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  38. {
  39. $CNF = &$this->_oModule->_oConfig->CNF;
  40. if (isset($CNF['FIELD_CHANGED']))
  41. $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
  42. return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  43. }
  44. function delete ($iContentId, $aContentInfo = array())
  45. {
  46. $CNF = &$this->_oModule->_oConfig->CNF;
  47. // delete associated files
  48. if (!empty($CNF['OBJECT_STORAGE'])) {
  49. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  50. if ($oStorage)
  51. $oStorage->queueFilesForDeletionFromGhosts($aContentInfo[$CNF['FIELD_AUTHOR']], $iContentId);
  52. }
  53. // delete associated objects data
  54. if (!empty($CNF['OBJECT_VIEWS'])) {
  55. $o = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $iContentId);
  56. if ($o) $o->onObjectDelete();
  57. }
  58. if (!empty($CNF['OBJECT_VOTES'])) {
  59. $o = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  60. if ($o) $o->onObjectDelete();
  61. }
  62. if (!empty($CNF['OBJECT_COMMENTS'])) {
  63. $o = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  64. if ($o) $o->onObjectDelete();
  65. }
  66. if (!empty($CNF['OBJECT_METATAGS'])) {
  67. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  68. $oMetatags->onDeleteContent($iContentId);
  69. }
  70. // delete db record
  71. return parent::delete($iContentId);
  72. }
  73. protected function genCustomInputLocation ($aInput)
  74. {
  75. $sProto = (0 == strncmp('https', BX_DOL_URL_ROOT, 5)) ? 'https' : 'http';
  76. $this->oTemplate->addJs($sProto . '://maps.google.com/maps/api/js?sensor=false');
  77. $aInput['checked'] = $this->getCleanValue($aInput['name'] . '_lat') && $this->getCleanValue($aInput['name'] . '_lng') ? 1 : 0;
  78. $aVars = array (
  79. 'name' => $aInput['name'],
  80. 'id_status' => $this->getInputId($aInput) . '_status',
  81. 'location_string' => _t('_sys_location_undefined'),
  82. );
  83. $aLocationIndexes = array ('lat', 'lng', 'country', 'state', 'city', 'zip');
  84. foreach ($aLocationIndexes as $sKey)
  85. $aVars[$sKey] = $this->getLoctionVal($aInput, $sKey);
  86. if ($aVars['country']) {
  87. $aCountries = BxDolFormQuery::getDataItems('Country');
  88. $aVars['location_string'] = ($aVars['city'] ? $aVars['city'] . ', ' : '') . $aCountries[$aVars['country']];
  89. }
  90. if ($this->getLoctionVal($aInput, 'lat') && $this->getLoctionVal($aInput, 'lng'))
  91. $aInput['checked'] = true;
  92. $aVars['input'] = $this->genInputSwitcher($aInput);
  93. return $this->oTemplate->parseHtmlByName('form_field_location.html', $aVars);
  94. }
  95. protected function getLoctionVal ($aInput, $sIndex)
  96. {
  97. $s = $aInput['name'] . '_' . $sIndex;
  98. if (isset($this->_aSpecificValues[$s]))
  99. return $this->_aSpecificValues[$s];
  100. return $this->getCleanValue($s);
  101. }
  102. function addCssJs ()
  103. {
  104. if (!isset($this->aParams['view_mode']) || !$this->aParams['view_mode']) {
  105. if (self::$_isCssJsAdded)
  106. return;
  107. $this->_oModule->_oTemplate->addCss('forms.css');
  108. }
  109. return parent::addCssJs ();
  110. }
  111. function genViewRowValue(&$aInput)
  112. {
  113. $s = parent::genViewRowValue($aInput);
  114. if ($this->_oMetatagsObject && in_array($aInput['name'], $this->_aMetatagsFieldsWithKeywords) && $s)
  115. $s = $this->_oMetatagsObject->keywordsParse($this->_oMetatagsContentId, $s);
  116. return $s;
  117. }
  118. function setMetatagsKeywordsData($iId, $a, $o)
  119. {
  120. $this->_oMetatagsContentId = $iId;
  121. $this->_aMetatagsFieldsWithKeywords = $a;
  122. $this->_oMetatagsObject = $o;
  123. }
  124. }
  125. /** @} */