BxAdsModule.php 82 KB

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