BxAdsModule.php 79 KB

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