BxMarketFormEntry.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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 Market Market
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Create/Edit entry form
  13. */
  14. class BxMarketFormEntry extends BxBaseModTextFormEntry
  15. {
  16. protected $_bPhotoGhostCheckboxes;
  17. /*
  18. * Header Image and Icon fields shown in API forms only, the site sets them on view product page.
  19. */
  20. protected $_aImageFieldsApi;
  21. protected $_aContentInfoApi;
  22. public function __construct($aInfo, $oTemplate = false)
  23. {
  24. $this->MODULE = 'bx_market';
  25. parent::__construct($aInfo, $oTemplate);
  26. $CNF = &$this->_oModule->_oConfig->CNF;
  27. /*
  28. * Disabled since Header Image and Icon uploaders were moved on view product page.
  29. */
  30. $this->_bPhotoGhostCheckboxes = false;
  31. $iProfileId = bx_get_logged_profile_id();
  32. if(isset($this->aInputs[$CNF['FIELD_TITLE']], $this->aInputs[$CNF['FIELD_NAME']])) {
  33. $sJsObject = $this->_oModule->_oConfig->getJsObject('form');
  34. $aMask = array('mask' => "javascript:%s.checkName(this, '%s', '%s');", $sJsObject, $CNF['FIELD_TITLE'], $CNF['FIELD_NAME']);
  35. if($this->aParams['display'] == $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'] && bx_get('id') !== false) {
  36. $aMask['mask'] = "javascript:%s.checkName(this, '%s', '%s', %d);";
  37. $aMask[] = (int)bx_get('id');
  38. }
  39. $sOnBlur = call_user_func_array('sprintf', array_values($aMask));
  40. $this->aInputs[$CNF['FIELD_TITLE']]['attrs']['onblur'] = $sOnBlur;
  41. $this->aInputs[$CNF['FIELD_NAME']]['attrs']['onblur'] = $sOnBlur;
  42. }
  43. if(isset($this->aInputs[$CNF['FIELD_COVER_RAW']]))
  44. $this->aInputs[$CNF['FIELD_COVER_RAW']]['code'] = 1;
  45. if(isset($this->aInputs[$CNF['FIELD_FILE']])) {
  46. $this->aInputs[$CNF['FIELD_FILE']]['storage_object'] = $CNF['OBJECT_STORAGE_FILES'];
  47. $this->aInputs[$CNF['FIELD_FILE']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_FILE']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_FILE']]['value']) : $CNF['OBJECT_UPLOADERS'];
  48. $this->aInputs[$CNF['FIELD_FILE']]['images_transcoder'] = '';
  49. $this->aInputs[$CNF['FIELD_FILE']]['storage_private'] = 1;
  50. $this->aInputs[$CNF['FIELD_FILE']]['multiple'] = true;
  51. $this->aInputs[$CNF['FIELD_FILE']]['content_id'] = 0;
  52. $this->aInputs[$CNF['FIELD_FILE']]['ghost_template'] = '';
  53. }
  54. $bRecurring = $this->_oModule->_oDb->getParam($CNF['OPTION_ENABLE_RECURRING']) == 'on';
  55. if(!$bRecurring) {
  56. $this->aInputs[$CNF['FIELD_DURATION_RECURRING']]['type'] = 'hidden';
  57. $this->aInputs[$CNF['FIELD_PRICE_RECURRING']]['type'] = 'hidden';
  58. $this->aInputs[$CNF['FIELD_PRICE_RECURRING']]['value'] = 0;
  59. unset($this->aInputs[$CNF['FIELD_HEADER_BEG_RECURRING']]);
  60. unset($this->aInputs[$CNF['FIELD_HEADER_END_RECURRING']]);
  61. }
  62. $oPayment = BxDolPayments::getInstance();
  63. $bNoPayments = $this->_oModule->_oDb->getParam($CNF['PARAM_NO_PAYMENTS']) == 'on';
  64. if(isset($this->aInputs[$CNF['FIELD_WARNING_SINGLE']])) {
  65. if(!$bNoPayments && !$oPayment->isAcceptingPayments($iProfileId, BX_PAYMENT_TYPE_SINGLE))
  66. $this->aInputs[$CNF['FIELD_WARNING_SINGLE']]['value'] = MsgBox(_t($this->aInputs[$CNF['FIELD_WARNING_SINGLE']]['value'], $oPayment->getDetailsUrl()));
  67. else
  68. unset($this->aInputs[$CNF['FIELD_WARNING_SINGLE']]);
  69. }
  70. if(isset($this->aInputs[$CNF['FIELD_WARNING_RECURRING']])) {
  71. if(!$bNoPayments && $bRecurring && !$oPayment->isAcceptingPayments($iProfileId, BX_PAYMENT_TYPE_RECURRING))
  72. $this->aInputs[$CNF['FIELD_WARNING_RECURRING']]['value'] = MsgBox(_t($this->aInputs[$CNF['FIELD_WARNING_RECURRING']]['value'], $oPayment->getDetailsUrl()));
  73. else
  74. unset($this->aInputs[$CNF['FIELD_WARNING_RECURRING']]);
  75. }
  76. if(isset($this->aInputs[$CNF['FIELD_ALLOW_PURCHASE_TO']]))
  77. $this->aInputs[$CNF['FIELD_ALLOW_PURCHASE_TO']] = BxDolPrivacy::getGroupChooser($CNF['OBJECT_PRIVACY_PURCHASE']);
  78. $aDynamicGroups = array(
  79. array ('key' => '', 'value' => '----'),
  80. array ('key' => 'c', 'value' => _t('_bx_market_privacy_group_customers'))
  81. );
  82. if(isset($this->aInputs[$CNF['FIELD_ALLOW_COMMENT_TO']])) {
  83. $this->aInputs[$CNF['FIELD_ALLOW_COMMENT_TO']] = BxDolPrivacy::getGroupChooser($CNF['OBJECT_PRIVACY_COMMENT'], $iProfileId, array('dynamic_groups' => $aDynamicGroups));
  84. $this->aInputs[$CNF['FIELD_ALLOW_COMMENT_TO']]['db']['pass'] = 'Xss';
  85. }
  86. if(isset($this->aInputs[$CNF['FIELD_ALLOW_VOTE_TO']])) {
  87. $this->aInputs[$CNF['FIELD_ALLOW_VOTE_TO']] = BxDolPrivacy::getGroupChooser($CNF['OBJECT_PRIVACY_VOTE'], $iProfileId, array('dynamic_groups' => $aDynamicGroups));
  88. $this->aInputs[$CNF['FIELD_ALLOW_VOTE_TO']]['db']['pass'] = 'Xss';
  89. }
  90. if(isset($this->aInputs[$CNF['FIELD_SUBENTRIES']]) && $this->_oModule->checkAllowedSetSubentries() !== CHECK_ACTION_RESULT_ALLOWED)
  91. unset($this->aInputs[$CNF['FIELD_SUBENTRIES']]);
  92. $this->_aImageFieldsApi = [];
  93. $this->_aContentInfoApi = [];
  94. if($this->_bIsApi && $this->_oModule->checkAllowedSetCover() === CHECK_ACTION_RESULT_ALLOWED)
  95. $this->_addImageFieldsApi();
  96. }
  97. protected function _addImageFieldsApi()
  98. {
  99. $CNF = &$this->_oModule->_oConfig->CNF;
  100. if(getParam($CNF['PARAM_USE_ICON']) == 'on')
  101. $this->_aImageFieldsApi[$CNF['FIELD_THUMB']] = '_bx_market_form_entry_input_pictures_use_as_thumb';
  102. $this->_aImageFieldsApi[$CNF['FIELD_COVER']] = '_bx_market_form_entry_input_pictures_use_as_cover';
  103. // Tells the app how to show and crop the image, field names differ between modules.
  104. $aImageTypes = [
  105. $CNF['FIELD_THUMB'] => 'picture',
  106. $CNF['FIELD_COVER'] => 'cover',
  107. ];
  108. $aInputs = [];
  109. foreach($this->_aImageFieldsApi as $sField => $sCaption)
  110. $aInputs[$sField] = [
  111. 'type' => 'files',
  112. 'name' => $sField,
  113. 'caption' => _t($sCaption),
  114. 'image_type' => $aImageTypes[$sField],
  115. 'storage_object' => $CNF['OBJECT_STORAGE'],
  116. 'uploaders' => $CNF['OBJECT_UPLOADERS'],
  117. 'images_transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW'],
  118. 'storage_private' => 0,
  119. 'multiple' => false,
  120. 'content_id' => 0,
  121. 'ghost_template' => '',
  122. ];
  123. // Put them before product pictures.
  124. $iPos = array_search('pictures', array_keys($this->aInputs));
  125. if($iPos === false)
  126. $this->aInputs = array_merge($this->aInputs, $aInputs);
  127. else
  128. $this->aInputs = array_merge(array_slice($this->aInputs, 0, $iPos, true), $aInputs, array_slice($this->aInputs, $iPos, null, true));
  129. }
  130. public function getCodeAPI()
  131. {
  132. $aResult = parent::getCodeAPI();
  133. if(empty($this->_aImageFieldsApi) || empty($this->_aContentInfoApi) || empty($aResult['inputs']))
  134. return $aResult;
  135. $CNF = &$this->_oModule->_oConfig->CNF;
  136. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  137. if(!$oStorage)
  138. return $aResult;
  139. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  140. foreach($this->_aImageFieldsApi as $sField => $sCaption) {
  141. if(!isset($aResult['inputs'][$sField]) || !($iFileId = (int)($this->_aContentInfoApi[$sField] ?? 0)))
  142. continue;
  143. $aFile = $oStorage->getFile($iFileId);
  144. if(empty($aFile) || !is_array($aFile))
  145. continue;
  146. $sUrl = $oStorage->getFileUrlById($iFileId);
  147. $aResult['inputs'][$sField]['values_src'] = [[
  148. 'storage_object' => $CNF['OBJECT_STORAGE'],
  149. 'file_id' => $iFileId,
  150. 'file_type' => $aFile['mime_type'],
  151. 'file_name' => $aFile['file_name'],
  152. 'file_icon' => $oTranscoder ? $oTranscoder->getFileUrl($iFileId) : $sUrl,
  153. 'file_url' => $sUrl,
  154. ]];
  155. $aResult['inputs'][$sField]['value'] = (string)$iFileId;
  156. }
  157. return $aResult;
  158. }
  159. /**
  160. * Header Image and Icon ids submitted from API form: [field => file id], only for submitted fields.
  161. */
  162. protected function _getImageFieldsApiValues()
  163. {
  164. $aResult = [];
  165. foreach($this->_aImageFieldsApi as $sField => $sCaption) {
  166. $mixedValue = $this->getCleanValue($sField);
  167. if($mixedValue === false || $mixedValue === null)
  168. continue;
  169. if(!is_array($mixedValue))
  170. $mixedValue = $mixedValue !== '' ? explode(',', $mixedValue) : [];
  171. $aResult[$sField] = (int)array_pop($mixedValue);
  172. }
  173. return $aResult;
  174. }
  175. function getCode($bDynamicMode = false)
  176. {
  177. $sCss = '';
  178. $sJs = $this->_oModule->_oTemplate->addJs([
  179. 'form.js'
  180. ], $bDynamicMode);
  181. $sCode = '';
  182. if($bDynamicMode)
  183. $sCode .= $sCss . $sJs;
  184. $sCode .= $this->_oModule->_oTemplate->getJsCode('form');
  185. $sCode .= parent::getCode($bDynamicMode);
  186. return $sCode;
  187. }
  188. function initChecker ($aValues = array (), $aSpecificValues = array())
  189. {
  190. $CNF = &$this->_oModule->_oConfig->CNF;
  191. if(isset($this->aInputs[$CNF['FIELD_SUBENTRIES']]) && !empty($aValues[$CNF['FIELD_ID']])) {
  192. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION_SUBENTRIES']);
  193. if($oConnection)
  194. $this->aInputs[$CNF['FIELD_SUBENTRIES']]['value'] = $oConnection->getConnectedContent((int)$aValues[$CNF['FIELD_ID']]);
  195. }
  196. if(!empty($this->_aImageFieldsApi) && !empty($aValues[$CNF['FIELD_ID']]))
  197. $this->_aContentInfoApi = $aValues;
  198. return parent::initChecker($aValues, $aSpecificValues);
  199. }
  200. public function insert ($aValsToAdd = [], $isIgnore = false)
  201. {
  202. $CNF = &$this->_oModule->_oConfig->CNF;
  203. if(isset($this->aInputs[$CNF['FIELD_NAME']])) {
  204. $sName = BxDolForm::getSubmittedValue($CNF['FIELD_NAME'], $this->aFormAttrs['method'], $this->_aSpecificValues);
  205. if(!$sName && isset($this->aInputs[$CNF['FIELD_TITLE']]))
  206. $sName = BxDolForm::getSubmittedValue($CNF['FIELD_TITLE'], $this->aFormAttrs['method'], $this->_aSpecificValues);
  207. $sName = $this->_oModule->_oConfig->getEntryName($sName);
  208. BxDolForm::setSubmittedValue($CNF['FIELD_NAME'], $sName, $this->aFormAttrs['method'], $this->_aSpecificValues);
  209. }
  210. if($this->_oModule->checkAllowedSetCover() === CHECK_ACTION_RESULT_ALLOWED) {
  211. $aCover = isset($_POST[$CNF['FIELD_COVER']]) ? bx_process_input ($_POST[$CNF['FIELD_COVER']], BX_DATA_INT) : false;
  212. $aValsToAdd[$CNF['FIELD_COVER']] = 0;
  213. if(!empty($aCover) && is_array($aCover) && ($iFileCover = array_pop($aCover)))
  214. $aValsToAdd[$CNF['FIELD_COVER']] = $iFileCover;
  215. }
  216. if(!empty($this->_aImageFieldsApi))
  217. $aValsToAdd = array_merge($aValsToAdd, $this->_getImageFieldsApiValues());
  218. $aPackage = bx_process_input(bx_get($CNF['FIELD_PACKAGE']), BX_DATA_INT);
  219. $aValsToAdd[$CNF['FIELD_PACKAGE']] = 0;
  220. if(!empty($aPackage) && is_array($aPackage) && ($iFilePackage = array_pop($aPackage)))
  221. $aValsToAdd[$CNF['FIELD_PACKAGE']] = $iFilePackage;
  222. $iContentId = parent::insert ($aValsToAdd, $isIgnore);
  223. if(!empty($iContentId)) {
  224. $this->processFiles($CNF['FIELD_FILE'], $iContentId, true, $CNF['OBJECT_STORAGE_FILES']);
  225. // Cover is processed by parent.
  226. if(isset($this->_aImageFieldsApi[$CNF['FIELD_THUMB']]))
  227. $this->processFiles($CNF['FIELD_THUMB'], $iContentId, true);
  228. }
  229. return $iContentId;
  230. }
  231. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  232. {
  233. $CNF = &$this->_oModule->_oConfig->CNF;
  234. if(($sNameKey = $CNF['FIELD_NAME']) && isset($this->aInputs[$sNameKey])) {
  235. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  236. $bContentInfo = !empty($aContentInfo) && is_array($aContentInfo);
  237. $sName = $this->getCleanValue($sNameKey);
  238. if(!$sName) {
  239. if($bContentInfo && !empty($aContentInfo[$sNameKey])) {
  240. $sName = $aContentInfo[$sNameKey];
  241. BxDolForm::setSubmittedValue($sNameKey, $sName, $this->aFormAttrs['method'], $this->_aSpecificValues);
  242. }
  243. else if(($sTitleKey = $CNF['FIELD_TITLE']) && isset($this->aInputs[$sTitleKey]))
  244. $sName = $this->getCleanValue($sTitleKey);
  245. else
  246. $sName = 'ID' . time();
  247. }
  248. if($aContentInfo[$sNameKey] != $sName) {
  249. $sName = $this->_oModule->_oConfig->getEntryName($sName);
  250. BxDolForm::setSubmittedValue($sNameKey, $sName, $this->aFormAttrs['method'], $this->_aSpecificValues);
  251. }
  252. }
  253. $aImagesApi = [];
  254. if(!empty($this->_aImageFieldsApi)) {
  255. $aImagesApi = $this->_getImageFieldsApiValues();
  256. $aValsToAdd = array_merge($aValsToAdd, $aImagesApi);
  257. }
  258. else {
  259. $bSetImage = $this->_oModule->checkAllowedSetCover() === CHECK_ACTION_RESULT_ALLOWED; //--- Allow to set both Thumb and Cover.
  260. foreach(['FIELD_THUMB', 'FIELD_COVER'] as $sKey)
  261. if($bSetImage && ($aImage = bx_get($CNF[$sKey])) !== false) {
  262. $aImage = bx_process_input($aImage, BX_DATA_INT);
  263. $aValsToAdd[$CNF[$sKey]] = 0;
  264. if(!empty($aImage) && is_array($aImage) && ($iFileImage = array_pop($aImage)))
  265. $aValsToAdd[$CNF[$sKey]] = $iFileImage;
  266. }
  267. }
  268. $aPackage = bx_process_input(bx_get($CNF['FIELD_PACKAGE']), BX_DATA_INT);
  269. $aValsToAdd[$CNF['FIELD_PACKAGE']] = 0;
  270. if(!empty($aPackage) && is_array($aPackage) && ($iFilePackage = array_pop($aPackage)))
  271. $aValsToAdd[$CNF['FIELD_PACKAGE']] = $iFilePackage;
  272. $aContentInfoOld = !empty($aImagesApi) ? $this->_oModule->_oDb->getContentInfoById($iContentId) : [];
  273. $iResult = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  274. $this->processFiles($CNF['FIELD_FILE'], $iContentId, false, $CNF['OBJECT_STORAGE_FILES']);
  275. // Images change only with the saved product: on a failed save the old files stay in use.
  276. if($iResult !== false && !empty($aImagesApi)) {
  277. /*
  278. * API image fields have no content_id, so a file uploaded while editing is a ghost
  279. * with content_id = 0: associate it (only submitted ids are taken), otherwise
  280. * the ghost gets cleaned up and the field points to a deleted file.
  281. */
  282. foreach($aImagesApi as $sField => $iFileId)
  283. if($iFileId)
  284. $this->processFiles($sField, $iContentId, true);
  285. // The same as BxMarketModule::actionUpdateImage does: drop the replaced file and the cover position.
  286. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  287. foreach($aImagesApi as $sField => $iFileId) {
  288. $iFileIdOld = (int)($aContentInfoOld[$sField] ?? 0);
  289. if($iFileIdOld == $iFileId)
  290. continue;
  291. if($sField == $CNF['FIELD_COVER'])
  292. $this->_oModule->serviceUpdateImagePosition($iContentId, $sField, '', '');
  293. // Keep the file if it's still used as the other image.
  294. $bUsed = false;
  295. foreach(array_keys($this->_aImageFieldsApi) as $sFieldOther)
  296. if($sFieldOther != $sField && (int)($aImagesApi[$sFieldOther] ?? ($aContentInfoOld[$sFieldOther] ?? 0)) == $iFileIdOld)
  297. $bUsed = true;
  298. if($iFileIdOld && !$bUsed && $oStorage)
  299. $oStorage->deleteFile($iFileIdOld);
  300. }
  301. }
  302. return $iResult;
  303. }
  304. function delete ($iContentId, $aContentInfo = array())
  305. {
  306. $CNF = &$this->_oModule->_oConfig->CNF;
  307. $bResult = parent::delete($iContentId, $aContentInfo);
  308. if(!$bResult)
  309. return $bResult;
  310. // delete associated files
  311. if (!empty($CNF['OBJECT_STORAGE_FILES'])) {
  312. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_FILES']);
  313. if($oStorage)
  314. $oStorage->queueFilesForDeletionFromGhosts($aContentInfo[$CNF['FIELD_AUTHOR']], $iContentId);
  315. }
  316. // delete associations
  317. $bResult &= $this->_oModule->_oDb->deassociatePhotoWithContent($iContentId, 0);
  318. $bResult &= $this->_oModule->_oDb->deassociateFileWithContent($iContentId, 0);
  319. return $bResult;
  320. }
  321. protected function _associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId, $sPictureField = '')
  322. {
  323. parent::_associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId, $sPictureField);
  324. $sStorage = $oStorage->getObject();
  325. switch($sStorage) {
  326. case $this->_oModule->_oConfig->CNF['OBJECT_STORAGE']:
  327. $this->_oModule->_oDb->associatePhotoWithContent($iContentId, $iFileId, $this->getCleanValue('title-' . $iFileId));
  328. break;
  329. case $this->_oModule->_oConfig->CNF['OBJECT_STORAGE_FILES']:
  330. $aParams = array(
  331. 'type' => $this->getCleanValue('type-' . $iFileId)
  332. );
  333. switch ($aParams['type']) {
  334. case BX_MARKET_FILE_TYPE_VERSION:
  335. $aParams = array_merge($aParams, array(
  336. 'version' => $this->getCleanValue('version-' . $iFileId),
  337. ));
  338. break;
  339. case BX_MARKET_FILE_TYPE_UPDATE:
  340. $aParams = array_merge($aParams, array(
  341. 'version' => $this->getCleanValue('version-from-' . $iFileId),
  342. 'version_to' => $this->getCleanValue('version-to-' . $iFileId),
  343. ));
  344. break;
  345. }
  346. $this->_oModule->_oDb->associateFileWithContent($iContentId, $iFileId, $aParams);
  347. break;
  348. }
  349. }
  350. protected function _getPhotoGhostTmplVars($aContentInfo = [])
  351. {
  352. $CNF = &$this->_oModule->_oConfig->CNF;
  353. $aResult = parent::_getPhotoGhostTmplVars($aContentInfo);
  354. if(!empty($aResult['bx_if:set_thumb']))
  355. $aResult['bx_if:set_thumb']['condition'] = $this->_bPhotoGhostCheckboxes && $aResult['bx_if:set_thumb']['condition'];
  356. return array_merge($aResult, [
  357. 'thumb_id' => $aContentInfo[$CNF['FIELD_THUMB']] ?? 0,
  358. 'cover_id' => $aContentInfo[$CNF['FIELD_COVER']] ?? 0,
  359. 'bx_if:set_cover' => [
  360. 'condition' => $this->_bPhotoGhostCheckboxes && $this->_oModule->checkAllowedSetCover() === CHECK_ACTION_RESULT_ALLOWED,
  361. 'content' => [
  362. 'name_cover' => $CNF['FIELD_COVER'],
  363. ]
  364. ]
  365. ]);
  366. }
  367. protected function _getFileGhostTmplVars($aContentInfo = array())
  368. {
  369. $CNF = &$this->_oModule->_oConfig->CNF;
  370. $aResult = parent::_getFileGhostTmplVars($aContentInfo);
  371. $aResult = array_merge($aResult, array(
  372. 'thumb_id' => isset($aContentInfo[$CNF['FIELD_PACKAGE']]) ? $aContentInfo[$CNF['FIELD_PACKAGE']] : 0,
  373. 'bx_if:set_thumb' => array (
  374. 'condition' => true,
  375. 'content' => array(
  376. 'name_thumb' => $CNF['FIELD_PACKAGE'],
  377. ),
  378. ),
  379. ));
  380. return $aResult;
  381. }
  382. function genInputPrice(&$aInput)
  383. {
  384. $CNF = &$this->_oModule->_oConfig->CNF;
  385. if(!isset($aInput['value_currency'])) {
  386. $iAuthorId = 0;
  387. if(!empty($this->_iContentId)) {
  388. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_iContentId);
  389. if(!empty($aContentInfo) || is_array($aContentInfo))
  390. $iAuthorId = $aContentInfo[$CNF['FIELD_AUTHOR']];
  391. }
  392. else
  393. $iAuthorId = bx_get_logged_profile_id();
  394. $aInput['value_currency'] = BxDolPayments::getInstance()->getCurrencyCode($iAuthorId);
  395. }
  396. return parent::genInputPrice($aInput);
  397. }
  398. protected function genCustomInputSubentries ($aInput)
  399. {
  400. $CNF = &$this->_oModule->_oConfig->CNF;
  401. $aInput['ajax_get_suggestions'] = BX_DOL_URL_ROOT . $this->_oModule->_oConfig->getBaseUri() . 'get_subentries';
  402. $aInput['placeholder'] = _t('_bx_market_form_entry_input_subentries_placeholder');
  403. $sVals = '';
  404. if(!empty($aInput['value']) && is_array($aInput['value'])) {
  405. foreach($aInput['value'] as $iValue) {
  406. $iValue = (int)$iValue;
  407. if(!$iValue)
  408. continue;
  409. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iValue);
  410. if(empty($aContentInfo) || !is_array($aContentInfo))
  411. continue;
  412. $sVals .= '<b class="val bx-def-color-bg-hl bx-def-round-corners">' . $aContentInfo[$CNF['FIELD_TITLE']] . '<i class="sys-icon times ltr:ml-1 rtl:mr-1"></i><input type="hidden" name="' . $aInput['name'] . '[]" value="' . $iValue . '" /></b>';
  413. }
  414. $sVals = trim($sVals, ',');
  415. }
  416. $aInput['value'] = $sVals;
  417. return $this->genCustomInputUsernamesSuggestions($aInput);
  418. }
  419. }
  420. /** @} */