BxAdsModule.php 49 KB

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