BxAdsModule.php 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Ads Ads
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_ADS_STATUS_OFFER', 'offer');
  12. define('BX_ADS_STATUS_SOLD', 'sold');
  13. define('BX_ADS_OFFER_STATUS_ACCEPTED', 'accepted');
  14. define('BX_ADS_OFFER_STATUS_AWAITING', 'awaiting');
  15. define('BX_ADS_OFFER_STATUS_DECLINED', 'declined');
  16. define('BX_ADS_OFFER_STATUS_CANCELED', 'canceled');
  17. /**
  18. * Ads module
  19. */
  20. class BxAdsModule extends BxBaseModTextModule
  21. {
  22. protected $_aOfferStatuses;
  23. function __construct(&$aModule)
  24. {
  25. parent::__construct($aModule);
  26. $this->_oConfig->init($this->_oDb);
  27. $CNF = &$this->_oConfig->CNF;
  28. $this->_aSearchableNamesExcept = array_merge($this->_aSearchableNamesExcept, array(
  29. $CNF['FIELD_CATEGORY_VIEW'],
  30. $CNF['FIELD_CATEGORY_SELECT']
  31. ));
  32. $this->_aOfferStatuses = array(
  33. BX_ADS_OFFER_STATUS_ACCEPTED,
  34. BX_ADS_OFFER_STATUS_AWAITING,
  35. BX_ADS_OFFER_STATUS_DECLINED
  36. );
  37. }
  38. public function actionGetCategoryForm()
  39. {
  40. if(bx_get('category') === false)
  41. return echoJson(array());
  42. return echoJson(array(
  43. 'content' => $this->serviceGetCreatePostForm(array(
  44. 'absolute_action_url' => true,
  45. 'dynamic_mode' => true
  46. ))
  47. ));
  48. }
  49. public function actionCheckName()
  50. {
  51. $CNF = &$this->_oConfig->CNF;
  52. $iId = (int)bx_get($CNF['FIELD_ID']);
  53. $sTitle = bx_process_input(bx_get($CNF['FIELD_TITLE']));
  54. echoJson($this->serviceCheckName($sTitle, $iId));
  55. }
  56. public function actionInterested()
  57. {
  58. $CNF = &$this->_oConfig->CNF;
  59. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  60. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  61. if(empty($aContentInfo) || !is_array($aContentInfo))
  62. return echoJson(array());
  63. $iViewer = bx_get_logged_profile_id();
  64. $oViewer = BxDolProfile::getInstance($iViewer);
  65. if(!$oViewer)
  66. return echoJson(array());
  67. $iContentAuthor = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  68. if($iContentAuthor == $iViewer)
  69. return echoJson(array('msg' => _t('_bx_ads_txt_err_your_own')));
  70. if($this->_oDb->isInterested($iContentId, $iViewer))
  71. return echoJson(array('msg' => _t('_bx_ads_txt_err_duplicate')));
  72. $iInterestId = $this->_oDb->insertInterested(array('entry_id' => $iContentId, 'profile_id' => $iViewer));
  73. if(!$iInterestId)
  74. return echoJson(array('msg' => _t('_bx_ads_txt_err_cannot_perform_action')));
  75. bx_alert($this->getName(), 'doInterest', $iContentId, $iViewer, array(
  76. 'subobject_id' => $iInterestId,
  77. 'subobject_author_id' => $iViewer,
  78. 'object_author_id' => $iContentAuthor
  79. ));
  80. if(getParam($CNF['PARAM_USE_IIN']) == 'on')
  81. sendMailTemplate($CNF['ETEMPLATE_INTERESTED'], 0, $iContentAuthor, array(
  82. 'viewer_name' => $oViewer->getDisplayName(),
  83. 'viewer_url' => $oViewer->getUrl(),
  84. 'ad_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  85. 'ad_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  86. 'i' => $CNF['URI_VIEW_ENTRY'],
  87. $CNF['FIELD_ID'] => $iContentId
  88. ))
  89. ));
  90. return echoJson(array('msg' => _t('_bx_ads_txt_msg_author_notified')));
  91. }
  92. public function actionMakeOffer()
  93. {
  94. $CNF = &$this->_oConfig->CNF;
  95. $sJsObject = $this->_oConfig->getJsObject('entry');
  96. $iAuthorId = bx_get_logged_profile_id();
  97. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  98. if(empty($iAuthorId))
  99. return echoJson(array('code' => 1, 'eval' => 'window.open("' . BxDolPermalinks::getInstance()->permalink('page.php?i=login') . '", "_self");'));
  100. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  101. if(empty($aContentInfo) || !is_array($aContentInfo))
  102. return echoJson(array());
  103. $aOffer = $this->_oDb->getOffersBy(array(
  104. 'type' => 'content_and_author_ids',
  105. 'content_id' => $iContentId,
  106. 'author_id' => $iAuthorId,
  107. 'status' => BX_ADS_OFFER_STATUS_AWAITING
  108. ));
  109. if(!empty($aOffer) && is_array($aOffer))
  110. return echoJson(array('code' => 2, 'msg' => _t('_bx_ads_txt_err_duplicate')));
  111. $aOffer = $this->_oDb->getOffersBy(array(
  112. 'type' => 'content_and_author_ids',
  113. 'content_id' => $iContentId,
  114. 'author_id' => $iAuthorId,
  115. 'status' => BX_ADS_OFFER_STATUS_ACCEPTED
  116. ));
  117. if(!empty($aOffer) && is_array($aOffer))
  118. return echoJson(array('code' => 3, 'msg' => _t('_bx_ads_txt_err_offer_accepted')));
  119. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_OFFER'], $CNF['OBJECT_FORM_OFFER_DISPLAY_ADD']);
  120. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . bx_append_url_params($this->_oConfig->getBaseUri() . 'make_offer', array('id' => $iContentId));
  121. $oForm->initChecker();
  122. if($oForm->isSubmittedAndValid()) {
  123. $aValToAdd = array('content_id' => $iContentId, 'author_id' => $iAuthorId);
  124. $iId = (int)$oForm->insert($aValToAdd);
  125. if($iId != 0)
  126. $aResult = array('code' => 0, 'msg' => _t('_bx_ads_txt_msg_offer_added'), 'eval' => $sJsObject . '.onMakeOffer(oData);', 'id' => $iId);
  127. else
  128. $aResult = array('code' => 4, 'msg' => _t('_bx_ads_txt_err_cannot_perform_action'));
  129. $this->onOfferAdded($iId);
  130. return echoJson($aResult);
  131. }
  132. $sContent = BxTemplFunctions::getInstance()->transBox($this->_oConfig->getHtmlIds('offer_popup'), $this->_oTemplate->parseHtmlByName('offer_popup.html', array(
  133. 'form_id' => $oForm->getId(),
  134. 'form' => $oForm->getCode(true)
  135. )));
  136. return echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false, 'removeOnClose' => true))));
  137. }
  138. public function actionCancelOffer()
  139. {
  140. $CNF = &$this->_oConfig->CNF;
  141. $iOfferId = bx_process_input(bx_get('id'), BX_DATA_INT);
  142. $aOffer = $this->_oDb->getOffersBy(array(
  143. 'type' => 'id',
  144. 'id' => $iOfferId
  145. ));
  146. if(empty($aOffer) || !is_array($aOffer))
  147. return echoJson(array());
  148. if(!$this->_oDb->updateOffer(array($CNF['FIELD_OFR_STATUS'] => BX_ADS_OFFER_STATUS_CANCELED), array($CNF['FIELD_OFR_ID'] => $iOfferId)))
  149. return echoJson(array('msg' => _t('_bx_ads_txt_err_cannot_perform_action')));
  150. $this->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => BX_BASE_MOD_TEXT_STATUS_ACTIVE), array($CNF['FIELD_ID'] => $aOffer[$CNF['FIELD_OFR_CONTENT']]));
  151. $this->onOfferCanceled($iOfferId);
  152. return echoJson(array('msg' => _t('_bx_ads_txt_msg_offer_canceled'), 'reload' => 1));
  153. }
  154. public function actionShipped()
  155. {
  156. return echoJson($this->_actionMarkAs('shipped'));
  157. }
  158. public function actionReceived()
  159. {
  160. return echoJson($this->_actionMarkAs('received'));
  161. }
  162. public function serviceGetSafeServices()
  163. {
  164. $a = parent::serviceGetSafeServices();
  165. return array_merge($a, array (
  166. 'EntityReviews' => '',
  167. 'EntityReviewsRating' => '',
  168. 'CategoriesList' => '',
  169. 'BrowseCategory' => '',
  170. ));
  171. }
  172. public function serviceCheckName($sTitle, $iId = 0)
  173. {
  174. $CNF = &$this->_oConfig->CNF;
  175. if(empty($sTitle))
  176. return array();
  177. $sName = '';
  178. if(!empty($iId)) {
  179. $aEntry = $this->_oDb->getContentInfoById($iId);
  180. if(strcmp($sTitle, $aEntry[$CNF['FIELD_NAME']]) == 0)
  181. $sName = $sTitle;
  182. }
  183. return array(
  184. 'title' => $sTitle,
  185. 'name' => !empty($sName) ? $sName : $this->_oConfig->getEntryName($sTitle, $iId)
  186. );
  187. }
  188. public function serviceUpdateCategoriesStats()
  189. {
  190. $aStats = $this->_oDb->getCategories(array('type' => 'collect_stats'));
  191. if(empty($aStats) || !is_array($aStats))
  192. return true;
  193. $iUpdated = 0;
  194. foreach($aStats as $aStat)
  195. if($this->_oDb->updateCategory(array('items' => $aStat['count']), array('id' => $aStat['id'])))
  196. $iUpdated++;
  197. return count($aStats) == $iUpdated;
  198. }
  199. public function serviceGetCategoryOptions($iParentId, $bPleaseSelect = false)
  200. {
  201. $aValues = array();
  202. if($bPleaseSelect)
  203. $aValues[] = array('key' => '', 'value' => _t('_sys_please_select'));
  204. $this->_getCategoryOptions($iParentId, $aValues);
  205. return $aValues;
  206. }
  207. public function serviceGetSearchableFields($aInputsAdd = array())
  208. {
  209. $CNF = &$this->_oConfig->CNF;
  210. $aResult = parent::serviceGetSearchableFields(array_merge($aInputsAdd, $this->_getSearchableFields()));
  211. unset($aResult[$CNF['FIELD_NOTES_PURCHASED']]);
  212. unset($aResult[$CNF['FIELD_CATEGORY_VIEW']], $aResult[$CNF['FIELD_CATEGORY_SELECT']]);
  213. unset($aResult[$CNF['FIELD_PRICE']], $aResult[$CNF['FIELD_YEAR']]);
  214. return $aResult;
  215. }
  216. public function serviceGetSearchableFieldsExtended($aInputsAdd = array())
  217. {
  218. $CNF = &$this->_oConfig->CNF;
  219. $aInputsAdd = array_merge($aInputsAdd, $this->_getSearchableFields());
  220. if(isset($aInputsAdd[$CNF['FIELD_CATEGORY']])) {
  221. $aInputsAdd[$CNF['FIELD_CATEGORY']]['type'] = 'select';
  222. $aInputsAdd[$CNF['FIELD_CATEGORY']]['values_src'] = BxDolService::getSerializedService($this->_oConfig->getName(), 'get_category_options', array(0));
  223. }
  224. if(isset($aInputsAdd[$CNF['FIELD_PRICE']])) {
  225. $aInputsAdd[$CNF['FIELD_PRICE']]['search_type'] = 'text_range';
  226. $aInputsAdd[$CNF['FIELD_PRICE']]['search_operator'] = 'between';
  227. }
  228. if(isset($aInputsAdd[$CNF['FIELD_YEAR']])) {
  229. $aInputsAdd[$CNF['FIELD_YEAR']]['search_type'] = 'text_range';
  230. $aInputsAdd[$CNF['FIELD_YEAR']]['search_operator'] = 'between';
  231. }
  232. return parent::serviceGetSearchableFieldsExtended($aInputsAdd);
  233. }
  234. public function serviceEntityCreate ($sParams = false)
  235. {
  236. if(($sDisplay = $this->getCategoryDisplay('add')) !== false) {
  237. if(empty($sParams) || !is_array($sParams))
  238. $sParams = array();
  239. $sParams['display'] = $sDisplay;
  240. }
  241. return parent::serviceEntityCreate($sParams);
  242. }
  243. /**
  244. * @page service Service Calls
  245. * @section bx_ads Ads
  246. * @subsection bx_ads-page_blocks Page Blocks
  247. * @subsubsection bx_ads-entity_reviews entity_reviews
  248. *
  249. * @code bx_srv('bx_ads', 'entity_reviews', [...]); @endcode
  250. *
  251. * Get reviews for particular content
  252. * @param $iContentId content ID
  253. *
  254. * @see BxAdsModule::serviceEntityReviews
  255. */
  256. /**
  257. * @ref bx_ads-entity_reviews "entity_reviews"
  258. */
  259. public function serviceEntityReviews($iContentId = 0)
  260. {
  261. $CNF = &$this->_oConfig->CNF;
  262. if(empty($CNF['OBJECT_REVIEWS']))
  263. return false;
  264. return $this->_entityComments($CNF['OBJECT_REVIEWS'], $iContentId);
  265. }
  266. /**
  267. * @page service Service Calls
  268. * @section bx_ads Ads
  269. * @subsection bx_ads-page_blocks Page Blocks
  270. * @subsubsection bx_ads-entity_reviews_rating entity_reviews_rating
  271. *
  272. * @code bx_srv('bx_ads', 'entity_reviews_rating', [...]); @endcode
  273. *
  274. * Get reviews rating for particular content
  275. * @param $iContentId content ID
  276. *
  277. * @see BxAdsModule::serviceEntityReviewsRating
  278. */
  279. /**
  280. * @ref bx_ads-entity_reviews_rating "entity_reviews_rating"
  281. */
  282. public function serviceEntityReviewsRating($iContentId = 0)
  283. {
  284. $CNF = &$this->_oConfig->CNF;
  285. if(empty($CNF['OBJECT_REVIEWS']))
  286. return false;
  287. if(!$iContentId)
  288. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  289. if(!$iContentId)
  290. return false;
  291. $oCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_REVIEWS'], $iContentId);
  292. if (!$oCmts || !$oCmts->isEnabled())
  293. return false;
  294. return $oCmts->getRatingBlock(array('in_designbox' => false));
  295. }
  296. /**
  297. * @page service Service Calls
  298. * @section bx_ads Ads
  299. * @subsection bx_ads-page_blocks Page Blocks
  300. * @subsubsection bx_ads-categories_list categories_list
  301. *
  302. * @code bx_srv('bx_ads', 'categories_list', [...]); @endcode
  303. *
  304. * Get reviews rating for particular content
  305. * @param $aParams additional params array, such as 'show_empty'
  306. *
  307. * @see BxAdsModule::serviceCategoriesList
  308. */
  309. /**
  310. * @ref bx_ads-categories_list "categories_list"
  311. */
  312. public function serviceCategoriesList($aParams = array())
  313. {
  314. if(!isset($aParams['show_empty']))
  315. $aParams['show_empty'] = true;
  316. return $this->_oTemplate->categoriesList($aParams);
  317. }
  318. /**
  319. * @page service Service Calls
  320. * @section bx_ads Ads
  321. * @subsection bx_ads-browse Browse
  322. * @subsubsection bx_ads-browse_category browse_category
  323. *
  324. * @code bx_srv('bx_ads', 'browse_category', [...]); @endcode
  325. *
  326. * Get reviews rating for particular content
  327. * @param $iCategoryId category ID
  328. * @param $aParams additional params array, such as empty_message, ajax_paginate, etc
  329. *
  330. * @see BxAdsModule::serviceBrowseCategory
  331. */
  332. /**
  333. * @ref bx_ads-browse_category "browse_category"
  334. */
  335. public function serviceBrowseCategory($iCategoryId = 0, $aParams = array())
  336. {
  337. $sParamName = $sParamGet = 'category';
  338. if(!$iCategoryId && bx_get($sParamGet) !== false)
  339. $iCategoryId = bx_process_input(bx_get($sParamGet), BX_DATA_INT);
  340. $bEmptyMessage = true;
  341. if(isset($aParams['empty_message'])) {
  342. $bEmptyMessage = (bool)$aParams['empty_message'];
  343. unset($aParams['empty_message']);
  344. }
  345. $bAjaxPaginate = true;
  346. if(isset($aParams['ajax_paginate'])) {
  347. $bAjaxPaginate = (bool)$aParams['ajax_paginate'];
  348. unset($aParams['ajax_paginate']);
  349. }
  350. $aBlock = $this->_serviceBrowse ($sParamName, array_merge(array($sParamName => $iCategoryId), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  351. if(!empty($aBlock['content'])) {
  352. $aCategory = $this->_oDb->getCategories(array('type' => 'id', 'id' => $iCategoryId));
  353. if(!empty($aCategory['title']))
  354. $aBlock['title'] = _t('_bx_ads_page_block_title_entries_by_category_mask', _t($aCategory['title']));
  355. }
  356. return $aBlock;
  357. }
  358. public function serviceGetNotificationsData()
  359. {
  360. $sModule = $this->_aModule['name'];
  361. $sEventPrivacy = $sModule . '_allow_view_event_to';
  362. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  363. $sEventPrivacy = '';
  364. $aResult = parent::serviceGetNotificationsData();
  365. $aResult['handlers'] = array_merge($aResult['handlers'], array(
  366. 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)
  367. ));
  368. $aResult['settings'] = array_merge($aResult['settings'], array(
  369. array('group' => 'interest', 'unit' => $sModule, 'action' => 'doInterest', 'types' => array('personal'))
  370. ));
  371. $aResult['alerts'] = array_merge($aResult['alerts'], array(
  372. array('unit' => $sModule, 'action' => 'doInterest')
  373. ));
  374. return $aResult;
  375. }
  376. public function serviceGetNotificationsInterest($aEvent)
  377. {
  378. $CNF = &$this->_oConfig->CNF;
  379. $iContentId = (int)$aEvent['object_id'];
  380. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  381. if(empty($aContentInfo) || !is_array($aContentInfo))
  382. return array();
  383. $iInterestedId = (int)$aEvent['subobject_id'];
  384. $aInterestedInfo = $this->_oDb->getInterested(array('type' => 'id', 'id' => $iInterestedId));
  385. if(empty($aInterestedInfo) || !is_array($aInterestedInfo))
  386. return array();
  387. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
  388. return array(
  389. 'entry_sample' => $CNF['T']['txt_sample_single'],
  390. 'entry_url' => $sEntryUrl,
  391. 'entry_caption' => $aContentInfo[$CNF['FIELD_TITLE']],
  392. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  393. 'subentry_sample' => $CNF['T']['txt_sample_interest_single'],
  394. 'subentry_url' => '',
  395. '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.
  396. );
  397. }
  398. /**
  399. * @page service Service Calls
  400. * @section bx_ads Ads
  401. * @subsection bx_ads-page_blocks Page Blocks
  402. * @subsubsection bx_ads-block_licenses block_licenses
  403. *
  404. * @code bx_srv('bx_ads', 'block_licenses', [...]); @endcode
  405. *
  406. * Get page block with a list of licenses purchased by currently logged member.
  407. *
  408. * @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.
  409. *
  410. * @see BxAdsModule::serviceBlockLicenses
  411. */
  412. /**
  413. * @ref bx_ads-block_licenses "block_licenses"
  414. */
  415. public function serviceBlockLicenses()
  416. {
  417. return $this->_getBlockLicenses();
  418. }
  419. /**
  420. * @page service Service Calls
  421. * @section bx_ads Ads
  422. * @subsection bx_ads-page_blocks Page Blocks
  423. * @subsubsection bx_ads-block_licenses_administration block_licenses_administration
  424. *
  425. * @code bx_srv('bx_ads', 'block_licenses_administration', [...]); @endcode
  426. *
  427. * Get page block with a list of all licenses. It's needed for moderators/administrators.
  428. *
  429. * @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.
  430. *
  431. * @see BxAdsModule::serviceBlockLicensesAdministration
  432. */
  433. /**
  434. * @ref bx_ads-block_licenses "block_licenses"
  435. */
  436. public function serviceBlockLicensesAdministration()
  437. {
  438. return $this->_getBlockLicenses('administration');
  439. }
  440. /**
  441. * @page service Service Calls
  442. * @section bx_ads Ads
  443. * @subsection bx_ads-page_blocks Page Blocks
  444. * @subsubsection bx_ads-block_licenses_note block_licenses_note
  445. *
  446. * @code bx_srv('bx_ads', 'block_licenses_note', [...]); @endcode
  447. *
  448. * Get page block with a notice for licenses usage.
  449. *
  450. * @return HTML string with block content to display on the site.
  451. *
  452. * @see BxAdsModule::serviceBlockLicensesNote
  453. */
  454. /**
  455. * @ref bx_ads-block_licenses_note "block_licenses_note"
  456. */
  457. public function serviceBlockLicensesNote()
  458. {
  459. return MsgBox(_t('_bx_ads_page_block_content_licenses_note'));
  460. }
  461. /**
  462. * @page service Service Calls
  463. * @section bx_ads Ads
  464. * @subsection bx_ads-payments Payments
  465. * @subsubsection bx_ads-get_payment_data get_payment_data
  466. *
  467. * @code bx_srv('bx_ads', 'get_payment_data', [...]); @endcode
  468. *
  469. * Get an array with module's description. Is needed for payments processing module.
  470. *
  471. * @return an array with module's description.
  472. *
  473. * @see BxAdsModule::serviceGetPaymentData
  474. */
  475. /**
  476. * @ref bx_ads-get_payment_data "get_payment_data"
  477. */
  478. public function serviceGetPaymentData()
  479. {
  480. $CNF = &$this->_oConfig->CNF;
  481. $oPermalink = BxDolPermalinks::getInstance();
  482. $aResult = $this->_aModule;
  483. $aResult['url_browse_order_common'] = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_LICENSES_COMMON'], array('filter' => '{order}'));
  484. $aResult['url_browse_order_administration'] = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_LICENSES_ADMINISTRATION'], array('filter' => '{order}'));
  485. return $aResult;
  486. }
  487. /**
  488. * @page service Service Calls
  489. * @section bx_ads Ads
  490. * @subsection bx_ads-payments Payments
  491. * @subsubsection bx_ads-get_cart_item get_cart_item
  492. *
  493. * @code bx_srv('bx_ads', 'get_cart_item', [...]); @endcode
  494. *
  495. * Get an array with prodict's description. Is used in Shopping Cart in payments processing module.
  496. *
  497. * @param $mixedItemId product's ID or Unique Name.
  498. * @return an array with prodict's description. Empty array is returned if something is wrong.
  499. *
  500. * @see BxAdsModule::serviceGetCartItem
  501. */
  502. /**
  503. * @ref bx_ads-get_cart_item "get_cart_item"
  504. */
  505. public function serviceGetCartItem($mixedItemId)
  506. {
  507. $CNF = &$this->_oConfig->CNF;
  508. if(!$mixedItemId)
  509. return array();
  510. if(is_numeric($mixedItemId))
  511. $aItem = $this->_oDb->getContentInfoById((int)$mixedItemId);
  512. else
  513. $aItem = $this->_oDb->getContentInfoByName($mixedItemId);
  514. if(empty($aItem) || !is_array($aItem))
  515. return array();
  516. $iItemId = (int)$aItem[$CNF['FIELD_ID']];
  517. $fItemPrice = (float)$aItem[$CNF['FIELD_PRICE']];
  518. if($this->isAuction($aItem)) {
  519. $iUserId = bx_get_logged_profile_id();
  520. $aOffer = $this->_oDb->getOffersBy(array(
  521. 'type' => 'content_and_author_ids',
  522. 'content_id' => $iItemId,
  523. 'author_id' => $iUserId,
  524. 'status' => BX_ADS_OFFER_STATUS_ACCEPTED
  525. ));
  526. if(!empty($aOffer) && is_array($aOffer))
  527. $fItemPrice = (float)$aOffer[$CNF['FIELD_OFR_AMOUNT']];
  528. }
  529. return array (
  530. 'id' => $iItemId,
  531. 'author_id' => $aItem[$CNF['FIELD_AUTHOR']],
  532. 'name' => $aItem[$CNF['FIELD_NAME']],
  533. 'title' => $aItem[$CNF['FIELD_TITLE']],
  534. 'description' => $aItem[$CNF['FIELD_TEXT']],
  535. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'], array('id' => $aItem[$CNF['FIELD_ID']])),
  536. 'price_single' => $fItemPrice,
  537. 'price_recurring' => '',
  538. 'period_recurring' => 0,
  539. 'period_unit_recurring' => '',
  540. 'trial_recurring' => ''
  541. );
  542. }
  543. /**
  544. * @page service Service Calls
  545. * @section bx_ads Ads
  546. * @subsection bx_ads-payments Payments
  547. * @subsubsection bx_ads-get_cart_items get_cart_items
  548. *
  549. * @code bx_srv('bx_ads', 'get_cart_items', [...]); @endcode
  550. *
  551. * Get an array with prodicts' descriptions by seller. Is used in Manual Order Processing in payments processing module.
  552. *
  553. * @param $iSellerId seller ID.
  554. * @return an array with prodicts' descriptions. Empty array is returned if something is wrong or seller doesn't have any products.
  555. *
  556. * @see BxAdsModule::serviceGetCartItems
  557. */
  558. /**
  559. * @ref bx_ads-get_cart_items "get_cart_items"
  560. */
  561. public function serviceGetCartItems($iSellerId)
  562. {
  563. $CNF = &$this->_oConfig->CNF;
  564. $iSellerId = (int)$iSellerId;
  565. if(empty($iSellerId))
  566. return array();
  567. $aItems = $this->_oDb->getEntriesByAuthor($iSellerId);
  568. $aResult = array();
  569. foreach($aItems as $aItem)
  570. $aResult[] = array(
  571. 'id' => $aItem[$CNF['FIELD_ID']],
  572. 'author_id' => $aItem[$CNF['FIELD_AUTHOR']],
  573. 'name' => $aItem[$CNF['FIELD_NAME']],
  574. 'title' => $aItem[$CNF['FIELD_TITLE']],
  575. 'description' => $aItem[$CNF['FIELD_TEXT']],
  576. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'], array('id' => $aItem[$CNF['FIELD_ID']])),
  577. 'price_single' => $aItem[$CNF['FIELD_PRICE_SINGLE']],
  578. 'price_recurring' => '',
  579. 'period_recurring' => 0,
  580. 'period_unit_recurring' => '',
  581. 'trial_recurring' => ''
  582. );
  583. return $aResult;
  584. }
  585. /**
  586. * @page service Service Calls
  587. * @section bx_ads Ads
  588. * @subsection bx_ads-payments Payments
  589. * @subsubsection bx_ads-register_cart_item register_cart_item
  590. *
  591. * @code bx_srv('bx_ads', 'register_cart_item', [...]); @endcode
  592. *
  593. * Register a processed single time payment inside the Ads module. Is called with payment processing module after the payment was registered there.
  594. *
  595. * @param $iClientId client ID.
  596. * @param $iSellerId seller ID
  597. * @param $iItemId item ID.
  598. * @param $iItemCount the number of purchased items.
  599. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  600. * @param $sLicense license number genereted with payment processing module for internal usage
  601. * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
  602. *
  603. * @see BxAdsModule::serviceRegisterCartItem
  604. */
  605. /**
  606. * @ref bx_ads-register_cart_item "register_cart_item"
  607. */
  608. public function serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  609. {
  610. $CNF = &$this->_oConfig->CNF;
  611. $aItem = $this->serviceGetCartItem($iItemId);
  612. if(empty($aItem) || !is_array($aItem))
  613. return array();
  614. $aEntry = $this->_oDb->getContentInfoById($iItemId);
  615. $iEntryQnt = (int)$aEntry[$CNF['FIELD_QUANTITY']];
  616. if(empty($aEntry) || !is_array($aEntry) || ($iEntryQnt - $iItemCount) < 0)
  617. return array();
  618. if(!$this->_oDb->registerLicense($iClientId, $iItemId, $iItemCount, $sOrder, $sLicense))
  619. return array();
  620. $iEntryQnt -= $iItemCount;
  621. $this->_oDb->updateEntriesBy(array(
  622. $CNF['FIELD_QUANTITY'] => $iEntryQnt,
  623. $CNF['FIELD_STATUS'] => $iEntryQnt == 0 ? BX_ADS_STATUS_SOLD : BX_BASE_MOD_TEXT_STATUS_ACTIVE
  624. ), array($CNF['FIELD_ID'] => $iItemId));
  625. bx_alert($this->getName(), 'license_register', 0, false, array(
  626. 'product_id' => $iItemId,
  627. 'profile_id' => $iClientId,
  628. 'order' => $sOrder,
  629. 'license' => $sLicense,
  630. 'count' => $iItemCount
  631. ));
  632. if($iEntryQnt == 0) {
  633. $aParams = $this->_alertParams($aEntry);
  634. bx_alert($this->getName(), 'sold', $iItemId, false, $aParams);
  635. }
  636. $oClient = BxDolProfile::getInstanceMagic($iClientId);
  637. $oSeller = BxDolProfile::getInstanceMagic($iSellerId);
  638. $sSellerUrl = $oSeller->getUrl();
  639. $sSellerName = $oSeller->getDisplayName();
  640. $sNote = $aEntry[$CNF['FIELD_NOTES_PURCHASED']];
  641. if(empty($sNote))
  642. $sNote = _t('_bx_ads_txt_purchased_note', $sSellerUrl, $sSellerName);
  643. sendMailTemplate($CNF['ETEMPLATE_PURCHASED'], 0, $iClientId, array(
  644. 'client_name' => $oClient->getDisplayName(),
  645. 'entry_name' => $aEntry[$CNF['FIELD_TITLE']],
  646. 'entry_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'], array('id' => $aEntry[$CNF['FIELD_ID']])),
  647. 'vendor_url' => $sSellerUrl,
  648. 'vendor_name' => $sSellerName,
  649. 'count' => (int)$iItemCount,
  650. 'license' => $sLicense,
  651. 'notes' => $sNote,
  652. ));
  653. return $aItem;
  654. }
  655. /**
  656. * @page service Service Calls
  657. * @section bx_ads Ads
  658. * @subsection bx_ads-payments Payments
  659. * @subsubsection bx_ads-register_subscription_item register_subscription_item
  660. *
  661. * @code bx_srv('bx_ads', 'register_subscription_item', [...]); @endcode
  662. *
  663. * Register a processed subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was registered there.
  664. *
  665. * @param $iClientId client ID.
  666. * @param $iSellerId seller ID
  667. * @param $iItemId item ID.
  668. * @param $iItemCount the number of purchased items.
  669. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  670. * @param $sLicense license number genereted with payment processing module for internal usage
  671. * @return an array with subscribed prodict's description. Empty array is returned if something is wrong.
  672. *
  673. * @see BxAdsModule::serviceRegisterSubscriptionItem
  674. */
  675. /**
  676. * @ref bx_ads-register_subscription_item "register_subscription_item"
  677. */
  678. public function serviceRegisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  679. {
  680. return array();
  681. }
  682. /**
  683. * @page service Service Calls
  684. * @section bx_ads Ads
  685. * @subsection bx_ads-payments Payments
  686. * @subsubsection bx_ads-reregister_cart_item reregister_cart_item
  687. *
  688. * @code bx_srv('bx_ads', 'reregister_cart_item', [...]); @endcode
  689. *
  690. * Reregister a single time payment inside the Ads module. Is called with payment processing module after the payment was reregistered there.
  691. *
  692. * @param $iClientId client ID.
  693. * @param $iSellerId seller ID
  694. * @param $iItemIdOld old item ID.
  695. * @param $iItemIdNew new item ID.
  696. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  697. * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
  698. *
  699. * @see BxAdsModule::serviceReregisterCartItem
  700. */
  701. /**
  702. * @ref bx_ads-reregister_cart_item "reregister_cart_item"
  703. */
  704. public function serviceReregisterCartItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  705. {
  706. return array();
  707. }
  708. /**
  709. * @page service Service Calls
  710. * @section bx_ads Ads
  711. * @subsection bx_ads-payments Payments
  712. * @subsubsection bx_ads-reregister_subscription_item reregister_subscription_item
  713. *
  714. * @code bx_srv('bx_ads', 'reregister_subscription_item', [...]); @endcode
  715. *
  716. * Reregister a subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was reregistered there.
  717. *
  718. * @param $iClientId client ID.
  719. * @param $iSellerId seller ID
  720. * @param $iItemIdOld old item ID.
  721. * @param $iItemIdNew new item ID.
  722. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  723. * @return an array with subscribed prodict's description. Empty array is returned if something is wrong.
  724. *
  725. * @see BxAdsModule::serviceReregisterSubscriptionItem
  726. */
  727. /**
  728. * @ref bx_ads-reregister_subscription_item "reregister_subscription_item"
  729. */
  730. public function serviceReregisterSubscriptionItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  731. {
  732. return array();
  733. }
  734. /**
  735. * @page service Service Calls
  736. * @section bx_ads Ads
  737. * @subsection bx_ads-payments Payments
  738. * @subsubsection bx_ads-unregister_cart_item unregister_cart_item
  739. *
  740. * @code bx_srv('bx_ads', 'unregister_cart_item', [...]); @endcode
  741. *
  742. * Unregister an earlier processed single time payment inside the Ads module. Is called with payment processing module after the payment was unregistered there.
  743. *
  744. * @param $iClientId client ID.
  745. * @param $iSellerId seller ID
  746. * @param $iItemId item ID.
  747. * @param $iItemCount the number of purchased items.
  748. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  749. * @param $sLicense license number genereted with payment processing module for internal usage
  750. * @return boolean value determining where the payment was unregistered or not.
  751. *
  752. * @see BxAdsModule::serviceUnregisterCartItem
  753. */
  754. /**
  755. * @ref bx_ads-unregister_cart_item "unregister_cart_item"
  756. */
  757. public function serviceUnregisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  758. {
  759. if(!$this->_oDb->unregisterLicense($iClientId, $iItemId, $sOrder, $sLicense))
  760. return false;
  761. bx_alert($this->getName(), 'license_unregister', 0, false, array(
  762. 'product_id' => $iItemId,
  763. 'profile_id' => $iClientId,
  764. 'order' => $sOrder,
  765. 'license' => $sLicense,
  766. 'count' => $iItemCount
  767. ));
  768. return true;;
  769. }
  770. /**
  771. * @page service Service Calls
  772. * @section bx_ads Ads
  773. * @subsection bx_ads-payments Payments
  774. * @subsubsection bx_ads-unregister_subscription_item unregister_subscription_item
  775. *
  776. * @code bx_srv('bx_ads', 'unregister_subscription_item', [...]); @endcode
  777. *
  778. * Unregister an earlier processed subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was unregistered there.
  779. *
  780. * @param $iClientId client ID.
  781. * @param $iSellerId seller ID
  782. * @param $iItemId item ID.
  783. * @param $iItemCount the number of purchased items.
  784. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  785. * @param $sLicense license number genereted with payment processing module for internal usage
  786. * @return boolean value determining where the subscription was unregistered or not.
  787. *
  788. * @see BxAdsModule::serviceUnregisterSubscriptionItem
  789. */
  790. /**
  791. * @ref bx_ads-unregister_subscription_item "unregister_subscription_item"
  792. */
  793. public function serviceUnregisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  794. {
  795. return true;
  796. }
  797. /**
  798. * @page service Service Calls
  799. * @section bx_ads Ads
  800. * @subsection bx_ads-payments Payments
  801. * @subsubsection bx_ads-cancel_subscription_item cancel_subscription_item
  802. *
  803. * @code bx_srv('bx_ads', 'cancel_subscription_item', [...]); @endcode
  804. *
  805. * Cancel an earlier processed subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was canceled there.
  806. *
  807. * @param $iClientId client ID.
  808. * @param $iSellerId seller ID
  809. * @param $iItemId item ID.
  810. * @param $iItemCount the number of purchased items.
  811. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  812. * @return boolean value determining where the subscription was canceled or not.
  813. *
  814. * @see BxAdsModule::serviceCancelSubscriptionItem
  815. */
  816. /**
  817. * @ref bx_ads-cancel_subscription_item "cancel_subscription_item"
  818. */
  819. public function serviceCancelSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  820. {
  821. return true;
  822. }
  823. public function serviceGetOffersCount($sStatus = '')
  824. {
  825. if(!$this->_oConfig->isAuction())
  826. return 0;
  827. if(empty($sStatus) || !in_array($sStatus, $this->_aOfferStatuses))
  828. $sStatus = BX_ADS_OFFER_STATUS_AWAITING;
  829. $iUserId = bx_get_logged_profile_id();
  830. return $this->_oDb->getOffersBy(array('type' => 'content_author_id', 'author_id' => $iUserId, 'status' => $sStatus, 'count' => true));
  831. }
  832. public function serviceGetLiveUpdates($sStatus, $aMenuItemParent, $aMenuItemChild, $iCount = 0)
  833. {
  834. if(!in_array($sStatus, $this->_aOfferStatuses))
  835. return false;
  836. $iUserId = bx_get_logged_profile_id();
  837. $iCountNew = $this->_oDb->getOffersBy(array('type' => 'content_author_id', 'author_id' => $iUserId, 'status' => $sStatus, 'count' => true));
  838. if($iCountNew == $iCount)
  839. return false;
  840. return array(
  841. 'count' => $iCountNew, // required
  842. 'method' => 'bx_menu_show_live_update(oData)', // required
  843. 'data' => array(
  844. 'code' => BxDolTemplate::getInstance()->parseHtmlByTemplateName('menu_item_addon', array(
  845. 'content' => '{count}'
  846. )),
  847. 'mi_parent' => $aMenuItemParent,
  848. 'mi_child' => $aMenuItemChild
  849. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  850. );
  851. }
  852. public function serviceOffers()
  853. {
  854. $CNF = &$this->_oConfig->CNF;
  855. if(!$this->_oConfig->isAuction())
  856. return '';
  857. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_OFFERS_ALL']);
  858. if(!$oGrid)
  859. return '';
  860. return $oGrid->getCode();
  861. }
  862. public function serviceEntityOffers($iContentId = 0)
  863. {
  864. $CNF = &$this->_oConfig->CNF;
  865. if(!$this->_oConfig->isAuction())
  866. return '';
  867. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_OFFERS']);
  868. if(!$oGrid)
  869. return '';
  870. if(empty($iContentId) && ($_iContentId = bx_get('id')) !== false)
  871. $iContentId = (int)$_iContentId;
  872. $oGrid->setContentId($iContentId);
  873. return $oGrid->getCode();
  874. }
  875. public function serviceEntityOfferAccepted($iContentId = 0)
  876. {
  877. $CNF = &$this->_oConfig->CNF;
  878. if(!$this->_oConfig->isAuction())
  879. return '';
  880. $iUserId = bx_get_logged_profile_id();
  881. if(empty($iContentId) && ($_iContentId = bx_get('id')) !== false)
  882. $iContentId = (int)$_iContentId;
  883. $aContent = $this->_oDb->getContentInfoById($iContentId);
  884. if(empty($aContent) || !is_array($aContent) || $aContent[$CNF['FIELD_QUANTITY']] <= 0)
  885. return '';
  886. $aOffer = $this->_oDb->getOffersBy(array(
  887. 'type' => 'content_and_author_ids',
  888. 'content_id' => $iContentId,
  889. 'author_id' => $iUserId,
  890. 'status' => BX_ADS_OFFER_STATUS_ACCEPTED
  891. ));
  892. if(empty($aOffer) || !is_array($aOffer))
  893. return '';
  894. return $this->_oTemplate->entryOfferAccepted($iUserId, $aContent, $aOffer);
  895. }
  896. public function isEntryActive($aContentInfo)
  897. {
  898. $CNF = &$this->_oConfig->CNF;
  899. if($aContentInfo[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id() || $this->_isModerator())
  900. return true;
  901. 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)))
  902. return false;
  903. if(isset($CNF['FIELD_STATUS_ADMIN']) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active')
  904. return false;
  905. return true;
  906. }
  907. public function isAuction($aContentInfo)
  908. {
  909. $CNF = &$this->_oConfig->CNF;
  910. return $this->_oConfig->isAuction() && (int)$aContentInfo[$CNF['FIELD_AUCTION']] != 0;
  911. }
  912. public function isAllowedMakeOffer($mixedContent, $isPerformAction = false)
  913. {
  914. return $this->checkAllowedMakeOffer($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  915. }
  916. public function checkAllowedMakeOffer($mixedContent, $isPerformAction = false)
  917. {
  918. $CNF = &$this->_oConfig->CNF;
  919. $sTxtError = '_sys_txt_access_denied';
  920. if(!is_array($mixedContent))
  921. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  922. if(empty($mixedContent) || !is_array($mixedContent))
  923. return _t($sTxtError);
  924. if(!$this->isAuction($mixedContent) || (int)$mixedContent[$CNF['FIELD_QUANTITY']] <= 0)
  925. return _t($sTxtError);
  926. if($mixedContent[$CNF['FIELD_AUTHOR']] != bx_get_logged_profile_id())
  927. return CHECK_ACTION_RESULT_ALLOWED;
  928. return _t($sTxtError);
  929. }
  930. public function isAllowedViewOffers($mixedContent, $isPerformAction = false)
  931. {
  932. return $this->checkAllowedViewOffers($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  933. }
  934. public function checkAllowedViewOffers($mixedContent, $isPerformAction = false)
  935. {
  936. $CNF = &$this->_oConfig->CNF;
  937. $sTxtError = '_sys_txt_access_denied';
  938. if(!is_array($mixedContent))
  939. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  940. if(empty($mixedContent) || !is_array($mixedContent))
  941. return _t($sTxtError);
  942. if(!$this->isAuction($mixedContent))
  943. return _t($sTxtError);
  944. if($this->_isModerator())
  945. return CHECK_ACTION_RESULT_ALLOWED;
  946. if($mixedContent[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id())
  947. return CHECK_ACTION_RESULT_ALLOWED;
  948. return _t($sTxtError);
  949. }
  950. public function isAllowedMarkShipped($mixedContent, $isPerformAction = false)
  951. {
  952. return $this->checkAllowedMarkShipped($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  953. }
  954. public function checkAllowedMarkShipped($mixedContent, $isPerformAction = false)
  955. {
  956. $CNF = &$this->_oConfig->CNF;
  957. $sTxtError = '_sys_txt_access_denied';
  958. if(!is_array($mixedContent))
  959. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  960. if(empty($mixedContent) || !is_array($mixedContent))
  961. return _t($sTxtError);
  962. if((int)$mixedContent[$CNF['FIELD_SHIPPED']] != 0 || $mixedContent[$CNF['FIELD_AUTHOR']] != bx_get_logged_profile_id())
  963. return _t($sTxtError);
  964. return CHECK_ACTION_RESULT_ALLOWED;
  965. }
  966. public function isAllowedMarkReceived($mixedContent, $isPerformAction = false)
  967. {
  968. return $this->checkAllowedMarkReceived($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  969. }
  970. public function checkAllowedMarkReceived($mixedContent, $isPerformAction = false)
  971. {
  972. $CNF = &$this->_oConfig->CNF;
  973. $sTxtError = '_sys_txt_access_denied';
  974. if(!is_array($mixedContent))
  975. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  976. if(empty($mixedContent) || !is_array($mixedContent))
  977. return _t($sTxtError);
  978. if((int)$mixedContent[$CNF['FIELD_RECEIVED']] != 0 || !$this->_oDb->hasLicense(bx_get_logged_profile_id(), $mixedContent[$CNF['FIELD_ID']]))
  979. return _t($sTxtError);
  980. return CHECK_ACTION_RESULT_ALLOWED;
  981. }
  982. public function onOfferAdded($iOfferId)
  983. {
  984. $CNF = &$this->_oConfig->CNF;
  985. $aOfferInfo = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
  986. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  987. return;
  988. $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  989. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  990. if(empty($aContentInfo) || !is_array($aContentInfo))
  991. return;
  992. $iViewer = bx_get_logged_profile_id();
  993. $oViewer = BxDolProfile::getInstanceMagic($iViewer);
  994. sendMailTemplate($CNF['ETEMPLATE_OFFER_ADDED'], 0, $aContentInfo[$CNF['FIELD_AUTHOR']], array(
  995. 'viewer_name' => $oViewer->getDisplayName(),
  996. 'viewer_url' => $oViewer->getUrl(),
  997. 'entry_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  998. 'entry_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  999. 'i' => $CNF['URI_VIEW_ENTRY'],
  1000. $CNF['FIELD_ID'] => $iContentId
  1001. ))
  1002. ));
  1003. $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
  1004. bx_alert($this->getName(), 'offer_added', $iOfferId, $aOfferInfo[$CNF['FIELD_OFR_AUTHOR']], $aParams);
  1005. }
  1006. public function onOfferAccepted($iOfferId)
  1007. {
  1008. $CNF = &$this->_oConfig->CNF;
  1009. $aOfferInfo = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
  1010. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  1011. return;
  1012. $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  1013. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1014. if(empty($aContentInfo) || !is_array($aContentInfo))
  1015. return;
  1016. if(!$this->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => BX_ADS_STATUS_OFFER), array($CNF['FIELD_ID'] => $iContentId)))
  1017. return;
  1018. $iOfferer = (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']];
  1019. $oOfferer = BxDolProfile::getInstanceMagic($iOfferer);
  1020. sendMailTemplate($CNF['ETEMPLATE_OFFER_ACCEPTED'], 0, $iOfferer, array(
  1021. 'offerer_name' => $oOfferer->getDisplayName(),
  1022. 'offerer_url' => $oOfferer->getUrl(),
  1023. 'entry_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  1024. 'entry_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  1025. 'i' => $CNF['URI_VIEW_ENTRY'],
  1026. $CNF['FIELD_ID'] => $iContentId
  1027. ))
  1028. ));
  1029. $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
  1030. bx_alert($this->getName(), 'offer_accepted', $iOfferId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  1031. }
  1032. public function onOfferDeclined($iOfferId)
  1033. {
  1034. $CNF = &$this->_oConfig->CNF;
  1035. $aOfferInfo = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
  1036. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  1037. return;
  1038. $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  1039. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1040. if(empty($aContentInfo) || !is_array($aContentInfo))
  1041. return;
  1042. $iOfferer = (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']];
  1043. $oOfferer = BxDolProfile::getInstanceMagic($iOfferer);
  1044. sendMailTemplate($CNF['ETEMPLATE_OFFER_DECLINED'], 0, $iOfferer, array(
  1045. 'offerer_name' => $oOfferer->getDisplayName(),
  1046. 'offerer_url' => $oOfferer->getUrl(),
  1047. 'entry_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  1048. 'entry_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  1049. 'i' => $CNF['URI_VIEW_ENTRY'],
  1050. $CNF['FIELD_ID'] => $iContentId
  1051. ))
  1052. ));
  1053. $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
  1054. bx_alert($this->getName(), 'offer_declined', $iOfferId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  1055. }
  1056. public function onOfferCanceled($iOfferId)
  1057. {
  1058. $CNF = &$this->_oConfig->CNF;
  1059. $aOfferInfo = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
  1060. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  1061. return;
  1062. $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  1063. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1064. if(empty($aContentInfo) || !is_array($aContentInfo))
  1065. return;
  1066. $iOfferer = (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']];
  1067. $oOfferer = BxDolProfile::getInstanceMagic($iOfferer);
  1068. sendMailTemplate($CNF['ETEMPLATE_OFFER_CANCELED'], 0, (int)$aContentInfo[$CNF['FIELD_AUTHOR']], array(
  1069. 'offerer_name' => $oOfferer->getDisplayName(),
  1070. 'offerer_url' => $oOfferer->getUrl(),
  1071. 'entry_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  1072. 'entry_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  1073. 'i' => $CNF['URI_VIEW_ENTRY'],
  1074. $CNF['FIELD_ID'] => $iContentId
  1075. ))
  1076. ));
  1077. $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
  1078. bx_alert($this->getName(), 'offer_canceled', $iOfferId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  1079. }
  1080. /**
  1081. * Common methods.
  1082. */
  1083. public function onShipped($mixedContent)
  1084. {
  1085. $CNF = &$this->_oConfig->CNF;
  1086. if(!is_array($mixedContent))
  1087. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  1088. $iContentId = (int)$mixedContent[$CNF['FIELD_ID']];
  1089. $aOffer = $this->_oDb->getOffersBy(array('type' => 'accepted', 'content_id' => $iContentId));
  1090. if(empty($aOffer) || !is_array($aOffer))
  1091. return;
  1092. $iClient = (int)$aOffer[$CNF['FIELD_OFR_AUTHOR']];
  1093. $iVendor = (int)$mixedContent[$CNF['FIELD_AUTHOR']];
  1094. $oVendor = BxDolProfile::getInstanceMagic($iVendor);
  1095. sendMailTemplate($CNF['ETEMPLATE_SHIPPED'], 0, $iClient, array(
  1096. 'vendor_name' => $oVendor->getDisplayName(),
  1097. 'vendor_url' => $oVendor->getUrl(),
  1098. 'entry_name' => $mixedContent[$CNF['FIELD_TITLE']],
  1099. 'entry_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  1100. 'i' => $CNF['URI_VIEW_ENTRY'],
  1101. $CNF['FIELD_ID'] => $iContentId
  1102. ))
  1103. ));
  1104. $aParams = $this->_alertParams($mixedContent);
  1105. $aParams['offer_author_id'] = $iClient;
  1106. bx_alert($this->getName(), 'shipped', $iContentId, false, $aParams);
  1107. }
  1108. public function onReceived($mixedContent)
  1109. {
  1110. $CNF = &$this->_oConfig->CNF;
  1111. if(!is_array($mixedContent))
  1112. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  1113. $iContentId = (int)$mixedContent[$CNF['FIELD_ID']];
  1114. $aOffer = $this->_oDb->getOffersBy(array('type' => 'accepted', 'content_id' => $iContentId));
  1115. if(empty($aOffer) || !is_array($aOffer))
  1116. return;
  1117. $iClient = (int)$aOffer[$CNF['FIELD_OFR_AUTHOR']];
  1118. $oClient = BxDolProfile::getInstanceMagic($iClient);
  1119. sendMailTemplate($CNF['ETEMPLATE_RECEIVED'], 0, (int)$mixedContent[$CNF['FIELD_AUTHOR']], array(
  1120. 'client_name' => $oClient->getDisplayName(),
  1121. 'client_url' => $oClient->getUrl(),
  1122. 'entry_name' => $mixedContent[$CNF['FIELD_TITLE']],
  1123. 'entry_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  1124. 'i' => $CNF['URI_VIEW_ENTRY'],
  1125. $CNF['FIELD_ID'] => $iContentId
  1126. ))
  1127. ));
  1128. $aParams = $this->_alertParams($mixedContent);
  1129. $aParams['offer_author_id'] = $iClient;
  1130. bx_alert($this->getName(), 'received', $iContentId, false, $aParams);
  1131. }
  1132. public function processMetasAdd($iContentId)
  1133. {
  1134. if(!parent::processMetasAdd($iContentId))
  1135. return false;
  1136. $CNF = &$this->_oConfig->CNF;
  1137. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1138. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1139. $aCategoryTypes = $this->_oDb->getCategoryTypes(array('type' => 'all'));
  1140. foreach($aCategoryTypes as $aCategoryType)
  1141. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $aCategoryType['display_add']);
  1142. return true;
  1143. }
  1144. public function processMetasEdit($iContentId, $oForm)
  1145. {
  1146. if(!parent::processMetasEdit($iContentId, $oForm))
  1147. return false;
  1148. $CNF = &$this->_oConfig->CNF;
  1149. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1150. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1151. $aCategoryTypes = $this->_oDb->getCategoryTypes(array('type' => 'all'));
  1152. foreach($aCategoryTypes as $aCategoryType)
  1153. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $aCategoryType['display_edit']);
  1154. return true;
  1155. }
  1156. public function getCategoryDisplay($sDisplayType, $iCategory = 0)
  1157. {
  1158. if(empty($iCategory) && bx_get('category') !== false)
  1159. $iCategory = (int)bx_get('category');
  1160. if(empty($iCategory))
  1161. return false;
  1162. $aCategory = $this->_oDb->getCategories(array('type' => 'id_full', 'id' => $iCategory));
  1163. $sKey = 'type_display_' . $sDisplayType;
  1164. if(empty($aCategory[$sKey]))
  1165. return false;
  1166. return $aCategory[$sKey];
  1167. }
  1168. /**
  1169. * Internal methods.
  1170. */
  1171. protected function _actionMarkAs($sAction)
  1172. {
  1173. $CNF = &$this->_oConfig->CNF;
  1174. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1175. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1176. $sMethodCheck = 'checkAllowedMark' . bx_gen_method_name($sAction);
  1177. if(!method_exists($this, $sMethodCheck))
  1178. return array();
  1179. if(($mixedCheckResult = $this->$sMethodCheck($aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED)
  1180. return array('msg' => $mixedCheckResult);
  1181. if((int)$this->_oDb->updateEntriesBy(array($CNF['FIELD_' . strtoupper($sAction)] => time()), array($CNF['FIELD_ID'] => $iContentId)) == 0)
  1182. return array('msg' => _t('_bx_ads_txt_err_cannot_perform_action'));
  1183. $this->$sMethodCheck($aContentInfo, true);
  1184. $sMethodOnResult = 'on' . bx_gen_method_name($sAction);
  1185. if(method_exists($this, $sMethodOnResult))
  1186. $this->$sMethodOnResult($aContentInfo);
  1187. return array(
  1188. 'reload' => 1
  1189. );
  1190. }
  1191. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  1192. {
  1193. $CNF = &$this->_oConfig->CNF;
  1194. $mixedContent = $this->_getContent($iContentId, true);
  1195. if($mixedContent === false)
  1196. return false;
  1197. list($iContentId, $aContentInfo) = $mixedContent;
  1198. $sDisplayType = false;
  1199. switch($sFormMethod) {
  1200. case 'editDataForm':
  1201. $sDisplayType = 'edit';
  1202. break;
  1203. case 'viewDataForm':
  1204. case 'viewDataEntry':
  1205. $sDisplayType = 'view';
  1206. break;
  1207. }
  1208. if($sDisplayType !== false && ($sDisplayNew = $this->getCategoryDisplay($sDisplayType, $aContentInfo[$CNF['FIELD_CATEGORY']])) !== false)
  1209. $sDisplay = $sDisplayNew;
  1210. return parent::_serviceEntityForm ($sFormMethod, $iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  1211. }
  1212. protected function _getCategoryOptions($iParentId, &$aValues)
  1213. {
  1214. $aCategories = $this->_oDb->getCategories(array('type' => 'parent_id', 'parent_id' => $iParentId, 'active' => true));
  1215. foreach($aCategories as $aCategory) {
  1216. $aValues[] = array('key' => $aCategory['id'], 'value' => str_repeat('--', (int)$aCategory['level']) . ' ' . _t($aCategory['title']));
  1217. $this->_getCategoryOptions($aCategory['id'], $aValues);
  1218. }
  1219. }
  1220. protected function _getSearchableFields($mixedDisplayType = '')
  1221. {
  1222. $CNF = &$this->_oConfig->CNF;
  1223. if(empty($mixedDisplayType))
  1224. $mixedDisplayType = array('add', 'edit');
  1225. $aResult = array();
  1226. $aDisplays = $this->_oDb->getDisplays($this->_oConfig->getName() . '_entry', $mixedDisplayType);
  1227. foreach($aDisplays as $aDisplay) {
  1228. if($aDisplay['display_name'] == $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])
  1229. continue;
  1230. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $aDisplay['display_name'], $this->_oTemplate);
  1231. if(!$oForm)
  1232. continue;
  1233. $aResult = array_merge($aResult, $oForm->aInputs);
  1234. }
  1235. return $aResult;
  1236. }
  1237. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  1238. {
  1239. $CNF = &$this->_oConfig->CNF;
  1240. $bDynamic = isset($aBrowseParams['dynamic_mode']) && (bool)$aBrowseParams['dynamic_mode'] === true;
  1241. $sCategory = '';
  1242. if(!empty($CNF['FIELD_CATEGORY']) && !empty($aContentInfo[$CNF['FIELD_CATEGORY']])) {
  1243. $iCategory = (int)$aContentInfo[$CNF['FIELD_CATEGORY']];
  1244. $aCategory = $this->_oDb->getCategories(array('type' => 'id', 'id' => $iCategory));
  1245. $sCategory = _t($aCategory['title']);
  1246. $sCategoryLink = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_CATEGORIES'], array($CNF['GET_PARAM_CATEGORY'] => $iCategory));
  1247. }
  1248. $sPrice = _t('_bx_ads_txt_free');
  1249. if(!empty($CNF['FIELD_PRICE']) && !empty($aContentInfo[$CNF['FIELD_PRICE']]))
  1250. $sPrice = _t_format_currency((float)$aContentInfo[$CNF['FIELD_PRICE']]);
  1251. $sInclude = $this->_oTemplate->addCss(array('timeline.css'), $bDynamic);
  1252. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  1253. $aResult['text'] = $this->_oTemplate->parseHtmlByName('timeline_post_text.html', array(
  1254. 'category_link' => $sCategoryLink,
  1255. 'category_title' => $sCategory,
  1256. 'category_title_attr' => bx_html_attribute($sCategory),
  1257. 'price' => $sPrice,
  1258. 'text' => $aResult['text']
  1259. )) . ($bDynamic ? $sInclude : '');
  1260. return $aResult;
  1261. }
  1262. protected function _getBlockLicenses($sType = '')
  1263. {
  1264. $CNF = &$this->_oConfig->CNF;
  1265. $sGrid = $CNF['OBJECT_GRID_LICENSES' . (!empty($sType) ? '_' . strtoupper($sType) : '')];
  1266. $oGrid = BxDolGrid::getObjectInstance($sGrid);
  1267. if(!$oGrid)
  1268. return '';
  1269. $this->_oDb->updateLicense(array('new' => 0), array('profile_id' => bx_get_logged_profile_id(), 'new' => 1));
  1270. $this->_oTemplate->addJs(array('licenses.js'));
  1271. return array(
  1272. 'content' => $this->_oTemplate->getJsCode('licenses', array('sObjNameGrid' => $sGrid)) . $oGrid->getCode(),
  1273. 'menu' => $CNF['OBJECT_MENU_LICENSES']
  1274. );
  1275. }
  1276. protected function _alertParamsOffer($aContentInfo, $aOfferInfo)
  1277. {
  1278. $CNF = &$this->_oConfig->CNF;
  1279. $aParams = array(
  1280. 'object_id' => (int)$aContentInfo[$CNF['FIELD_ID']],
  1281. 'object_author_id' => (int)$aContentInfo[$CNF['FIELD_AUTHOR']],
  1282. 'offer_id' => (int)$aOfferInfo[$CNF['FIELD_OFR_ID']],
  1283. 'offer_author_id' => (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']],
  1284. );
  1285. if(isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  1286. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  1287. return $aParams;
  1288. }
  1289. }
  1290. /** @} */