BxAdsModule.php 98 KB

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