BxAdsModule.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332
  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. define('BX_ADS_STATUS_ACTIVE', 'active');
  12. define('BX_ADS_STATUS_HIDDEN', 'hidden');
  13. define('BX_ADS_STATUS_PENDING', 'pending');
  14. define('BX_ADS_OFFER_STATUS_ACCEPTED', 'accepted');
  15. define('BX_ADS_OFFER_STATUS_AWAITING', 'awaiting');
  16. define('BX_ADS_OFFER_STATUS_DECLINED', 'declined');
  17. /**
  18. * Ads module
  19. */
  20. class BxAdsModule extends BxBaseModTextModule
  21. {
  22. protected $_aOfferStatuses;
  23. function __construct(&$aModule)
  24. {
  25. parent::__construct($aModule);
  26. $this->_oConfig->init($this->_oDb);
  27. $CNF = &$this->_oConfig->CNF;
  28. $this->_aSearchableNamesExcept = array_merge($this->_aSearchableNamesExcept, array(
  29. $CNF['FIELD_CATEGORY_VIEW'],
  30. $CNF['FIELD_CATEGORY_SELECT']
  31. ));
  32. $this->_aOfferStatuses = array(
  33. BX_ADS_OFFER_STATUS_ACCEPTED,
  34. BX_ADS_OFFER_STATUS_AWAITING,
  35. BX_ADS_OFFER_STATUS_DECLINED
  36. );
  37. }
  38. public function actionGetCategoryForm()
  39. {
  40. if(bx_get('category') === false)
  41. return echoJson(array());
  42. return echoJson(array(
  43. 'content' => $this->serviceGetCreatePostForm(array(
  44. 'absolute_action_url' => true,
  45. 'dynamic_mode' => true
  46. ))
  47. ));
  48. }
  49. public function actionCheckName()
  50. {
  51. $CNF = &$this->_oConfig->CNF;
  52. $sName = '';
  53. $sTitle = bx_process_input(bx_get($CNF['FIELD_TITLE']));
  54. if(empty($sTitle))
  55. return echoJson(array());
  56. $iId = (int)bx_get($CNF['FIELD_ID']);
  57. if(!empty($iId)) {
  58. $aEntry = $this->_oDb->getContentInfoById($iId);
  59. if(strcmp($sTitle, $aEntry[$CNF['FIELD_NAME']]) == 0)
  60. $sName = $sTitle;
  61. }
  62. echoJson(array(
  63. 'title' => $sTitle,
  64. 'name' => !empty($sName) ? $sName : $this->_oConfig->getEntryName($sTitle, $iId)
  65. ));
  66. }
  67. public function actionInterested()
  68. {
  69. $CNF = &$this->_oConfig->CNF;
  70. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  71. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  72. if(empty($aContentInfo) || !is_array($aContentInfo))
  73. return echoJson(array());
  74. $iViewer = bx_get_logged_profile_id();
  75. $oViewer = BxDolProfile::getInstance($iViewer);
  76. if(!$oViewer)
  77. return echoJson(array());
  78. $iContentAuthor = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  79. if($iContentAuthor == $iViewer)
  80. return echoJson(array('msg' => _t('_bx_ads_txt_err_your_own')));
  81. if($this->_oDb->isInterested($iContentId, $iViewer))
  82. return echoJson(array('msg' => _t('_bx_ads_txt_err_duplicate')));
  83. $iInterestId = $this->_oDb->insertInterested(array('entry_id' => $iContentId, 'profile_id' => $iViewer));
  84. if(!$iInterestId)
  85. return echoJson(array('msg' => _t('_bx_ads_txt_err_cannot_perform_action')));
  86. bx_alert($this->getName(), 'doInterest', $iContentId, $iViewer, array(
  87. 'subobject_id' => $iInterestId,
  88. 'subobject_author_id' => $iViewer,
  89. 'object_author_id' => $iContentAuthor
  90. ));
  91. if(getParam($CNF['PARAM_USE_IIN']) == 'on')
  92. sendMailTemplate($CNF['ETEMPLATE_INTERESTED'], 0, $iContentAuthor, array(
  93. 'viewer_name' => $oViewer->getDisplayName(),
  94. 'viewer_url' => $oViewer->getUrl(),
  95. 'ad_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  96. 'ad_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  97. 'i' => $CNF['URI_VIEW_ENTRY'],
  98. $CNF['FIELD_ID'] => $iContentId
  99. ))
  100. ));
  101. return echoJson(array('msg' => _t('_bx_ads_txt_msg_author_notified')));
  102. }
  103. public function actionMakeOffer()
  104. {
  105. $CNF = &$this->_oConfig->CNF;
  106. $sJsObject = $this->_oConfig->getJsObject('entry');
  107. $iAuthorId = bx_get_logged_profile_id();
  108. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  109. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  110. if(empty($aContentInfo) || !is_array($aContentInfo))
  111. return echoJson(array());
  112. $aOffer = $this->_oDb->getOffersBy(array(
  113. 'type' => 'content_and_author_ids',
  114. 'content_id' => $iContentId,
  115. 'author_id' => $iAuthorId,
  116. 'status' => BX_ADS_OFFER_STATUS_AWAITING
  117. ));
  118. if(!empty($aOffer) && is_array($aOffer))
  119. return echoJson(array('code' => 1, 'msg' => _t('_bx_ads_txt_err_duplicate')));
  120. $aOffer = $this->_oDb->getOffersBy(array(
  121. 'type' => 'content_and_author_ids',
  122. 'content_id' => $iContentId,
  123. 'author_id' => $iAuthorId,
  124. 'status' => BX_ADS_OFFER_STATUS_ACCEPTED
  125. ));
  126. if(!empty($aOffer) && is_array($aOffer))
  127. return echoJson(array('code' => 1, 'msg' => _t('_bx_ads_txt_err_offer_accepted')));
  128. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_OFFER'], $CNF['OBJECT_FORM_OFFER_DISPLAY_ADD']);
  129. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . bx_append_url_params($this->_oConfig->getBaseUri() . 'make_offer', array('id' => $iContentId));
  130. $oForm->initChecker();
  131. if($oForm->isSubmittedAndValid()) {
  132. $aValToAdd = array('content_id' => $iContentId, 'author_id' => $iAuthorId);
  133. $iId = (int)$oForm->insert($aValToAdd);
  134. if($iId != 0)
  135. $aResult = array('code' => 0, 'msg' => _t('_bx_ads_txt_msg_offer_added'), 'eval' => $sJsObject . '.onMakeOffer(oData);', 'id' => $iId);
  136. else
  137. $aResult = array('code' => 2, 'msg' => _t('_bx_ads_txt_err_cannot_perform_action'));
  138. $this->onOfferAdded($iId);
  139. return echoJson($aResult);
  140. }
  141. $sContent = BxTemplFunctions::getInstance()->transBox($this->_oConfig->getHtmlIds('offer_popup'), $this->_oTemplate->parseHtmlByName('offer_popup.html', array(
  142. 'form_id' => $oForm->getId(),
  143. 'form' => $oForm->getCode(true)
  144. )));
  145. return echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false, 'removeOnClose' => true))));
  146. }
  147. public function serviceGetSafeServices()
  148. {
  149. $a = parent::serviceGetSafeServices();
  150. return array_merge($a, array (
  151. 'EntityReviews' => '',
  152. 'EntityReviewsRating' => '',
  153. 'CategoriesList' => '',
  154. 'BrowseCategory' => '',
  155. ));
  156. }
  157. public function serviceUpdateCategoriesStats()
  158. {
  159. $aStats = $this->_oDb->getCategories(array('type' => 'collect_stats'));
  160. if(empty($aStats) || !is_array($aStats))
  161. return true;
  162. $iUpdated = 0;
  163. foreach($aStats as $aStat)
  164. if($this->_oDb->updateCategory(array('items' => $aStat['count']), array('id' => $aStat['id'])))
  165. $iUpdated++;
  166. return count($aStats) == $iUpdated;
  167. }
  168. public function serviceGetCategoryOptions($iParentId, $bPleaseSelect = false)
  169. {
  170. $aValues = array();
  171. if($bPleaseSelect)
  172. $aValues[] = array('key' => '', 'value' => _t('_sys_please_select'));
  173. $this->_getCategoryOptions($iParentId, $aValues);
  174. return $aValues;
  175. }
  176. public function serviceGetSearchableFields($aInputsAdd = array())
  177. {
  178. $CNF = &$this->_oConfig->CNF;
  179. $aResult = parent::serviceGetSearchableFields(array_merge($aInputsAdd, $this->_getSearchableFields()));
  180. unset($aResult[$CNF['FIELD_NOTES_PURCHASED']]);
  181. unset($aResult[$CNF['FIELD_CATEGORY_VIEW']], $aResult[$CNF['FIELD_CATEGORY_SELECT']]);
  182. unset($aResult[$CNF['FIELD_PRICE']], $aResult[$CNF['FIELD_YEAR']]);
  183. return $aResult;
  184. }
  185. public function serviceGetSearchableFieldsExtended($aInputsAdd = array())
  186. {
  187. $CNF = &$this->_oConfig->CNF;
  188. $aInputsAdd = array_merge($aInputsAdd, $this->_getSearchableFields());
  189. if(isset($aInputsAdd[$CNF['FIELD_CATEGORY']])) {
  190. $aInputsAdd[$CNF['FIELD_CATEGORY']]['type'] = 'select';
  191. $aInputsAdd[$CNF['FIELD_CATEGORY']]['values_src'] = BxDolService::getSerializedService($this->_oConfig->getName(), 'get_category_options', array(0));
  192. }
  193. if(isset($aInputsAdd[$CNF['FIELD_PRICE']])) {
  194. $aInputsAdd[$CNF['FIELD_PRICE']]['search_type'] = 'text_range';
  195. $aInputsAdd[$CNF['FIELD_PRICE']]['search_operator'] = 'between';
  196. }
  197. if(isset($aInputsAdd[$CNF['FIELD_YEAR']])) {
  198. $aInputsAdd[$CNF['FIELD_YEAR']]['search_type'] = 'text_range';
  199. $aInputsAdd[$CNF['FIELD_YEAR']]['search_operator'] = 'between';
  200. }
  201. return parent::serviceGetSearchableFieldsExtended($aInputsAdd);
  202. }
  203. public function serviceEntityCreate ($sParams = false)
  204. {
  205. if(($sDisplay = $this->getCategoryDisplay('add')) !== false) {
  206. if(empty($sParams) || !is_array($sParams))
  207. $sParams = array();
  208. $sParams['display'] = $sDisplay;
  209. }
  210. return parent::serviceEntityCreate($sParams);
  211. }
  212. /**
  213. * @page service Service Calls
  214. * @section bx_ads Ads
  215. * @subsection bx_ads-page_blocks Page Blocks
  216. * @subsubsection bx_ads-entity_reviews entity_reviews
  217. *
  218. * @code bx_srv('bx_ads', 'entity_reviews', [...]); @endcode
  219. *
  220. * Get reviews for particular content
  221. * @param $iContentId content ID
  222. *
  223. * @see BxAdsModule::serviceEntityReviews
  224. */
  225. /**
  226. * @ref bx_ads-entity_reviews "entity_reviews"
  227. */
  228. public function serviceEntityReviews($iContentId = 0)
  229. {
  230. $CNF = &$this->_oConfig->CNF;
  231. if(empty($CNF['OBJECT_REVIEWS']))
  232. return false;
  233. return $this->_entityComments($CNF['OBJECT_REVIEWS'], $iContentId);
  234. }
  235. /**
  236. * @page service Service Calls
  237. * @section bx_ads Ads
  238. * @subsection bx_ads-page_blocks Page Blocks
  239. * @subsubsection bx_ads-entity_reviews_rating entity_reviews_rating
  240. *
  241. * @code bx_srv('bx_ads', 'entity_reviews_rating', [...]); @endcode
  242. *
  243. * Get reviews rating for particular content
  244. * @param $iContentId content ID
  245. *
  246. * @see BxAdsModule::serviceEntityReviewsRating
  247. */
  248. /**
  249. * @ref bx_ads-entity_reviews_rating "entity_reviews_rating"
  250. */
  251. public function serviceEntityReviewsRating($iContentId = 0)
  252. {
  253. $CNF = &$this->_oConfig->CNF;
  254. if(empty($CNF['OBJECT_REVIEWS']))
  255. return false;
  256. if(!$iContentId)
  257. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  258. if(!$iContentId)
  259. return false;
  260. $oCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_REVIEWS'], $iContentId);
  261. if (!$oCmts || !$oCmts->isEnabled())
  262. return false;
  263. return $oCmts->getRatingBlock(array('in_designbox' => false));
  264. }
  265. /**
  266. * @page service Service Calls
  267. * @section bx_ads Ads
  268. * @subsection bx_ads-page_blocks Page Blocks
  269. * @subsubsection bx_ads-categories_list categories_list
  270. *
  271. * @code bx_srv('bx_ads', 'categories_list', [...]); @endcode
  272. *
  273. * Get reviews rating for particular content
  274. * @param $aParams additional params array, such as 'show_empty'
  275. *
  276. * @see BxAdsModule::serviceCategoriesList
  277. */
  278. /**
  279. * @ref bx_ads-categories_list "categories_list"
  280. */
  281. public function serviceCategoriesList($aParams = array())
  282. {
  283. if(!isset($aParams['show_empty']))
  284. $aParams['show_empty'] = true;
  285. return $this->_oTemplate->categoriesList($aParams);
  286. }
  287. /**
  288. * @page service Service Calls
  289. * @section bx_ads Ads
  290. * @subsection bx_ads-browse Browse
  291. * @subsubsection bx_ads-browse_category browse_category
  292. *
  293. * @code bx_srv('bx_ads', 'browse_category', [...]); @endcode
  294. *
  295. * Get reviews rating for particular content
  296. * @param $iCategoryId category ID
  297. * @param $aParams additional params array, such as empty_message, ajax_paginate, etc
  298. *
  299. * @see BxAdsModule::serviceBrowseCategory
  300. */
  301. /**
  302. * @ref bx_ads-browse_category "browse_category"
  303. */
  304. public function serviceBrowseCategory($iCategoryId = 0, $aParams = array())
  305. {
  306. $sParamName = $sParamGet = 'category';
  307. if(!$iCategoryId && bx_get($sParamGet) !== false)
  308. $iCategoryId = bx_process_input(bx_get($sParamGet), BX_DATA_INT);
  309. $bEmptyMessage = true;
  310. if(isset($aParams['empty_message'])) {
  311. $bEmptyMessage = (bool)$aParams['empty_message'];
  312. unset($aParams['empty_message']);
  313. }
  314. $bAjaxPaginate = true;
  315. if(isset($aParams['ajax_paginate'])) {
  316. $bAjaxPaginate = (bool)$aParams['ajax_paginate'];
  317. unset($aParams['ajax_paginate']);
  318. }
  319. $aBlock = $this->_serviceBrowse ($sParamName, array_merge(array($sParamName => $iCategoryId), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  320. if(!empty($aBlock['content'])) {
  321. $aCategory = $this->_oDb->getCategories(array('type' => 'id', 'id' => $iCategoryId));
  322. if(!empty($aCategory['title']))
  323. $aBlock['title'] = _t('_bx_ads_page_block_title_entries_by_category_mask', _t($aCategory['title']));
  324. }
  325. return $aBlock;
  326. }
  327. public function serviceGetNotificationsData()
  328. {
  329. $sModule = $this->_aModule['name'];
  330. $sEventPrivacy = $sModule . '_allow_view_event_to';
  331. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  332. $sEventPrivacy = '';
  333. $aResult = parent::serviceGetNotificationsData();
  334. $aResult['handlers'] = array_merge($aResult['handlers'], array(
  335. array('group' => $sModule . '_interest', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doInterest', 'module_name' => $sModule, 'module_method' => 'get_notifications_interest', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy)
  336. ));
  337. $aResult['settings'] = array_merge($aResult['settings'], array(
  338. array('group' => 'interest', 'unit' => $sModule, 'action' => 'doInterest', 'types' => array('personal'))
  339. ));
  340. $aResult['alerts'] = array_merge($aResult['alerts'], array(
  341. array('unit' => $sModule, 'action' => 'doInterest')
  342. ));
  343. return $aResult;
  344. }
  345. public function serviceGetNotificationsInterest($aEvent)
  346. {
  347. $CNF = &$this->_oConfig->CNF;
  348. $iContentId = (int)$aEvent['object_id'];
  349. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  350. if(empty($aContentInfo) || !is_array($aContentInfo))
  351. return array();
  352. $iInterestedId = (int)$aEvent['subobject_id'];
  353. $aInterestedInfo = $this->_oDb->getInterested(array('type' => 'id', 'id' => $iInterestedId));
  354. if(empty($aInterestedInfo) || !is_array($aInterestedInfo))
  355. return array();
  356. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
  357. return array(
  358. 'entry_sample' => $CNF['T']['txt_sample_single'],
  359. 'entry_url' => $sEntryUrl,
  360. 'entry_caption' => $aContentInfo[$CNF['FIELD_TITLE']],
  361. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  362. 'subentry_sample' => $CNF['T']['txt_sample_interest_single'],
  363. 'subentry_url' => '',
  364. 'lang_key' => '_bx_ads_txt_ntfs_subobject_interested', //may be empty or not specified. In this case the default one from Notification module will be used.
  365. );
  366. }
  367. /**
  368. * @page service Service Calls
  369. * @section bx_ads Ads
  370. * @subsection bx_ads-page_blocks Page Blocks
  371. * @subsubsection bx_ads-block_licenses block_licenses
  372. *
  373. * @code bx_srv('bx_ads', 'block_licenses', [...]); @endcode
  374. *
  375. * Get page block with a list of licenses purchased by currently logged member.
  376. *
  377. * @return an array describing a block to display on the site or false if there is no enough input data. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  378. *
  379. * @see BxAdsModule::serviceBlockLicenses
  380. */
  381. /**
  382. * @ref bx_ads-block_licenses "block_licenses"
  383. */
  384. public function serviceBlockLicenses()
  385. {
  386. return $this->_getBlockLicenses();
  387. }
  388. /**
  389. * @page service Service Calls
  390. * @section bx_ads Ads
  391. * @subsection bx_ads-page_blocks Page Blocks
  392. * @subsubsection bx_ads-block_licenses_administration block_licenses_administration
  393. *
  394. * @code bx_srv('bx_ads', 'block_licenses_administration', [...]); @endcode
  395. *
  396. * Get page block with a list of all licenses. It's needed for moderators/administrators.
  397. *
  398. * @return an array describing a block to display on the site or false if there is no enough input data. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  399. *
  400. * @see BxAdsModule::serviceBlockLicensesAdministration
  401. */
  402. /**
  403. * @ref bx_ads-block_licenses "block_licenses"
  404. */
  405. public function serviceBlockLicensesAdministration()
  406. {
  407. return $this->_getBlockLicenses('administration');
  408. }
  409. /**
  410. * @page service Service Calls
  411. * @section bx_ads Ads
  412. * @subsection bx_ads-page_blocks Page Blocks
  413. * @subsubsection bx_ads-block_licenses_note block_licenses_note
  414. *
  415. * @code bx_srv('bx_ads', 'block_licenses_note', [...]); @endcode
  416. *
  417. * Get page block with a notice for licenses usage.
  418. *
  419. * @return HTML string with block content to display on the site.
  420. *
  421. * @see BxAdsModule::serviceBlockLicensesNote
  422. */
  423. /**
  424. * @ref bx_ads-block_licenses_note "block_licenses_note"
  425. */
  426. public function serviceBlockLicensesNote()
  427. {
  428. return MsgBox(_t('_bx_ads_page_block_content_licenses_note'));
  429. }
  430. /**
  431. * @page service Service Calls
  432. * @section bx_ads Ads
  433. * @subsection bx_ads-payments Payments
  434. * @subsubsection bx_ads-get_payment_data get_payment_data
  435. *
  436. * @code bx_srv('bx_ads', 'get_payment_data', [...]); @endcode
  437. *
  438. * Get an array with module's description. Is needed for payments processing module.
  439. *
  440. * @return an array with module's description.
  441. *
  442. * @see BxAdsModule::serviceGetPaymentData
  443. */
  444. /**
  445. * @ref bx_ads-get_payment_data "get_payment_data"
  446. */
  447. public function serviceGetPaymentData()
  448. {
  449. $CNF = &$this->_oConfig->CNF;
  450. $oPermalink = BxDolPermalinks::getInstance();
  451. $aResult = $this->_aModule;
  452. $aResult['url_browse_order_common'] = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_LICENSES_COMMON'], array('filter' => '{order}'));
  453. $aResult['url_browse_order_administration'] = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_LICENSES_ADMINISTRATION'], array('filter' => '{order}'));
  454. return $aResult;
  455. }
  456. /**
  457. * @page service Service Calls
  458. * @section bx_ads Ads
  459. * @subsection bx_ads-payments Payments
  460. * @subsubsection bx_ads-get_cart_item get_cart_item
  461. *
  462. * @code bx_srv('bx_ads', 'get_cart_item', [...]); @endcode
  463. *
  464. * Get an array with prodict's description. Is used in Shopping Cart in payments processing module.
  465. *
  466. * @param $mixedItemId product's ID or Unique Name.
  467. * @return an array with prodict's description. Empty array is returned if something is wrong.
  468. *
  469. * @see BxAdsModule::serviceGetCartItem
  470. */
  471. /**
  472. * @ref bx_ads-get_cart_item "get_cart_item"
  473. */
  474. public function serviceGetCartItem($mixedItemId)
  475. {
  476. $CNF = &$this->_oConfig->CNF;
  477. if(!$mixedItemId)
  478. return array();
  479. if(is_numeric($mixedItemId))
  480. $aItem = $this->_oDb->getContentInfoById((int)$mixedItemId);
  481. else
  482. $aItem = $this->_oDb->getContentInfoByName($mixedItemId);
  483. if(empty($aItem) || !is_array($aItem))
  484. return array();
  485. $iItemId = (int)$aItem[$CNF['FIELD_ID']];
  486. $fItemPrice = (float)$aItem[$CNF['FIELD_PRICE']];
  487. if($this->isAuction($aItem)) {
  488. $iUserId = bx_get_logged_profile_id();
  489. $aOffer = $this->_oDb->getOffersBy(array(
  490. 'type' => 'content_and_author_ids',
  491. 'content_id' => $iItemId,
  492. 'author_id' => $iUserId,
  493. 'status' => BX_ADS_OFFER_STATUS_ACCEPTED
  494. ));
  495. if(!empty($aOffer) && is_array($aOffer))
  496. $fItemPrice = (float)$aOffer[$CNF['FIELD_OFR_AMOUNT']];
  497. }
  498. return array (
  499. 'id' => $iItemId,
  500. 'author_id' => $aItem[$CNF['FIELD_AUTHOR']],
  501. 'name' => $aItem[$CNF['FIELD_NAME']],
  502. 'title' => $aItem[$CNF['FIELD_TITLE']],
  503. 'description' => $aItem[$CNF['FIELD_TEXT']],
  504. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'], array('id' => $aItem[$CNF['FIELD_ID']])),
  505. 'price_single' => $fItemPrice,
  506. 'price_recurring' => '',
  507. 'period_recurring' => 0,
  508. 'period_unit_recurring' => '',
  509. 'trial_recurring' => ''
  510. );
  511. }
  512. /**
  513. * @page service Service Calls
  514. * @section bx_ads Ads
  515. * @subsection bx_ads-payments Payments
  516. * @subsubsection bx_ads-get_cart_items get_cart_items
  517. *
  518. * @code bx_srv('bx_ads', 'get_cart_items', [...]); @endcode
  519. *
  520. * Get an array with prodicts' descriptions by seller. Is used in Manual Order Processing in payments processing module.
  521. *
  522. * @param $iSellerId seller ID.
  523. * @return an array with prodicts' descriptions. Empty array is returned if something is wrong or seller doesn't have any products.
  524. *
  525. * @see BxAdsModule::serviceGetCartItems
  526. */
  527. /**
  528. * @ref bx_ads-get_cart_items "get_cart_items"
  529. */
  530. public function serviceGetCartItems($iSellerId)
  531. {
  532. $CNF = &$this->_oConfig->CNF;
  533. $iSellerId = (int)$iSellerId;
  534. if(empty($iSellerId))
  535. return array();
  536. $aItems = $this->_oDb->getEntriesByAuthor($iSellerId);
  537. $aResult = array();
  538. foreach($aItems as $aItem)
  539. $aResult[] = array(
  540. 'id' => $aItem[$CNF['FIELD_ID']],
  541. 'author_id' => $aItem[$CNF['FIELD_AUTHOR']],
  542. 'name' => $aItem[$CNF['FIELD_NAME']],
  543. 'title' => $aItem[$CNF['FIELD_TITLE']],
  544. 'description' => $aItem[$CNF['FIELD_TEXT']],
  545. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'], array('id' => $aItem[$CNF['FIELD_ID']])),
  546. 'price_single' => $aItem[$CNF['FIELD_PRICE_SINGLE']],
  547. 'price_recurring' => '',
  548. 'period_recurring' => 0,
  549. 'period_unit_recurring' => '',
  550. 'trial_recurring' => ''
  551. );
  552. return $aResult;
  553. }
  554. /**
  555. * @page service Service Calls
  556. * @section bx_ads Ads
  557. * @subsection bx_ads-payments Payments
  558. * @subsubsection bx_ads-register_cart_item register_cart_item
  559. *
  560. * @code bx_srv('bx_ads', 'register_cart_item', [...]); @endcode
  561. *
  562. * Register a processed single time payment inside the Ads module. Is called with payment processing module after the payment was registered there.
  563. *
  564. * @param $iClientId client ID.
  565. * @param $iSellerId seller ID
  566. * @param $iItemId item ID.
  567. * @param $iItemCount the number of purchased items.
  568. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  569. * @param $sLicense license number genereted with payment processing module for internal usage
  570. * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
  571. *
  572. * @see BxAdsModule::serviceRegisterCartItem
  573. */
  574. /**
  575. * @ref bx_ads-register_cart_item "register_cart_item"
  576. */
  577. public function serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  578. {
  579. $CNF = &$this->_oConfig->CNF;
  580. $aItem = $this->serviceGetCartItem($iItemId);
  581. if(empty($aItem) || !is_array($aItem))
  582. return array();
  583. $aEntry = $this->_oDb->getContentInfoById($iItemId);
  584. if(empty($aEntry) || !is_array($aEntry) || (int)$aEntry[$CNF['FIELD_QUANTITY']] <= 0)
  585. return array();
  586. if(!$this->_oDb->registerLicense($iClientId, $iItemId, $iItemCount, $sOrder, $sLicense))
  587. return array();
  588. $this->_oDb->updateEntriesBy(array($CNF['FIELD_QUANTITY'] => (int)$aEntry[$CNF['FIELD_QUANTITY']] - $iItemCount), array($CNF['FIELD_ID'] => $iItemId));
  589. bx_alert($this->getName(), 'license_register', 0, false, array(
  590. 'product_id' => $iItemId,
  591. 'profile_id' => $iClientId,
  592. 'order' => $sOrder,
  593. 'license' => $sLicense,
  594. 'count' => $iItemCount
  595. ));
  596. $oClient = BxDolProfile::getInstanceMagic($iClientId);
  597. $oSeller = BxDolProfile::getInstanceMagic($iSellerId);
  598. $sSellerUrl = $oSeller->getUrl();
  599. $sSellerName = $oSeller->getDisplayName();
  600. $sNote = $aEntry[$CNF['FIELD_NOTES_PURCHASED']];
  601. if(empty($sNote))
  602. $sNote = _t('_bx_ads_txt_purchased_note', $sSellerUrl, $sSellerName);
  603. sendMailTemplate($CNF['ETEMPLATE_PURCHASED'], 0, $iClientId, array(
  604. 'client_name' => $oClient->getDisplayName(),
  605. 'entry_name' => $aEntry[$CNF['FIELD_TITLE']],
  606. 'entry_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'], array('id' => $aEntry[$CNF['FIELD_ID']])),
  607. 'vendor_url' => $sSellerUrl,
  608. 'vendor_name' => $sSellerName,
  609. 'count' => (int)$iItemCount,
  610. 'license' => $sLicense,
  611. 'notes' => $sNote,
  612. ));
  613. return $aItem;
  614. }
  615. /**
  616. * @page service Service Calls
  617. * @section bx_ads Ads
  618. * @subsection bx_ads-payments Payments
  619. * @subsubsection bx_ads-register_subscription_item register_subscription_item
  620. *
  621. * @code bx_srv('bx_ads', 'register_subscription_item', [...]); @endcode
  622. *
  623. * Register a processed subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was registered there.
  624. *
  625. * @param $iClientId client ID.
  626. * @param $iSellerId seller ID
  627. * @param $iItemId item ID.
  628. * @param $iItemCount the number of purchased items.
  629. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  630. * @param $sLicense license number genereted with payment processing module for internal usage
  631. * @return an array with subscribed prodict's description. Empty array is returned if something is wrong.
  632. *
  633. * @see BxAdsModule::serviceRegisterSubscriptionItem
  634. */
  635. /**
  636. * @ref bx_ads-register_subscription_item "register_subscription_item"
  637. */
  638. public function serviceRegisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  639. {
  640. return array();
  641. }
  642. /**
  643. * @page service Service Calls
  644. * @section bx_ads Ads
  645. * @subsection bx_ads-payments Payments
  646. * @subsubsection bx_ads-reregister_cart_item reregister_cart_item
  647. *
  648. * @code bx_srv('bx_ads', 'reregister_cart_item', [...]); @endcode
  649. *
  650. * Reregister a single time payment inside the Ads module. Is called with payment processing module after the payment was reregistered there.
  651. *
  652. * @param $iClientId client ID.
  653. * @param $iSellerId seller ID
  654. * @param $iItemIdOld old item ID.
  655. * @param $iItemIdNew new item ID.
  656. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  657. * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
  658. *
  659. * @see BxAdsModule::serviceReregisterCartItem
  660. */
  661. /**
  662. * @ref bx_ads-reregister_cart_item "reregister_cart_item"
  663. */
  664. public function serviceReregisterCartItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  665. {
  666. return array();
  667. }
  668. /**
  669. * @page service Service Calls
  670. * @section bx_ads Ads
  671. * @subsection bx_ads-payments Payments
  672. * @subsubsection bx_ads-reregister_subscription_item reregister_subscription_item
  673. *
  674. * @code bx_srv('bx_ads', 'reregister_subscription_item', [...]); @endcode
  675. *
  676. * Reregister a subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was reregistered there.
  677. *
  678. * @param $iClientId client ID.
  679. * @param $iSellerId seller ID
  680. * @param $iItemIdOld old item ID.
  681. * @param $iItemIdNew new item ID.
  682. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  683. * @return an array with subscribed prodict's description. Empty array is returned if something is wrong.
  684. *
  685. * @see BxAdsModule::serviceReregisterSubscriptionItem
  686. */
  687. /**
  688. * @ref bx_ads-reregister_subscription_item "reregister_subscription_item"
  689. */
  690. public function serviceReregisterSubscriptionItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  691. {
  692. return array();
  693. }
  694. /**
  695. * @page service Service Calls
  696. * @section bx_ads Ads
  697. * @subsection bx_ads-payments Payments
  698. * @subsubsection bx_ads-unregister_cart_item unregister_cart_item
  699. *
  700. * @code bx_srv('bx_ads', 'unregister_cart_item', [...]); @endcode
  701. *
  702. * Unregister an earlier processed single time payment inside the Ads module. Is called with payment processing module after the payment was unregistered there.
  703. *
  704. * @param $iClientId client ID.
  705. * @param $iSellerId seller ID
  706. * @param $iItemId item ID.
  707. * @param $iItemCount the number of purchased items.
  708. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  709. * @param $sLicense license number genereted with payment processing module for internal usage
  710. * @return boolean value determining where the payment was unregistered or not.
  711. *
  712. * @see BxAdsModule::serviceUnregisterCartItem
  713. */
  714. /**
  715. * @ref bx_ads-unregister_cart_item "unregister_cart_item"
  716. */
  717. public function serviceUnregisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  718. {
  719. if(!$this->_oDb->unregisterLicense($iClientId, $iItemId, $sOrder, $sLicense))
  720. return false;
  721. bx_alert($this->getName(), 'license_unregister', 0, false, array(
  722. 'product_id' => $iItemId,
  723. 'profile_id' => $iClientId,
  724. 'order' => $sOrder,
  725. 'license' => $sLicense,
  726. 'count' => $iItemCount
  727. ));
  728. return true;;
  729. }
  730. /**
  731. * @page service Service Calls
  732. * @section bx_ads Ads
  733. * @subsection bx_ads-payments Payments
  734. * @subsubsection bx_ads-unregister_subscription_item unregister_subscription_item
  735. *
  736. * @code bx_srv('bx_ads', 'unregister_subscription_item', [...]); @endcode
  737. *
  738. * Unregister an earlier processed subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was unregistered there.
  739. *
  740. * @param $iClientId client ID.
  741. * @param $iSellerId seller ID
  742. * @param $iItemId item ID.
  743. * @param $iItemCount the number of purchased items.
  744. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  745. * @param $sLicense license number genereted with payment processing module for internal usage
  746. * @return boolean value determining where the subscription was unregistered or not.
  747. *
  748. * @see BxAdsModule::serviceUnregisterSubscriptionItem
  749. */
  750. /**
  751. * @ref bx_ads-unregister_subscription_item "unregister_subscription_item"
  752. */
  753. public function serviceUnregisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  754. {
  755. return true;
  756. }
  757. /**
  758. * @page service Service Calls
  759. * @section bx_ads Ads
  760. * @subsection bx_ads-payments Payments
  761. * @subsubsection bx_ads-cancel_subscription_item cancel_subscription_item
  762. *
  763. * @code bx_srv('bx_ads', 'cancel_subscription_item', [...]); @endcode
  764. *
  765. * Cancel an earlier processed subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was canceled there.
  766. *
  767. * @param $iClientId client ID.
  768. * @param $iSellerId seller ID
  769. * @param $iItemId item ID.
  770. * @param $iItemCount the number of purchased items.
  771. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  772. * @return boolean value determining where the subscription was canceled or not.
  773. *
  774. * @see BxAdsModule::serviceCancelSubscriptionItem
  775. */
  776. /**
  777. * @ref bx_ads-cancel_subscription_item "cancel_subscription_item"
  778. */
  779. public function serviceCancelSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  780. {
  781. return true;
  782. }
  783. public function serviceGetOffersCount($sStatus = '')
  784. {
  785. if(!$this->_oConfig->isAuction())
  786. return 0;
  787. if(empty($sStatus) || !in_array($sStatus, $this->_aOfferStatuses))
  788. $sStatus = BX_ADS_OFFER_STATUS_AWAITING;
  789. $iUserId = bx_get_logged_profile_id();
  790. return $this->_oDb->getOffersBy(array('type' => 'content_author_id', 'author_id' => $iUserId, 'status' => $sStatus, 'count' => true));
  791. }
  792. public function serviceGetLiveUpdates($sStatus, $aMenuItemParent, $aMenuItemChild, $iCount = 0)
  793. {
  794. if(!in_array($sStatus, $this->_aOfferStatuses))
  795. return false;
  796. $iUserId = bx_get_logged_profile_id();
  797. $iCountNew = $this->_oDb->getOffersBy(array('type' => 'content_author_id', 'author_id' => $iUserId, 'status' => $sStatus, 'count' => true));
  798. if($iCountNew == $iCount)
  799. return false;
  800. return array(
  801. 'count' => $iCountNew, // required
  802. 'method' => 'bx_menu_show_live_update(oData)', // required
  803. 'data' => array(
  804. 'code' => BxDolTemplate::getInstance()->parseHtmlByTemplateName('menu_item_addon', array(
  805. 'content' => '{count}'
  806. )),
  807. 'mi_parent' => $aMenuItemParent,
  808. 'mi_child' => $aMenuItemChild
  809. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  810. );
  811. }
  812. public function serviceOffers()
  813. {
  814. $CNF = &$this->_oConfig->CNF;
  815. if(!$this->_oConfig->isAuction())
  816. return '';
  817. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_OFFERS_ALL']);
  818. if(!$oGrid)
  819. return '';
  820. return $oGrid->getCode();
  821. }
  822. public function serviceEntityOffers($iContentId = 0)
  823. {
  824. $CNF = &$this->_oConfig->CNF;
  825. if(!$this->_oConfig->isAuction())
  826. return '';
  827. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_OFFERS']);
  828. if(!$oGrid)
  829. return '';
  830. if(empty($iContentId) && ($_iContentId = bx_get('id')) !== false)
  831. $iContentId = (int)$_iContentId;
  832. $oGrid->setContentId($iContentId);
  833. return $oGrid->getCode();
  834. }
  835. public function serviceEntityOfferAccepted($iContentId = 0)
  836. {
  837. if(!$this->_oConfig->isAuction())
  838. return '';
  839. $iUserId = bx_get_logged_profile_id();
  840. if(empty($iContentId) && ($_iContentId = bx_get('id')) !== false)
  841. $iContentId = (int)$_iContentId;
  842. $aContent = $this->_oDb->getContentInfoById($iContentId);
  843. if(empty($aContent) || !is_array($aContent))
  844. return '';
  845. $aOffer = $this->_oDb->getOffersBy(array(
  846. 'type' => 'content_and_author_ids',
  847. 'content_id' => $iContentId,
  848. 'author_id' => $iUserId,
  849. 'status' => BX_ADS_OFFER_STATUS_ACCEPTED
  850. ));
  851. if(empty($aOffer) || !is_array($aOffer))
  852. return '';
  853. return $this->_oTemplate->entryOfferAccepted($iUserId, $aContent, $aOffer);
  854. }
  855. public function isAuction($aContentInfo)
  856. {
  857. $CNF = &$this->_oConfig->CNF;
  858. return $this->_oConfig->isAuction() && (int)$aContentInfo[$CNF['FIELD_AUCTION']] != 0;
  859. }
  860. public function isAllowedMakeOffer($mixedContent, $isPerformAction = false)
  861. {
  862. return $this->checkAllowedMakeOffer($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  863. }
  864. public function checkAllowedMakeOffer($mixedContent, $isPerformAction = false)
  865. {
  866. $CNF = &$this->_oConfig->CNF;
  867. if(!is_array($mixedContent))
  868. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  869. if(!$this->isAuction($mixedContent))
  870. return _t('_sys_txt_access_denied');
  871. if(!empty($mixedContent) && is_array($mixedContent) && $mixedContent[$CNF['FIELD_AUTHOR']] != bx_get_logged_profile_id())
  872. return CHECK_ACTION_RESULT_ALLOWED;
  873. return _t('_sys_txt_access_denied');
  874. }
  875. public function isAllowedViewOffers($mixedContent, $isPerformAction = false)
  876. {
  877. return $this->checkAllowedViewOffers($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  878. }
  879. public function checkAllowedViewOffers($mixedContent, $isPerformAction = false)
  880. {
  881. $CNF = &$this->_oConfig->CNF;
  882. if(!is_array($mixedContent))
  883. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  884. if(!$this->isAuction($mixedContent))
  885. return _t('_sys_txt_access_denied');
  886. if($this->checkAllowedEditAnyEntry($isPerformAction) === CHECK_ACTION_RESULT_ALLOWED)
  887. return CHECK_ACTION_RESULT_ALLOWED;
  888. if(!empty($mixedContent) && is_array($mixedContent) && $mixedContent[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id())
  889. return CHECK_ACTION_RESULT_ALLOWED;
  890. return _t('_sys_txt_access_denied');
  891. }
  892. public function onOfferAdded($iOfferId)
  893. {
  894. $CNF = &$this->_oConfig->CNF;
  895. $aOfferInfo = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
  896. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  897. return;
  898. $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  899. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  900. if(empty($aContentInfo) || !is_array($aContentInfo))
  901. return;
  902. $iViewer = bx_get_logged_profile_id();
  903. $oViewer = BxDolProfile::getInstanceMagic($iViewer);
  904. sendMailTemplate($CNF['ETEMPLATE_OFFER_ADDED'], 0, $aContentInfo[$CNF['FIELD_AUTHOR']], array(
  905. 'viewer_name' => $oViewer->getDisplayName(),
  906. 'viewer_url' => $oViewer->getUrl(),
  907. 'ad_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  908. 'ad_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  909. 'i' => $CNF['URI_VIEW_ENTRY'],
  910. $CNF['FIELD_ID'] => $iContentId
  911. ))
  912. ));
  913. $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
  914. bx_alert($this->getName(), 'offer_added', $iOfferId, $aOfferInfo[$CNF['FIELD_OFR_AUTHOR']], $aParams);
  915. }
  916. public function onOfferAccepted($iOfferId)
  917. {
  918. $CNF = &$this->_oConfig->CNF;
  919. $aOfferInfo = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
  920. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  921. return;
  922. $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  923. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  924. if(empty($aContentInfo) || !is_array($aContentInfo))
  925. return;
  926. $iOfferer = (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']];
  927. $oOfferer = BxDolProfile::getInstanceMagic($iOfferer);
  928. sendMailTemplate($CNF['ETEMPLATE_OFFER_ACCEPTED'], 0, $iOfferer, array(
  929. 'offerer_name' => $oOfferer->getDisplayName(),
  930. 'offerer_url' => $oOfferer->getUrl(),
  931. 'ad_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  932. 'ad_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  933. 'i' => $CNF['URI_VIEW_ENTRY'],
  934. $CNF['FIELD_ID'] => $iContentId
  935. ))
  936. ));
  937. $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
  938. bx_alert($this->getName(), 'offer_accepted', $iOfferId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  939. }
  940. public function onOfferDeclined($iOfferId)
  941. {
  942. $CNF = &$this->_oConfig->CNF;
  943. $aOfferInfo = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
  944. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  945. return;
  946. $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  947. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  948. if(empty($aContentInfo) || !is_array($aContentInfo))
  949. return;
  950. $iOfferer = (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']];
  951. $oOfferer = BxDolProfile::getInstanceMagic($iOfferer);
  952. sendMailTemplate($CNF['ETEMPLATE_OFFER_DECLINED'], 0, $iOfferer, array(
  953. 'offerer_name' => $oOfferer->getDisplayName(),
  954. 'offerer_url' => $oOfferer->getUrl(),
  955. 'ad_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  956. 'ad_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  957. 'i' => $CNF['URI_VIEW_ENTRY'],
  958. $CNF['FIELD_ID'] => $iContentId
  959. ))
  960. ));
  961. $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
  962. bx_alert($this->getName(), 'offer_declined', $iOfferId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  963. }
  964. /**
  965. * Common methods.
  966. */
  967. public function processMetasAdd($iContentId)
  968. {
  969. if(!parent::processMetasAdd($iContentId))
  970. return false;
  971. $CNF = &$this->_oConfig->CNF;
  972. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  973. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  974. $aCategoryTypes = $this->_oDb->getCategoryTypes(array('type' => 'all'));
  975. foreach($aCategoryTypes as $aCategoryType)
  976. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $aCategoryType['display_add']);
  977. return true;
  978. }
  979. public function processMetasEdit($iContentId, $oForm)
  980. {
  981. if(!parent::processMetasEdit($iContentId, $oForm))
  982. return false;
  983. $CNF = &$this->_oConfig->CNF;
  984. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  985. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  986. $aCategoryTypes = $this->_oDb->getCategoryTypes(array('type' => 'all'));
  987. foreach($aCategoryTypes as $aCategoryType)
  988. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $aCategoryType['display_edit']);
  989. return true;
  990. }
  991. public function getCategoryDisplay($sDisplayType, $iCategory = 0)
  992. {
  993. if(empty($iCategory) && bx_get('category') !== false)
  994. $iCategory = (int)bx_get('category');
  995. if(empty($iCategory))
  996. return false;
  997. $aCategory = $this->_oDb->getCategories(array('type' => 'id_full', 'id' => $iCategory));
  998. $sKey = 'type_display_' . $sDisplayType;
  999. if(empty($aCategory[$sKey]))
  1000. return false;
  1001. return $aCategory[$sKey];
  1002. }
  1003. /**
  1004. * Internal methods.
  1005. */
  1006. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  1007. {
  1008. $CNF = &$this->_oConfig->CNF;
  1009. $mixedContent = $this->_getContent($iContentId, true);
  1010. if($mixedContent === false)
  1011. return false;
  1012. list($iContentId, $aContentInfo) = $mixedContent;
  1013. $sDisplayType = false;
  1014. switch($sFormMethod) {
  1015. case 'editDataForm':
  1016. $sDisplayType = 'edit';
  1017. break;
  1018. case 'viewDataForm':
  1019. case 'viewDataEntry':
  1020. $sDisplayType = 'view';
  1021. break;
  1022. }
  1023. if($sDisplayType !== false && ($sDisplayNew = $this->getCategoryDisplay($sDisplayType, $aContentInfo[$CNF['FIELD_CATEGORY']])) !== false)
  1024. $sDisplay = $sDisplayNew;
  1025. return parent::_serviceEntityForm ($sFormMethod, $iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  1026. }
  1027. protected function _getCategoryOptions($iParentId, &$aValues)
  1028. {
  1029. $aCategories = $this->_oDb->getCategories(array('type' => 'parent_id', 'parent_id' => $iParentId));
  1030. foreach($aCategories as $aCategory) {
  1031. $aValues[] = array('key' => $aCategory['id'], 'value' => str_repeat('--', (int)$aCategory['level']) . ' ' . _t($aCategory['title']));
  1032. $this->_getCategoryOptions($aCategory['id'], $aValues);
  1033. }
  1034. }
  1035. protected function _getSearchableFields($mixedDisplayType = '')
  1036. {
  1037. $CNF = &$this->_oConfig->CNF;
  1038. if(empty($mixedDisplayType))
  1039. $mixedDisplayType = array('add', 'edit');
  1040. $aResult = array();
  1041. $aDisplays = $this->_oDb->getDisplays($this->_oConfig->getName() . '_entry', $mixedDisplayType);
  1042. foreach($aDisplays as $aDisplay) {
  1043. if($aDisplay['display_name'] == $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])
  1044. continue;
  1045. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $aDisplay['display_name'], $this->_oTemplate);
  1046. if(!$oForm)
  1047. continue;
  1048. $aResult = array_merge($aResult, $oForm->aInputs);
  1049. }
  1050. return $aResult;
  1051. }
  1052. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  1053. {
  1054. $CNF = &$this->_oConfig->CNF;
  1055. $bDynamic = isset($aBrowseParams['dynamic_mode']) && (bool)$aBrowseParams['dynamic_mode'] === true;
  1056. $sCategory = '';
  1057. if(!empty($CNF['FIELD_CATEGORY']) && !empty($aContentInfo[$CNF['FIELD_CATEGORY']])) {
  1058. $iCategory = (int)$aContentInfo[$CNF['FIELD_CATEGORY']];
  1059. $aCategory = $this->_oDb->getCategories(array('type' => 'id', 'id' => $iCategory));
  1060. $sCategory = _t($aCategory['title']);
  1061. $sCategoryLink = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_CATEGORIES'], array($CNF['GET_PARAM_CATEGORY'] => $iCategory));
  1062. }
  1063. $sPrice = _t('_bx_ads_txt_free');
  1064. if(!empty($CNF['FIELD_PRICE']) && !empty($aContentInfo[$CNF['FIELD_PRICE']]))
  1065. $sPrice = _t_format_currency((float)$aContentInfo[$CNF['FIELD_PRICE']]);
  1066. $sInclude = $this->_oTemplate->addCss(array('timeline.css'), $bDynamic);
  1067. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  1068. $aResult['text'] = $this->_oTemplate->parseHtmlByName('timeline_post_text.html', array(
  1069. 'category_link' => $sCategoryLink,
  1070. 'category_title' => $sCategory,
  1071. 'category_title_attr' => bx_html_attribute($sCategory),
  1072. 'price' => $sPrice,
  1073. 'text' => $aResult['text']
  1074. )) . ($bDynamic ? $sInclude : '');
  1075. return $aResult;
  1076. }
  1077. protected function _getBlockLicenses($sType = '')
  1078. {
  1079. $CNF = &$this->_oConfig->CNF;
  1080. $sGrid = $CNF['OBJECT_GRID_LICENSES' . (!empty($sType) ? '_' . strtoupper($sType) : '')];
  1081. $oGrid = BxDolGrid::getObjectInstance($sGrid);
  1082. if(!$oGrid)
  1083. return '';
  1084. $this->_oDb->updateLicense(array('new' => 0), array('profile_id' => bx_get_logged_profile_id(), 'new' => 1));
  1085. $this->_oTemplate->addJs(array('licenses.js'));
  1086. return array(
  1087. 'content' => $this->_oTemplate->getJsCode('licenses', array('sObjNameGrid' => $sGrid)) . $oGrid->getCode(),
  1088. 'menu' => $CNF['OBJECT_MENU_LICENSES']
  1089. );
  1090. }
  1091. protected function _alertParamsOffer($aContentInfo, $aOfferInfo)
  1092. {
  1093. $CNF = &$this->_oConfig->CNF;
  1094. $aParams = array(
  1095. 'object_id' => (int)$aContentInfo[$CNF['FIELD_ID']],
  1096. 'object_author_id' => (int)$aContentInfo[$CNF['FIELD_AUTHOR']],
  1097. 'offer_id' => (int)$aOfferInfo[$CNF['FIELD_OFR_ID']],
  1098. 'offer_author_id' => (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']],
  1099. );
  1100. if(isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  1101. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  1102. return $aParams;
  1103. }
  1104. }
  1105. /** @} */