BxAdsModule.php 79 KB

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