BxAdsModule.php 49 KB

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