BxAdsModule.php 76 KB

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