BxAdsFormEntry.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 Ads Ads
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Create/Edit entry form
  13. */
  14. class BxAdsFormEntry extends BxBaseModTextFormEntry
  15. {
  16. protected $_iCategory;
  17. protected $_sGhostTemplateCover = 'form_ghost_template_cover.html';
  18. public function __construct($aInfo, $oTemplate = false)
  19. {
  20. $this->MODULE = 'bx_ads';
  21. parent::__construct($aInfo, $oTemplate);
  22. $CNF = &$this->_oModule->_oConfig->CNF;
  23. $this->_initCategoryFields();
  24. if(isset($CNF['FIELD_COVER']) && isset($this->aInputs[$CNF['FIELD_COVER']])) {
  25. if($this->_oModule->checkAllowedSetThumb() === CHECK_ACTION_RESULT_ALLOWED) {
  26. $this->aInputs[$CNF['FIELD_COVER']]['storage_object'] = $CNF['OBJECT_STORAGE'];
  27. $this->aInputs[$CNF['FIELD_COVER']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_COVER']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_COVER']]['value']) : $CNF['OBJECT_UPLOADERS'];
  28. $this->aInputs[$CNF['FIELD_COVER']]['upload_buttons_titles'] = array(
  29. 'Simple' => _t('_bx_ads_form_entry_input_covers_uploader_simple_title'),
  30. 'HTML5' => _t('_bx_ads_form_entry_input_covers_uploader_html5_title')
  31. );
  32. $this->aInputs[$CNF['FIELD_COVER']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW'];
  33. $this->aInputs[$CNF['FIELD_COVER']]['storage_private'] = 0;
  34. $this->aInputs[$CNF['FIELD_COVER']]['multiple'] = false;
  35. $this->aInputs[$CNF['FIELD_COVER']]['content_id'] = 0;
  36. $this->aInputs[$CNF['FIELD_COVER']]['ghost_template'] = '';
  37. }
  38. else
  39. unset($this->aInputs[$CNF['FIELD_COVER']]);
  40. }
  41. if(isset($CNF['FIELD_PHOTO']) && isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
  42. $this->aInputs[$CNF['FIELD_PHOTO']]['storage_object'] = $CNF['OBJECT_STORAGE_PHOTOS'];
  43. $this->aInputs[$CNF['FIELD_PHOTO']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_PHOTO']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_PHOTO']]['value']) : $CNF['OBJECT_UPLOADERS'];
  44. $this->aInputs[$CNF['FIELD_PHOTO']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS'];
  45. $this->aInputs[$CNF['FIELD_PHOTO']]['storage_private'] = 0;
  46. $this->aInputs[$CNF['FIELD_PHOTO']]['multiple'] = true;
  47. $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = 0;
  48. $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = '';
  49. $this->aInputs[$CNF['FIELD_PHOTO']]['tr_attrs'] = array('class'=> 'bx-base-text-attachment-item');
  50. }
  51. if(isset($this->aInputs[$CNF['FIELD_VIDEO']])) {
  52. $this->aInputs[$CNF['FIELD_VIDEO']]['storage_object'] = $CNF['OBJECT_STORAGE_VIDEOS'];
  53. $this->aInputs[$CNF['FIELD_VIDEO']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_VIDEO']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_VIDEO']]['value']) : $CNF['OBJECT_UPLOADERS'];
  54. $this->aInputs[$CNF['FIELD_VIDEO']]['images_transcoder'] = $CNF['OBJECT_VIDEOS_TRANSCODERS']['poster_preview'];
  55. $this->aInputs[$CNF['FIELD_VIDEO']]['storage_private'] = 0;
  56. $this->aInputs[$CNF['FIELD_VIDEO']]['multiple'] = true;
  57. $this->aInputs[$CNF['FIELD_VIDEO']]['content_id'] = 0;
  58. $this->aInputs[$CNF['FIELD_VIDEO']]['ghost_template'] = '';
  59. $this->aInputs[$CNF['FIELD_VIDEO']]['tr_attrs'] = array('class'=> 'bx-base-text-attachment-item');
  60. }
  61. if (isset($CNF['FIELD_FILE']) && isset($this->aInputs[$CNF['FIELD_FILE']])) {
  62. $this->aInputs[$CNF['FIELD_FILE']]['storage_object'] = $CNF['OBJECT_STORAGE_FILES'];
  63. $this->aInputs[$CNF['FIELD_FILE']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_FILE']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_FILE']]['value']) : $CNF['OBJECT_UPLOADERS'];
  64. $this->aInputs[$CNF['FIELD_FILE']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES'];
  65. $this->aInputs[$CNF['FIELD_FILE']]['storage_private'] = 0;
  66. $this->aInputs[$CNF['FIELD_FILE']]['multiple'] = true;
  67. $this->aInputs[$CNF['FIELD_FILE']]['content_id'] = 0;
  68. $this->aInputs[$CNF['FIELD_FILE']]['ghost_template'] = '';
  69. $this->aInputs[$CNF['FIELD_FILE']]['tr_attrs'] = array('class'=> 'bx-base-text-attachment-item');
  70. }
  71. if(isset($this->aInputs[$CNF['FIELD_POLL']])) {
  72. $this->aInputs[$CNF['FIELD_POLL']]['tr_attrs'] = array('class'=> 'bx-base-text-attachment-item');
  73. }
  74. }
  75. function getCode($bDynamicMode = false)
  76. {
  77. $sInclude = $this->_oModule->_oTemplate->addJs(array('entry.js'), $bDynamicMode);
  78. return ($bDynamicMode ? $sInclude : '') . $this->_oModule->_oTemplate->getJsCode('entry') . parent::getCode($bDynamicMode);
  79. }
  80. function initChecker ($aValues = array (), $aSpecificValues = array())
  81. {
  82. $CNF = &$this->_oModule->_oConfig->CNF;
  83. $aContentInfo = array();
  84. if($aValues && !empty($aValues['id']))
  85. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($aValues['id']);
  86. $bContentInfo = !empty($aContentInfo) && is_array($aContentInfo);
  87. if($bContentInfo)
  88. $this->_initCategoryFields($aContentInfo[$CNF['FIELD_CATEGORY']]);
  89. if(isset($CNF['FIELD_COVER']) && isset($this->aInputs[$CNF['FIELD_COVER']])) {
  90. if($bContentInfo)
  91. $this->aInputs[$CNF['FIELD_COVER']]['content_id'] = $aContentInfo[$CNF['FIELD_ID']];
  92. $this->aInputs[$CNF['FIELD_COVER']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateCover, $this->_getCoverGhostTmplVars($aContentInfo));
  93. }
  94. parent::initChecker ($aValues, $aSpecificValues);
  95. }
  96. public function insert ($aValsToAdd = array(), $isIgnore = false)
  97. {
  98. $CNF = &$this->_oModule->_oConfig->CNF;
  99. $iContentId = parent::insert ($aValsToAdd, $isIgnore);
  100. if(!empty($iContentId))
  101. $this->processFiles($CNF['FIELD_COVER'], $iContentId, true);
  102. return $iContentId;
  103. }
  104. public function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  105. {
  106. $CNF = &$this->_oModule->_oConfig->CNF;
  107. $iResult = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  108. $this->processFiles($CNF['FIELD_COVER'], $iContentId, false);
  109. return $iResult;
  110. }
  111. protected function genCustomInputCategoryView(&$aInput)
  112. {
  113. $CNF = &$this->_oModule->_oConfig->CNF;
  114. if(!empty($this->_iCategory)) {
  115. $aCategory = $this->_oModule->_oDb->getCategories(array('type' => 'id', 'id' => $this->_iCategory));
  116. if(!empty($aCategory) && is_array($aCategory))
  117. $aInput['value'] = bx_process_output(_t($aCategory['title']));
  118. }
  119. return $this->genInputStandard($aInput);
  120. }
  121. protected function genCustomViewRowValueCategoryView(&$aInput)
  122. {
  123. $CNF = &$this->_oModule->_oConfig->CNF;
  124. if(empty($aInput['value']))
  125. return '';
  126. $aCategory = $this->_oModule->_oDb->getCategories(array('type' => 'id', 'id' => $aInput['value']));
  127. if(empty($aCategory) || !is_array($aCategory))
  128. return '';
  129. $sLink = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_CATEGORIES'], array($CNF['GET_PARAM_CATEGORY'] => $aCategory['id']));
  130. return $this->_oModule->_oTemplate->parseLink($sLink, bx_process_output(_t($aCategory['title'])));
  131. }
  132. protected function genCustomViewRowValuePrice(&$aInput)
  133. {
  134. return isset($aInput['value']) && $aInput['value'] !== '' ? getParam('currency_sign') . bx_process_output($aInput['value']) : null;
  135. }
  136. protected function _getCoverGhostTmplVars($aContentInfo = array())
  137. {
  138. $CNF = &$this->_oModule->_oConfig->CNF;
  139. return array (
  140. 'name' => $this->aInputs[$CNF['FIELD_COVER']]['name'],
  141. 'content_id' => $this->aInputs[$CNF['FIELD_COVER']]['content_id'],
  142. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
  143. 'thumb_id' => isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : 0,
  144. 'name_thumb' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : ''
  145. );
  146. }
  147. protected function _getPhotoGhostTmplVars($aContentInfo = array())
  148. {
  149. $CNF = &$this->_oModule->_oConfig->CNF;
  150. return array (
  151. 'name' => $this->aInputs[$CNF['FIELD_PHOTO']]['name'],
  152. 'content_id' => (int)$this->aInputs[$CNF['FIELD_PHOTO']]['content_id'],
  153. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : ''
  154. );
  155. }
  156. protected function _initCategoryFields($iCategory = 0)
  157. {
  158. $CNF = &$this->_oModule->_oConfig->CNF;
  159. $this->_iCategory = (int)$iCategory;
  160. if(empty($this->_iCategory) && bx_get('category') !== false)
  161. $this->_iCategory = (int)bx_get('category');
  162. if(isset($CNF['FIELD_CATEGORY']) && isset($this->aInputs[$CNF['FIELD_CATEGORY']]) && $this->_iCategory != 0)
  163. $this->aInputs[$CNF['FIELD_CATEGORY']]['value'] = $this->_iCategory;
  164. if(isset($CNF['FIELD_CATEGORY_VIEW']) && isset($this->aInputs[$CNF['FIELD_CATEGORY_VIEW']]) && $this->_iCategory != 0)
  165. $this->aInputs[$CNF['FIELD_CATEGORY_VIEW']]['value'] = $this->_iCategory;
  166. if(isset($CNF['FIELD_CATEGORY_SELECT']) && isset($this->aInputs[$CNF['FIELD_CATEGORY_SELECT']]))
  167. $this->aInputs[$CNF['FIELD_CATEGORY_SELECT']]['values'] = $this->_oModule->serviceGetCategoryOptions(0, true);
  168. }
  169. }
  170. /** @} */