BxAdsModule.php 82 KB

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