BxAdsModule.php 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588
  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_STATUS_ADMIN_UNPAID', 'unpaid');
  14. define('BX_ADS_COMMODITY_TYPE_PRODUCT', 'product');
  15. define('BX_ADS_COMMODITY_TYPE_PROMOTION', 'promotion');
  16. define('BX_ADS_OFFER_STATUS_ACCEPTED', 'accepted');
  17. define('BX_ADS_OFFER_STATUS_AWAITING', 'awaiting');
  18. define('BX_ADS_OFFER_STATUS_DECLINED', 'declined');
  19. define('BX_ADS_OFFER_STATUS_CANCELED', 'canceled');
  20. define('BX_ADS_OFFER_STATUS_PAID', 'paid');
  21. /**
  22. * Ads module
  23. */
  24. class BxAdsModule extends BxBaseModTextModule
  25. {
  26. protected $_aOfferStatuses;
  27. function __construct(&$aModule)
  28. {
  29. parent::__construct($aModule);
  30. $this->_oConfig->init($this->_oDb);
  31. $CNF = &$this->_oConfig->CNF;
  32. $this->_aSearchableNamesExcept = array_merge($this->_aSearchableNamesExcept, array(
  33. $CNF['FIELD_CATEGORY_VIEW'],
  34. $CNF['FIELD_CATEGORY_SELECT']
  35. ));
  36. $this->_aOfferStatuses = array(
  37. BX_ADS_OFFER_STATUS_ACCEPTED,
  38. BX_ADS_OFFER_STATUS_AWAITING,
  39. BX_ADS_OFFER_STATUS_DECLINED
  40. );
  41. }
  42. public function decodeDataApi ($aData, $bExtended = false)
  43. {
  44. $CNF = $this->_oConfig->CNF;
  45. $aResult = array_merge(parent::decodeDataApi($aData, $bExtended), [
  46. $CNF['FIELD_PRICE'] => $aData[$CNF['FIELD_PRICE']],
  47. $CNF['FIELD_QUANTITY'] => $aData[$CNF['FIELD_QUANTITY']],
  48. $CNF['FIELD_NOTES_PURCHASED'] => $aData[$CNF['FIELD_NOTES_PURCHASED']]
  49. ]);
  50. if($this->_oConfig->isSources() && !empty($aData[$CNF['FIELD_URL']]))
  51. $aResult[$CNF['FIELD_URL']] = $aData[$CNF['FIELD_URL']];
  52. return $aResult;
  53. }
  54. public function actionGetSource()
  55. {
  56. $aEntries = $this->serviceGetSourceData();
  57. header('Content-Type:text/javascript; charset=utf-8');
  58. echo(json_encode($aEntries));
  59. }
  60. public function serviceGetSourceData()
  61. {
  62. $sSourceType = bx_get('source_type');
  63. if(empty($sSourceType)) {
  64. $aSource = $this->serviceGetSource($this->_iProfileId);
  65. if(!empty($aSource) && is_array($aSource))
  66. $sSourceType = $aSource['name'];
  67. }
  68. $sTerm = bx_get('term');
  69. $aEntries = $this->serviceLoadEntriesFromSourceByTerm($sSourceType, $sTerm);
  70. return $aEntries;
  71. }
  72. public function actionLoadEntryFromSource()
  73. {
  74. $sSourceType = bx_process_url_param(bx_process_input(bx_get('source_type')));
  75. $sSource = bx_process_url_param(bx_process_input(bx_get('source')));
  76. if(empty($sSourceType) || empty($sSource))
  77. return echoJson(['code' => 1]);
  78. $aEntry = $this->serviceLoadEntryFromSource($sSourceType, $sSource);
  79. if(empty($aEntry) || !is_array($aEntry))
  80. return echoJson(['code' => 2]);
  81. return echoJson([
  82. 'code' => 0,
  83. 'fields' => $aEntry
  84. ]);
  85. }
  86. public function actionGetCategoryForm()
  87. {
  88. if(($iCategory = bx_get('category')) === false || (int)$iCategory == 0)
  89. return echoJson(['msg' => _t('_bx_ads_form_entry_input_category_select_err')]);
  90. return echoJson([
  91. 'eval' => $this->_oConfig->getJsObject('form') . '.onSelectCategory(oData)',
  92. 'content' => $this->serviceGetCreatePostForm([
  93. 'absolute_action_url' => true,
  94. 'dynamic_mode' => true,
  95. 'context_id' => ($iContextId = bx_get('context_id')) !== false ? (int)$iContextId : false
  96. ])
  97. ]);
  98. }
  99. public function actionCheckName()
  100. {
  101. $CNF = &$this->_oConfig->CNF;
  102. $iId = (int)bx_get($CNF['FIELD_ID']);
  103. $sTitle = bx_process_input(bx_get($CNF['FIELD_TITLE']));
  104. echoJson($this->serviceCheckName($sTitle, $iId));
  105. }
  106. public function actionInterested()
  107. {
  108. $CNF = &$this->_oConfig->CNF;
  109. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  110. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  111. if(empty($aContentInfo) || !is_array($aContentInfo))
  112. return echoJson(array());
  113. $iViewer = bx_get_logged_profile_id();
  114. $oViewer = BxDolProfile::getInstance($iViewer);
  115. if(!$oViewer)
  116. return echoJson(array());
  117. $iContentAuthor = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  118. if($iContentAuthor == $iViewer)
  119. return echoJson(array('msg' => _t('_bx_ads_txt_err_your_own')));
  120. if($this->_oDb->isInterested($iContentId, $iViewer))
  121. return echoJson(array('msg' => _t('_bx_ads_txt_err_duplicate')));
  122. $iInterestId = $this->_oDb->insertInterested(array('entry_id' => $iContentId, 'profile_id' => $iViewer));
  123. if(!$iInterestId)
  124. return echoJson(array('msg' => _t('_bx_ads_txt_err_cannot_perform_action')));
  125. bx_alert($this->getName(), 'doInterest', $iContentId, $iViewer, array(
  126. 'subobject_id' => $iInterestId,
  127. 'subobject_author_id' => $iViewer,
  128. 'object_author_id' => $iContentAuthor
  129. ));
  130. if(getParam($CNF['PARAM_USE_IIN']) == 'on')
  131. sendMailTemplate($CNF['ETEMPLATE_INTERESTED'], 0, $iContentAuthor, array(
  132. 'viewer_name' => $oViewer->getDisplayName(),
  133. 'viewer_url' => $oViewer->getUrl(),
  134. 'ad_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  135. 'ad_url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php', array(
  136. 'i' => $CNF['URI_VIEW_ENTRY'],
  137. $CNF['FIELD_ID'] => $iContentId
  138. )))
  139. ));
  140. return echoJson(array('msg' => _t('_bx_ads_txt_msg_author_notified')));
  141. }
  142. public function actionShow()
  143. {
  144. return echoJson($this->_actionChangeStatus(BX_BASE_MOD_TEXT_STATUS_ACTIVE));
  145. }
  146. public function actionHide()
  147. {
  148. return echoJson($this->_actionChangeStatus(BX_BASE_MOD_TEXT_STATUS_HIDDEN));
  149. }
  150. public function actionMakeOffer()
  151. {
  152. $CNF = &$this->_oConfig->CNF;
  153. $sJsObject = $this->_oConfig->getJsObject('entry');
  154. $iAuthorId = bx_get_logged_profile_id();
  155. $iContentId = bx_process_input(bx_get('content_id'), BX_DATA_INT);
  156. if(empty($iAuthorId))
  157. return echoJson(['code' => 1, 'eval' => 'window.open("' . BxDolPermalinks::getInstance()->permalink('page.php?i=login') . '", "_self");']);
  158. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  159. if(empty($aContentInfo) || !is_array($aContentInfo))
  160. return echoJson([]);
  161. if(($mixedCheck = $this->checkAllowedMakeOffer($aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED)
  162. return echoJson(['code' => 2, 'msg' => $mixedCheck]);
  163. $aOffer = $this->_oDb->getOffersBy([
  164. 'type' => 'content_and_author_ids',
  165. 'content_id' => $iContentId,
  166. 'author_id' => $iAuthorId,
  167. 'status' => BX_ADS_OFFER_STATUS_AWAITING
  168. ]);
  169. if(!empty($aOffer) && is_array($aOffer))
  170. return echoJson(['code' => 3, 'msg' => _t('_bx_ads_txt_err_duplicate')]);
  171. $aOffer = $this->_oDb->getOffersBy([
  172. 'type' => 'content_and_author_ids',
  173. 'content_id' => $iContentId,
  174. 'author_id' => $iAuthorId,
  175. 'status' => BX_ADS_OFFER_STATUS_ACCEPTED
  176. ]);
  177. if(!empty($aOffer) && is_array($aOffer))
  178. return echoJson(['code' => 4, 'msg' => _t('_bx_ads_txt_err_offer_accepted')]);
  179. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_OFFER'], $CNF['OBJECT_FORM_OFFER_DISPLAY_ADD']);
  180. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . bx_append_url_params($this->_oConfig->getBaseUri() . 'make_offer', ['content_id' => $iContentId]);
  181. $oForm->initChecker();
  182. if($oForm->isSubmittedAndValid()) {
  183. $iQuantity = (int)$oForm->getCleanValue($CNF['FIELD_OFR_QUANTITY']);
  184. $iQuantityAvailable = $this->getAvailableQuantity($aContentInfo);
  185. if($iQuantity > $iQuantityAvailable)
  186. return echoJson(['code' => 5, 'msg' => _t('_bx_ads_txt_err_offer_wrong_quantity', $iQuantityAvailable)]);
  187. $aValToAdd = ['content_id' => $iContentId, 'author_id' => $iAuthorId];
  188. if(($iId = (int)$oForm->insert($aValToAdd)) != 0) {
  189. $this->checkAllowedMakeOffer($aContentInfo, true);
  190. $this->onOfferAdded($iId, $aResult);
  191. $aResult = ['code' => 0, 'msg' => _t('_bx_ads_txt_msg_offer_added'), 'eval' => $sJsObject . '.onMakeOffer(oData);', 'id' => $iId];
  192. }
  193. else
  194. $aResult = ['code' => 6, 'msg' => _t('_bx_ads_txt_err_cannot_perform_action')];
  195. return echoJson($aResult);
  196. }
  197. $sContent = BxTemplFunctions::getInstance()->transBox($this->_oConfig->getHtmlIds('offer_popup'), $this->_oTemplate->parseHtmlByName('offer_popup.html', array(
  198. 'form_id' => $oForm->getId(),
  199. 'form' => $oForm->getCode(true)
  200. )));
  201. return echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false, 'removeOnClose' => true))));
  202. }
  203. public function actionViewOffer()
  204. {
  205. $CNF = &$this->_oConfig->CNF;
  206. $iAuthorId = bx_get_logged_profile_id();
  207. $iOfferId = bx_process_input(bx_get('id'), BX_DATA_INT);
  208. $aOffer = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
  209. if(empty($aOffer) || !is_array($aOffer))
  210. return echoJson(array());
  211. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_OFFER'], $CNF['OBJECT_FORM_OFFER_DISPLAY_VIEW']);
  212. $oForm->initChecker($aOffer);
  213. $sContent = BxTemplFunctions::getInstance()->transBox($this->_oConfig->getHtmlIds('offer_popup'), $this->_oTemplate->parseHtmlByName('offer_popup.html', array(
  214. 'form_id' => $oForm->getId(),
  215. 'form' => $oForm->getCode(true)
  216. )));
  217. return echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => true, 'removeOnClose' => true))));
  218. }
  219. public function actionAcceptOffer()
  220. {
  221. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  222. if(($mixedResult = $this->offerAccept($iId)) !== true)
  223. return echoJson(['msg' => $mixedResult !== false ? $mixedResult : _t('_bx_ads_txt_err_cannot_perform_action')]);
  224. return echoJson(['msg' => _t('_bx_ads_txt_msg_offer_accepted'), 'reload' => 1]);
  225. }
  226. public function actionDeclineOffer()
  227. {
  228. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  229. if(!$this->offerDecline($iId))
  230. return echoJson(array('msg' => _t('_bx_ads_txt_err_cannot_perform_action')));
  231. return echoJson(array('msg' => _t('_bx_ads_txt_msg_offer_declined'), 'reload' => 1));
  232. }
  233. public function actionCancelOffer()
  234. {
  235. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  236. if(!$this->offerCancel($iId))
  237. return echoJson(['msg' => _t('_bx_ads_txt_err_cannot_perform_action')]);
  238. return echoJson(['msg' => _t('_bx_ads_txt_msg_offer_canceled'), 'reload' => 1]);
  239. }
  240. public function actionPayOffer()
  241. {
  242. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  243. if(($mixedResult = $this->offerPay($iId)) !== false)
  244. return echoJson($mixedResult);
  245. return echoJson(array('msg' => _t('_bx_ads_txt_err_cannot_perform_action')));
  246. }
  247. public function actionShipped()
  248. {
  249. return echoJson($this->_actionMarkAs('shipped'));
  250. }
  251. public function actionReceived()
  252. {
  253. return echoJson($this->_actionMarkAs('received'));
  254. }
  255. public function actionRegisterImpression($iId)
  256. {
  257. echoJson($this->serviceRegisterImpression($iId));
  258. }
  259. public function actionRegisterClick($iId)
  260. {
  261. echoJson($this->serviceRegisterClick($iId));
  262. }
  263. public function serviceGetSafeServices()
  264. {
  265. return array_merge(parent::serviceGetSafeServices(), [
  266. 'IsSourcesAvaliable' => '',
  267. 'LoadEntryFromSource' => '',
  268. 'LoadEntriesFromSourceByTerm' => '',
  269. 'EntityReviews' => '',
  270. 'EntityReviewsRating' => '',
  271. 'CategoriesList' => '',
  272. 'BrowseCategory' => '',
  273. 'RegisterImpression' => '',
  274. 'RegisterClick' => '',
  275. 'BlockSourcesDetails' => '',
  276. 'GetSourceData' => '',
  277. ]);
  278. }
  279. public function serviceRegisterImpression($iId)
  280. {
  281. return ['code' => $this->_oDb->updatePromotionTracker($iId, 'impressions') ? 0 : 1];
  282. }
  283. public function serviceRegisterClick($iId)
  284. {
  285. $CNF = &$this->_oConfig->CNF;
  286. if(!$this->_oDb->updatePromotionTracker($iId, 'clicks'))
  287. return ['code' => 1];
  288. $sUrl = '';
  289. if($this->_oConfig->isSources()) {
  290. $aEntry = $this->_oDb->getContentInfoById($iId);
  291. if(!empty($aEntry) && is_array($aEntry) && !empty($aEntry[$CNF['FIELD_URL']]))
  292. $sUrl = $aEntry[$CNF['FIELD_URL']];
  293. }
  294. return [
  295. 'code' => 0,
  296. 'redirect' => !empty($sUrl) ? $sUrl : $this->_oConfig->getViewEntryUrl($iId)
  297. ];
  298. }
  299. public function serviceCheckName($sTitle, $iId = 0)
  300. {
  301. $CNF = &$this->_oConfig->CNF;
  302. if(empty($sTitle))
  303. return array();
  304. $sName = '';
  305. if(!empty($iId)) {
  306. $aEntry = $this->_oDb->getContentInfoById($iId);
  307. if(strcmp($sTitle, $aEntry[$CNF['FIELD_NAME']]) == 0)
  308. $sName = $sTitle;
  309. }
  310. return array(
  311. 'title' => $sTitle,
  312. 'name' => !empty($sName) ? $sName : $this->_oConfig->getEntryName($sTitle, $iId)
  313. );
  314. }
  315. public function serviceUpdateCategoriesStats($mixedContentInfo = false)
  316. {
  317. $aContentInfo = [];
  318. if(!empty($mixedContentInfo))
  319. $aContentInfo = !is_array($mixedContentInfo) ? $this->_oDb->getContentInfoById((int)$mixedContentInfo) : $mixedContentInfo;
  320. $iCategoryId = 0;
  321. if($aContentInfo && !empty($aContentInfo['category']))
  322. $iCategoryId = (int)$aContentInfo['category'];
  323. return $this->serviceUpdateCategoriesStatsByCategory($iCategoryId);
  324. }
  325. public function serviceUpdateCategoriesStatsByCategory($iCategoryId = 0)
  326. {
  327. $aParams = ['type' => 'collect_stats'];
  328. if($iCategoryId)
  329. $aParams['category_id'] = (int)$iCategoryId;
  330. $aStats = $this->_oDb->getCategories($aParams);
  331. if(empty($aStats) || !is_array($aStats))
  332. return true;
  333. $iUpdated = 0;
  334. foreach($aStats as $aStat)
  335. if($this->_oDb->updateCategory(array('items' => $aStat['count']), array('id' => $aStat['id'])))
  336. $iUpdated++;
  337. return count($aStats) == $iUpdated;
  338. }
  339. public function serviceGetCategoryOptions($iParentId, $bPleaseSelect = false)
  340. {
  341. $aValues = array();
  342. if($bPleaseSelect)
  343. $aValues[] = array('key' => '', 'value' => _t('_sys_please_select'));
  344. $this->_getCategoryOptions($iParentId, $aValues);
  345. return $aValues;
  346. }
  347. public function serviceGetSearchableFields($aInputsAdd = array())
  348. {
  349. $CNF = &$this->_oConfig->CNF;
  350. $aResult = parent::serviceGetSearchableFields(array_merge($aInputsAdd, $this->_getSearchableFields()));
  351. unset($aResult[$CNF['FIELD_NOTES_PURCHASED']]);
  352. unset($aResult[$CNF['FIELD_CATEGORY_VIEW']], $aResult[$CNF['FIELD_CATEGORY_SELECT']]);
  353. unset($aResult[$CNF['FIELD_PRICE']], $aResult[$CNF['FIELD_YEAR']]);
  354. return $aResult;
  355. }
  356. public function serviceGetSearchableFieldsExtended($aInputsAdd = array())
  357. {
  358. $CNF = &$this->_oConfig->CNF;
  359. $aInputsAdd = array_merge($aInputsAdd, $this->_getSearchableFields());
  360. if(isset($aInputsAdd[$CNF['FIELD_CATEGORY']])) {
  361. $aInputsAdd[$CNF['FIELD_CATEGORY']]['type'] = 'select';
  362. $aInputsAdd[$CNF['FIELD_CATEGORY']]['values_src'] = BxDolService::getSerializedService($this->_oConfig->getName(), 'get_category_options', array(0));
  363. }
  364. if(isset($aInputsAdd[$CNF['FIELD_PRICE']])) {
  365. $aInputsAdd[$CNF['FIELD_PRICE']]['search_type'] = 'text_range';
  366. $aInputsAdd[$CNF['FIELD_PRICE']]['search_operator'] = 'between';
  367. }
  368. if(isset($aInputsAdd[$CNF['FIELD_YEAR']])) {
  369. $aInputsAdd[$CNF['FIELD_YEAR']]['search_type'] = 'text_range';
  370. $aInputsAdd[$CNF['FIELD_YEAR']]['search_operator'] = 'between';
  371. }
  372. return parent::serviceGetSearchableFieldsExtended($aInputsAdd);
  373. }
  374. /**
  375. * Mark an ad as shipped/received by seller/bauer accordingly.
  376. * @param type $sAction - shipped/received action.
  377. * @param type $iContentId - an ad the action will be performed with.
  378. * @param integer $iProfileSrc - profile, who performed the action.
  379. * @param integer $iProfileDst - profile, the action is pointed on.
  380. * @return boolean - true or a string value with error message.
  381. */
  382. public function serviceMarkAs($sAction, $iContentId, $iProfileSrc = 0, $iProfileDst = 0)
  383. {
  384. $CNF = &$this->_oConfig->CNF;
  385. if(!$iProfileSrc)
  386. $iProfileSrc = bx_get_logged_profile_id();
  387. $sTxtError = '_bx_ads_txt_err_cannot_perform_action';
  388. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  389. $sMethodCheck = 'checkAllowedMark' . bx_gen_method_name($sAction) . 'ForProfile';
  390. if(!method_exists($this, $sMethodCheck))
  391. return _t($sTxtError);
  392. if(($mixedCheckResult = $this->$sMethodCheck($aContentInfo, false, $iProfileSrc)) !== CHECK_ACTION_RESULT_ALLOWED)
  393. return $mixedCheckResult;
  394. if((int)$this->_oDb->updateEntriesBy(array($CNF['FIELD_' . strtoupper($sAction)] => time()), array($CNF['FIELD_ID'] => $iContentId)) == 0)
  395. return _t($sTxtError);
  396. $this->$sMethodCheck($aContentInfo, true, $iProfileSrc);
  397. $sMethodOnResult = 'on' . bx_gen_method_name($sAction);
  398. if(method_exists($this, $sMethodOnResult))
  399. $this->$sMethodOnResult($aContentInfo, $iProfileSrc, $iProfileDst);
  400. return true;
  401. }
  402. public function serviceEntityCreate ($sParams = false)
  403. {
  404. $iCategory = is_numeric($sParams) ? (int)$sParams : 0;
  405. if(($sDisplay = $this->getCategoryDisplay('add', $iCategory)) !== false) {
  406. if(empty($sParams) || !is_array($sParams))
  407. $sParams = array();
  408. $sParams['display'] = $sDisplay;
  409. }
  410. if($iCategory)
  411. BxDolSession::getInstance()->setValue($sDisplay . '_category', $iCategory);
  412. return parent::serviceEntityCreate($sParams);
  413. }
  414. public function serviceEntityEditBudget ($iContentId = 0, $sDisplay = false)
  415. {
  416. $CNF = &$this->_oConfig->CNF;
  417. return parent::serviceEntityEdit($iContentId, $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_BUDGET']);
  418. }
  419. /**
  420. * @page service Service Calls
  421. * @section bx_ads Ads
  422. * @subsection bx_ads-page_blocks Page Blocks
  423. * @subsubsection bx_ads-entity_reviews entity_reviews
  424. *
  425. * @code bx_srv('bx_ads', 'entity_reviews', [...]); @endcode
  426. *
  427. * Get reviews for particular content
  428. * @param $iContentId content ID
  429. *
  430. * @see BxAdsModule::serviceEntityReviews
  431. */
  432. /**
  433. * @ref bx_ads-entity_reviews "entity_reviews"
  434. */
  435. public function serviceEntityReviews($iContentId = 0)
  436. {
  437. $CNF = &$this->_oConfig->CNF;
  438. if(empty($CNF['OBJECT_REVIEWS']))
  439. return false;
  440. return $this->_entityComments($CNF['OBJECT_REVIEWS'], $iContentId);
  441. }
  442. /**
  443. * @page service Service Calls
  444. * @section bx_ads Ads
  445. * @subsection bx_ads-page_blocks Page Blocks
  446. * @subsubsection bx_ads-entity_reviews_rating entity_reviews_rating
  447. *
  448. * @code bx_srv('bx_ads', 'entity_reviews_rating', [...]); @endcode
  449. *
  450. * Get reviews rating for particular content
  451. * @param $iContentId content ID
  452. *
  453. * @see BxAdsModule::serviceEntityReviewsRating
  454. */
  455. /**
  456. * @ref bx_ads-entity_reviews_rating "entity_reviews_rating"
  457. */
  458. public function serviceEntityReviewsRating($iContentId = 0)
  459. {
  460. $CNF = &$this->_oConfig->CNF;
  461. if(empty($CNF['OBJECT_REVIEWS']))
  462. return false;
  463. if(!$iContentId)
  464. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  465. if(!$iContentId)
  466. return false;
  467. $oCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_REVIEWS'], $iContentId);
  468. if (!$oCmts || !$oCmts->isEnabled())
  469. return false;
  470. return $oCmts->getRatingBlock(array('in_designbox' => false));
  471. }
  472. public function serviceEntityPromotionGrowth($iContentId = 0)
  473. {
  474. return $this->_serviceTemplateFunc('entryPromotionGrowth', $iContentId);
  475. }
  476. public function serviceEntityPromotionSummary($iContentId = 0)
  477. {
  478. return $this->_serviceTemplateFunc('entryPromotionSummary', $iContentId);
  479. }
  480. public function serviceEntityPromotionRoi($iContentId = 0)
  481. {
  482. return $this->_serviceTemplateFunc('entryPromotionRoi', $iContentId);
  483. }
  484. /**
  485. * @page service Service Calls
  486. * @section bx_ads Ads
  487. * @subsection bx_ads-page_blocks Page Blocks
  488. * @subsubsection bx_ads-categories_list categories_list
  489. *
  490. * @code bx_srv('bx_ads', 'categories_list', [...]); @endcode
  491. *
  492. * Get reviews rating for particular content
  493. * @param $aParams additional params array, such as 'show_empty'
  494. *
  495. * @see BxAdsModule::serviceCategoriesList
  496. */
  497. /**
  498. * @ref bx_ads-categories_list "categories_list"
  499. */
  500. public function serviceCategoriesList($aParams = array())
  501. {
  502. if(!isset($aParams['show_empty']))
  503. $aParams['show_empty'] = true;
  504. return $this->_oTemplate->categoriesList($aParams);
  505. }
  506. /**
  507. * @page service Service Calls
  508. * @section bx_ads Ads
  509. * @subsection bx_ads-browse Browse
  510. * @subsubsection bx_ads-browse_category browse_category
  511. *
  512. * @code bx_srv('bx_ads', 'browse_category', [...]); @endcode
  513. *
  514. * Get reviews rating for particular content
  515. * @param $iCategoryId category ID
  516. * @param $aParams additional params array, such as empty_message, ajax_paginate, etc
  517. *
  518. * @see BxAdsModule::serviceBrowseCategory
  519. */
  520. /**
  521. * @ref bx_ads-browse_category "browse_category"
  522. */
  523. public function serviceBrowseCategory($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $aParams = [])
  524. {
  525. $mixedResult = parent::serviceBrowseCategory($sUnitView, $bEmptyMessage, $bAjaxPaginate, $aParams);
  526. if(empty($mixedResult['content']))
  527. return $mixedResult;
  528. $aCategory = $this->_oDb->getCategories([
  529. 'type' => 'id',
  530. 'id' => !empty($aParams['category']) ? (int)$aParams['category'] : bx_process_input(bx_get('category'), BX_DATA_INT)
  531. ]);
  532. if(!empty($aCategory['title']))
  533. $mixedResult['title'] = _t('_bx_ads_page_block_title_entries_by_category_mask', _t($aCategory['title']));
  534. return $mixedResult;
  535. }
  536. public function serviceGetTimelinePost($aEvent, $aBrowseParams = [])
  537. {
  538. $CNF = &$this->_oConfig->CNF;
  539. $mixedResult = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  540. if(!$mixedResult)
  541. return $mixedResult;
  542. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  543. if($this->_oConfig->isSources() && !empty($aContentInfo[$CNF['FIELD_URL']]))
  544. $mixedResult['url'] = $aContentInfo[$CNF['FIELD_URL']];
  545. return $mixedResult;
  546. }
  547. public function serviceGetNotificationsData()
  548. {
  549. $sModule = $this->_aModule['name'];
  550. $sEventPrivacy = $sModule . '_allow_view_event_to';
  551. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  552. $sEventPrivacy = '';
  553. $aResult = parent::serviceGetNotificationsData();
  554. $aResult['handlers'] = array_merge($aResult['handlers'], array(
  555. 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),
  556. 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),
  557. //---> To Buyer
  558. 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),
  559. //<---
  560. 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),
  561. 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),
  562. //---> To Offerer
  563. 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),
  564. 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),
  565. //<---
  566. 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)
  567. ));
  568. $aResult['settings'] = array_merge($aResult['settings'], array(
  569. array('group' => 'interest', 'unit' => $sModule, 'action' => 'doInterest', 'types' => array('personal')),
  570. array('group' => 'usage', 'unit' => $sModule, 'action' => 'license_register', 'types' => array('personal')),
  571. array('group' => 'usage', 'unit' => $sModule, 'action' => 'shipped', 'types' => array('personal')),
  572. array('group' => 'usage', 'unit' => $sModule, 'action' => 'received', 'types' => array('personal')),
  573. array('group' => 'usage', 'unit' => $sModule, 'action' => 'offer_added', 'types' => array('personal')),
  574. array('group' => 'usage', 'unit' => $sModule, 'action' => 'offer_accepted', 'types' => array('personal')),
  575. array('group' => 'usage', 'unit' => $sModule, 'action' => 'offer_declined', 'types' => array('personal')),
  576. array('group' => 'usage', 'unit' => $sModule, 'action' => 'offer_canceled', 'types' => array('personal')),
  577. ));
  578. $aResult['alerts'] = array_merge($aResult['alerts'], array(
  579. array('unit' => $sModule, 'action' => 'doInterest'),
  580. array('unit' => $sModule, 'action' => 'license_register'),
  581. array('unit' => $sModule, 'action' => 'shipped'),
  582. array('unit' => $sModule, 'action' => 'received'),
  583. array('unit' => $sModule, 'action' => 'offer_added'),
  584. array('unit' => $sModule, 'action' => 'offer_accepted'),
  585. array('unit' => $sModule, 'action' => 'offer_declined'),
  586. array('unit' => $sModule, 'action' => 'offer_canceled'),
  587. ));
  588. return $aResult;
  589. }
  590. public function serviceGetNotificationsInsertData($oAlert, $aHandler, $aDataItems)
  591. {
  592. $CNF = &$this->_oConfig->CNF;
  593. $aResult = [];
  594. switch($oAlert->sAction) {
  595. case 'license_register':
  596. $aContentInfo = $this->_oDb->getContentInfoById($oAlert->aExtras['product_id']);
  597. if(empty($aContentInfo) || !is_array($aContentInfo)) {
  598. $aResult = $aDataItems;
  599. break;
  600. }
  601. foreach($aDataItems as $aDataItem) {
  602. $aDataItem = array_merge($aDataItem, [
  603. 'owner_id' => $oAlert->aExtras['profile_id'],
  604. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  605. 'object_owner_id' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  606. 'object_privacy_view' => BX_DOL_PG_ALL
  607. ]);
  608. $aResult[] = $aDataItem;
  609. }
  610. break;
  611. case 'shipped':
  612. foreach($aDataItems as $aDataItem) {
  613. $aLicense = $this->_oDb->getLicense(['type' => 'entry_id', 'entry_id' => $aDataItem['object_id'], 'newest' => true]);
  614. if(!empty($aLicense) && is_array($aLicense))
  615. $aDataItem['object_owner_id'] = $aLicense['profile_id'];
  616. $aResult[] = $aDataItem;
  617. }
  618. break;
  619. case 'offer_added':
  620. case 'offer_canceled':
  621. foreach($aDataItems as $aDataItem) {
  622. $aDataItem['object_owner_id'] = $oAlert->aExtras['object_author_id'];
  623. $aResult[] = $aDataItem;
  624. }
  625. break;
  626. case 'offer_accepted':
  627. case 'offer_declined':
  628. foreach($aDataItems as $aDataItem) {
  629. $aDataItem['object_owner_id'] = $oAlert->aExtras['offer_author_id'];
  630. $aResult[] = $aDataItem;
  631. }
  632. break;
  633. default:
  634. $aResult = $aDataItems;
  635. }
  636. return $aResult;
  637. }
  638. public function serviceGetNotificationsInterest($aEvent)
  639. {
  640. $CNF = &$this->_oConfig->CNF;
  641. $iContentId = (int)$aEvent['object_id'];
  642. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  643. if(empty($aContentInfo) || !is_array($aContentInfo))
  644. return [];
  645. $iInterestedId = (int)$aEvent['subobject_id'];
  646. $aInterestedInfo = $this->_oDb->getInterested(['type' => 'id', 'id' => $iInterestedId]);
  647. if(empty($aInterestedInfo) || !is_array($aInterestedInfo))
  648. return [];
  649. if(($oInterestedProfile = BxDolProfile::getInstance($aInterestedInfo['profile_id'])) !== false)
  650. $sEntryUrl = $oInterestedProfile->getUrl();
  651. else
  652. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId), '{bx_url_root}');
  653. return [
  654. 'entry_sample' => $CNF['T']['txt_sample_single'],
  655. 'entry_url' => $sEntryUrl,
  656. 'entry_caption' => $aContentInfo[$CNF['FIELD_TITLE']],
  657. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  658. 'subentry_sample' => $CNF['T']['txt_sample_interest_single'],
  659. 'subentry_url' => '',
  660. '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.
  661. ];
  662. }
  663. public function serviceGetNotificationsLicenseRegister($aEvent)
  664. {
  665. return $this->_serviceGetNotificationsByEntryAndAction($aEvent, 'license_register');
  666. }
  667. public function serviceGetNotificationsShipped($aEvent)
  668. {
  669. $aResult = $this->_serviceGetNotificationsByEntryAndAction($aEvent, 'shipped');
  670. $aResult['entry_author'] = $aEvent['object_owner_id'];
  671. return $aResult;
  672. }
  673. public function serviceGetNotificationsReceived($aEvent)
  674. {
  675. return $this->_serviceGetNotificationsByEntryAndAction($aEvent, 'received');
  676. }
  677. public function serviceGetNotificationsOfferAdded($aEvent)
  678. {
  679. return $this->_serviceGetNotificationsByOfferAndAction($aEvent, 'offer_added');
  680. }
  681. public function serviceGetNotificationsOfferAccepted($aEvent)
  682. {
  683. $aResult = $this->_serviceGetNotificationsByOfferAndAction($aEvent, 'offer_accepted');
  684. $aResult['entry_author'] = $aEvent['object_owner_id'];
  685. return $aResult;
  686. }
  687. public function serviceGetNotificationsOfferDeclined($aEvent)
  688. {
  689. $aResult = $this->_serviceGetNotificationsByOfferAndAction($aEvent, 'offer_declined');
  690. $aResult['entry_author'] = $aEvent['object_owner_id'];
  691. return $aResult;
  692. }
  693. public function serviceGetNotificationsOfferCanceled($aEvent)
  694. {
  695. return $this->_serviceGetNotificationsByOfferAndAction($aEvent, 'offer_canceled');
  696. }
  697. protected function _serviceGetNotificationsByEntryAndAction($aEvent, $sAction)
  698. {
  699. $CNF = &$this->_oConfig->CNF;
  700. $iContentId = (int)$aEvent['object_id'];
  701. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  702. if(empty($aContentInfo) || !is_array($aContentInfo))
  703. return array();
  704. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId), '{bx_url_root}');
  705. return array(
  706. 'entry_sample' => $CNF['T']['txt_sample_single'],
  707. 'entry_url' => $sEntryUrl,
  708. 'entry_caption' => $aContentInfo[$CNF['FIELD_TITLE']],
  709. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  710. 'subentry_sample' => '',
  711. 'subentry_url' => '',
  712. '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.
  713. );
  714. }
  715. protected function _serviceGetNotificationsByOfferAndAction($aEvent, $sAction)
  716. {
  717. $CNF = &$this->_oConfig->CNF;
  718. $iOfferId = (int)$aEvent['object_id'];
  719. $aOfferInfo = $this->_oDb->getOffersBy(['type' => 'id', 'id' => $iOfferId]);
  720. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  721. return array();
  722. $iContentId = $aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  723. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  724. if(empty($aContentInfo) || !is_array($aContentInfo))
  725. return array();
  726. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId), '{bx_url_root}');
  727. return array(
  728. 'object_id' => $iContentId,
  729. 'entry_sample' => $CNF['T']['txt_sample_single'],
  730. 'entry_url' => $sEntryUrl,
  731. 'entry_caption' => $aContentInfo[$CNF['FIELD_TITLE']],
  732. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  733. 'subentry_sample' => '',
  734. 'subentry_url' => '',
  735. '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.
  736. );
  737. }
  738. /**
  739. * @page service Service Calls
  740. * @section bx_ads Ads
  741. * @subsection bx_ads-page_blocks Page Blocks
  742. * @subsubsection bx_ads-block_licenses block_licenses
  743. *
  744. * @code bx_srv('bx_ads', 'block_licenses', [...]); @endcode
  745. *
  746. * Get page block with a list of licenses purchased by currently logged member.
  747. *
  748. * @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.
  749. *
  750. * @see BxAdsModule::serviceBlockLicenses
  751. */
  752. /**
  753. * @ref bx_ads-block_licenses "block_licenses"
  754. */
  755. public function serviceBlockLicenses()
  756. {
  757. return $this->_getBlockLicenses();
  758. }
  759. /**
  760. * @page service Service Calls
  761. * @section bx_ads Ads
  762. * @subsection bx_ads-page_blocks Page Blocks
  763. * @subsubsection bx_ads-block_licenses_administration block_licenses_administration
  764. *
  765. * @code bx_srv('bx_ads', 'block_licenses_administration', [...]); @endcode
  766. *
  767. * Get page block with a list of all licenses. It's needed for moderators/administrators.
  768. *
  769. * @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.
  770. *
  771. * @see BxAdsModule::serviceBlockLicensesAdministration
  772. */
  773. /**
  774. * @ref bx_ads-block_licenses "block_licenses"
  775. */
  776. public function serviceBlockLicensesAdministration()
  777. {
  778. return $this->_getBlockLicenses('administration');
  779. }
  780. /**
  781. * @page service Service Calls
  782. * @section bx_ads Ads
  783. * @subsection bx_ads-page_blocks Page Blocks
  784. * @subsubsection bx_ads-block_licenses_note block_licenses_note
  785. *
  786. * @code bx_srv('bx_ads', 'block_licenses_note', [...]); @endcode
  787. *
  788. * Get page block with a notice for licenses usage.
  789. *
  790. * @return HTML string with block content to display on the site.
  791. *
  792. * @see BxAdsModule::serviceBlockLicensesNote
  793. */
  794. /**
  795. * @ref bx_ads-block_licenses_note "block_licenses_note"
  796. */
  797. public function serviceBlockLicensesNote()
  798. {
  799. return MsgBox(_t('_bx_ads_page_block_content_licenses_note'));
  800. }
  801. /**
  802. * @page service Service Calls
  803. * @section bx_ads Ads
  804. * @subsection bx_ads-payments Payments
  805. * @subsubsection bx_ads-get_payment_data get_payment_data
  806. *
  807. * @code bx_srv('bx_ads', 'get_payment_data', [...]); @endcode
  808. *
  809. * Get an array with module's description. Is needed for payments processing module.
  810. *
  811. * @return an array with module's description.
  812. *
  813. * @see BxAdsModule::serviceGetPaymentData
  814. */
  815. /**
  816. * @ref bx_ads-get_payment_data "get_payment_data"
  817. */
  818. public function serviceGetPaymentData()
  819. {
  820. $CNF = &$this->_oConfig->CNF;
  821. $oPermalink = BxDolPermalinks::getInstance();
  822. $aResult = $this->_aModule;
  823. $aResult['url_browse_order_common'] = bx_absolute_url($oPermalink->permalink($CNF['URL_LICENSES_COMMON'], array('filter' => '{order}')));
  824. $aResult['url_browse_order_administration'] = bx_absolute_url($oPermalink->permalink($CNF['URL_LICENSES_ADMINISTRATION'], array('filter' => '{order}')));
  825. return $aResult;
  826. }
  827. /**
  828. * @page service Service Calls
  829. * @section bx_ads Ads
  830. * @subsection bx_ads-payments Payments
  831. * @subsubsection bx_ads-get_cart_item get_cart_item
  832. *
  833. * @code bx_srv('bx_ads', 'get_cart_item', [...]); @endcode
  834. *
  835. * Get an array with prodict's description. Is used in Shopping Cart in payments processing module.
  836. *
  837. * @param $mixedItemId product's ID or Unique Name.
  838. * @return an array with prodict's description. Empty array is returned if something is wrong.
  839. *
  840. * @see BxAdsModule::serviceGetCartItem
  841. */
  842. /**
  843. * @ref bx_ads-get_cart_item "get_cart_item"
  844. */
  845. public function serviceGetCartItem($mixedItemId, $iClientId = 0)
  846. {
  847. $CNF = &$this->_oConfig->CNF;
  848. if(!$mixedItemId || !is_numeric($mixedItemId))
  849. return [];
  850. $aCommodity = $this->_oDb->getCommodity(['sample' => 'id_with_entry', 'id' => (int)$mixedItemId]);
  851. if(empty($aCommodity) || !is_array($aCommodity))
  852. return [];
  853. $iItemId = (int)$aCommodity['id'];
  854. $sItemType = $aCommodity['type'];
  855. $iItemAuthor = 0;
  856. $fItemPrice = 0;
  857. switch($sItemType) {
  858. case BX_ADS_COMMODITY_TYPE_PRODUCT:
  859. $iItemAuthor = $aCommodity['entry_' . $CNF['FIELD_AUTHOR']];
  860. $fItemPrice = (float)$aCommodity['entry_' . $CNF['FIELD_PRICE']];
  861. if($this->_oConfig->isAuction() && (int)$aCommodity['entry_' . $CNF['FIELD_AUCTION']] != 0) {
  862. $aOffer = $this->_oDb->getOffersBy([
  863. 'type' => 'content_and_author_ids',
  864. 'content_id' => $iItemId,
  865. 'author_id' => $iClientId,
  866. 'status' => BX_ADS_OFFER_STATUS_ACCEPTED
  867. ]);
  868. if(!empty($aOffer) && is_array($aOffer))
  869. $fItemPrice = (float)$aOffer[$CNF['FIELD_OFR_AMOUNT']];
  870. }
  871. break;
  872. case BX_ADS_COMMODITY_TYPE_PROMOTION:
  873. $iItemAuthor = BxDolPayments::getInstance()->getOption('site_admin');
  874. $fItemPrice = (float)$aCommodity['amount'];
  875. break;
  876. }
  877. if(!$iClientId)
  878. $iClientId = bx_get_logged_profile_id();
  879. return [
  880. 'id' => $iItemId,
  881. 'author_id' => $iItemAuthor,
  882. 'name' => $aCommodity['entry_' . $CNF['FIELD_NAME']] . '-' . $sItemType,
  883. 'title' => $aCommodity['entry_' . $CNF['FIELD_TITLE']],
  884. 'description' => $sItemDescription = _t($CNF['T']['txt_cd_ct_' . $sItemType]),
  885. 'url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'], ['id' => $aCommodity['entry_' . $CNF['FIELD_ID']]])),
  886. 'price_single' => $fItemPrice,
  887. 'price_recurring' => '',
  888. 'period_recurring' => 0,
  889. 'period_unit_recurring' => '',
  890. 'trial_recurring' => ''
  891. ];
  892. }
  893. /**
  894. * @page service Service Calls
  895. * @section bx_ads Ads
  896. * @subsection bx_ads-payments Payments
  897. * @subsubsection bx_ads-get_cart_items get_cart_items
  898. *
  899. * @code bx_srv('bx_ads', 'get_cart_items', [...]); @endcode
  900. *
  901. * Get an array with prodicts' descriptions by seller. Is used in Manual Order Processing in payments processing module.
  902. *
  903. * @param $iSellerId seller ID.
  904. * @return an array with prodicts' descriptions. Empty array is returned if something is wrong or seller doesn't have any products.
  905. *
  906. * @see BxAdsModule::serviceGetCartItems
  907. */
  908. /**
  909. * @ref bx_ads-get_cart_items "get_cart_items"
  910. */
  911. public function serviceGetCartItems($iSellerId)
  912. {
  913. $CNF = &$this->_oConfig->CNF;
  914. $iSellerId = (int)$iSellerId;
  915. if(empty($iSellerId))
  916. return [];
  917. $aItems = $this->_oDb->getCommodity(['sample' => 'entry_author', 'author' => $iSellerId, 'type' => BX_ADS_COMMODITY_TYPE_PRODUCT]);
  918. $aResult = [];
  919. foreach($aItems as $aItem) {
  920. $aItemInfo = $this->_oDb->getContentInfoById((int)$aItem['entry_id']);
  921. if(empty($aItemInfo) || !is_array($aItemInfo) || $aItemInfo[$CNF['FIELD_STATUS']] != BX_BASE_MOD_TEXT_STATUS_ACTIVE || empty($aItemInfo[$CNF['FIELD_QUANTITY']]))
  922. continue;
  923. $aResult[] = $this->serviceGetCartItem($aItem['id']);
  924. }
  925. return $aResult;
  926. }
  927. /**
  928. * @page service Service Calls
  929. * @section bx_ads Ads
  930. * @subsection bx_ads-payments Payments
  931. * @subsubsection bx_ads-authorize_cart_item authorize_cart_item
  932. *
  933. * @code bx_srv('bx_ads', 'authorize_cart_item', [...]); @endcode
  934. *
  935. * 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.
  936. *
  937. * @param $iClientId client ID.
  938. * @param $iSellerId seller ID
  939. * @param $iItemId item ID.
  940. * @param $iItemCount the number of purchased items.
  941. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  942. * @return an array with authorize prodict's description. Empty array is returned if something is wrong.
  943. *
  944. * @see BxAdsModule::serviceAuthorizeCartItem
  945. */
  946. /**
  947. * @ref bx_ads-authorize_cart_item "authorize_cart_item"
  948. */
  949. public function serviceAuthorizeCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  950. {
  951. $CNF = &$this->_oConfig->CNF;
  952. $aItem = $this->serviceGetCartItem($iItemId);
  953. if(empty($aItem) || !is_array($aItem))
  954. return [];
  955. $aCommodity = $this->_oDb->getCommodity(['sample' => 'id_with_entry', 'id' => (int)$iItemId]);
  956. if(empty($aCommodity) || !is_array($aCommodity))
  957. return [];
  958. bx_alert($this->getName(), 'order_authorize', 0, false, [
  959. 'id' => $aCommodity['id'],
  960. 'type' => $aCommodity['type'],
  961. 'product_id' => $aCommodity['entry_id'],
  962. 'profile_id' => $iClientId,
  963. 'order' => $sOrder,
  964. 'count' => $iItemCount
  965. ]);
  966. return $aItem;
  967. }
  968. /**
  969. * @page service Service Calls
  970. * @section bx_ads Ads
  971. * @subsection bx_ads-payments Payments
  972. * @subsubsection bx_ads-register_cart_item register_cart_item
  973. *
  974. * @code bx_srv('bx_ads', 'register_cart_item', [...]); @endcode
  975. *
  976. * Register a processed single time payment inside the Ads module. Is called with payment processing module after the payment was registered there.
  977. *
  978. * @param $iClientId client ID.
  979. * @param $iSellerId seller ID
  980. * @param $iItemId item ID.
  981. * @param $iItemCount the number of purchased items.
  982. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  983. * @param $sLicense license number genereted with payment processing module for internal usage
  984. * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
  985. *
  986. * @see BxAdsModule::serviceRegisterCartItem
  987. */
  988. /**
  989. * @ref bx_ads-register_cart_item "register_cart_item"
  990. */
  991. public function serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  992. {
  993. $aCommodity = $this->_oDb->getCommodity(['sample' => 'id', 'id' => (int)$iItemId]);
  994. if(empty($aCommodity) || !is_array($aCommodity))
  995. return [];
  996. $sMethod = '_registerCartItem' . bx_gen_method_name($aCommodity['type']);
  997. if(!method_exists($this, $sMethod))
  998. return [];
  999. return $this->$sMethod($iClientId, $iSellerId, $aCommodity, $iItemCount, $sOrder, $sLicense);
  1000. }
  1001. protected function _registerCartItemProduct($iClientId, $iSellerId, $aCommodity, $iItemCount, $sOrder, $sLicense)
  1002. {
  1003. $CNF = &$this->_oConfig->CNF;
  1004. $sModule = $this->getName();
  1005. $aItem = $this->serviceGetCartItem($aCommodity['id']);
  1006. if(empty($aItem) || !is_array($aItem))
  1007. return [];
  1008. $aEntry = $this->_oDb->getContentInfoById($aCommodity['entry_id']);
  1009. if(empty($aEntry) || !is_array($aEntry))
  1010. return [];
  1011. $iEntryId = (int)$aCommodity['entry_id'];
  1012. $iEntryQnt = (int)$aEntry[$CNF['FIELD_QUANTITY']];
  1013. if(($iEntryQnt - $iItemCount) < 0 || !$this->_oDb->registerLicense($iClientId, $iEntryId, $iItemCount, $sOrder, $sLicense))
  1014. return [];
  1015. $aOffer = $this->_oDb->getOffersBy([
  1016. 'type' => 'content_and_author_ids',
  1017. 'content_id' => $iEntryId,
  1018. 'author_id' => $iClientId,
  1019. 'status' => BX_ADS_OFFER_STATUS_ACCEPTED
  1020. ]);
  1021. if(!empty($aOffer) && is_array($aOffer))
  1022. $this->_oDb->updateOffer([$CNF['FIELD_OFR_STATUS'] => BX_ADS_OFFER_STATUS_PAID], [$CNF['FIELD_OFR_ID'] => $aOffer[$CNF['FIELD_OFR_ID']]]);
  1023. $iEntryQnt -= $iItemCount;
  1024. $bEntrySold = $iEntryQnt == 0;
  1025. $aUpdate = [
  1026. $CNF['FIELD_QUANTITY'] => $iEntryQnt
  1027. ];
  1028. if($bEntrySold)
  1029. $aUpdate = array_merge($aUpdate, [
  1030. $CNF['FIELD_STATUS'] => BX_ADS_STATUS_SOLD,
  1031. $CNF['FIELD_SOLD'] => time()
  1032. ]);
  1033. $this->_oDb->updateEntriesBy($aUpdate, [$CNF['FIELD_ID'] => $iEntryId]);
  1034. bx_alert($sModule, 'license_register', 0, false, [
  1035. 'id' => $aCommodity['id'],
  1036. 'type' => $aCommodity['type'],
  1037. 'product_id' => $iEntryId,
  1038. 'profile_id' => $iClientId,
  1039. 'order' => $sOrder,
  1040. 'license' => $sLicense,
  1041. 'count' => $iItemCount
  1042. ]);
  1043. if($bEntrySold) {
  1044. $aParams = $this->_alertParams($aEntry);
  1045. bx_alert($sModule, 'sold', $iEntryId, false, $aParams);
  1046. }
  1047. $oAuthor = BxDolProfile::getInstanceMagic($aEntry[$CNF['FIELD_AUTHOR']]);
  1048. $oClient = BxDolProfile::getInstanceMagic($iClientId);
  1049. $oSeller = BxDolProfile::getInstanceMagic($iSellerId);
  1050. $sSellerUrl = $oSeller->getUrl();
  1051. $sSellerName = $oSeller->getDisplayName();
  1052. $sNote = $aEntry[$CNF['FIELD_NOTES_PURCHASED']];
  1053. if(empty($sNote))
  1054. $sNote = _t('_bx_ads_txt_purchased_note', $sSellerUrl, $sSellerName);
  1055. $sEmailTemplate = $CNF['ETEMPLATE_PURCHASED'];
  1056. $aEmailParams = [
  1057. 'client_name' => $oClient->getDisplayName(),
  1058. 'entry_name' => $aEntry[$CNF['FIELD_TITLE']],
  1059. 'entry_url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'], ['id' => $iEntryId])),
  1060. 'author_url' => $oAuthor->getUrl(),
  1061. 'author_name' => $oAuthor->getDisplayName(),
  1062. 'vendor_url' => $sSellerUrl,
  1063. 'vendor_name' => $sSellerName,
  1064. 'count' => (int)$iItemCount,
  1065. 'license' => $sLicense,
  1066. 'notes' => $sNote,
  1067. ];
  1068. $bCancel = false;
  1069. bx_alert($sModule, 'license_register_notif', 0, false, [
  1070. 'entry_id' => $iEntryId,
  1071. 'order' => $sOrder,
  1072. 'recipient_id' => &$iClientId,
  1073. 'email_template' => &$sEmailTemplate,
  1074. 'email_params' => &$aEmailParams,
  1075. 'cancel' => &$bCancel
  1076. ]);
  1077. if(!$bCancel)
  1078. sendMailTemplate($sEmailTemplate, 0, $iClientId, $aEmailParams);
  1079. return $aItem;
  1080. }
  1081. protected function _registerCartItemPromotion($iClientId, $iSellerId, $aCommodity, $iItemCount, $sOrder, $sLicense)
  1082. {
  1083. $CNF = &$this->_oConfig->CNF;
  1084. $aItem = $this->serviceGetCartItem($aCommodity['id']);
  1085. if(empty($aItem) || !is_array($aItem))
  1086. return [];
  1087. $aEntry = $this->_oDb->getContentInfoById($aCommodity['entry_id']);
  1088. if(empty($aEntry) || !is_array($aEntry))
  1089. return [];
  1090. $iEntryId = (int)$aCommodity['entry_id'];
  1091. if(!$this->_oDb->registerPromotion($aEntry[$CNF['FIELD_AUTHOR']], $aCommodity['id'], $iEntryId, $aCommodity['amount'], $sOrder, $sLicense))
  1092. return [];
  1093. if($aEntry[$CNF['FIELD_STATUS_ADMIN']] == BX_ADS_STATUS_ADMIN_UNPAID) {
  1094. $aUpdate[$CNF['FIELD_STATUS_ADMIN']] = BX_BASE_MOD_GENERAL_STATUS_ACTIVE;
  1095. if(!$this->_isModerator() && !$this->_oConfig->isAutoApproveEnabled())
  1096. $aUpdate[$CNF['FIELD_STATUS_ADMIN']] = BX_BASE_MOD_GENERAL_STATUS_PENDING;
  1097. $this->_oDb->updateEntriesBy($aUpdate, [$CNF['FIELD_ID'] => $iEntryId]);
  1098. }
  1099. bx_alert($this->getName(), 'promotion_register', 0, false, [
  1100. 'id' => $aCommodity['id'],
  1101. 'type' => $aCommodity['type'],
  1102. 'product_id' => $iEntryId,
  1103. 'profile_id' => $iClientId,
  1104. 'amount' => $aCommodity['amount'],
  1105. 'order' => $sOrder,
  1106. 'license' => $sLicense,
  1107. ]);
  1108. return $aItem;
  1109. }
  1110. /**
  1111. * @page service Service Calls
  1112. * @section bx_ads Ads
  1113. * @subsection bx_ads-payments Payments
  1114. * @subsubsection bx_ads-authorize_subscription_item authorize_subscription_item
  1115. *
  1116. * @code bx_srv('bx_ads', 'authorize_subscription_item', [...]); @endcode
  1117. *
  1118. * 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.
  1119. *
  1120. * @param $iClientId client ID.
  1121. * @param $iSellerId seller ID
  1122. * @param $iItemId item ID.
  1123. * @param $iItemCount the number of purchased items.
  1124. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  1125. * @return an array with authorize prodict's description. Empty array is returned if something is wrong.
  1126. *
  1127. * @see BxAdsModule::serviceAuthorizeSubscriptionItem
  1128. */
  1129. /**
  1130. * @ref bx_ads-authorize_subscription_item "authorize_subscription_item"
  1131. */
  1132. public function serviceAuthorizeSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  1133. {
  1134. return [];
  1135. }
  1136. /**
  1137. * @page service Service Calls
  1138. * @section bx_ads Ads
  1139. * @subsection bx_ads-payments Payments
  1140. * @subsubsection bx_ads-register_subscription_item register_subscription_item
  1141. *
  1142. * @code bx_srv('bx_ads', 'register_subscription_item', [...]); @endcode
  1143. *
  1144. * Register a processed subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was registered there.
  1145. *
  1146. * @param $iClientId client ID.
  1147. * @param $iSellerId seller ID
  1148. * @param $iItemId item ID.
  1149. * @param $iItemCount the number of purchased items.
  1150. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  1151. * @param $sLicense license number genereted with payment processing module for internal usage
  1152. * @return an array with subscribed prodict's description. Empty array is returned if something is wrong.
  1153. *
  1154. * @see BxAdsModule::serviceRegisterSubscriptionItem
  1155. */
  1156. /**
  1157. * @ref bx_ads-register_subscription_item "register_subscription_item"
  1158. */
  1159. public function serviceRegisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  1160. {
  1161. return [];
  1162. }
  1163. /**
  1164. * @page service Service Calls
  1165. * @section bx_ads Ads
  1166. * @subsection bx_ads-payments Payments
  1167. * @subsubsection bx_ads-reregister_cart_item reregister_cart_item
  1168. *
  1169. * @code bx_srv('bx_ads', 'reregister_cart_item', [...]); @endcode
  1170. *
  1171. * Reregister a single time payment inside the Ads module. Is called with payment processing module after the payment was reregistered there.
  1172. *
  1173. * @param $iClientId client ID.
  1174. * @param $iSellerId seller ID
  1175. * @param $iItemIdOld old item ID.
  1176. * @param $iItemIdNew new item ID.
  1177. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  1178. * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
  1179. *
  1180. * @see BxAdsModule::serviceReregisterCartItem
  1181. */
  1182. /**
  1183. * @ref bx_ads-reregister_cart_item "reregister_cart_item"
  1184. */
  1185. public function serviceReregisterCartItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  1186. {
  1187. return [];
  1188. }
  1189. /**
  1190. * @page service Service Calls
  1191. * @section bx_ads Ads
  1192. * @subsection bx_ads-payments Payments
  1193. * @subsubsection bx_ads-reregister_subscription_item reregister_subscription_item
  1194. *
  1195. * @code bx_srv('bx_ads', 'reregister_subscription_item', [...]); @endcode
  1196. *
  1197. * Reregister a subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was reregistered there.
  1198. *
  1199. * @param $iClientId client ID.
  1200. * @param $iSellerId seller ID
  1201. * @param $iItemIdOld old item ID.
  1202. * @param $iItemIdNew new item ID.
  1203. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  1204. * @return an array with subscribed prodict's description. Empty array is returned if something is wrong.
  1205. *
  1206. * @see BxAdsModule::serviceReregisterSubscriptionItem
  1207. */
  1208. /**
  1209. * @ref bx_ads-reregister_subscription_item "reregister_subscription_item"
  1210. */
  1211. public function serviceReregisterSubscriptionItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  1212. {
  1213. return [];
  1214. }
  1215. /**
  1216. * @page service Service Calls
  1217. * @section bx_ads Ads
  1218. * @subsection bx_ads-payments Payments
  1219. * @subsubsection bx_ads-unregister_cart_item unregister_cart_item
  1220. *
  1221. * @code bx_srv('bx_ads', 'unregister_cart_item', [...]); @endcode
  1222. *
  1223. * Unregister an earlier processed single time payment inside the Ads module. Is called with payment processing module after the payment was unregistered there.
  1224. *
  1225. * @param $iClientId client ID.
  1226. * @param $iSellerId seller ID
  1227. * @param $iItemId item ID.
  1228. * @param $iItemCount the number of purchased items.
  1229. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  1230. * @param $sLicense license number genereted with payment processing module for internal usage
  1231. * @return boolean value determining where the payment was unregistered or not.
  1232. *
  1233. * @see BxAdsModule::serviceUnregisterCartItem
  1234. */
  1235. /**
  1236. * @ref bx_ads-unregister_cart_item "unregister_cart_item"
  1237. */
  1238. public function serviceUnregisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  1239. {
  1240. $aCommodity = $this->_oDb->getCommodity(['sample' => 'id', 'id' => (int)$iItemId]);
  1241. if(empty($aCommodity) || !is_array($aCommodity))
  1242. return [];
  1243. $sMethod = '_unregisterCartItem' . bx_gen_method_name($aCommodity['type']);
  1244. if(!method_exists($this, $sMethod))
  1245. return [];
  1246. return $this->$sMethod($iClientId, $iSellerId, $aCommodity, $iItemCount, $sOrder, $sLicense);
  1247. }
  1248. protected function _unregisterCartItemProduct($iClientId, $iSellerId, $aCommodity, $iItemCount, $sOrder, $sLicense)
  1249. {
  1250. $iEntryId = (int)$aCommodity['entry_id'];
  1251. if(!$this->_oDb->unregisterLicense($iClientId, $iEntryId, $sOrder, $sLicense))
  1252. return false;
  1253. bx_alert($this->getName(), 'license_unregister', 0, false, [
  1254. 'id' => $aCommodity['id'],
  1255. 'type' => $aCommodity['type'],
  1256. 'product_id' => $iEntryId,
  1257. 'profile_id' => $iClientId,
  1258. 'order' => $sOrder,
  1259. 'license' => $sLicense,
  1260. 'count' => $iItemCount
  1261. ]);
  1262. return true;
  1263. }
  1264. protected function _unregisterCartItemPromotion($iClientId, $iSellerId, $aCommodity, $iItemCount, $sOrder, $sLicense)
  1265. {
  1266. $CNF = &$this->_oConfig->CNF;
  1267. $aEntry = $this->_oDb->getContentInfoById($aCommodity['entry_id']);
  1268. if(empty($aEntry) || !is_array($aEntry))
  1269. return false;
  1270. $iEntryId = (int)$aCommodity['entry_id'];
  1271. if(!$this->_oDb->unregisterPromotion($aEntry[$CNF['FIELD_AUTHOR']], $aCommodity['id'], $iEntryId, $sOrder, $sLicense))
  1272. return false;
  1273. bx_alert($this->getName(), 'promotion_unregister', 0, false, [
  1274. 'id' => $aCommodity['id'],
  1275. 'type' => $aCommodity['type'],
  1276. 'product_id' => $iEntryId,
  1277. 'profile_id' => $iClientId,
  1278. 'amount' => $aCommodity['amount'],
  1279. 'order' => $sOrder,
  1280. 'license' => $sLicense
  1281. ]);
  1282. return true;
  1283. }
  1284. /**
  1285. * @page service Service Calls
  1286. * @section bx_ads Ads
  1287. * @subsection bx_ads-payments Payments
  1288. * @subsubsection bx_ads-unregister_subscription_item unregister_subscription_item
  1289. *
  1290. * @code bx_srv('bx_ads', 'unregister_subscription_item', [...]); @endcode
  1291. *
  1292. * Unregister an earlier processed subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was unregistered there.
  1293. *
  1294. * @param $iClientId client ID.
  1295. * @param $iSellerId seller ID
  1296. * @param $iItemId item ID.
  1297. * @param $iItemCount the number of purchased items.
  1298. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  1299. * @param $sLicense license number genereted with payment processing module for internal usage
  1300. * @return boolean value determining where the subscription was unregistered or not.
  1301. *
  1302. * @see BxAdsModule::serviceUnregisterSubscriptionItem
  1303. */
  1304. /**
  1305. * @ref bx_ads-unregister_subscription_item "unregister_subscription_item"
  1306. */
  1307. public function serviceUnregisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  1308. {
  1309. return true;
  1310. }
  1311. /**
  1312. * @page service Service Calls
  1313. * @section bx_ads Ads
  1314. * @subsection bx_ads-payments Payments
  1315. * @subsubsection bx_ads-cancel_subscription_item cancel_subscription_item
  1316. *
  1317. * @code bx_srv('bx_ads', 'cancel_subscription_item', [...]); @endcode
  1318. *
  1319. * Cancel an earlier processed subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was canceled there.
  1320. *
  1321. * @param $iClientId client ID.
  1322. * @param $iSellerId seller ID
  1323. * @param $iItemId item ID.
  1324. * @param $iItemCount the number of purchased items.
  1325. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  1326. * @return boolean value determining where the subscription was canceled or not.
  1327. *
  1328. * @see BxAdsModule::serviceCancelSubscriptionItem
  1329. */
  1330. /**
  1331. * @ref bx_ads-cancel_subscription_item "cancel_subscription_item"
  1332. */
  1333. public function serviceCancelSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  1334. {
  1335. return true;
  1336. }
  1337. public function serviceGetOffersCount($sStatus = '')
  1338. {
  1339. if(!$this->_oConfig->isAuction())
  1340. return 0;
  1341. if(empty($sStatus) || !in_array($sStatus, $this->_aOfferStatuses))
  1342. $sStatus = BX_ADS_OFFER_STATUS_AWAITING;
  1343. $iUserId = bx_get_logged_profile_id();
  1344. return $this->_oDb->getOffersBy(array('type' => 'content_author_id', 'author_id' => $iUserId, 'status' => $sStatus, 'count' => true));
  1345. }
  1346. public function serviceGetLiveUpdates($sStatus, $aMenuItemParent, $aMenuItemChild, $iCount = 0)
  1347. {
  1348. if(!in_array($sStatus, $this->_aOfferStatuses))
  1349. return false;
  1350. $iUserId = bx_get_logged_profile_id();
  1351. $iCountNew = $this->_oDb->getOffersBy(array('type' => 'content_author_id', 'author_id' => $iUserId, 'status' => $sStatus, 'count' => true));
  1352. if($iCountNew == $iCount)
  1353. return false;
  1354. return array(
  1355. 'count' => $iCountNew, // required
  1356. 'method' => 'bx_menu_show_live_update(oData)', // required
  1357. 'data' => array(
  1358. 'code' => BxDolTemplate::getInstance()->parseHtmlByTemplateName('menu_item_addon', array(
  1359. 'content' => '{count}'
  1360. )),
  1361. 'mi_parent' => $aMenuItemParent,
  1362. 'mi_child' => $aMenuItemChild
  1363. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  1364. );
  1365. }
  1366. public function serviceOffers()
  1367. {
  1368. $CNF = &$this->_oConfig->CNF;
  1369. if(!$this->_oConfig->isAuction())
  1370. return '';
  1371. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_OFFERS_ALL']);
  1372. if(!$oGrid)
  1373. return '';
  1374. return $oGrid->getCode();
  1375. }
  1376. public function serviceEntityOffers($iContentId = 0)
  1377. {
  1378. $CNF = &$this->_oConfig->CNF;
  1379. if(!$this->_oConfig->isAuction())
  1380. return '';
  1381. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_OFFERS']);
  1382. if(!$oGrid)
  1383. return '';
  1384. if(empty($iContentId) && ($_iContentId = bx_get('id')) !== false)
  1385. $iContentId = (int)$_iContentId;
  1386. $oGrid->setContentId($iContentId);
  1387. return $oGrid->getCode();
  1388. }
  1389. public function serviceEntityOfferAccepted($iContentId = 0)
  1390. {
  1391. $CNF = &$this->_oConfig->CNF;
  1392. if(!$this->_oConfig->isAuction())
  1393. return '';
  1394. $iUserId = bx_get_logged_profile_id();
  1395. if(empty($iContentId) && ($_iContentId = bx_get('id')) !== false)
  1396. $iContentId = (int)$_iContentId;
  1397. $aContent = $this->_oDb->getContentInfoById($iContentId);
  1398. if(empty($aContent) || !is_array($aContent) || $aContent[$CNF['FIELD_QUANTITY']] <= 0)
  1399. return '';
  1400. $aOffer = $this->_oDb->getOffersBy(array(
  1401. 'type' => 'content_and_author_ids',
  1402. 'content_id' => $iContentId,
  1403. 'author_id' => $iUserId,
  1404. 'status' => BX_ADS_OFFER_STATUS_ACCEPTED
  1405. ));
  1406. if(empty($aOffer) || !is_array($aOffer))
  1407. return '';
  1408. return $this->_oTemplate->entryOfferAccepted($iUserId, $aContent, $aOffer);
  1409. }
  1410. public function serviceIsSourcesAvaliable()
  1411. {
  1412. return $this->_oConfig->isSources();
  1413. }
  1414. public function serviceGetSources($iAuthorId)
  1415. {
  1416. $aSources = $this->_oDb->getSources(['sample' => 'all']);
  1417. $aOptions = $this->_oDb->getSourcesOptions($iAuthorId);
  1418. $aResult = [];
  1419. foreach($aSources as $sSource => $aSource) {
  1420. if(!isset($aOptions[$aSource['option_prefix'] . 'active']) || (int)$aOptions[$aSource['option_prefix'] . 'active']['value'] != 1)
  1421. continue;
  1422. foreach($aOptions as $sName => $aOption)
  1423. if(strpos($sName, $aSource['option_prefix']) !== false)
  1424. $aSource['options'][$sName] = $aOption;
  1425. $aResult[$sSource] = $aSource;
  1426. }
  1427. return $aResult;
  1428. }
  1429. public function serviceGetSource($iAuthorId, $sAuthorSource = '')
  1430. {
  1431. $aSourcesOptions = $this->serviceGetSources($iAuthorId);
  1432. if(empty($aSourcesOptions) || !is_array($aSourcesOptions))
  1433. return false;
  1434. $mixedResult = false;
  1435. if(!empty($sAuthorSource)) {
  1436. if(!empty($aSourcesOptions[$sAuthorSource]) && is_array($aSourcesOptions[$sAuthorSource]))
  1437. $mixedResult = $aSourcesOptions[$sAuthorSource];
  1438. }
  1439. else
  1440. $mixedResult = array_shift($aSourcesOptions);
  1441. return $mixedResult;
  1442. }
  1443. public function serviceLoadEntriesFromSourceByTerm($sSourceType, $sTerm)
  1444. {
  1445. $CNF = &$this->_oConfig->CNF;
  1446. $oSource = $this->getObjectSource($sSourceType, $this->_iProfileId);
  1447. if(!$oSource)
  1448. return [];
  1449. $aEntries = $oSource->getEntries(['sample' => 'all_id_title_pairs']);
  1450. if(empty($aEntries) || !is_array($aEntries))
  1451. return [];
  1452. $aResults = [];
  1453. foreach($aEntries as $aEntry) {
  1454. if(stripos($aEntry[$CNF['FIELD_TITLE']], $sTerm) === false)
  1455. continue;
  1456. $aResults[] = [
  1457. 'label' => $aEntry[$CNF['FIELD_TITLE']],
  1458. 'value' => $aEntry[$CNF['FIELD_SOURCE']],
  1459. ];
  1460. }
  1461. return $aResults;
  1462. }
  1463. public function serviceLoadEntryFromSource($sSourceType, $sSource)
  1464. {
  1465. $CNF = &$this->_oConfig->CNF;
  1466. $aResult = [];
  1467. $oSource = $this->getObjectSource($sSourceType, $this->_iProfileId);
  1468. if(!$oSource)
  1469. return $aResult;
  1470. $aEntry = $oSource->getEntry($sSource);
  1471. if(empty($aEntry) || !is_array($aEntry))
  1472. return $aResult;
  1473. $aName = $this->serviceCheckName($aEntry[$CNF['FIELD_TITLE']]);
  1474. if(!empty($aName) && is_array($aName))
  1475. $aResult[$CNF['FIELD_NAME']] = ['type' => 'text', 'value' => $aName['name']];
  1476. $aKey2Type = [
  1477. $CNF['FIELD_TITLE'] => 'text',
  1478. $CNF['FIELD_URL'] => 'hidden',
  1479. $CNF['FIELD_TEXT'] => 'text_html',
  1480. $CNF['FIELD_TAGS'] => 'text',
  1481. $CNF['FIELD_PRICE'] => 'text',
  1482. $CNF['FIELD_QUANTITY'] => 'text'
  1483. ];
  1484. foreach($aEntry as $sKey => $sValue)
  1485. if(isset($aKey2Type[$sKey]))
  1486. $aResult[$sKey] = ['type' => $aKey2Type[$sKey], 'value' => $sValue];
  1487. return $aResult;
  1488. }
  1489. public function serviceBlockSourcesDetails($iProfileId = 0)
  1490. {
  1491. $CNF = &$this->_oConfig->CNF;
  1492. if(!isLogged())
  1493. return bx_is_api() ? [bx_api_get_msg(_t('_Access denied'))] : ['content' => MsgBox(_t('_Access denied'))];
  1494. $iProfileId = !empty($iProfileId) ? $iProfileId : bx_get_logged_profile_id();
  1495. $oForm = BxTemplFormView::getObjectInstance($CNF['OBJECT_FORM_SOURCES_DETAILS'], $CNF['OBJECT_FORM_SOURCES_DETAILS_DISPLAY_EDIT']);
  1496. $oForm->setProfileId($iProfileId);
  1497. $oForm->initChecker();
  1498. if($oForm->isSubmitted()) {
  1499. if($oForm->isValid()) {
  1500. $aOptions = $this->_oDb->getSourcesOptions();
  1501. foreach($aOptions as $aOption) {
  1502. $sValue = bx_get($aOption['name']) !== false ? bx_get($aOption['name']) : '';
  1503. $this->_oDb->updateSourceOption($iProfileId, $aOption['id'], bx_process_input($sValue));
  1504. }
  1505. if (bx_is_api()){
  1506. return [
  1507. bx_api_get_block('form', $oForm->getCodeAPI(), ['ext' => ['name' => $this->getName(), 'request' => ['url' => '/api.php?r=' . $this->getName() . '/block_sources_details', 'immutable' => true]]]),
  1508. bx_api_get_block('redirect', ['uri' => '/' . BxDolPermalinks::getInstance()->permalink($CNF['URL_SOURCES']), 'timeout' => 100])
  1509. ];
  1510. }
  1511. else{
  1512. header('Location: ' . bx_absolute_url(BxDolPermalinks::getInstance()->permalink($CNF['URL_SOURCES'])));
  1513. return;
  1514. }
  1515. }
  1516. else
  1517. foreach($oForm->aInputs as $aInput)
  1518. if(!empty($aInput['error']) && !empty($aInput['attrs']['bx-data-source'])) {
  1519. $sSourceBlock = 'source_' . (int)$aInput['attrs']['bx-data-source'] . '_begin';
  1520. if(!empty($oForm->aInputs[$sSourceBlock]))
  1521. $oForm->aInputs[$sSourceBlock]['collapsed'] = false;
  1522. }
  1523. }
  1524. return bx_is_api() ? [bx_api_get_block('form', $oForm->getCodeAPI(), ['ext' => ['name' => $this->getName(), 'request' => ['url' => '/api.php?r=' . $this->getName() . '/block_sources_details', 'immutable' => true]]])] : ['content' => $oForm->getCode()];
  1525. }
  1526. public function isEntryActive($aContentInfo)
  1527. {
  1528. $CNF = &$this->_oConfig->CNF;
  1529. $iViewer = bx_get_logged_profile_id();
  1530. $bModerator = $this->_isModerator();
  1531. $mixedResult = null;
  1532. bx_alert($this->getName(), 'is_entry_active', 0, 0, ['viewer_id' => $iViewer, 'is_moderator' => $bModerator, 'content_info' => $aContentInfo, 'override_result' => &$mixedResult]);
  1533. if($mixedResult !== null)
  1534. return $mixedResult;
  1535. if($aContentInfo[$CNF['FIELD_AUTHOR']] == $iViewer || $bModerator)
  1536. return true;
  1537. 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)))
  1538. return false;
  1539. if(isset($CNF['FIELD_STATUS_ADMIN']) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active')
  1540. return false;
  1541. return true;
  1542. }
  1543. public function isAuction($aContentInfo)
  1544. {
  1545. $CNF = &$this->_oConfig->CNF;
  1546. return $this->_oConfig->isAuction() && (int)$aContentInfo[$CNF['FIELD_AUCTION']] != 0;
  1547. }
  1548. public function isAllowedMakeOffer($mixedContent, $isPerformAction = false)
  1549. {
  1550. return $this->checkAllowedMakeOffer($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  1551. }
  1552. public function checkAllowedMakeOffer($mixedContent, $isPerformAction = false)
  1553. {
  1554. $CNF = &$this->_oConfig->CNF;
  1555. $sTxtError = '_sys_txt_access_denied';
  1556. $iProfileId = bx_get_logged_profile_id();
  1557. if(!is_array($mixedContent))
  1558. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  1559. if(empty($mixedContent) || !is_array($mixedContent))
  1560. return _t($sTxtError);
  1561. if(!$this->isAuction($mixedContent) || (int)$mixedContent[$CNF['FIELD_QUANTITY']] <= 0)
  1562. return _t($sTxtError);
  1563. if($mixedContent[$CNF['FIELD_AUTHOR']] == $iProfileId)
  1564. return _t($sTxtError);
  1565. $aCheck = checkActionModule($iProfileId, 'make offer', $this->getName(), $isPerformAction);
  1566. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1567. return $aCheck[CHECK_ACTION_MESSAGE];
  1568. return CHECK_ACTION_RESULT_ALLOWED;
  1569. }
  1570. public function isAllowedViewOffers($mixedContent, $isPerformAction = false)
  1571. {
  1572. return $this->checkAllowedViewOffers($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  1573. }
  1574. public function checkAllowedViewOffers($mixedContent, $isPerformAction = false)
  1575. {
  1576. $CNF = &$this->_oConfig->CNF;
  1577. $sTxtError = '_sys_txt_access_denied';
  1578. if(!is_array($mixedContent))
  1579. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  1580. if(empty($mixedContent) || !is_array($mixedContent))
  1581. return _t($sTxtError);
  1582. if(!$this->isAuction($mixedContent))
  1583. return _t($sTxtError);
  1584. if($this->_isModerator())
  1585. return CHECK_ACTION_RESULT_ALLOWED;
  1586. if($mixedContent[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id())
  1587. return CHECK_ACTION_RESULT_ALLOWED;
  1588. return _t($sTxtError);
  1589. }
  1590. public function isAllowedMarkShipped($mixedContent, $isPerformAction = false)
  1591. {
  1592. return $this->checkAllowedMarkShipped($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  1593. }
  1594. public function checkAllowedMarkShipped($mixedContent, $isPerformAction = false)
  1595. {
  1596. return $this->checkAllowedMarkShippedForProfile($mixedContent, $isPerformAction);
  1597. }
  1598. public function checkAllowedMarkShippedForProfile($mixedContent, $isPerformAction = false, $iProfileId = false)
  1599. {
  1600. $CNF = &$this->_oConfig->CNF;
  1601. $sTxtError = '_sys_txt_access_denied';
  1602. if(!$iProfileId)
  1603. $iProfileId = bx_get_logged_profile_id();
  1604. if(!is_array($mixedContent))
  1605. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  1606. if(empty($mixedContent) || !is_array($mixedContent) || !$this->isSingle($mixedContent))
  1607. return _t($sTxtError);
  1608. if((int)$mixedContent[$CNF['FIELD_SHIPPED']] != 0 || $mixedContent[$CNF['FIELD_STATUS']] != BX_ADS_STATUS_SOLD || $mixedContent[$CNF['FIELD_AUTHOR']] != $iProfileId)
  1609. return _t($sTxtError);
  1610. return CHECK_ACTION_RESULT_ALLOWED;
  1611. }
  1612. public function isAllowedMarkReceived($mixedContent, $isPerformAction = false)
  1613. {
  1614. return $this->checkAllowedMarkReceived($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  1615. }
  1616. public function checkAllowedMarkReceived($mixedContent, $isPerformAction = false)
  1617. {
  1618. return $this->checkAllowedMarkReceivedForProfile($mixedContent, $isPerformAction);
  1619. }
  1620. public function checkAllowedMarkReceivedForProfile($mixedContent, $isPerformAction = false, $iProfileId = false)
  1621. {
  1622. $CNF = &$this->_oConfig->CNF;
  1623. $sTxtError = '_sys_txt_access_denied';
  1624. if(!$iProfileId)
  1625. $iProfileId = bx_get_logged_profile_id();
  1626. if(!is_array($mixedContent))
  1627. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  1628. if(empty($mixedContent) || !is_array($mixedContent) || !$this->isSingle($mixedContent))
  1629. return _t($sTxtError);
  1630. if((int)$mixedContent[$CNF['FIELD_RECEIVED']] != 0 || !$this->_oDb->hasLicense($iProfileId, $mixedContent[$CNF['FIELD_ID']]))
  1631. return _t($sTxtError);
  1632. return CHECK_ACTION_RESULT_ALLOWED;
  1633. }
  1634. public function onPublished($iContentId)
  1635. {
  1636. $this->serviceUpdateCategoriesStats($iContentId);
  1637. parent::onPublished($iContentId);
  1638. }
  1639. public function onOfferAdded($iOfferId, &$aResult)
  1640. {
  1641. $CNF = &$this->_oConfig->CNF;
  1642. $aOfferInfo = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
  1643. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  1644. return;
  1645. $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  1646. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1647. if(empty($aContentInfo) || !is_array($aContentInfo))
  1648. return;
  1649. $iViewer = bx_get_logged_profile_id();
  1650. $oViewer = BxDolProfile::getInstanceMagic($iViewer);
  1651. if(getParam($CNF['PARAM_USE_IIN']) == 'on')
  1652. sendMailTemplate($CNF['ETEMPLATE_OFFER_ADDED'], 0, $aContentInfo[$CNF['FIELD_AUTHOR']], array(
  1653. 'viewer_name' => $oViewer->getDisplayName(),
  1654. 'viewer_url' => $oViewer->getUrl(),
  1655. 'entry_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  1656. 'entry_url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php', array(
  1657. 'i' => $CNF['URI_VIEW_ENTRY'],
  1658. $CNF['FIELD_ID'] => $iContentId
  1659. )))
  1660. ));
  1661. $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
  1662. $aParams['override_result'] = &$aResult;
  1663. bx_alert($this->getName(), 'offer_added', $iOfferId, $aOfferInfo[$CNF['FIELD_OFR_AUTHOR']], $aParams);
  1664. }
  1665. public function onOfferAccepted($iOfferId)
  1666. {
  1667. $CNF = &$this->_oConfig->CNF;
  1668. $aOfferInfo = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
  1669. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  1670. return;
  1671. $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  1672. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1673. if(empty($aContentInfo) || !is_array($aContentInfo))
  1674. return;
  1675. if($aContentInfo[$CNF['FIELD_STATUS']] != BX_ADS_STATUS_OFFER && ($this->isSingle($aContentInfo) || $this->getAvailableQuantity($aContentInfo) <= 0))
  1676. if(!$this->_oDb->updateEntriesBy([$CNF['FIELD_STATUS'] => BX_ADS_STATUS_OFFER], [$CNF['FIELD_ID'] => $iContentId]))
  1677. return;
  1678. $this->serviceUpdateCategoriesStats($iContentId);
  1679. $iOfferer = (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']];
  1680. $oOfferer = BxDolProfile::getInstanceMagic($iOfferer);
  1681. if(getParam($CNF['PARAM_USE_IIN']) == 'on')
  1682. sendMailTemplate($CNF['ETEMPLATE_OFFER_ACCEPTED'], 0, $iOfferer, array(
  1683. 'offerer_name' => $oOfferer->getDisplayName(),
  1684. 'offerer_url' => $oOfferer->getUrl(),
  1685. 'entry_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  1686. 'entry_url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php', array(
  1687. 'i' => $CNF['URI_VIEW_ENTRY'],
  1688. $CNF['FIELD_ID'] => $iContentId
  1689. )))
  1690. ));
  1691. $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
  1692. bx_alert($this->getName(), 'offer_accepted', $iOfferId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  1693. }
  1694. public function onOfferDeclined($iOfferId)
  1695. {
  1696. $CNF = &$this->_oConfig->CNF;
  1697. $aOfferInfo = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
  1698. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  1699. return;
  1700. $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  1701. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1702. if(empty($aContentInfo) || !is_array($aContentInfo))
  1703. return;
  1704. $iOfferer = (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']];
  1705. $oOfferer = BxDolProfile::getInstanceMagic($iOfferer);
  1706. if(getParam($CNF['PARAM_USE_IIN']) == 'on')
  1707. sendMailTemplate($CNF['ETEMPLATE_OFFER_DECLINED'], 0, $iOfferer, array(
  1708. 'offerer_name' => $oOfferer->getDisplayName(),
  1709. 'offerer_url' => $oOfferer->getUrl(),
  1710. 'entry_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  1711. 'entry_url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php', array(
  1712. 'i' => $CNF['URI_VIEW_ENTRY'],
  1713. $CNF['FIELD_ID'] => $iContentId
  1714. )))
  1715. ));
  1716. $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
  1717. bx_alert($this->getName(), 'offer_declined', $iOfferId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  1718. }
  1719. public function onOfferCanceled($iOfferId)
  1720. {
  1721. $CNF = &$this->_oConfig->CNF;
  1722. $aOfferInfo = $this->_oDb->getOffersBy(['type' => 'id', 'id' => $iOfferId]);
  1723. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  1724. return;
  1725. $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  1726. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1727. if(empty($aContentInfo) || !is_array($aContentInfo))
  1728. return;
  1729. if(!$this->_oDb->updateEntriesBy([$CNF['FIELD_STATUS'] => BX_BASE_MOD_TEXT_STATUS_ACTIVE], [$CNF['FIELD_ID'] => $iContentId]))
  1730. return;
  1731. $this->serviceUpdateCategoriesStats($iContentId);
  1732. $iOfferer = (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']];
  1733. $oOfferer = BxDolProfile::getInstanceMagic($iOfferer);
  1734. if(getParam($CNF['PARAM_USE_IIN']) == 'on')
  1735. sendMailTemplate($CNF['ETEMPLATE_OFFER_CANCELED'], 0, (int)$aContentInfo[$CNF['FIELD_AUTHOR']], [
  1736. 'offerer_name' => $oOfferer->getDisplayName(),
  1737. 'offerer_url' => $oOfferer->getUrl(),
  1738. 'entry_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  1739. 'entry_url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php', [
  1740. 'i' => $CNF['URI_VIEW_ENTRY'],
  1741. $CNF['FIELD_ID'] => $iContentId
  1742. ]))
  1743. ]);
  1744. $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
  1745. bx_alert($this->getName(), 'offer_canceled', $iOfferId, $aOfferInfo[$CNF['FIELD_OFR_AUTHOR']], $aParams);
  1746. }
  1747. /**
  1748. * Common methods.
  1749. */
  1750. public function onShipped($mixedContent, $iProfileSrc = 0, $iProfileDst = 0)
  1751. {
  1752. $CNF = &$this->_oConfig->CNF;
  1753. if(!is_array($mixedContent))
  1754. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  1755. $iContentId = (int)$mixedContent[$CNF['FIELD_ID']];
  1756. if(empty($iProfileSrc))
  1757. $iProfileSrc = (int)$mixedContent[$CNF['FIELD_AUTHOR']];
  1758. $oProfileSrc = BxDolProfile::getInstanceMagic($iProfileSrc);
  1759. $aOffer = $this->_oDb->getOffersBy(array('type' => 'accepted', 'content_id' => $iContentId));
  1760. $bOffer = !empty($aOffer) && is_array($aOffer);
  1761. if(empty($iProfileDst) && $bOffer)
  1762. $iProfileDst = (int)$aOffer[$CNF['FIELD_OFR_AUTHOR']];
  1763. if(!empty($oProfileSrc) && !empty($iProfileDst) && getParam($CNF['PARAM_USE_IIN']) == 'on')
  1764. sendMailTemplate($CNF['ETEMPLATE_SHIPPED'], 0, $iProfileDst, array(
  1765. 'vendor_name' => $oProfileSrc->getDisplayName(),
  1766. 'vendor_url' => $oProfileSrc->getUrl(),
  1767. 'entry_name' => $mixedContent[$CNF['FIELD_TITLE']],
  1768. 'entry_url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php', array(
  1769. 'i' => $CNF['URI_VIEW_ENTRY'],
  1770. $CNF['FIELD_ID'] => $iContentId
  1771. )))
  1772. ));
  1773. $aParams = $this->_alertParams($mixedContent);
  1774. $aParams = array_merge($aParams, array(
  1775. 'profile_src' => $iProfileSrc,
  1776. 'profile_dst' => $iProfileDst,
  1777. 'offer_id' => $bOffer ? (int)$aOffer[$CNF['FIELD_OFR_ID']] : 0,
  1778. ));
  1779. bx_alert($this->getName(), 'shipped', $iContentId, false, $aParams);
  1780. }
  1781. public function onReceived($mixedContent, $iProfileSrc = 0, $iProfileDst = 0)
  1782. {
  1783. $CNF = &$this->_oConfig->CNF;
  1784. if(!is_array($mixedContent))
  1785. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  1786. $iContentId = (int)$mixedContent[$CNF['FIELD_ID']];
  1787. if(empty($iProfileDst))
  1788. $iProfileDst = (int)$mixedContent[$CNF['FIELD_AUTHOR']];
  1789. $aOffer = $this->_oDb->getOffersBy(array('type' => 'accepted', 'content_id' => $iContentId));
  1790. $bOffer = !empty($aOffer) && is_array($aOffer);
  1791. if(empty($iProfileSrc) && $bOffer)
  1792. $iProfileSrc = (int)$aOffer[$CNF['FIELD_OFR_AUTHOR']];
  1793. $oProfileSrc = BxDolProfile::getInstanceMagic($iProfileSrc);
  1794. if(!empty($iProfileSrc) && !empty($iProfileDst) && getParam($CNF['PARAM_USE_IIN']) == 'on')
  1795. sendMailTemplate($CNF['ETEMPLATE_RECEIVED'], 0, $iProfileDst, array(
  1796. 'client_name' => $oProfileSrc->getDisplayName(),
  1797. 'client_url' => $oProfileSrc->getUrl(),
  1798. 'entry_name' => $mixedContent[$CNF['FIELD_TITLE']],
  1799. 'entry_url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php', array(
  1800. 'i' => $CNF['URI_VIEW_ENTRY'],
  1801. $CNF['FIELD_ID'] => $iContentId
  1802. )))
  1803. ));
  1804. $aParams = $this->_alertParams($mixedContent);
  1805. $aParams = array_merge($aParams, array(
  1806. 'profile_src' => $iProfileSrc,
  1807. 'profile_dst' => $iProfileDst,
  1808. 'offer_id' => $bOffer ? (int)$aOffer[$CNF['FIELD_OFR_ID']] : 0,
  1809. ));
  1810. bx_alert($this->getName(), 'received', $iContentId, false, $aParams);
  1811. }
  1812. public function getObjectSource($sSource, $iProfileId = 0)
  1813. {
  1814. $aSource = $this->_oDb->getSources(array('sample' => 'by_name', 'name' => $sSource));
  1815. if(empty($aSource) || !is_array($aSource) || empty($aSource['class_name']))
  1816. return false;
  1817. if(!empty($iProfileId)) {
  1818. $aSource['author'] = (int)$iProfileId;
  1819. $aSource['options'] = $this->_oDb->getSourcesOptions((int)$iProfileId, $aSource['id']);
  1820. }
  1821. $sClassPath = !empty($aSource['class_file']) ? BX_DIRECTORY_PATH_ROOT . $aSource['class_file'] : $this->_oConfig->getClassPath() . $aSource['class_name'] . '.php';
  1822. if(!file_exists($sClassPath))
  1823. return false;
  1824. require_once($sClassPath);
  1825. return new $aSource['class_name']($this->_iProfileId, $aSource, $this);
  1826. }
  1827. public function offerAccept($iId)
  1828. {
  1829. $CNF = &$this->_oConfig->CNF;
  1830. $aOfferInfo = $this->_oDb->getOffersBy(['type' => 'id', 'id' => $iId]);
  1831. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  1832. return false;
  1833. $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  1834. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1835. if(empty($aContentInfo) || !is_array($aContentInfo))
  1836. return false;
  1837. $iQuantity = (int)$aOfferInfo[$CNF['FIELD_OFR_QUANTITY']];
  1838. $iQuantityAvailable = $this->getAvailableQuantity($aContentInfo);
  1839. if($iQuantity > $iQuantityAvailable)
  1840. return _t('_bx_ads_txt_err_offer_wrong_quantity', $iQuantityAvailable);
  1841. if(!$this->_oDb->updateOffer([$CNF['FIELD_OFR_STATUS'] => BX_ADS_OFFER_STATUS_ACCEPTED], [$CNF['FIELD_OFR_ID'] => $iId]))
  1842. return false;
  1843. $this->onOfferAccepted($iId);
  1844. return true;
  1845. }
  1846. public function offerDecline($iId)
  1847. {
  1848. $CNF = &$this->_oConfig->CNF;
  1849. if(!$this->_oDb->updateOffer([$CNF['FIELD_OFR_STATUS'] => BX_ADS_OFFER_STATUS_DECLINED], [$CNF['FIELD_OFR_ID'] => $iId]))
  1850. return false;
  1851. $this->onOfferDeclined($iId);
  1852. return true;
  1853. }
  1854. public function offerCancel($iId)
  1855. {
  1856. $CNF = &$this->_oConfig->CNF;
  1857. if(!$this->_oDb->updateOffer([$CNF['FIELD_OFR_STATUS'] => BX_ADS_OFFER_STATUS_CANCELED], [$CNF['FIELD_OFR_ID'] => $iId]))
  1858. return false;
  1859. $this->onOfferCanceled($iId);
  1860. return true;
  1861. }
  1862. public function offerPay($iId)
  1863. {
  1864. $CNF = &$this->_oConfig->CNF;
  1865. $aOffer = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iId));
  1866. if(empty($aOffer) || !is_array($aOffer))
  1867. return false;
  1868. $iContent = (int)$aOffer[$CNF['FIELD_OFR_CONTENT']];
  1869. $aContent = $this->_oDb->getContentInfoById($iContent);
  1870. $iContentAuthor = (int)$aContent[$CNF['FIELD_AUTHOR']];
  1871. $aReturn = array(
  1872. 'redirect' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php', array(
  1873. 'i' => $CNF['URI_VIEW_ENTRY'],
  1874. $CNF['FIELD_ID'] => $aOffer[$CNF['FIELD_OFR_CONTENT']]
  1875. )))
  1876. );
  1877. $oPayments = BxDolPayments::getInstance();
  1878. $aResult = $oPayments->addToCart($iContentAuthor, $this->getName(), $iContent, $aOffer[$CNF['FIELD_OFR_QUANTITY']]);
  1879. if(!empty($aResult) && is_array($aResult)) {
  1880. if(!empty($aResult['message']))
  1881. $aReturn['msg'] = $aResult['message'];
  1882. if(isset($aResult['code']) && (int)$aResult['code'] == 0)
  1883. $aReturn['redirect'] = $oPayments->getCartUrl($iContentAuthor);
  1884. }
  1885. return $aReturn;
  1886. }
  1887. public function processMetasAdd($iContentId)
  1888. {
  1889. if(!parent::processMetasAdd($iContentId))
  1890. return false;
  1891. $CNF = &$this->_oConfig->CNF;
  1892. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1893. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1894. $aCategoryTypes = $this->_oDb->getCategoryTypes(array('type' => 'all'));
  1895. foreach($aCategoryTypes as $aCategoryType)
  1896. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $aCategoryType['display_add']);
  1897. return true;
  1898. }
  1899. public function processMetasEdit($iContentId, $oForm)
  1900. {
  1901. if(!parent::processMetasEdit($iContentId, $oForm))
  1902. return false;
  1903. $CNF = &$this->_oConfig->CNF;
  1904. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1905. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1906. $aCategoryTypes = $this->_oDb->getCategoryTypes(array('type' => 'all'));
  1907. foreach($aCategoryTypes as $aCategoryType)
  1908. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $aCategoryType['display_edit']);
  1909. return true;
  1910. }
  1911. public function getCategoryDisplay($sDisplayType, $iCategory = 0)
  1912. {
  1913. if(empty($iCategory) && bx_get('category') !== false)
  1914. $iCategory = (int)bx_get('category');
  1915. if(empty($iCategory))
  1916. return false;
  1917. $aCategory = $this->_oDb->getCategories(array('type' => 'id_full', 'id' => $iCategory));
  1918. $sKey = 'type_display_' . $sDisplayType;
  1919. if(empty($aCategory[$sKey]))
  1920. return false;
  1921. return $aCategory[$sKey];
  1922. }
  1923. public function isSingle($mixedContent)
  1924. {
  1925. $CNF = &$this->_oConfig->CNF;
  1926. if(!is_array($mixedContent))
  1927. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  1928. return (int)$mixedContent[$CNF['FIELD_SINGLE']] == 1;
  1929. }
  1930. public function getAvailableQuantity($mixedContent)
  1931. {
  1932. $CNF = &$this->_oConfig->CNF;
  1933. if(!is_array($mixedContent))
  1934. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  1935. if(!$this->_oConfig->isAuction() || (int)$mixedContent[$CNF['FIELD_AUCTION']] == 0)
  1936. return (int)$mixedContent[$CNF['FIELD_QUANTITY']];
  1937. $iQuantity = (int)$this->_oDb->getOffersBy([
  1938. 'type' => 'quantity_reserved',
  1939. 'content_id' => $mixedContent[$CNF['FIELD_ID']],
  1940. 'status' => BX_ADS_OFFER_STATUS_ACCEPTED
  1941. ]);
  1942. return (int)$mixedContent[$CNF['FIELD_QUANTITY']] - $iQuantity;
  1943. }
  1944. /**
  1945. * Internal methods.
  1946. */
  1947. protected function _actionMarkAs($sAction)
  1948. {
  1949. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1950. if(($mixedResult = $this->serviceMarkAs($sAction, $iContentId)) !== true)
  1951. return array('msg' => $mixedResult);
  1952. return array(
  1953. 'reload' => 1
  1954. );
  1955. }
  1956. protected function _actionChangeStatus($sStatus)
  1957. {
  1958. $CNF = &$this->_oConfig->CNF;
  1959. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1960. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1961. if(($mixedResult = $this->checkAllowedEdit($aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED)
  1962. return array('msg' => $mixedResult);
  1963. if(!$this->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => $sStatus), array($CNF['FIELD_ID'] => $iContentId)))
  1964. return array('msg' => _t('_bx_ads_txt_err_cannot_perform_action'));
  1965. $this->serviceUpdateCategoriesStats($aContentInfo);
  1966. return array(
  1967. 'reload' => 1
  1968. );
  1969. }
  1970. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  1971. {
  1972. $CNF = &$this->_oConfig->CNF;
  1973. $mixedContent = $this->_getContent($iContentId, true);
  1974. if($mixedContent === false)
  1975. return false;
  1976. list($iContentId, $aContentInfo) = $mixedContent;
  1977. $sDisplayType = false;
  1978. switch($sFormMethod) {
  1979. case 'editDataForm':
  1980. if($sDisplay === false)
  1981. $sDisplayType = 'edit';
  1982. break;
  1983. case 'viewDataForm':
  1984. case 'viewDataEntry':
  1985. $sDisplayType = 'view';
  1986. break;
  1987. }
  1988. if($sDisplayType !== false && ($sDisplayNew = $this->getCategoryDisplay($sDisplayType, $aContentInfo[$CNF['FIELD_CATEGORY']])) !== false)
  1989. $sDisplay = $sDisplayNew;
  1990. return parent::_serviceEntityForm ($sFormMethod, $iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  1991. }
  1992. protected function _getCategoryOptions($iParentId, &$aValues)
  1993. {
  1994. $aCategories = $this->_oDb->getCategories(array('type' => 'parent_id', 'parent_id' => $iParentId, 'active' => true));
  1995. foreach($aCategories as $aCategory) {
  1996. $aValues[] = array('key' => $aCategory['id'], 'value' => str_repeat('--', (int)$aCategory['level']) . ' ' . _t($aCategory['title']));
  1997. $this->_getCategoryOptions($aCategory['id'], $aValues);
  1998. }
  1999. }
  2000. protected function _getSearchableFields($mixedDisplayType = '')
  2001. {
  2002. $CNF = &$this->_oConfig->CNF;
  2003. if(empty($mixedDisplayType))
  2004. $mixedDisplayType = array('add', 'edit');
  2005. $aResult = array();
  2006. $aDisplays = $this->_oDb->getDisplays($this->_oConfig->getName() . '_entry', $mixedDisplayType);
  2007. foreach($aDisplays as $aDisplay) {
  2008. if($aDisplay['display_name'] == $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])
  2009. continue;
  2010. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $aDisplay['display_name'], $this->_oTemplate);
  2011. if(!$oForm)
  2012. continue;
  2013. $aResult = array_merge($aResult, $oForm->aInputs);
  2014. }
  2015. return $aResult;
  2016. }
  2017. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  2018. {
  2019. $CNF = &$this->_oConfig->CNF;
  2020. $bDynamic = isset($aBrowseParams['dynamic_mode']) && (bool)$aBrowseParams['dynamic_mode'] === true;
  2021. $sCategory = '';
  2022. if(!empty($CNF['FIELD_CATEGORY']) && !empty($aContentInfo[$CNF['FIELD_CATEGORY']])) {
  2023. $iCategory = (int)$aContentInfo[$CNF['FIELD_CATEGORY']];
  2024. $aCategory = $this->_oDb->getCategories(array('type' => 'id', 'id' => $iCategory));
  2025. $sCategory = _t($aCategory['title']);
  2026. $sCategoryLink = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($CNF['URL_CATEGORIES'], array($CNF['GET_PARAM_CATEGORY'] => $iCategory)));
  2027. }
  2028. $sPrice = _t('_bx_ads_txt_free');
  2029. if(!empty($CNF['FIELD_PRICE']) && !empty($aContentInfo[$CNF['FIELD_PRICE']]))
  2030. $sPrice = _t_format_currency_ext((float)$aContentInfo[$CNF['FIELD_PRICE']], [
  2031. 'sign' => BxDolPayments::getInstance()->getCurrencySign((int)$aContentInfo[$CNF['FIELD_AUTHOR']])
  2032. ]);
  2033. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  2034. if(empty($aResult['raw']))
  2035. $aResult['raw'] = '';
  2036. if($this->_bIsApi)
  2037. $aResult = array_merge($aResult, [
  2038. 'price' => $sPrice,
  2039. 'category_title' => $sCategory,
  2040. 'register_click' => $this->_oConfig->isPromotion() ? 'bx_ads/register_click&params[]=' . $aContentInfo[$CNF['FIELD_ID']] : false,
  2041. 'register_impression' => $this->_oConfig->isPromotion() ? 'bx_ads/register_impression&params[]=' . $aContentInfo[$CNF['FIELD_ID']] : false,
  2042. ]);
  2043. else
  2044. $aResult['text'] = $this->_oTemplate->parseHtmlByName('timeline_post_text.html', [
  2045. 'category_link' => $sCategoryLink,
  2046. 'category_title' => $sCategory,
  2047. 'category_title_attr' => bx_html_attribute($sCategory),
  2048. 'price' => $sPrice,
  2049. 'text' => $aResult['text']
  2050. ]);
  2051. if($this->_oConfig->isSources() && !empty($aContentInfo[$CNF['FIELD_URL']]))
  2052. $aResult['url'] = $aContentInfo[$CNF['FIELD_URL']];
  2053. if($this->_oConfig->isPromotion()) {
  2054. $sJsObject = $this->_oConfig->getJsObject('main');
  2055. $sHtmlId = $this->_oConfig->getHtmlIds('unit') . $aContentInfo[$CNF['FIELD_ID']] . '-' . time() . '-' . mt_rand(0, 100);
  2056. $aResult['onclick'] = 'return ' . $sJsObject . '.registerClick(this, ' . $aContentInfo[$CNF['FIELD_ID']] . ')';
  2057. $aResult['raw'] .= $this->_oTemplate->parseHtmlByName('timeline_post_promotion.html', [
  2058. 'html_id' => $sHtmlId,
  2059. 'js_code' => $this->_oTemplate->_wrapInTagJsCode($sJsObject . '.registerTrakerForTimeline(' . $aContentInfo[$CNF['FIELD_ID']] . ', \'' . $sHtmlId . '\');')
  2060. ]);
  2061. }
  2062. $sInclude = $this->_oTemplate->addCss(['timeline.css'], $bDynamic);
  2063. if($bDynamic)
  2064. $aResult['raw'] .= $sInclude;
  2065. return $aResult;
  2066. }
  2067. protected function _getBlockLicenses($sType = '')
  2068. {
  2069. $CNF = &$this->_oConfig->CNF;
  2070. $sGrid = $CNF['OBJECT_GRID_LICENSES' . (!empty($sType) ? '_' . strtoupper($sType) : '')];
  2071. $oGrid = BxDolGrid::getObjectInstance($sGrid);
  2072. if(!$oGrid)
  2073. return '';
  2074. $this->_oDb->updateLicense(array('new' => 0), array('profile_id' => bx_get_logged_profile_id(), 'new' => 1));
  2075. $this->_oTemplate->addJs(array('licenses.js'));
  2076. return array(
  2077. 'content' => $this->_oTemplate->getJsCode('licenses', array('sObjNameGrid' => $sGrid)) . $oGrid->getCode(),
  2078. 'menu' => $CNF['OBJECT_MENU_LICENSES']
  2079. );
  2080. }
  2081. protected function _alertParamsOffer($aContentInfo, $aOfferInfo)
  2082. {
  2083. $CNF = &$this->_oConfig->CNF;
  2084. $aParams = array(
  2085. 'object_id' => (int)$aContentInfo[$CNF['FIELD_ID']],
  2086. 'object_author_id' => (int)$aContentInfo[$CNF['FIELD_AUTHOR']],
  2087. 'offer_id' => (int)$aOfferInfo[$CNF['FIELD_OFR_ID']],
  2088. 'offer_author_id' => (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']],
  2089. );
  2090. if(isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  2091. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  2092. return $aParams;
  2093. }
  2094. }
  2095. /** @} */