BxAdsModule.php 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Ads Ads
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_ADS_STATUS_OFFER', 'offer');
  12. define('BX_ADS_STATUS_SOLD', 'sold');
  13. define('BX_ADS_OFFER_STATUS_ACCEPTED', 'accepted');
  14. define('BX_ADS_OFFER_STATUS_AWAITING', 'awaiting');
  15. define('BX_ADS_OFFER_STATUS_DECLINED', 'declined');
  16. define('BX_ADS_OFFER_STATUS_CANCELED', 'canceled');
  17. /**
  18. * Ads module
  19. */
  20. class BxAdsModule extends BxBaseModTextModule
  21. {
  22. protected $_aOfferStatuses;
  23. function __construct(&$aModule)
  24. {
  25. parent::__construct($aModule);
  26. $this->_oConfig->init($this->_oDb);
  27. $CNF = &$this->_oConfig->CNF;
  28. $this->_aSearchableNamesExcept = array_merge($this->_aSearchableNamesExcept, array(
  29. $CNF['FIELD_CATEGORY_VIEW'],
  30. $CNF['FIELD_CATEGORY_SELECT']
  31. ));
  32. $this->_aOfferStatuses = array(
  33. BX_ADS_OFFER_STATUS_ACCEPTED,
  34. BX_ADS_OFFER_STATUS_AWAITING,
  35. BX_ADS_OFFER_STATUS_DECLINED
  36. );
  37. }
  38. public function actionGetCategoryForm()
  39. {
  40. if(bx_get('category') === false)
  41. return echoJson(array());
  42. return echoJson(array(
  43. 'content' => $this->serviceGetCreatePostForm(array(
  44. 'absolute_action_url' => true,
  45. 'dynamic_mode' => true
  46. ))
  47. ));
  48. }
  49. public function actionCheckName()
  50. {
  51. $CNF = &$this->_oConfig->CNF;
  52. $iId = (int)bx_get($CNF['FIELD_ID']);
  53. $sTitle = bx_process_input(bx_get($CNF['FIELD_TITLE']));
  54. echoJson($this->serviceCheckName($sTitle, $iId));
  55. }
  56. public function actionInterested()
  57. {
  58. $CNF = &$this->_oConfig->CNF;
  59. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  60. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  61. if(empty($aContentInfo) || !is_array($aContentInfo))
  62. return echoJson(array());
  63. $iViewer = bx_get_logged_profile_id();
  64. $oViewer = BxDolProfile::getInstance($iViewer);
  65. if(!$oViewer)
  66. return echoJson(array());
  67. $iContentAuthor = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  68. if($iContentAuthor == $iViewer)
  69. return echoJson(array('msg' => _t('_bx_ads_txt_err_your_own')));
  70. if($this->_oDb->isInterested($iContentId, $iViewer))
  71. return echoJson(array('msg' => _t('_bx_ads_txt_err_duplicate')));
  72. $iInterestId = $this->_oDb->insertInterested(array('entry_id' => $iContentId, 'profile_id' => $iViewer));
  73. if(!$iInterestId)
  74. return echoJson(array('msg' => _t('_bx_ads_txt_err_cannot_perform_action')));
  75. bx_alert($this->getName(), 'doInterest', $iContentId, $iViewer, array(
  76. 'subobject_id' => $iInterestId,
  77. 'subobject_author_id' => $iViewer,
  78. 'object_author_id' => $iContentAuthor
  79. ));
  80. if(getParam($CNF['PARAM_USE_IIN']) == 'on')
  81. sendMailTemplate($CNF['ETEMPLATE_INTERESTED'], 0, $iContentAuthor, array(
  82. 'viewer_name' => $oViewer->getDisplayName(),
  83. 'viewer_url' => $oViewer->getUrl(),
  84. 'ad_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  85. 'ad_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  86. 'i' => $CNF['URI_VIEW_ENTRY'],
  87. $CNF['FIELD_ID'] => $iContentId
  88. ))
  89. ));
  90. return echoJson(array('msg' => _t('_bx_ads_txt_msg_author_notified')));
  91. }
  92. public function actionShow()
  93. {
  94. return echoJson($this->_actionChangeStatus(BX_BASE_MOD_TEXT_STATUS_ACTIVE));
  95. }
  96. public function actionHide()
  97. {
  98. return echoJson($this->_actionChangeStatus(BX_BASE_MOD_TEXT_STATUS_HIDDEN));
  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. if(($mixedCheck = $this->checkAllowedMakeOffer($aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED)
  112. return echoJson(array('code' => 2, 'msg' => $mixedCheck));
  113. $aOffer = $this->_oDb->getOffersBy(array(
  114. 'type' => 'content_and_author_ids',
  115. 'content_id' => $iContentId,
  116. 'author_id' => $iAuthorId,
  117. 'status' => BX_ADS_OFFER_STATUS_AWAITING
  118. ));
  119. if(!empty($aOffer) && is_array($aOffer))
  120. return echoJson(array('code' => 3, 'msg' => _t('_bx_ads_txt_err_duplicate')));
  121. $aOffer = $this->_oDb->getOffersBy(array(
  122. 'type' => 'content_and_author_ids',
  123. 'content_id' => $iContentId,
  124. 'author_id' => $iAuthorId,
  125. 'status' => BX_ADS_OFFER_STATUS_ACCEPTED
  126. ));
  127. if(!empty($aOffer) && is_array($aOffer))
  128. return echoJson(array('code' => 4, 'msg' => _t('_bx_ads_txt_err_offer_accepted')));
  129. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_OFFER'], $CNF['OBJECT_FORM_OFFER_DISPLAY_ADD']);
  130. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . bx_append_url_params($this->_oConfig->getBaseUri() . 'make_offer', array('id' => $iContentId));
  131. $oForm->initChecker();
  132. if($oForm->isSubmittedAndValid()) {
  133. $aValToAdd = array('content_id' => $iContentId, 'author_id' => $iAuthorId);
  134. $iId = (int)$oForm->insert($aValToAdd);
  135. if($iId != 0) {
  136. $this->checkAllowedMakeOffer($aContentInfo, true);
  137. $this->onOfferAdded($iId, $aResult);
  138. $aResult = array('code' => 0, 'msg' => _t('_bx_ads_txt_msg_offer_added'), 'eval' => $sJsObject . '.onMakeOffer(oData);', 'id' => $iId);
  139. }
  140. else
  141. $aResult = array('code' => 5, 'msg' => _t('_bx_ads_txt_err_cannot_perform_action'));
  142. return echoJson($aResult);
  143. }
  144. $sContent = BxTemplFunctions::getInstance()->transBox($this->_oConfig->getHtmlIds('offer_popup'), $this->_oTemplate->parseHtmlByName('offer_popup.html', array(
  145. 'form_id' => $oForm->getId(),
  146. 'form' => $oForm->getCode(true)
  147. )));
  148. return echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false, 'removeOnClose' => true))));
  149. }
  150. public function actionViewOffer()
  151. {
  152. $CNF = &$this->_oConfig->CNF;
  153. $iAuthorId = bx_get_logged_profile_id();
  154. $iOfferId = bx_process_input(bx_get('id'), BX_DATA_INT);
  155. $aOffer = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
  156. if(empty($aOffer) || !is_array($aOffer))
  157. return echoJson(array());
  158. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_OFFER'], $CNF['OBJECT_FORM_OFFER_DISPLAY_VIEW']);
  159. $oForm->initChecker($aOffer);
  160. $sContent = BxTemplFunctions::getInstance()->transBox($this->_oConfig->getHtmlIds('offer_popup'), $this->_oTemplate->parseHtmlByName('offer_popup.html', array(
  161. 'form_id' => $oForm->getId(),
  162. 'form' => $oForm->getCode(true)
  163. )));
  164. return echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => true, 'removeOnClose' => true))));
  165. }
  166. public function actionAcceptOffer()
  167. {
  168. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  169. if(!$this->offerAccept($iId))
  170. return echoJson(array('msg' => _t('_bx_ads_txt_err_cannot_perform_action')));
  171. return echoJson(array('msg' => _t('_bx_ads_txt_msg_offer_accepted'), 'reload' => 1));
  172. }
  173. public function actionDeclineOffer()
  174. {
  175. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  176. if(!$this->offerDecline($iId))
  177. return echoJson(array('msg' => _t('_bx_ads_txt_err_cannot_perform_action')));
  178. return echoJson(array('msg' => _t('_bx_ads_txt_msg_offer_declined'), 'reload' => 1));
  179. }
  180. public function actionCancelOffer()
  181. {
  182. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  183. if(!$this->offerCancel($iId))
  184. return echoJson(array('msg' => _t('_bx_ads_txt_err_cannot_perform_action')));
  185. return echoJson(array('msg' => _t('_bx_ads_txt_msg_offer_canceled'), 'reload' => 1));
  186. }
  187. public function actionPayOffer()
  188. {
  189. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  190. if(($mixedResult = $this->offerPay($iId)) !== false)
  191. return echoJson($mixedResult);
  192. return echoJson(array('msg' => _t('_bx_ads_txt_err_cannot_perform_action')));
  193. }
  194. public function actionShipped()
  195. {
  196. return echoJson($this->_actionMarkAs('shipped'));
  197. }
  198. public function actionReceived()
  199. {
  200. return echoJson($this->_actionMarkAs('received'));
  201. }
  202. public function serviceGetSafeServices()
  203. {
  204. $a = parent::serviceGetSafeServices();
  205. return array_merge($a, array (
  206. 'EntityReviews' => '',
  207. 'EntityReviewsRating' => '',
  208. 'CategoriesList' => '',
  209. 'BrowseCategory' => '',
  210. ));
  211. }
  212. public function serviceCheckName($sTitle, $iId = 0)
  213. {
  214. $CNF = &$this->_oConfig->CNF;
  215. if(empty($sTitle))
  216. return array();
  217. $sName = '';
  218. if(!empty($iId)) {
  219. $aEntry = $this->_oDb->getContentInfoById($iId);
  220. if(strcmp($sTitle, $aEntry[$CNF['FIELD_NAME']]) == 0)
  221. $sName = $sTitle;
  222. }
  223. return array(
  224. 'title' => $sTitle,
  225. 'name' => !empty($sName) ? $sName : $this->_oConfig->getEntryName($sTitle, $iId)
  226. );
  227. }
  228. public function serviceUpdateCategoriesStats($mixedContentInfo = false)
  229. {
  230. $aContentInfo = [];
  231. if(!empty($mixedContentInfo))
  232. $aContentInfo = !is_array($mixedContentInfo) ? $this->_oDb->getContentInfoById((int)$mixedContentInfo) : $mixedContentInfo;
  233. $iCategoryId = 0;
  234. if($aContentInfo && !empty($aContentInfo['category']))
  235. $iCategoryId = (int)$aContentInfo['category'];
  236. return $this->serviceUpdateCategoriesStatsByCategory($iCategoryId);
  237. }
  238. public function serviceUpdateCategoriesStatsByCategory($iCategoryId = 0)
  239. {
  240. $aParams = ['type' => 'collect_stats'];
  241. if($iCategoryId)
  242. $aParams['category_id'] = (int)$iCategoryId;
  243. $aStats = $this->_oDb->getCategories($aParams);
  244. if(empty($aStats) || !is_array($aStats))
  245. return true;
  246. $iUpdated = 0;
  247. foreach($aStats as $aStat)
  248. if($this->_oDb->updateCategory(array('items' => $aStat['count']), array('id' => $aStat['id'])))
  249. $iUpdated++;
  250. return count($aStats) == $iUpdated;
  251. }
  252. public function serviceGetCategoryOptions($iParentId, $bPleaseSelect = false)
  253. {
  254. $aValues = array();
  255. if($bPleaseSelect)
  256. $aValues[] = array('key' => '', 'value' => _t('_sys_please_select'));
  257. $this->_getCategoryOptions($iParentId, $aValues);
  258. return $aValues;
  259. }
  260. public function serviceGetSearchableFields($aInputsAdd = array())
  261. {
  262. $CNF = &$this->_oConfig->CNF;
  263. $aResult = parent::serviceGetSearchableFields(array_merge($aInputsAdd, $this->_getSearchableFields()));
  264. unset($aResult[$CNF['FIELD_NOTES_PURCHASED']]);
  265. unset($aResult[$CNF['FIELD_CATEGORY_VIEW']], $aResult[$CNF['FIELD_CATEGORY_SELECT']]);
  266. unset($aResult[$CNF['FIELD_PRICE']], $aResult[$CNF['FIELD_YEAR']]);
  267. return $aResult;
  268. }
  269. public function serviceGetSearchableFieldsExtended($aInputsAdd = array())
  270. {
  271. $CNF = &$this->_oConfig->CNF;
  272. $aInputsAdd = array_merge($aInputsAdd, $this->_getSearchableFields());
  273. if(isset($aInputsAdd[$CNF['FIELD_CATEGORY']])) {
  274. $aInputsAdd[$CNF['FIELD_CATEGORY']]['type'] = 'select';
  275. $aInputsAdd[$CNF['FIELD_CATEGORY']]['values_src'] = BxDolService::getSerializedService($this->_oConfig->getName(), 'get_category_options', array(0));
  276. }
  277. if(isset($aInputsAdd[$CNF['FIELD_PRICE']])) {
  278. $aInputsAdd[$CNF['FIELD_PRICE']]['search_type'] = 'text_range';
  279. $aInputsAdd[$CNF['FIELD_PRICE']]['search_operator'] = 'between';
  280. }
  281. if(isset($aInputsAdd[$CNF['FIELD_YEAR']])) {
  282. $aInputsAdd[$CNF['FIELD_YEAR']]['search_type'] = 'text_range';
  283. $aInputsAdd[$CNF['FIELD_YEAR']]['search_operator'] = 'between';
  284. }
  285. return parent::serviceGetSearchableFieldsExtended($aInputsAdd);
  286. }
  287. /**
  288. * Mark an ad as shipped/received by seller/bauer accordingly.
  289. * @param type $sAction - shipped/received action.
  290. * @param type $iContentId - an ad the action will be performed with.
  291. * @param integer $iProfileSrc - profile, who performed the action.
  292. * @param integer $iProfileDst - profile, the action is pointed on.
  293. * @return boolean - true or a string value with error message.
  294. */
  295. public function serviceMarkAs($sAction, $iContentId, $iProfileSrc = 0, $iProfileDst = 0)
  296. {
  297. $CNF = &$this->_oConfig->CNF;
  298. if(!$iProfileSrc)
  299. $iProfileSrc = bx_get_logged_profile_id();
  300. $sTxtError = '_bx_ads_txt_err_cannot_perform_action';
  301. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  302. $sMethodCheck = 'checkAllowedMark' . bx_gen_method_name($sAction) . 'ForProfile';
  303. if(!method_exists($this, $sMethodCheck))
  304. return _t($sTxtError);
  305. if(($mixedCheckResult = $this->$sMethodCheck($aContentInfo, false, $iProfileSrc)) !== CHECK_ACTION_RESULT_ALLOWED)
  306. return $mixedCheckResult;
  307. if((int)$this->_oDb->updateEntriesBy(array($CNF['FIELD_' . strtoupper($sAction)] => time()), array($CNF['FIELD_ID'] => $iContentId)) == 0)
  308. return _t($sTxtError);
  309. $this->$sMethodCheck($aContentInfo, true, $iProfileSrc);
  310. $sMethodOnResult = 'on' . bx_gen_method_name($sAction);
  311. if(method_exists($this, $sMethodOnResult))
  312. $this->$sMethodOnResult($aContentInfo, $iProfileSrc, $iProfileDst);
  313. return true;
  314. }
  315. public function serviceEntityCreate ($sParams = false)
  316. {
  317. if(($sDisplay = $this->getCategoryDisplay('add')) !== false) {
  318. if(empty($sParams) || !is_array($sParams))
  319. $sParams = array();
  320. $sParams['display'] = $sDisplay;
  321. }
  322. return parent::serviceEntityCreate($sParams);
  323. }
  324. /**
  325. * @page service Service Calls
  326. * @section bx_ads Ads
  327. * @subsection bx_ads-page_blocks Page Blocks
  328. * @subsubsection bx_ads-entity_reviews entity_reviews
  329. *
  330. * @code bx_srv('bx_ads', 'entity_reviews', [...]); @endcode
  331. *
  332. * Get reviews for particular content
  333. * @param $iContentId content ID
  334. *
  335. * @see BxAdsModule::serviceEntityReviews
  336. */
  337. /**
  338. * @ref bx_ads-entity_reviews "entity_reviews"
  339. */
  340. public function serviceEntityReviews($iContentId = 0)
  341. {
  342. $CNF = &$this->_oConfig->CNF;
  343. if(empty($CNF['OBJECT_REVIEWS']))
  344. return false;
  345. return $this->_entityComments($CNF['OBJECT_REVIEWS'], $iContentId);
  346. }
  347. /**
  348. * @page service Service Calls
  349. * @section bx_ads Ads
  350. * @subsection bx_ads-page_blocks Page Blocks
  351. * @subsubsection bx_ads-entity_reviews_rating entity_reviews_rating
  352. *
  353. * @code bx_srv('bx_ads', 'entity_reviews_rating', [...]); @endcode
  354. *
  355. * Get reviews rating for particular content
  356. * @param $iContentId content ID
  357. *
  358. * @see BxAdsModule::serviceEntityReviewsRating
  359. */
  360. /**
  361. * @ref bx_ads-entity_reviews_rating "entity_reviews_rating"
  362. */
  363. public function serviceEntityReviewsRating($iContentId = 0)
  364. {
  365. $CNF = &$this->_oConfig->CNF;
  366. if(empty($CNF['OBJECT_REVIEWS']))
  367. return false;
  368. if(!$iContentId)
  369. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  370. if(!$iContentId)
  371. return false;
  372. $oCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_REVIEWS'], $iContentId);
  373. if (!$oCmts || !$oCmts->isEnabled())
  374. return false;
  375. return $oCmts->getRatingBlock(array('in_designbox' => false));
  376. }
  377. /**
  378. * @page service Service Calls
  379. * @section bx_ads Ads
  380. * @subsection bx_ads-page_blocks Page Blocks
  381. * @subsubsection bx_ads-categories_list categories_list
  382. *
  383. * @code bx_srv('bx_ads', 'categories_list', [...]); @endcode
  384. *
  385. * Get reviews rating for particular content
  386. * @param $aParams additional params array, such as 'show_empty'
  387. *
  388. * @see BxAdsModule::serviceCategoriesList
  389. */
  390. /**
  391. * @ref bx_ads-categories_list "categories_list"
  392. */
  393. public function serviceCategoriesList($aParams = array())
  394. {
  395. if(!isset($aParams['show_empty']))
  396. $aParams['show_empty'] = true;
  397. return $this->_oTemplate->categoriesList($aParams);
  398. }
  399. /**
  400. * @page service Service Calls
  401. * @section bx_ads Ads
  402. * @subsection bx_ads-browse Browse
  403. * @subsubsection bx_ads-browse_category browse_category
  404. *
  405. * @code bx_srv('bx_ads', 'browse_category', [...]); @endcode
  406. *
  407. * Get reviews rating for particular content
  408. * @param $iCategoryId category ID
  409. * @param $aParams additional params array, such as empty_message, ajax_paginate, etc
  410. *
  411. * @see BxAdsModule::serviceBrowseCategory
  412. */
  413. /**
  414. * @ref bx_ads-browse_category "browse_category"
  415. */
  416. public function serviceBrowseCategory($iCategoryId = 0, $aParams = array())
  417. {
  418. $sParamName = $sParamGet = 'category';
  419. if(!$iCategoryId && bx_get($sParamGet) !== false)
  420. $iCategoryId = bx_process_input(bx_get($sParamGet), BX_DATA_INT);
  421. $bEmptyMessage = true;
  422. if(isset($aParams['empty_message'])) {
  423. $bEmptyMessage = (bool)$aParams['empty_message'];
  424. unset($aParams['empty_message']);
  425. }
  426. $bAjaxPaginate = true;
  427. if(isset($aParams['ajax_paginate'])) {
  428. $bAjaxPaginate = (bool)$aParams['ajax_paginate'];
  429. unset($aParams['ajax_paginate']);
  430. }
  431. $aBlock = $this->_serviceBrowse ($sParamName, array_merge(array($sParamName => $iCategoryId), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  432. if(!empty($aBlock['content'])) {
  433. $aCategory = $this->_oDb->getCategories(array('type' => 'id', 'id' => $iCategoryId));
  434. if(!empty($aCategory['title']))
  435. $aBlock['title'] = _t('_bx_ads_page_block_title_entries_by_category_mask', _t($aCategory['title']));
  436. }
  437. return $aBlock;
  438. }
  439. public function serviceGetNotificationsData()
  440. {
  441. $sModule = $this->_aModule['name'];
  442. $sEventPrivacy = $sModule . '_allow_view_event_to';
  443. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  444. $sEventPrivacy = '';
  445. $aResult = parent::serviceGetNotificationsData();
  446. $aResult['handlers'] = array_merge($aResult['handlers'], array(
  447. 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),
  448. array('group' => $sModule . '_paid', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'license_register', 'module_name' => $sModule, 'module_method' => 'get_notifications_license_register', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  449. //---> To Buyer
  450. array('group' => $sModule . '_shipped', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'shipped', 'module_name' => $sModule, 'module_method' => 'get_notifications_shipped', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  451. //<---
  452. array('group' => $sModule . '_received', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'received', 'module_name' => $sModule, 'module_method' => 'get_notifications_received', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  453. array('group' => $sModule . '_offer_added', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'offer_added', 'module_name' => $sModule, 'module_method' => 'get_notifications_offer_added', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  454. //---> To Offerer
  455. array('group' => $sModule . '_offer_accepted', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'offer_accepted', 'module_name' => $sModule, 'module_method' => 'get_notifications_offer_accepted', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  456. array('group' => $sModule . '_offer_declined', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'offer_declined', 'module_name' => $sModule, 'module_method' => 'get_notifications_offer_declined', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  457. //<---
  458. array('group' => $sModule . '_offer_canceled', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'offer_canceled', 'module_name' => $sModule, 'module_method' => 'get_notifications_offer_canceled', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy)
  459. ));
  460. $aResult['settings'] = array_merge($aResult['settings'], array(
  461. array('group' => 'interest', 'unit' => $sModule, 'action' => 'doInterest', 'types' => array('personal')),
  462. array('group' => 'usage', 'unit' => $sModule, 'action' => 'license_register', 'types' => array('personal')),
  463. array('group' => 'usage', 'unit' => $sModule, 'action' => 'shipped', 'types' => array('personal')),
  464. array('group' => 'usage', 'unit' => $sModule, 'action' => 'received', 'types' => array('personal')),
  465. array('group' => 'usage', 'unit' => $sModule, 'action' => 'offer_added', 'types' => array('personal')),
  466. array('group' => 'usage', 'unit' => $sModule, 'action' => 'offer_accepted', 'types' => array('personal')),
  467. array('group' => 'usage', 'unit' => $sModule, 'action' => 'offer_declined', 'types' => array('personal')),
  468. array('group' => 'usage', 'unit' => $sModule, 'action' => 'offer_canceled', 'types' => array('personal')),
  469. ));
  470. $aResult['alerts'] = array_merge($aResult['alerts'], array(
  471. array('unit' => $sModule, 'action' => 'doInterest'),
  472. array('unit' => $sModule, 'action' => 'license_register'),
  473. array('unit' => $sModule, 'action' => 'shipped'),
  474. array('unit' => $sModule, 'action' => 'received'),
  475. array('unit' => $sModule, 'action' => 'offer_added'),
  476. array('unit' => $sModule, 'action' => 'offer_accepted'),
  477. array('unit' => $sModule, 'action' => 'offer_declined'),
  478. array('unit' => $sModule, 'action' => 'offer_canceled'),
  479. ));
  480. return $aResult;
  481. }
  482. public function serviceGetNotificationsInsertData($oAlert, $aHandler, $aDataItems)
  483. {
  484. $CNF = &$this->_oConfig->CNF;
  485. $aResult = [];
  486. switch($oAlert->sAction) {
  487. case 'license_register':
  488. $aContentInfo = $this->_oDb->getContentInfoById($oAlert->aExtras['product_id']);
  489. if(empty($aContentInfo) || !is_array($aContentInfo)) {
  490. $aResult = $aDataItems;
  491. break;
  492. }
  493. foreach($aDataItems as $aDataItem) {
  494. $aDataItem = array_merge($aDataItem, [
  495. 'owner_id' => $oAlert->aExtras['profile_id'],
  496. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  497. 'object_owner_id' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  498. 'object_privacy_view' => BX_DOL_PG_ALL
  499. ]);
  500. $aResult[] = $aDataItem;
  501. }
  502. break;
  503. case 'shipped':
  504. foreach($aDataItems as $aDataItem) {
  505. $aLicense = $this->_oDb->getLicense(['type' => 'entry_id', 'entry_id' => $aDataItem['object_id'], 'newest' => true]);
  506. if(!empty($aLicense) && is_array($aLicense))
  507. $aDataItem['object_owner_id'] = $aLicense['profile_id'];
  508. $aResult[] = $aDataItem;
  509. }
  510. break;
  511. case 'offer_added':
  512. case 'offer_canceled':
  513. foreach($aDataItems as $aDataItem) {
  514. $aDataItem['object_owner_id'] = $oAlert->aExtras['object_author_id'];
  515. $aResult[] = $aDataItem;
  516. }
  517. break;
  518. case 'offer_accepted':
  519. case 'offer_declined':
  520. foreach($aDataItems as $aDataItem) {
  521. $aDataItem['object_owner_id'] = $oAlert->aExtras['offer_author_id'];
  522. $aResult[] = $aDataItem;
  523. }
  524. break;
  525. default:
  526. $aResult = $aDataItems;
  527. }
  528. return $aResult;
  529. }
  530. public function serviceGetNotificationsInterest($aEvent)
  531. {
  532. $CNF = &$this->_oConfig->CNF;
  533. $iContentId = (int)$aEvent['object_id'];
  534. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  535. if(empty($aContentInfo) || !is_array($aContentInfo))
  536. return array();
  537. $iInterestedId = (int)$aEvent['subobject_id'];
  538. $aInterestedInfo = $this->_oDb->getInterested(array('type' => 'id', 'id' => $iInterestedId));
  539. if(empty($aInterestedInfo) || !is_array($aInterestedInfo))
  540. return array();
  541. $sEntryUrl = '{bx_url_root}' . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
  542. return array(
  543. 'entry_sample' => $CNF['T']['txt_sample_single'],
  544. 'entry_url' => $sEntryUrl,
  545. 'entry_caption' => $aContentInfo[$CNF['FIELD_TITLE']],
  546. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  547. 'subentry_sample' => $CNF['T']['txt_sample_interest_single'],
  548. 'subentry_url' => '',
  549. '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.
  550. );
  551. }
  552. public function serviceGetNotificationsLicenseRegister($aEvent)
  553. {
  554. return $this->_serviceGetNotificationsByEntryAndAction($aEvent, 'license_register');
  555. }
  556. public function serviceGetNotificationsShipped($aEvent)
  557. {
  558. $aResult = $this->_serviceGetNotificationsByEntryAndAction($aEvent, 'shipped');
  559. $aResult['entry_author'] = $aEvent['object_owner_id'];
  560. return $aResult;
  561. }
  562. public function serviceGetNotificationsReceived($aEvent)
  563. {
  564. return $this->_serviceGetNotificationsByEntryAndAction($aEvent, 'received');
  565. }
  566. public function serviceGetNotificationsOfferAdded($aEvent)
  567. {
  568. return $this->_serviceGetNotificationsByOfferAndAction($aEvent, 'offer_added');
  569. }
  570. public function serviceGetNotificationsOfferAccepted($aEvent)
  571. {
  572. $aResult = $this->_serviceGetNotificationsByOfferAndAction($aEvent, 'offer_accepted');
  573. $aResult['entry_author'] = $aEvent['object_owner_id'];
  574. return $aResult;
  575. }
  576. public function serviceGetNotificationsOfferDeclined($aEvent)
  577. {
  578. $aResult = $this->_serviceGetNotificationsByOfferAndAction($aEvent, 'offer_declined');
  579. $aResult['entry_author'] = $aEvent['object_owner_id'];
  580. return $aResult;
  581. }
  582. public function serviceGetNotificationsOfferCanceled($aEvent)
  583. {
  584. return $this->_serviceGetNotificationsByOfferAndAction($aEvent, 'offer_canceled');
  585. }
  586. protected function _serviceGetNotificationsByEntryAndAction($aEvent, $sAction)
  587. {
  588. $CNF = &$this->_oConfig->CNF;
  589. $iContentId = (int)$aEvent['object_id'];
  590. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  591. if(empty($aContentInfo) || !is_array($aContentInfo))
  592. return array();
  593. $sEntryUrl = '{bx_url_root}' . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
  594. return array(
  595. 'entry_sample' => $CNF['T']['txt_sample_single'],
  596. 'entry_url' => $sEntryUrl,
  597. 'entry_caption' => $aContentInfo[$CNF['FIELD_TITLE']],
  598. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  599. 'subentry_sample' => '',
  600. 'subentry_url' => '',
  601. 'lang_key' => '_bx_ads_txt_ntfs_object_' . $sAction, //may be empty or not specified. In this case the default one from Notification module will be used.
  602. );
  603. }
  604. protected function _serviceGetNotificationsByOfferAndAction($aEvent, $sAction)
  605. {
  606. $CNF = &$this->_oConfig->CNF;
  607. $iOfferId = (int)$aEvent['object_id'];
  608. $aOfferInfo = $this->_oDb->getOffersBy(['type' => 'id', 'id' => $iOfferId]);
  609. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  610. return array();
  611. $iContentId = $aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  612. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  613. if(empty($aContentInfo) || !is_array($aContentInfo))
  614. return array();
  615. $sEntryUrl = '{bx_url_root}' . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
  616. return array(
  617. 'object_id' => $iContentId,
  618. 'entry_sample' => $CNF['T']['txt_sample_single'],
  619. 'entry_url' => $sEntryUrl,
  620. 'entry_caption' => $aContentInfo[$CNF['FIELD_TITLE']],
  621. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  622. 'subentry_sample' => '',
  623. 'subentry_url' => '',
  624. 'lang_key' => '_bx_ads_txt_ntfs_' . $sAction, //may be empty or not specified. In this case the default one from Notification module will be used.
  625. );
  626. }
  627. /**
  628. * @page service Service Calls
  629. * @section bx_ads Ads
  630. * @subsection bx_ads-page_blocks Page Blocks
  631. * @subsubsection bx_ads-block_licenses block_licenses
  632. *
  633. * @code bx_srv('bx_ads', 'block_licenses', [...]); @endcode
  634. *
  635. * Get page block with a list of licenses purchased by currently logged member.
  636. *
  637. * @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.
  638. *
  639. * @see BxAdsModule::serviceBlockLicenses
  640. */
  641. /**
  642. * @ref bx_ads-block_licenses "block_licenses"
  643. */
  644. public function serviceBlockLicenses()
  645. {
  646. return $this->_getBlockLicenses();
  647. }
  648. /**
  649. * @page service Service Calls
  650. * @section bx_ads Ads
  651. * @subsection bx_ads-page_blocks Page Blocks
  652. * @subsubsection bx_ads-block_licenses_administration block_licenses_administration
  653. *
  654. * @code bx_srv('bx_ads', 'block_licenses_administration', [...]); @endcode
  655. *
  656. * Get page block with a list of all licenses. It's needed for moderators/administrators.
  657. *
  658. * @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.
  659. *
  660. * @see BxAdsModule::serviceBlockLicensesAdministration
  661. */
  662. /**
  663. * @ref bx_ads-block_licenses "block_licenses"
  664. */
  665. public function serviceBlockLicensesAdministration()
  666. {
  667. return $this->_getBlockLicenses('administration');
  668. }
  669. /**
  670. * @page service Service Calls
  671. * @section bx_ads Ads
  672. * @subsection bx_ads-page_blocks Page Blocks
  673. * @subsubsection bx_ads-block_licenses_note block_licenses_note
  674. *
  675. * @code bx_srv('bx_ads', 'block_licenses_note', [...]); @endcode
  676. *
  677. * Get page block with a notice for licenses usage.
  678. *
  679. * @return HTML string with block content to display on the site.
  680. *
  681. * @see BxAdsModule::serviceBlockLicensesNote
  682. */
  683. /**
  684. * @ref bx_ads-block_licenses_note "block_licenses_note"
  685. */
  686. public function serviceBlockLicensesNote()
  687. {
  688. return MsgBox(_t('_bx_ads_page_block_content_licenses_note'));
  689. }
  690. /**
  691. * @page service Service Calls
  692. * @section bx_ads Ads
  693. * @subsection bx_ads-payments Payments
  694. * @subsubsection bx_ads-get_payment_data get_payment_data
  695. *
  696. * @code bx_srv('bx_ads', 'get_payment_data', [...]); @endcode
  697. *
  698. * Get an array with module's description. Is needed for payments processing module.
  699. *
  700. * @return an array with module's description.
  701. *
  702. * @see BxAdsModule::serviceGetPaymentData
  703. */
  704. /**
  705. * @ref bx_ads-get_payment_data "get_payment_data"
  706. */
  707. public function serviceGetPaymentData()
  708. {
  709. $CNF = &$this->_oConfig->CNF;
  710. $oPermalink = BxDolPermalinks::getInstance();
  711. $aResult = $this->_aModule;
  712. $aResult['url_browse_order_common'] = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_LICENSES_COMMON'], array('filter' => '{order}'));
  713. $aResult['url_browse_order_administration'] = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_LICENSES_ADMINISTRATION'], array('filter' => '{order}'));
  714. return $aResult;
  715. }
  716. /**
  717. * @page service Service Calls
  718. * @section bx_ads Ads
  719. * @subsection bx_ads-payments Payments
  720. * @subsubsection bx_ads-get_cart_item get_cart_item
  721. *
  722. * @code bx_srv('bx_ads', 'get_cart_item', [...]); @endcode
  723. *
  724. * Get an array with prodict's description. Is used in Shopping Cart in payments processing module.
  725. *
  726. * @param $mixedItemId product's ID or Unique Name.
  727. * @return an array with prodict's description. Empty array is returned if something is wrong.
  728. *
  729. * @see BxAdsModule::serviceGetCartItem
  730. */
  731. /**
  732. * @ref bx_ads-get_cart_item "get_cart_item"
  733. */
  734. public function serviceGetCartItem($mixedItemId)
  735. {
  736. $CNF = &$this->_oConfig->CNF;
  737. if(!$mixedItemId)
  738. return array();
  739. if(is_numeric($mixedItemId))
  740. $aItem = $this->_oDb->getContentInfoById((int)$mixedItemId);
  741. else
  742. $aItem = $this->_oDb->getContentInfoByName($mixedItemId);
  743. if(empty($aItem) || !is_array($aItem))
  744. return array();
  745. $iItemId = (int)$aItem[$CNF['FIELD_ID']];
  746. $fItemPrice = (float)$aItem[$CNF['FIELD_PRICE']];
  747. if($this->isAuction($aItem)) {
  748. $aOffer = $this->_oDb->getOffersBy(array(
  749. 'type' => 'accepted',
  750. 'content_id' => $iItemId,
  751. 'status' => BX_ADS_OFFER_STATUS_ACCEPTED
  752. ));
  753. if(!empty($aOffer) && is_array($aOffer))
  754. $fItemPrice = (float)$aOffer[$CNF['FIELD_OFR_AMOUNT']];
  755. }
  756. return array (
  757. 'id' => $iItemId,
  758. 'author_id' => $aItem[$CNF['FIELD_AUTHOR']],
  759. 'name' => $aItem[$CNF['FIELD_NAME']],
  760. 'title' => $aItem[$CNF['FIELD_TITLE']],
  761. 'description' => $aItem[$CNF['FIELD_TEXT']],
  762. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'], array('id' => $aItem[$CNF['FIELD_ID']])),
  763. 'price_single' => $fItemPrice,
  764. 'price_recurring' => '',
  765. 'period_recurring' => 0,
  766. 'period_unit_recurring' => '',
  767. 'trial_recurring' => ''
  768. );
  769. }
  770. /**
  771. * @page service Service Calls
  772. * @section bx_ads Ads
  773. * @subsection bx_ads-payments Payments
  774. * @subsubsection bx_ads-get_cart_items get_cart_items
  775. *
  776. * @code bx_srv('bx_ads', 'get_cart_items', [...]); @endcode
  777. *
  778. * Get an array with prodicts' descriptions by seller. Is used in Manual Order Processing in payments processing module.
  779. *
  780. * @param $iSellerId seller ID.
  781. * @return an array with prodicts' descriptions. Empty array is returned if something is wrong or seller doesn't have any products.
  782. *
  783. * @see BxAdsModule::serviceGetCartItems
  784. */
  785. /**
  786. * @ref bx_ads-get_cart_items "get_cart_items"
  787. */
  788. public function serviceGetCartItems($iSellerId)
  789. {
  790. $CNF = &$this->_oConfig->CNF;
  791. $iSellerId = (int)$iSellerId;
  792. if(empty($iSellerId))
  793. return array();
  794. $aItems = $this->_oDb->getEntriesByAuthor($iSellerId);
  795. $aResult = array();
  796. foreach($aItems as $aItem) {
  797. if($aItem[$CNF['FIELD_STATUS']] != BX_BASE_MOD_TEXT_STATUS_ACTIVE || empty($aItem[$CNF['FIELD_QUANTITY']]))
  798. continue;
  799. $aResult[] = array(
  800. 'id' => $aItem[$CNF['FIELD_ID']],
  801. 'author_id' => $aItem[$CNF['FIELD_AUTHOR']],
  802. 'name' => $aItem[$CNF['FIELD_NAME']],
  803. 'title' => $aItem[$CNF['FIELD_TITLE']],
  804. 'description' => $aItem[$CNF['FIELD_TEXT']],
  805. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'], array('id' => $aItem[$CNF['FIELD_ID']])),
  806. 'price_single' => $aItem[$CNF['FIELD_PRICE_SINGLE']],
  807. 'price_recurring' => '',
  808. 'period_recurring' => 0,
  809. 'period_unit_recurring' => '',
  810. 'trial_recurring' => ''
  811. );
  812. }
  813. return $aResult;
  814. }
  815. /**
  816. * @page service Service Calls
  817. * @section bx_ads Ads
  818. * @subsection bx_ads-payments Payments
  819. * @subsubsection bx_ads-authorize_cart_item authorize_cart_item
  820. *
  821. * @code bx_srv('bx_ads', 'authorize_cart_item', [...]); @endcode
  822. *
  823. * Authorize the order to process a single time payment inside the Ads module in future. Is called with payment processing module after the order was authorized there.
  824. *
  825. * @param $iClientId client ID.
  826. * @param $iSellerId seller ID
  827. * @param $iItemId item ID.
  828. * @param $iItemCount the number of purchased items.
  829. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  830. * @return an array with authorize prodict's description. Empty array is returned if something is wrong.
  831. *
  832. * @see BxAdsModule::serviceAuthorizeCartItem
  833. */
  834. /**
  835. * @ref bx_ads-authorize_cart_item "authorize_cart_item"
  836. */
  837. public function serviceAuthorizeCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  838. {
  839. $CNF = &$this->_oConfig->CNF;
  840. $aItem = $this->serviceGetCartItem($iItemId);
  841. if(empty($aItem) || !is_array($aItem))
  842. return [];
  843. $aEntry = $this->_oDb->getContentInfoById($iItemId);
  844. if(empty($aEntry) || !is_array($aEntry))
  845. return [];
  846. bx_alert($this->getName(), 'order_authorize', 0, false, [
  847. 'product_id' => $iItemId,
  848. 'profile_id' => $iClientId,
  849. 'order' => $sOrder,
  850. 'count' => $iItemCount
  851. ]);
  852. return $aItem;
  853. }
  854. /**
  855. * @page service Service Calls
  856. * @section bx_ads Ads
  857. * @subsection bx_ads-payments Payments
  858. * @subsubsection bx_ads-register_cart_item register_cart_item
  859. *
  860. * @code bx_srv('bx_ads', 'register_cart_item', [...]); @endcode
  861. *
  862. * Register a processed single time payment inside the Ads module. Is called with payment processing module after the payment was registered there.
  863. *
  864. * @param $iClientId client ID.
  865. * @param $iSellerId seller ID
  866. * @param $iItemId item ID.
  867. * @param $iItemCount the number of purchased items.
  868. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  869. * @param $sLicense license number genereted with payment processing module for internal usage
  870. * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
  871. *
  872. * @see BxAdsModule::serviceRegisterCartItem
  873. */
  874. /**
  875. * @ref bx_ads-register_cart_item "register_cart_item"
  876. */
  877. public function serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  878. {
  879. $CNF = &$this->_oConfig->CNF;
  880. $aItem = $this->serviceGetCartItem($iItemId);
  881. if(empty($aItem) || !is_array($aItem))
  882. return array();
  883. $aEntry = $this->_oDb->getContentInfoById($iItemId);
  884. $iEntryQnt = (int)$aEntry[$CNF['FIELD_QUANTITY']];
  885. if(empty($aEntry) || !is_array($aEntry) || ($iEntryQnt - $iItemCount) < 0)
  886. return array();
  887. if(!$this->_oDb->registerLicense($iClientId, $iItemId, $iItemCount, $sOrder, $sLicense))
  888. return array();
  889. $iEntryQnt -= $iItemCount;
  890. $this->_oDb->updateEntriesBy(array(
  891. $CNF['FIELD_QUANTITY'] => $iEntryQnt,
  892. $CNF['FIELD_STATUS'] => $iEntryQnt == 0 ? BX_ADS_STATUS_SOLD : BX_BASE_MOD_TEXT_STATUS_ACTIVE,
  893. $CNF['FIELD_SOLD'] => $iEntryQnt == 0 ? time() : 0,
  894. ), array($CNF['FIELD_ID'] => $iItemId));
  895. bx_alert($this->getName(), 'license_register', 0, false, array(
  896. 'product_id' => $iItemId,
  897. 'profile_id' => $iClientId,
  898. 'order' => $sOrder,
  899. 'license' => $sLicense,
  900. 'count' => $iItemCount
  901. ));
  902. if($iEntryQnt == 0) {
  903. $aParams = $this->_alertParams($aEntry);
  904. bx_alert($this->getName(), 'sold', $iItemId, false, $aParams);
  905. }
  906. $oClient = BxDolProfile::getInstanceMagic($iClientId);
  907. $oSeller = BxDolProfile::getInstanceMagic($iSellerId);
  908. $sSellerUrl = $oSeller->getUrl();
  909. $sSellerName = $oSeller->getDisplayName();
  910. $sNote = $aEntry[$CNF['FIELD_NOTES_PURCHASED']];
  911. if(empty($sNote))
  912. $sNote = _t('_bx_ads_txt_purchased_note', $sSellerUrl, $sSellerName);
  913. sendMailTemplate($CNF['ETEMPLATE_PURCHASED'], 0, $iClientId, array(
  914. 'client_name' => $oClient->getDisplayName(),
  915. 'entry_name' => $aEntry[$CNF['FIELD_TITLE']],
  916. 'entry_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'], array('id' => $aEntry[$CNF['FIELD_ID']])),
  917. 'vendor_url' => $sSellerUrl,
  918. 'vendor_name' => $sSellerName,
  919. 'count' => (int)$iItemCount,
  920. 'license' => $sLicense,
  921. 'notes' => $sNote,
  922. ));
  923. return $aItem;
  924. }
  925. /**
  926. * @page service Service Calls
  927. * @section bx_ads Ads
  928. * @subsection bx_ads-payments Payments
  929. * @subsubsection bx_ads-authorize_subscription_item authorize_subscription_item
  930. *
  931. * @code bx_srv('bx_ads', 'authorize_subscription_item', [...]); @endcode
  932. *
  933. * Authorize the order to process a subscription (recurring payment) inside the Ads module in future. Is called with payment processing module after the order for subscription was authorized there.
  934. *
  935. * @param $iClientId client ID.
  936. * @param $iSellerId seller ID
  937. * @param $iItemId item ID.
  938. * @param $iItemCount the number of purchased items.
  939. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  940. * @return an array with authorize prodict's description. Empty array is returned if something is wrong.
  941. *
  942. * @see BxAdsModule::serviceAuthorizeSubscriptionItem
  943. */
  944. /**
  945. * @ref bx_ads-authorize_subscription_item "authorize_subscription_item"
  946. */
  947. public function serviceAuthorizeSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  948. {
  949. return [];
  950. }
  951. /**
  952. * @page service Service Calls
  953. * @section bx_ads Ads
  954. * @subsection bx_ads-payments Payments
  955. * @subsubsection bx_ads-register_subscription_item register_subscription_item
  956. *
  957. * @code bx_srv('bx_ads', 'register_subscription_item', [...]); @endcode
  958. *
  959. * Register a processed subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was registered there.
  960. *
  961. * @param $iClientId client ID.
  962. * @param $iSellerId seller ID
  963. * @param $iItemId item ID.
  964. * @param $iItemCount the number of purchased items.
  965. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  966. * @param $sLicense license number genereted with payment processing module for internal usage
  967. * @return an array with subscribed prodict's description. Empty array is returned if something is wrong.
  968. *
  969. * @see BxAdsModule::serviceRegisterSubscriptionItem
  970. */
  971. /**
  972. * @ref bx_ads-register_subscription_item "register_subscription_item"
  973. */
  974. public function serviceRegisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  975. {
  976. return [];
  977. }
  978. /**
  979. * @page service Service Calls
  980. * @section bx_ads Ads
  981. * @subsection bx_ads-payments Payments
  982. * @subsubsection bx_ads-reregister_cart_item reregister_cart_item
  983. *
  984. * @code bx_srv('bx_ads', 'reregister_cart_item', [...]); @endcode
  985. *
  986. * Reregister a single time payment inside the Ads module. Is called with payment processing module after the payment was reregistered there.
  987. *
  988. * @param $iClientId client ID.
  989. * @param $iSellerId seller ID
  990. * @param $iItemIdOld old item ID.
  991. * @param $iItemIdNew new item ID.
  992. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  993. * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
  994. *
  995. * @see BxAdsModule::serviceReregisterCartItem
  996. */
  997. /**
  998. * @ref bx_ads-reregister_cart_item "reregister_cart_item"
  999. */
  1000. public function serviceReregisterCartItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  1001. {
  1002. return array();
  1003. }
  1004. /**
  1005. * @page service Service Calls
  1006. * @section bx_ads Ads
  1007. * @subsection bx_ads-payments Payments
  1008. * @subsubsection bx_ads-reregister_subscription_item reregister_subscription_item
  1009. *
  1010. * @code bx_srv('bx_ads', 'reregister_subscription_item', [...]); @endcode
  1011. *
  1012. * Reregister a subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was reregistered there.
  1013. *
  1014. * @param $iClientId client ID.
  1015. * @param $iSellerId seller ID
  1016. * @param $iItemIdOld old item ID.
  1017. * @param $iItemIdNew new item ID.
  1018. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  1019. * @return an array with subscribed prodict's description. Empty array is returned if something is wrong.
  1020. *
  1021. * @see BxAdsModule::serviceReregisterSubscriptionItem
  1022. */
  1023. /**
  1024. * @ref bx_ads-reregister_subscription_item "reregister_subscription_item"
  1025. */
  1026. public function serviceReregisterSubscriptionItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  1027. {
  1028. return array();
  1029. }
  1030. /**
  1031. * @page service Service Calls
  1032. * @section bx_ads Ads
  1033. * @subsection bx_ads-payments Payments
  1034. * @subsubsection bx_ads-unregister_cart_item unregister_cart_item
  1035. *
  1036. * @code bx_srv('bx_ads', 'unregister_cart_item', [...]); @endcode
  1037. *
  1038. * Unregister an earlier processed single time payment inside the Ads module. Is called with payment processing module after the payment was unregistered there.
  1039. *
  1040. * @param $iClientId client ID.
  1041. * @param $iSellerId seller ID
  1042. * @param $iItemId item ID.
  1043. * @param $iItemCount the number of purchased items.
  1044. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  1045. * @param $sLicense license number genereted with payment processing module for internal usage
  1046. * @return boolean value determining where the payment was unregistered or not.
  1047. *
  1048. * @see BxAdsModule::serviceUnregisterCartItem
  1049. */
  1050. /**
  1051. * @ref bx_ads-unregister_cart_item "unregister_cart_item"
  1052. */
  1053. public function serviceUnregisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  1054. {
  1055. if(!$this->_oDb->unregisterLicense($iClientId, $iItemId, $sOrder, $sLicense))
  1056. return false;
  1057. bx_alert($this->getName(), 'license_unregister', 0, false, array(
  1058. 'product_id' => $iItemId,
  1059. 'profile_id' => $iClientId,
  1060. 'order' => $sOrder,
  1061. 'license' => $sLicense,
  1062. 'count' => $iItemCount
  1063. ));
  1064. return true;;
  1065. }
  1066. /**
  1067. * @page service Service Calls
  1068. * @section bx_ads Ads
  1069. * @subsection bx_ads-payments Payments
  1070. * @subsubsection bx_ads-unregister_subscription_item unregister_subscription_item
  1071. *
  1072. * @code bx_srv('bx_ads', 'unregister_subscription_item', [...]); @endcode
  1073. *
  1074. * Unregister an earlier processed subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was unregistered there.
  1075. *
  1076. * @param $iClientId client ID.
  1077. * @param $iSellerId seller ID
  1078. * @param $iItemId item ID.
  1079. * @param $iItemCount the number of purchased items.
  1080. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  1081. * @param $sLicense license number genereted with payment processing module for internal usage
  1082. * @return boolean value determining where the subscription was unregistered or not.
  1083. *
  1084. * @see BxAdsModule::serviceUnregisterSubscriptionItem
  1085. */
  1086. /**
  1087. * @ref bx_ads-unregister_subscription_item "unregister_subscription_item"
  1088. */
  1089. public function serviceUnregisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  1090. {
  1091. return true;
  1092. }
  1093. /**
  1094. * @page service Service Calls
  1095. * @section bx_ads Ads
  1096. * @subsection bx_ads-payments Payments
  1097. * @subsubsection bx_ads-cancel_subscription_item cancel_subscription_item
  1098. *
  1099. * @code bx_srv('bx_ads', 'cancel_subscription_item', [...]); @endcode
  1100. *
  1101. * Cancel an earlier processed subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was canceled there.
  1102. *
  1103. * @param $iClientId client ID.
  1104. * @param $iSellerId seller ID
  1105. * @param $iItemId item ID.
  1106. * @param $iItemCount the number of purchased items.
  1107. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  1108. * @return boolean value determining where the subscription was canceled or not.
  1109. *
  1110. * @see BxAdsModule::serviceCancelSubscriptionItem
  1111. */
  1112. /**
  1113. * @ref bx_ads-cancel_subscription_item "cancel_subscription_item"
  1114. */
  1115. public function serviceCancelSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  1116. {
  1117. return true;
  1118. }
  1119. public function serviceGetOffersCount($sStatus = '')
  1120. {
  1121. if(!$this->_oConfig->isAuction())
  1122. return 0;
  1123. if(empty($sStatus) || !in_array($sStatus, $this->_aOfferStatuses))
  1124. $sStatus = BX_ADS_OFFER_STATUS_AWAITING;
  1125. $iUserId = bx_get_logged_profile_id();
  1126. return $this->_oDb->getOffersBy(array('type' => 'content_author_id', 'author_id' => $iUserId, 'status' => $sStatus, 'count' => true));
  1127. }
  1128. public function serviceGetLiveUpdates($sStatus, $aMenuItemParent, $aMenuItemChild, $iCount = 0)
  1129. {
  1130. if(!in_array($sStatus, $this->_aOfferStatuses))
  1131. return false;
  1132. $iUserId = bx_get_logged_profile_id();
  1133. $iCountNew = $this->_oDb->getOffersBy(array('type' => 'content_author_id', 'author_id' => $iUserId, 'status' => $sStatus, 'count' => true));
  1134. if($iCountNew == $iCount)
  1135. return false;
  1136. return array(
  1137. 'count' => $iCountNew, // required
  1138. 'method' => 'bx_menu_show_live_update(oData)', // required
  1139. 'data' => array(
  1140. 'code' => BxDolTemplate::getInstance()->parseHtmlByTemplateName('menu_item_addon', array(
  1141. 'content' => '{count}'
  1142. )),
  1143. 'mi_parent' => $aMenuItemParent,
  1144. 'mi_child' => $aMenuItemChild
  1145. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  1146. );
  1147. }
  1148. public function serviceOffers()
  1149. {
  1150. $CNF = &$this->_oConfig->CNF;
  1151. if(!$this->_oConfig->isAuction())
  1152. return '';
  1153. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_OFFERS_ALL']);
  1154. if(!$oGrid)
  1155. return '';
  1156. return $oGrid->getCode();
  1157. }
  1158. public function serviceEntityOffers($iContentId = 0)
  1159. {
  1160. $CNF = &$this->_oConfig->CNF;
  1161. if(!$this->_oConfig->isAuction())
  1162. return '';
  1163. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_OFFERS']);
  1164. if(!$oGrid)
  1165. return '';
  1166. if(empty($iContentId) && ($_iContentId = bx_get('id')) !== false)
  1167. $iContentId = (int)$_iContentId;
  1168. $oGrid->setContentId($iContentId);
  1169. return $oGrid->getCode();
  1170. }
  1171. public function serviceEntityOfferAccepted($iContentId = 0)
  1172. {
  1173. $CNF = &$this->_oConfig->CNF;
  1174. if(!$this->_oConfig->isAuction())
  1175. return '';
  1176. $iUserId = bx_get_logged_profile_id();
  1177. if(empty($iContentId) && ($_iContentId = bx_get('id')) !== false)
  1178. $iContentId = (int)$_iContentId;
  1179. $aContent = $this->_oDb->getContentInfoById($iContentId);
  1180. if(empty($aContent) || !is_array($aContent) || $aContent[$CNF['FIELD_QUANTITY']] <= 0)
  1181. return '';
  1182. $aOffer = $this->_oDb->getOffersBy(array(
  1183. 'type' => 'content_and_author_ids',
  1184. 'content_id' => $iContentId,
  1185. 'author_id' => $iUserId,
  1186. 'status' => BX_ADS_OFFER_STATUS_ACCEPTED
  1187. ));
  1188. if(empty($aOffer) || !is_array($aOffer))
  1189. return '';
  1190. return $this->_oTemplate->entryOfferAccepted($iUserId, $aContent, $aOffer);
  1191. }
  1192. public function isEntryActive($aContentInfo)
  1193. {
  1194. $CNF = &$this->_oConfig->CNF;
  1195. if($aContentInfo[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id() || $this->_isModerator())
  1196. return true;
  1197. if(isset($CNF['FIELD_STATUS']) && !in_array($aContentInfo[$CNF['FIELD_STATUS']], array(BX_BASE_MOD_TEXT_STATUS_ACTIVE, BX_ADS_STATUS_OFFER, BX_ADS_STATUS_SOLD)))
  1198. return false;
  1199. if(isset($CNF['FIELD_STATUS_ADMIN']) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active')
  1200. return false;
  1201. return true;
  1202. }
  1203. public function isAuction($aContentInfo)
  1204. {
  1205. $CNF = &$this->_oConfig->CNF;
  1206. return $this->_oConfig->isAuction() && (int)$aContentInfo[$CNF['FIELD_AUCTION']] != 0;
  1207. }
  1208. public function isAllowedMakeOffer($mixedContent, $isPerformAction = false)
  1209. {
  1210. return $this->checkAllowedMakeOffer($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  1211. }
  1212. public function checkAllowedMakeOffer($mixedContent, $isPerformAction = false)
  1213. {
  1214. $CNF = &$this->_oConfig->CNF;
  1215. $sTxtError = '_sys_txt_access_denied';
  1216. $iProfileId = bx_get_logged_profile_id();
  1217. if(!is_array($mixedContent))
  1218. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  1219. if(empty($mixedContent) || !is_array($mixedContent))
  1220. return _t($sTxtError);
  1221. if(!$this->isAuction($mixedContent) || (int)$mixedContent[$CNF['FIELD_QUANTITY']] <= 0)
  1222. return _t($sTxtError);
  1223. if($mixedContent[$CNF['FIELD_AUTHOR']] == $iProfileId)
  1224. return _t($sTxtError);
  1225. $aCheck = checkActionModule($iProfileId, 'make offer', $this->getName(), $isPerformAction);
  1226. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1227. return $aCheck[CHECK_ACTION_MESSAGE];
  1228. return CHECK_ACTION_RESULT_ALLOWED;
  1229. }
  1230. public function isAllowedViewOffers($mixedContent, $isPerformAction = false)
  1231. {
  1232. return $this->checkAllowedViewOffers($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  1233. }
  1234. public function checkAllowedViewOffers($mixedContent, $isPerformAction = false)
  1235. {
  1236. $CNF = &$this->_oConfig->CNF;
  1237. $sTxtError = '_sys_txt_access_denied';
  1238. if(!is_array($mixedContent))
  1239. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  1240. if(empty($mixedContent) || !is_array($mixedContent))
  1241. return _t($sTxtError);
  1242. if(!$this->isAuction($mixedContent))
  1243. return _t($sTxtError);
  1244. if($this->_isModerator())
  1245. return CHECK_ACTION_RESULT_ALLOWED;
  1246. if($mixedContent[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id())
  1247. return CHECK_ACTION_RESULT_ALLOWED;
  1248. return _t($sTxtError);
  1249. }
  1250. public function isAllowedMarkShipped($mixedContent, $isPerformAction = false)
  1251. {
  1252. return $this->checkAllowedMarkShipped($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  1253. }
  1254. public function checkAllowedMarkShipped($mixedContent, $isPerformAction = false)
  1255. {
  1256. return $this->checkAllowedMarkShippedForProfile($mixedContent, $isPerformAction);
  1257. }
  1258. public function checkAllowedMarkShippedForProfile($mixedContent, $isPerformAction = false, $iProfileId = false)
  1259. {
  1260. $CNF = &$this->_oConfig->CNF;
  1261. $sTxtError = '_sys_txt_access_denied';
  1262. if(!$iProfileId)
  1263. $iProfileId = bx_get_logged_profile_id();
  1264. if(!is_array($mixedContent))
  1265. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  1266. if(empty($mixedContent) || !is_array($mixedContent))
  1267. return _t($sTxtError);
  1268. if((int)$mixedContent[$CNF['FIELD_SHIPPED']] != 0 || $mixedContent[$CNF['FIELD_AUTHOR']] != $iProfileId)
  1269. return _t($sTxtError);
  1270. return CHECK_ACTION_RESULT_ALLOWED;
  1271. }
  1272. public function isAllowedMarkReceived($mixedContent, $isPerformAction = false)
  1273. {
  1274. return $this->checkAllowedMarkReceived($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  1275. }
  1276. public function checkAllowedMarkReceived($mixedContent, $isPerformAction = false)
  1277. {
  1278. return $this->checkAllowedMarkReceivedForProfile($mixedContent, $isPerformAction);
  1279. }
  1280. public function checkAllowedMarkReceivedForProfile($mixedContent, $isPerformAction = false, $iProfileId = false)
  1281. {
  1282. $CNF = &$this->_oConfig->CNF;
  1283. $sTxtError = '_sys_txt_access_denied';
  1284. if(!$iProfileId)
  1285. $iProfileId = bx_get_logged_profile_id();
  1286. if(!is_array($mixedContent))
  1287. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  1288. if(empty($mixedContent) || !is_array($mixedContent))
  1289. return _t($sTxtError);
  1290. if((int)$mixedContent[$CNF['FIELD_RECEIVED']] != 0 || !$this->_oDb->hasLicense($iProfileId, $mixedContent[$CNF['FIELD_ID']]))
  1291. return _t($sTxtError);
  1292. return CHECK_ACTION_RESULT_ALLOWED;
  1293. }
  1294. public function onPublished($iContentId)
  1295. {
  1296. $this->serviceUpdateCategoriesStats($iContentId);
  1297. parent::onPublished($iContentId);
  1298. }
  1299. public function onOfferAdded($iOfferId, &$aResult)
  1300. {
  1301. $CNF = &$this->_oConfig->CNF;
  1302. $aOfferInfo = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
  1303. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  1304. return;
  1305. $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  1306. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1307. if(empty($aContentInfo) || !is_array($aContentInfo))
  1308. return;
  1309. $iViewer = bx_get_logged_profile_id();
  1310. $oViewer = BxDolProfile::getInstanceMagic($iViewer);
  1311. if(getParam($CNF['PARAM_USE_IIN']) == 'on')
  1312. sendMailTemplate($CNF['ETEMPLATE_OFFER_ADDED'], 0, $aContentInfo[$CNF['FIELD_AUTHOR']], array(
  1313. 'viewer_name' => $oViewer->getDisplayName(),
  1314. 'viewer_url' => $oViewer->getUrl(),
  1315. 'entry_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  1316. 'entry_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  1317. 'i' => $CNF['URI_VIEW_ENTRY'],
  1318. $CNF['FIELD_ID'] => $iContentId
  1319. ))
  1320. ));
  1321. $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
  1322. $aParams['override_result'] = &$aResult;
  1323. bx_alert($this->getName(), 'offer_added', $iOfferId, $aOfferInfo[$CNF['FIELD_OFR_AUTHOR']], $aParams);
  1324. }
  1325. public function onOfferAccepted($iOfferId)
  1326. {
  1327. $CNF = &$this->_oConfig->CNF;
  1328. $aOfferInfo = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
  1329. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  1330. return;
  1331. $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  1332. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1333. if(empty($aContentInfo) || !is_array($aContentInfo))
  1334. return;
  1335. if(!$this->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => BX_ADS_STATUS_OFFER), array($CNF['FIELD_ID'] => $iContentId)))
  1336. return;
  1337. $iOfferer = (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']];
  1338. $oOfferer = BxDolProfile::getInstanceMagic($iOfferer);
  1339. if(getParam($CNF['PARAM_USE_IIN']) == 'on')
  1340. sendMailTemplate($CNF['ETEMPLATE_OFFER_ACCEPTED'], 0, $iOfferer, array(
  1341. 'offerer_name' => $oOfferer->getDisplayName(),
  1342. 'offerer_url' => $oOfferer->getUrl(),
  1343. 'entry_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  1344. 'entry_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  1345. 'i' => $CNF['URI_VIEW_ENTRY'],
  1346. $CNF['FIELD_ID'] => $iContentId
  1347. ))
  1348. ));
  1349. $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
  1350. bx_alert($this->getName(), 'offer_accepted', $iOfferId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  1351. }
  1352. public function onOfferDeclined($iOfferId)
  1353. {
  1354. $CNF = &$this->_oConfig->CNF;
  1355. $aOfferInfo = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
  1356. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  1357. return;
  1358. $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  1359. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1360. if(empty($aContentInfo) || !is_array($aContentInfo))
  1361. return;
  1362. $iOfferer = (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']];
  1363. $oOfferer = BxDolProfile::getInstanceMagic($iOfferer);
  1364. if(getParam($CNF['PARAM_USE_IIN']) == 'on')
  1365. sendMailTemplate($CNF['ETEMPLATE_OFFER_DECLINED'], 0, $iOfferer, array(
  1366. 'offerer_name' => $oOfferer->getDisplayName(),
  1367. 'offerer_url' => $oOfferer->getUrl(),
  1368. 'entry_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  1369. 'entry_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  1370. 'i' => $CNF['URI_VIEW_ENTRY'],
  1371. $CNF['FIELD_ID'] => $iContentId
  1372. ))
  1373. ));
  1374. $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
  1375. bx_alert($this->getName(), 'offer_declined', $iOfferId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  1376. }
  1377. public function onOfferCanceled($iOfferId)
  1378. {
  1379. $CNF = &$this->_oConfig->CNF;
  1380. $aOfferInfo = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
  1381. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  1382. return;
  1383. $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  1384. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1385. if(empty($aContentInfo) || !is_array($aContentInfo))
  1386. return;
  1387. if(!$this->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => BX_BASE_MOD_TEXT_STATUS_ACTIVE), array($CNF['FIELD_ID'] => $iContentId)))
  1388. return;
  1389. $iOfferer = (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']];
  1390. $oOfferer = BxDolProfile::getInstanceMagic($iOfferer);
  1391. if(getParam($CNF['PARAM_USE_IIN']) == 'on')
  1392. sendMailTemplate($CNF['ETEMPLATE_OFFER_CANCELED'], 0, (int)$aContentInfo[$CNF['FIELD_AUTHOR']], array(
  1393. 'offerer_name' => $oOfferer->getDisplayName(),
  1394. 'offerer_url' => $oOfferer->getUrl(),
  1395. 'entry_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  1396. 'entry_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  1397. 'i' => $CNF['URI_VIEW_ENTRY'],
  1398. $CNF['FIELD_ID'] => $iContentId
  1399. ))
  1400. ));
  1401. $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
  1402. bx_alert($this->getName(), 'offer_canceled', $iOfferId, $aOfferInfo[$CNF['FIELD_OFR_AUTHOR']], $aParams);
  1403. }
  1404. /**
  1405. * Common methods.
  1406. */
  1407. public function onShipped($mixedContent, $iProfileSrc = 0, $iProfileDst = 0)
  1408. {
  1409. $CNF = &$this->_oConfig->CNF;
  1410. if(!is_array($mixedContent))
  1411. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  1412. $iContentId = (int)$mixedContent[$CNF['FIELD_ID']];
  1413. if(empty($iProfileSrc))
  1414. $iProfileSrc = (int)$mixedContent[$CNF['FIELD_AUTHOR']];
  1415. $oProfileSrc = BxDolProfile::getInstanceMagic($iProfileSrc);
  1416. $aOffer = $this->_oDb->getOffersBy(array('type' => 'accepted', 'content_id' => $iContentId));
  1417. $bOffer = !empty($aOffer) && is_array($aOffer);
  1418. if(empty($iProfileDst) && $bOffer)
  1419. $iProfileDst = (int)$aOffer[$CNF['FIELD_OFR_AUTHOR']];
  1420. if(!empty($oProfileSrc) && !empty($iProfileDst) && getParam($CNF['PARAM_USE_IIN']) == 'on')
  1421. sendMailTemplate($CNF['ETEMPLATE_SHIPPED'], 0, $iProfileDst, array(
  1422. 'vendor_name' => $oProfileSrc->getDisplayName(),
  1423. 'vendor_url' => $oProfileSrc->getUrl(),
  1424. 'entry_name' => $mixedContent[$CNF['FIELD_TITLE']],
  1425. 'entry_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  1426. 'i' => $CNF['URI_VIEW_ENTRY'],
  1427. $CNF['FIELD_ID'] => $iContentId
  1428. ))
  1429. ));
  1430. $aParams = $this->_alertParams($mixedContent);
  1431. $aParams = array_merge($aParams, array(
  1432. 'profile_src' => $iProfileSrc,
  1433. 'profile_dst' => $iProfileDst,
  1434. 'offer_id' => $bOffer ? (int)$aOffer[$CNF['FIELD_OFR_ID']] : 0,
  1435. ));
  1436. bx_alert($this->getName(), 'shipped', $iContentId, false, $aParams);
  1437. }
  1438. public function onReceived($mixedContent, $iProfileSrc = 0, $iProfileDst = 0)
  1439. {
  1440. $CNF = &$this->_oConfig->CNF;
  1441. if(!is_array($mixedContent))
  1442. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  1443. $iContentId = (int)$mixedContent[$CNF['FIELD_ID']];
  1444. if(empty($iProfileDst))
  1445. $iProfileDst = (int)$mixedContent[$CNF['FIELD_AUTHOR']];
  1446. $aOffer = $this->_oDb->getOffersBy(array('type' => 'accepted', 'content_id' => $iContentId));
  1447. $bOffer = !empty($aOffer) && is_array($aOffer);
  1448. if(empty($iProfileSrc) && $bOffer)
  1449. $iProfileSrc = (int)$aOffer[$CNF['FIELD_OFR_AUTHOR']];
  1450. $oProfileSrc = BxDolProfile::getInstanceMagic($iProfileSrc);
  1451. if(!empty($iProfileSrc) && !empty($iProfileDst) && getParam($CNF['PARAM_USE_IIN']) == 'on')
  1452. sendMailTemplate($CNF['ETEMPLATE_RECEIVED'], 0, $iProfileDst, array(
  1453. 'client_name' => $oProfileSrc->getDisplayName(),
  1454. 'client_url' => $oProfileSrc->getUrl(),
  1455. 'entry_name' => $mixedContent[$CNF['FIELD_TITLE']],
  1456. 'entry_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  1457. 'i' => $CNF['URI_VIEW_ENTRY'],
  1458. $CNF['FIELD_ID'] => $iContentId
  1459. ))
  1460. ));
  1461. $aParams = $this->_alertParams($mixedContent);
  1462. $aParams = array_merge($aParams, array(
  1463. 'profile_src' => $iProfileSrc,
  1464. 'profile_dst' => $iProfileDst,
  1465. 'offer_id' => $bOffer ? (int)$aOffer[$CNF['FIELD_OFR_ID']] : 0,
  1466. ));
  1467. bx_alert($this->getName(), 'received', $iContentId, false, $aParams);
  1468. }
  1469. public function offerAccept($iId)
  1470. {
  1471. $CNF = &$this->_oConfig->CNF;
  1472. if(!$this->_oDb->updateOffer(array($CNF['FIELD_OFR_STATUS'] => BX_ADS_OFFER_STATUS_ACCEPTED), array($CNF['FIELD_OFR_ID'] => $iId)))
  1473. return false;
  1474. $this->onOfferAccepted($iId);
  1475. return true;
  1476. }
  1477. public function offerDecline($iId)
  1478. {
  1479. $CNF = &$this->_oConfig->CNF;
  1480. if(!$this->_oDb->updateOffer(array($CNF['FIELD_OFR_STATUS'] => BX_ADS_OFFER_STATUS_DECLINED), array($CNF['FIELD_OFR_ID'] => $iId)))
  1481. return false;
  1482. $this->onOfferDeclined($iId);
  1483. return true;
  1484. }
  1485. public function offerCancel($iId)
  1486. {
  1487. $CNF = &$this->_oConfig->CNF;
  1488. if(!$this->_oDb->updateOffer(array($CNF['FIELD_OFR_STATUS'] => BX_ADS_OFFER_STATUS_CANCELED), array($CNF['FIELD_OFR_ID'] => $iId)))
  1489. return false;
  1490. $this->onOfferCanceled($iId);
  1491. return true;
  1492. }
  1493. public function offerPay($iId)
  1494. {
  1495. $CNF = &$this->_oConfig->CNF;
  1496. $aOffer = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iId));
  1497. if(empty($aOffer) || !is_array($aOffer))
  1498. return false;
  1499. $iContent = (int)$aOffer[$CNF['FIELD_OFR_CONTENT']];
  1500. $aContent = $this->_oDb->getContentInfoById($iContent);
  1501. $iContentAuthor = (int)$aContent[$CNF['FIELD_AUTHOR']];
  1502. $aReturn = array(
  1503. 'redirect' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  1504. 'i' => $CNF['URI_VIEW_ENTRY'],
  1505. $CNF['FIELD_ID'] => $aOffer[$CNF['FIELD_OFR_CONTENT']]
  1506. ))
  1507. );
  1508. $oPayments = BxDolPayments::getInstance();
  1509. $aResult = $oPayments->addToCart($iContentAuthor, $this->getName(), $iContent, $aOffer[$CNF['FIELD_OFR_QUANTITY']]);
  1510. if(!empty($aResult) && is_array($aResult)) {
  1511. if(!empty($aResult['message']))
  1512. $aReturn['msg'] = $aResult['message'];
  1513. if(isset($aResult['code']) && (int)$aResult['code'] == 0)
  1514. $aReturn['redirect'] = $oPayments->getCartUrl($iContentAuthor);
  1515. }
  1516. return $aReturn;
  1517. }
  1518. public function processMetasAdd($iContentId)
  1519. {
  1520. if(!parent::processMetasAdd($iContentId))
  1521. return false;
  1522. $CNF = &$this->_oConfig->CNF;
  1523. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1524. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1525. $aCategoryTypes = $this->_oDb->getCategoryTypes(array('type' => 'all'));
  1526. foreach($aCategoryTypes as $aCategoryType)
  1527. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $aCategoryType['display_add']);
  1528. return true;
  1529. }
  1530. public function processMetasEdit($iContentId, $oForm)
  1531. {
  1532. if(!parent::processMetasEdit($iContentId, $oForm))
  1533. return false;
  1534. $CNF = &$this->_oConfig->CNF;
  1535. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1536. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1537. $aCategoryTypes = $this->_oDb->getCategoryTypes(array('type' => 'all'));
  1538. foreach($aCategoryTypes as $aCategoryType)
  1539. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $aCategoryType['display_edit']);
  1540. return true;
  1541. }
  1542. public function getCategoryDisplay($sDisplayType, $iCategory = 0)
  1543. {
  1544. if(empty($iCategory) && bx_get('category') !== false)
  1545. $iCategory = (int)bx_get('category');
  1546. if(empty($iCategory))
  1547. return false;
  1548. $aCategory = $this->_oDb->getCategories(array('type' => 'id_full', 'id' => $iCategory));
  1549. $sKey = 'type_display_' . $sDisplayType;
  1550. if(empty($aCategory[$sKey]))
  1551. return false;
  1552. return $aCategory[$sKey];
  1553. }
  1554. /**
  1555. * Internal methods.
  1556. */
  1557. protected function _actionMarkAs($sAction)
  1558. {
  1559. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1560. if(($mixedResult = $this->serviceMarkAs($sAction, $iContentId)) !== true)
  1561. return array('msg' => $mixedResult);
  1562. return array(
  1563. 'reload' => 1
  1564. );
  1565. }
  1566. protected function _actionChangeStatus($sStatus)
  1567. {
  1568. $CNF = &$this->_oConfig->CNF;
  1569. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1570. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1571. if(($mixedResult = $this->checkAllowedEdit($aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED)
  1572. return array('msg' => $mixedResult);
  1573. if(!$this->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => $sStatus), array($CNF['FIELD_ID'] => $iContentId)))
  1574. return array('msg' => _t('_bx_ads_txt_err_cannot_perform_action'));
  1575. $this->serviceUpdateCategoriesStats($aContentInfo);
  1576. return array(
  1577. 'reload' => 1
  1578. );
  1579. }
  1580. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  1581. {
  1582. $CNF = &$this->_oConfig->CNF;
  1583. $mixedContent = $this->_getContent($iContentId, true);
  1584. if($mixedContent === false)
  1585. return false;
  1586. list($iContentId, $aContentInfo) = $mixedContent;
  1587. $sDisplayType = false;
  1588. switch($sFormMethod) {
  1589. case 'editDataForm':
  1590. $sDisplayType = 'edit';
  1591. break;
  1592. case 'viewDataForm':
  1593. case 'viewDataEntry':
  1594. $sDisplayType = 'view';
  1595. break;
  1596. }
  1597. if($sDisplayType !== false && ($sDisplayNew = $this->getCategoryDisplay($sDisplayType, $aContentInfo[$CNF['FIELD_CATEGORY']])) !== false)
  1598. $sDisplay = $sDisplayNew;
  1599. return parent::_serviceEntityForm ($sFormMethod, $iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  1600. }
  1601. protected function _getCategoryOptions($iParentId, &$aValues)
  1602. {
  1603. $aCategories = $this->_oDb->getCategories(array('type' => 'parent_id', 'parent_id' => $iParentId, 'active' => true));
  1604. foreach($aCategories as $aCategory) {
  1605. $aValues[] = array('key' => $aCategory['id'], 'value' => str_repeat('--', (int)$aCategory['level']) . ' ' . _t($aCategory['title']));
  1606. $this->_getCategoryOptions($aCategory['id'], $aValues);
  1607. }
  1608. }
  1609. protected function _getSearchableFields($mixedDisplayType = '')
  1610. {
  1611. $CNF = &$this->_oConfig->CNF;
  1612. if(empty($mixedDisplayType))
  1613. $mixedDisplayType = array('add', 'edit');
  1614. $aResult = array();
  1615. $aDisplays = $this->_oDb->getDisplays($this->_oConfig->getName() . '_entry', $mixedDisplayType);
  1616. foreach($aDisplays as $aDisplay) {
  1617. if($aDisplay['display_name'] == $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])
  1618. continue;
  1619. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $aDisplay['display_name'], $this->_oTemplate);
  1620. if(!$oForm)
  1621. continue;
  1622. $aResult = array_merge($aResult, $oForm->aInputs);
  1623. }
  1624. return $aResult;
  1625. }
  1626. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  1627. {
  1628. $CNF = &$this->_oConfig->CNF;
  1629. $bDynamic = isset($aBrowseParams['dynamic_mode']) && (bool)$aBrowseParams['dynamic_mode'] === true;
  1630. $sCategory = '';
  1631. if(!empty($CNF['FIELD_CATEGORY']) && !empty($aContentInfo[$CNF['FIELD_CATEGORY']])) {
  1632. $iCategory = (int)$aContentInfo[$CNF['FIELD_CATEGORY']];
  1633. $aCategory = $this->_oDb->getCategories(array('type' => 'id', 'id' => $iCategory));
  1634. $sCategory = _t($aCategory['title']);
  1635. $sCategoryLink = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_CATEGORIES'], array($CNF['GET_PARAM_CATEGORY'] => $iCategory));
  1636. }
  1637. $sPrice = _t('_bx_ads_txt_free');
  1638. if(!empty($CNF['FIELD_PRICE']) && !empty($aContentInfo[$CNF['FIELD_PRICE']]))
  1639. $sPrice = _t_format_currency((float)$aContentInfo[$CNF['FIELD_PRICE']]);
  1640. $sInclude = $this->_oTemplate->addCss(array('timeline.css'), $bDynamic);
  1641. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  1642. $aResult['text'] = $this->_oTemplate->parseHtmlByName('timeline_post_text.html', array(
  1643. 'category_link' => $sCategoryLink,
  1644. 'category_title' => $sCategory,
  1645. 'category_title_attr' => bx_html_attribute($sCategory),
  1646. 'price' => $sPrice,
  1647. 'text' => $aResult['text']
  1648. )) . ($bDynamic ? $sInclude : '');
  1649. return $aResult;
  1650. }
  1651. protected function _getBlockLicenses($sType = '')
  1652. {
  1653. $CNF = &$this->_oConfig->CNF;
  1654. $sGrid = $CNF['OBJECT_GRID_LICENSES' . (!empty($sType) ? '_' . strtoupper($sType) : '')];
  1655. $oGrid = BxDolGrid::getObjectInstance($sGrid);
  1656. if(!$oGrid)
  1657. return '';
  1658. $this->_oDb->updateLicense(array('new' => 0), array('profile_id' => bx_get_logged_profile_id(), 'new' => 1));
  1659. $this->_oTemplate->addJs(array('licenses.js'));
  1660. return array(
  1661. 'content' => $this->_oTemplate->getJsCode('licenses', array('sObjNameGrid' => $sGrid)) . $oGrid->getCode(),
  1662. 'menu' => $CNF['OBJECT_MENU_LICENSES']
  1663. );
  1664. }
  1665. protected function _alertParamsOffer($aContentInfo, $aOfferInfo)
  1666. {
  1667. $CNF = &$this->_oConfig->CNF;
  1668. $aParams = array(
  1669. 'object_id' => (int)$aContentInfo[$CNF['FIELD_ID']],
  1670. 'object_author_id' => (int)$aContentInfo[$CNF['FIELD_AUTHOR']],
  1671. 'offer_id' => (int)$aOfferInfo[$CNF['FIELD_OFR_ID']],
  1672. 'offer_author_id' => (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']],
  1673. );
  1674. if(isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  1675. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  1676. return $aParams;
  1677. }
  1678. }
  1679. /** @} */