BxMarketModule.php 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211
  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 Market Market
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_MARKET_LICENSE_TYPE_SINGLE', 'single'); //--- one-time payment license
  12. define('BX_MARKET_LICENSE_TYPE_RECURRING', 'recurring'); //--- recurring payment license
  13. define('BX_MARKET_FILE_TYPE_VERSION', 'version');
  14. define('BX_MARKET_FILE_TYPE_UPDATE', 'update');
  15. /**
  16. * Market module
  17. */
  18. class BxMarketModule extends BxBaseModTextModule
  19. {
  20. function __construct(&$aModule)
  21. {
  22. parent::__construct($aModule);
  23. $CNF = &$this->_oConfig->CNF;
  24. $this->_aSearchableNamesExcept = array_merge($this->_aSearchableNamesExcept, array(
  25. $CNF['FIELD_NAME'],
  26. $CNF['FIELD_PRICE_SINGLE'],
  27. $CNF['FIELD_PRICE_RECURRING'],
  28. $CNF['FIELD_DURATION_RECURRING'],
  29. $CNF['FIELD_TRIAL_RECURRING'],
  30. $CNF['FIELD_ALLOW_PURCHASE_TO'],
  31. $CNF['FIELD_ALLOW_COMMENT_TO'],
  32. $CNF['FIELD_ALLOW_VOTE_TO']
  33. ));
  34. }
  35. public function actionPerform()
  36. {
  37. $CNF = &$this->_oConfig->CNF;
  38. $aContentInfo = $this->_getContentInfo();
  39. if(empty($aContentInfo) || !is_array($aContentInfo))
  40. return echoJson(array('code' => 1));
  41. $sAction = bx_process_input(bx_get('action'));
  42. if(empty($CNF['MENU_ITEM_TO_METHOD'][$CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']][$sAction]))
  43. return echoJson(array('code' => 2));
  44. $sMethodCheck = $CNF['MENU_ITEM_TO_METHOD'][$CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']][$sAction];
  45. $sMethodPerform = '_perform' . bx_gen_method_name($sAction, array('-', '_'));
  46. if(!method_exists($this, $sMethodCheck) || $this->$sMethodCheck($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED || !method_exists($this, $sMethodPerform))
  47. return echoJson(array('code' => 3, 'msg' => _t('_sys_txt_access_denied')));
  48. return $this->$sMethodPerform($aContentInfo);
  49. }
  50. public function actionCheckName()
  51. {
  52. $sTitle = bx_process_input(bx_get('title'));
  53. if(empty($sTitle))
  54. return echoJson(array());
  55. echoJson(array(
  56. 'title' => $sTitle,
  57. 'name' => $this->_oConfig->getEntryName($sTitle)
  58. ));
  59. }
  60. public function actionGetSubentries()
  61. {
  62. $CNF = &$this->_oConfig->CNF;
  63. $sTerm = bx_get('term');
  64. $iLimit = (int)bx_get('limit');
  65. if(empty($iLimit))
  66. $iLimit = 10;
  67. $aResult = array();
  68. $aEntries = $this->_oDb->searchByAuthorTerm($this->_iProfileId, $sTerm, $iLimit);
  69. foreach ($aEntries as $aEntry)
  70. $aResult[] = array('value' => $aEntry[$CNF['FIELD_ID']], 'label' => $aEntry[$CNF['FIELD_TITLE']]);
  71. // sort result
  72. usort($aResult, function($r1, $r2) {
  73. return strcmp($r1['label'], $r2['label']);
  74. });
  75. echoJson(array_slice($aResult, 0, $iLimit));
  76. }
  77. /**
  78. * @page service Service Calls
  79. * @section bx_market Market
  80. * @subsection bx_market-other Other
  81. * @subsubsection bx_market-get_searchable_fields get_searchable_fields
  82. *
  83. * @code bx_srv('bx_market', 'get_searchable_fields', [...]); @endcode
  84. *
  85. * Get a list of searchable fields. Is used in common search engine.
  86. *
  87. * @return an array with a list of searchable fields.
  88. *
  89. * @see BxMarketModule::serviceGetSearchableFields
  90. */
  91. /**
  92. * @ref bx_market-get_searchable_fields "get_searchable_fields"
  93. */
  94. public function serviceGetSearchableFields ()
  95. {
  96. $CNF = &$this->_oConfig->CNF;
  97. $aResult = parent::serviceGetSearchableFields();
  98. unset($aResult[$CNF['FIELD_PRICE_SINGLE']], $aResult[$CNF['FIELD_TRIAL_RECURRING']]);
  99. return $aResult;
  100. }
  101. /**
  102. * @page service Service Calls
  103. * @section bx_market Market
  104. * @subsection bx_market-page_blocks Page Blocks
  105. * @subsubsection bx_market-entity_create entity_create
  106. *
  107. * @code bx_srv('bx_market', 'entity_create', [...]); @endcode
  108. *
  109. * Get page block with product creation form or an error message if something wasn't configured correctly.
  110. *
  111. * @param $sDisplay form display name to use
  112. * @return HTML string with block content to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  113. *
  114. * @see BxMarketModule::serviceEntityCreate
  115. */
  116. /**
  117. * @ref bx_market-entity_create "entity_create"
  118. */
  119. public function serviceEntityCreate ($sDisplay = false)
  120. {
  121. $oPayments = BxDolPayments::getInstance();
  122. if(!$oPayments->isActive())
  123. return MsgBox(_t('_bx_market_err_no_payments'));
  124. if(!$oPayments->isAcceptingPayments($this->_iProfileId))
  125. return MsgBox(_t('_bx_market_err_not_accept_payments', $oPayments->getDetailsUrl()));
  126. $this->_oTemplate->addJs(array('entry.js'));
  127. return $this->_oTemplate->getJsCode('entry') . parent::serviceEntityCreate($sDisplay);
  128. }
  129. /**
  130. * @page service Service Calls
  131. * @section bx_market Market
  132. * @subsection bx_market-page_blocks Page Blocks
  133. * @subsubsection bx_market-entity_download entity_download
  134. *
  135. * @code bx_srv('bx_market', 'entity_download', [...]); @endcode
  136. *
  137. * Get page block with a list of downloadable packages attached to the product. If something is wrong an error message is returned.
  138. *
  139. * @param $iContentId (optional) product's ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  140. * @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.
  141. *
  142. * @see BxMarketModule::serviceEntityDownload
  143. */
  144. /**
  145. * @ref bx_market-entity_download "entity_download"
  146. */
  147. public function serviceEntityDownload ($iContentId = 0)
  148. {
  149. $CNF = &$this->_oConfig->CNF;
  150. if(!$iContentId)
  151. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  152. if(!$iContentId)
  153. return false;
  154. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  155. if(empty($aContentInfo) || !is_array($aContentInfo))
  156. return MsgBox(_t('_sys_txt_error_occured'));
  157. if($this->checkAllowedDownload($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
  158. return MsgBox(_t('_bx_market_err_access_denied'));
  159. $sJsObject = $this->_oConfig->getJsObject('entry');
  160. $oMenu = new BxTemplMenu(array('template' => 'menu_vertical.html', 'menu_id'=> 'bx-market-downloads', 'menu_items' => array(
  161. array('id' => 'bx-market-show-more', 'name' => 'bx-market-show-more', 'class' => '', 'link' => 'javascript:void(0)', 'target' => '_self', 'onclick' => 'javascript:' . $sJsObject . '.showMore();', 'title' => _t('_bx_market_menu_item_title_downloads_more')),
  162. )));
  163. return array(
  164. 'menu' => $oMenu,
  165. 'content' => $this->_oTemplate->entryAttachmentsByStorage($CNF['OBJECT_STORAGE_FILES'], $aContentInfo, array(
  166. 'filter_field' => ''
  167. ))
  168. );
  169. }
  170. /**
  171. * @page service Service Calls
  172. * @section bx_market Market
  173. * @subsection bx_market-page_blocks Page Blocks
  174. * @subsubsection bx_market-entity_rating entity_rating
  175. *
  176. * @code bx_srv('bx_market', 'entity_rating', [...]); @endcode
  177. *
  178. * Get page block with Stars based product's rating.
  179. *
  180. * @param $iContentId (optional) product's ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  181. * @return HTML string with block content 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.
  182. *
  183. * @see BxMarketModule::serviceEntityRating
  184. */
  185. /**
  186. * @ref bx_market-entity_rating "entity_rating"
  187. */
  188. public function serviceEntityRating($iContentId = 0)
  189. {
  190. return $this->_serviceTemplateFunc ('entryRating', $iContentId);
  191. }
  192. /**
  193. * @page service Service Calls
  194. * @section bx_market Market
  195. * @subsection bx_market-page_blocks Page Blocks
  196. * @subsubsection bx_market-entity_author_entities entity_author_entities
  197. *
  198. * @code bx_srv('bx_market', 'entity_author_entities', [...]); @endcode
  199. *
  200. * Get page block with a list of other products of the same author.
  201. *
  202. * @param $iContentId (optional) product's ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  203. * @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.
  204. *
  205. * @see BxMarketModule::serviceEntityAuthorEntities
  206. */
  207. /**
  208. * @ref bx_market-entity_author_entities "entity_author_entities"
  209. */
  210. public function serviceEntityAuthorEntities($iContentId = 0)
  211. {
  212. $CNF = &$this->_oConfig->CNF;
  213. $aContentInfo = $this->_getContentInfo($iContentId);
  214. if($aContentInfo === false)
  215. return false;
  216. $oProfile = BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]);
  217. if (!$oProfile)
  218. $oProfile = BxDolProfileUndefined::getInstance();
  219. $aBlock = $this->_serviceBrowse ('author', array('author' => $aContentInfo[$CNF['FIELD_AUTHOR']], 'except' => array($iContentId), 'per_page' => 2), BX_DB_PADDING_DEF, true);
  220. $aBlock['title'] = _t('_bx_market_page_block_title_entry_author_entries', $oProfile->getDisplayName());
  221. return $aBlock;
  222. }
  223. /**
  224. * @page service Service Calls
  225. * @section bx_market Market
  226. * @subsection bx_market-page_blocks Page Blocks
  227. * @subsubsection bx_market-block_licenses block_licenses
  228. *
  229. * @code bx_srv('bx_market', 'block_licenses', [...]); @endcode
  230. *
  231. * Get page block with a list of licenses purchased by currently logged member.
  232. *
  233. * @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.
  234. *
  235. * @see BxMarketModule::serviceBlockLicenses
  236. */
  237. /**
  238. * @ref bx_market-block_licenses "block_licenses"
  239. */
  240. public function serviceBlockLicenses()
  241. {
  242. $sGrid = $this->_oConfig->getGridObject('licenses');
  243. $oGrid = BxDolGrid::getObjectInstance($sGrid);
  244. if(!$oGrid)
  245. return '';
  246. $this->_oDb->updateLicense(array('new' => 0), array('profile_id' => bx_get_logged_profile_id(), 'new' => 1));
  247. $this->_oTemplate->addJs(array('licenses.js'));
  248. return array(
  249. 'content' => $this->_oTemplate->getJsCode('licenses', array('sObjNameGrid' => $sGrid)) . $oGrid->getCode(),
  250. );
  251. }
  252. /**
  253. * @page service Service Calls
  254. * @section bx_market Market
  255. * @subsection bx_market-page_blocks Page Blocks
  256. * @subsubsection bx_market-block_licenses_note block_licenses_note
  257. *
  258. * @code bx_srv('bx_market', 'block_licenses_note', [...]); @endcode
  259. *
  260. * Get page block with a notice for licenses usage.
  261. *
  262. * @return HTML string with block content to display on the site.
  263. *
  264. * @see BxMarketModule::serviceBlockLicensesNote
  265. */
  266. /**
  267. * @ref bx_market-block_licenses_note "block_licenses_note"
  268. */
  269. public function serviceBlockLicensesNote()
  270. {
  271. return MsgBox(_t('_bx_market_page_block_content_licenses_note'));
  272. }
  273. /**
  274. * @page service Service Calls
  275. * @section bx_market Market
  276. * @subsection bx_market-licenses Licenses
  277. * @subsubsection bx_market-get_unused_licenses_num get_unused_licenses_num
  278. *
  279. * @code bx_srv('bx_market', 'get_unused_licenses_num', [...]); @endcode
  280. *
  281. * Get number of unused licenses for some profile. It can be used in menus with "alert" counters.
  282. *
  283. * @param $iProfileId profile to get unused licenses for, if omitted then currently logged in profile is used
  284. * @return an integer value with a number of unused licenses.
  285. *
  286. * @see BxMarketModule::serviceGetUnusedLicensesNum
  287. */
  288. /**
  289. * @ref bx_market-get_unused_licenses_num "get_unused_licenses_num"
  290. */
  291. public function serviceGetUnusedLicensesNum ($iProfileId = 0)
  292. {
  293. if(!$iProfileId)
  294. $iProfileId = bx_get_logged_profile_id();
  295. $aLicenses = $this->_oDb->getLicense(array('type' => 'new', 'profile_id' => (int)$iProfileId));
  296. return !empty($aLicenses) && is_array($aLicenses) ? count($aLicenses) : 0;
  297. }
  298. /**
  299. * @page service Service Calls
  300. * @section bx_market Market
  301. * @subsection bx_market-licenses Licenses
  302. * @subsubsection bx_market-has_license has_license
  303. *
  304. * @code bx_srv('bx_market', 'has_license', [...]); @endcode
  305. *
  306. * Check whether a profile has a license for specified product. Domain on which the license is used can be attached to checking.
  307. *
  308. * @param $iProfileId profile which ownership will be checked.
  309. * @param $iProductId product which the license(s) will be searched for.
  310. * @param $sDomain (optional) domain name on which the license is used.
  311. * @return boolean value determining where the license is available or not.
  312. *
  313. * @see BxMarketModule::serviceHasLicense
  314. */
  315. /**
  316. * @ref bx_market-has_license "has_license"
  317. */
  318. public function serviceHasLicense ($iProfileId, $iProductId, $sDomain = '')
  319. {
  320. return $this->_oDb->hasLicense($iProfileId, $iProductId, $sDomain);
  321. }
  322. /**
  323. * @page service Service Calls
  324. * @section bx_market Market
  325. * @subsection bx_market-licenses Licenses
  326. * @subsubsection bx_market-get_license get_license
  327. *
  328. * @code bx_srv('bx_market', 'has_license', [...]); @endcode
  329. *
  330. * Get a list of licenses which meet requirements provided in the input array.
  331. *
  332. * @param $aParams array of requirements which will be used for searching.
  333. * @return an array of licenses which meet requirements.
  334. *
  335. * @see BxMarketModule::serviceGetLicense
  336. */
  337. /**
  338. * @ref bx_market-get_license "get_license"
  339. */
  340. public function serviceGetLicense ($aParams)
  341. {
  342. return $this->_oDb->getLicense($aParams);
  343. }
  344. /**
  345. * @page service Service Calls
  346. * @section bx_market Market
  347. * @subsection bx_market-licenses Licenses
  348. * @subsubsection bx_market-update_license update_license
  349. *
  350. * @code bx_srv('bx_market', 'update_license', [...]); @endcode
  351. *
  352. * Update license(s) changing necessary fields. Updatable license(s) should meet requirements provided in the input array.
  353. *
  354. * @param $aSet an array of data to be saved
  355. * @param $aWhere an array of requirements which will be used for searching.
  356. * @return an array of licenses which meet requirements.
  357. *
  358. * @see BxMarketModule::serviceUpdateLicense
  359. */
  360. /**
  361. * @ref bx_market-update_license "update_license"
  362. */
  363. public function serviceUpdateLicense ($aSet, $aWhere)
  364. {
  365. return $this->_oDb->updateLicense($aSet, $aWhere);
  366. }
  367. /**
  368. * @page service Service Calls
  369. * @section bx_market Market
  370. * @subsection bx_market-browsing Browsing
  371. * @subsubsection bx_market-get_entry_by get_entry_by
  372. *
  373. * @code bx_srv('bx_market', 'get_entry_by', [...]); @endcode
  374. *
  375. * Get entry (product) which meets requirements.
  376. *
  377. * @param $sType string with search type.
  378. * @param $mixedValue mixed value to be used for searching.
  379. * @return an array describing a product which meets requirements.
  380. *
  381. * @see BxMarketModule::serviceGetEntryBy
  382. */
  383. /**
  384. * @ref bx_market-get_entry_by "get_entry_by"
  385. */
  386. public function serviceGetEntryBy($sType, $mixedValue)
  387. {
  388. return $this->_oDb->getContentInfoBy(array('type' => $sType, 'value' => $mixedValue));
  389. }
  390. /**
  391. * @page service Service Calls
  392. * @section bx_market Market
  393. * @subsection bx_market-browsing Browsing
  394. * @subsubsection bx_market-get_entries_by get_entries_by
  395. *
  396. * @code bx_srv('bx_market', 'get_entries_by', [...]); @endcode
  397. *
  398. * Get an array of entries (products) which meet requirements.
  399. *
  400. * @param $aParams an array of requirements which will be used for searching.
  401. * @return an array of products which meets requirements.
  402. *
  403. * @see BxMarketModule::serviceGetEntriesBy
  404. */
  405. /**
  406. * @ref bx_market-get_entries_by "get_entries_by"
  407. */
  408. public function serviceGetEntriesBy($aParams)
  409. {
  410. return $this->_oDb->getContentInfoBy($aParams);
  411. }
  412. /**
  413. * @page service Service Calls
  414. * @section bx_market Market
  415. * @subsection bx_market-entry Entry
  416. * @subsubsection bx_market-get_thumbnail get_thumbnail
  417. *
  418. * @code bx_srv('bx_market', 'get_thumbnail', [...]); @endcode
  419. *
  420. * Get an array of image URLs for the product's thumbnail. Returned images have different dimensions ('small' and 'big').
  421. *
  422. * @param $iPhotoId photo ID which is attached to a product as thumbnail.
  423. * @return an array of image URLs.
  424. *
  425. * @see BxMarketModule::serviceGetThumbnail
  426. */
  427. /**
  428. * @ref bx_market-get_thumbnail "get_thumbnail"
  429. */
  430. public function serviceGetThumbnail($iPhotoId)
  431. {
  432. $CNF = &$this->_oConfig->CNF;
  433. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  434. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  435. return array(
  436. 'small' => $oImagesTranscoder ? $oImagesTranscoder->getFileUrl($iPhotoId) : '',
  437. 'big' => $oStorage ? $oStorage->getFileUrlById($iPhotoId) : ''
  438. );
  439. }
  440. /**
  441. * @page service Service Calls
  442. * @section bx_market Market
  443. * @subsection bx_market-entry Entry
  444. * @subsubsection bx_market-get_cover get_cover
  445. *
  446. * @code bx_srv('bx_market', 'get_cover', [...]); @endcode
  447. *
  448. * Get an array of image URLs for the product's cover. Returned images have different dimensions ('small', 'large' and 'big').
  449. *
  450. * @param $iPhotoId photo ID which is attached to a product as cover.
  451. * @return an array of image URLs.
  452. *
  453. * @see BxMarketModule::serviceGetCover
  454. */
  455. /**
  456. * @ref bx_market-get_cover "get_cover"
  457. */
  458. public function serviceGetCover($iPhotoId)
  459. {
  460. $CNF = &$this->_oConfig->CNF;
  461. $oTiGallery = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  462. $oTiPage = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_COVER']);
  463. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  464. return array(
  465. 'medium' => $oTiGallery ? $oTiGallery->getFileUrl($iPhotoId) : '',
  466. 'large' => $oTiPage ? $oTiPage->getFileUrl($iPhotoId) : '',
  467. 'big' => $oStorage ? $oStorage->getFileUrlById($iPhotoId) : ''
  468. );
  469. }
  470. /**
  471. * @page service Service Calls
  472. * @section bx_market Market
  473. * @subsection bx_market-entry Entry
  474. * @subsubsection bx_market-get_file get_file
  475. *
  476. * @code bx_srv('bx_market', 'get_file', [...]); @endcode
  477. *
  478. * Get an array with file's description.
  479. *
  480. * @param $iFileId file ID which is attached to a product as package (version, update, etc).
  481. * @return an array with file's description.
  482. *
  483. * @see BxMarketModule::serviceGetFile
  484. */
  485. /**
  486. * @ref bx_market-get_file "get_file"
  487. */
  488. public function serviceGetFile($iFileId)
  489. {
  490. $CNF = &$this->_oConfig->CNF;
  491. $aFile = $this->_oDb->getFile(array(
  492. 'type' => 'file_id_ext',
  493. 'file_id' => $iFileId
  494. ));
  495. if(!empty($aFile) && is_array($aFile)) {
  496. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_FILES']);
  497. $aFile['file_url'] = $oStorage ? $oStorage->getFileUrlById($iFileId) : '';
  498. }
  499. return $aFile;
  500. }
  501. /**
  502. * @page service Service Calls
  503. * @section bx_market Market
  504. * @subsection bx_market-entry Entry
  505. * @subsubsection bx_market-get_updates get_updates
  506. *
  507. * @code bx_srv('bx_market', 'get_updates', [...]); @endcode
  508. *
  509. * Get an array with update(s)' description(s).
  510. *
  511. * @param $iContentId product's ID.
  512. * @param $sVersion (optional) if version is specified then it will be used for searching as 'Version From'.
  513. * @return an array with update(s)' description(s).
  514. *
  515. * @see BxMarketModule::serviceGetUpdates
  516. */
  517. /**
  518. * @ref bx_market-get_updates "get_updates"
  519. */
  520. public function serviceGetUpdates($iContentId, $sVersion = '')
  521. {
  522. $CNF = &$this->_oConfig->CNF;
  523. $aFile = $this->_oDb->getFile(array(
  524. 'type' => 'content_id_and_type',
  525. 'content_id' => $iContentId,
  526. 'file_type' => 'update',
  527. 'version' => $sVersion
  528. ));
  529. if(!empty($aFile) && is_array($aFile)) {
  530. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_FILES']);
  531. $aFile['file_url'] = $oStorage ? $oStorage->getFileUrlById($aFile['file_id']) : '';
  532. }
  533. return $aFile;
  534. }
  535. /**
  536. * @page service Service Calls
  537. * @section bx_market Market
  538. * @subsection bx_market-entry Entry
  539. * @subsubsection bx_market-get_screenshots get_screenshots
  540. *
  541. * @code bx_srv('bx_market', 'get_screenshots', [...]); @endcode
  542. *
  543. * Get an array with screenshots' descriptions.
  544. *
  545. * @param $iItemId product's ID.
  546. * @return an array with screenshots' descriptions.
  547. *
  548. * @see BxMarketModule::serviceGetScreenshots
  549. */
  550. /**
  551. * @ref bx_market-get_screenshots "get_screenshots"
  552. */
  553. public function serviceGetScreenshots($iItemId)
  554. {
  555. $CNF = &$this->_oConfig->CNF;
  556. if(!$iItemId)
  557. return array();
  558. $aData = $this->_oDb->getContentInfoById($iItemId);
  559. $aPhotos = $this->_oDb->getPhoto(array('type' => 'content_id', 'content_id' => $aData[$CNF['FIELD_ID']], 'except' => array($aData[$CNF['FIELD_THUMB']], $aData[$CNF['FIELD_COVER']])));
  560. if(empty($aPhotos) || !is_array($aPhotos))
  561. return array();
  562. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  563. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_SCREENSHOT']);
  564. $aResult = array();
  565. foreach($aPhotos as $aPhoto)
  566. $aResult[] = array(
  567. 'id' => $aPhoto['file_id'],
  568. 'url_sm' => $oImagesTranscoder ? $oImagesTranscoder->getFileUrl($aPhoto['file_id']) : '',
  569. 'url_bg' => $oStorage ? $oStorage->getFileUrlById($aPhoto['file_id']) : ''
  570. );
  571. return $aResult;
  572. }
  573. /**
  574. * @page service Service Calls
  575. * @section bx_market Market
  576. * @subsection bx_market-payments Payments
  577. * @subsubsection bx_market-get_payment_data get_payment_data
  578. *
  579. * @code bx_srv('bx_market', 'get_payment_data', [...]); @endcode
  580. *
  581. * Get an array with module's description. Is needed for payments processing module.
  582. *
  583. * @return an array with module's description.
  584. *
  585. * @see BxMarketModule::serviceGetPaymentData
  586. */
  587. /**
  588. * @ref bx_market-get_payment_data "get_payment_data"
  589. */
  590. public function serviceGetPaymentData()
  591. {
  592. return $this->_aModule;
  593. }
  594. /**
  595. * @page service Service Calls
  596. * @section bx_market Market
  597. * @subsection bx_market-payments Payments
  598. * @subsubsection bx_market-get_cart_item get_cart_item
  599. *
  600. * @code bx_srv('bx_market', 'get_cart_item', [...]); @endcode
  601. *
  602. * Get an array with prodict's description. Is used in Shopping Cart in payments processing module.
  603. *
  604. * @param $iItemId product's ID.
  605. * @return an array with prodict's description. Empty array is returned if something is wrong.
  606. *
  607. * @see BxMarketModule::serviceGetCartItem
  608. */
  609. /**
  610. * @ref bx_market-get_cart_item "get_cart_item"
  611. */
  612. public function serviceGetCartItem($iItemId)
  613. {
  614. $CNF = &$this->_oConfig->CNF;
  615. if(!$iItemId)
  616. return array();
  617. $aItem = $this->_oDb->getContentInfoById($iItemId);
  618. if(empty($aItem) || !is_array($aItem))
  619. return array();
  620. return array (
  621. 'id' => $aItem[$CNF['FIELD_ID']],
  622. 'author_id' => $aItem[$CNF['FIELD_AUTHOR']],
  623. 'name' => $aItem[$CNF['FIELD_NAME']],
  624. 'title' => $aItem[$CNF['FIELD_TITLE']],
  625. 'description' => $aItem[$CNF['FIELD_TEXT']],
  626. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=view-product&id=' . $aItem[$CNF['FIELD_ID']]),
  627. 'price_single' => $aItem[$CNF['FIELD_PRICE_SINGLE']],
  628. 'price_recurring' => $aItem[$CNF['FIELD_PRICE_RECURRING']],
  629. 'period_recurring' => 1,
  630. 'period_unit_recurring' => $aItem[$CNF['FIELD_DURATION_RECURRING']],
  631. 'trial_recurring' => $aItem[$CNF['FIELD_TRIAL_RECURRING']]
  632. );
  633. }
  634. /**
  635. * @page service Service Calls
  636. * @section bx_market Market
  637. * @subsection bx_market-payments Payments
  638. * @subsubsection bx_market-get_cart_items get_cart_items
  639. *
  640. * @code bx_srv('bx_market', 'get_cart_items', [...]); @endcode
  641. *
  642. * Get an array with prodicts' descriptions by seller. Is used in Manual Order Processing in payments processing module.
  643. *
  644. * @param $iSellerId seller ID.
  645. * @return an array with prodicts' descriptions. Empty array is returned if something is wrong or seller doesn't have any products.
  646. *
  647. * @see BxMarketModule::serviceGetCartItems
  648. */
  649. /**
  650. * @ref bx_market-get_cart_items "get_cart_items"
  651. */
  652. public function serviceGetCartItems($iSellerId)
  653. {
  654. $CNF = &$this->_oConfig->CNF;
  655. $iSellerId = (int)$iSellerId;
  656. if(empty($iSellerId))
  657. return array();
  658. $aItems = $this->_oDb->getEntriesByAuthor($iSellerId);
  659. $aResult = array();
  660. foreach($aItems as $aItem)
  661. $aResult[] = array(
  662. 'id' => $aItem[$CNF['FIELD_ID']],
  663. 'author_id' => $aItem[$CNF['FIELD_AUTHOR']],
  664. 'name' => $aItem[$CNF['FIELD_NAME']],
  665. 'title' => $aItem[$CNF['FIELD_TITLE']],
  666. 'description' => $aItem[$CNF['FIELD_TEXT']],
  667. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=view-product&id=' . $aItem[$CNF['FIELD_ID']]),
  668. 'price_single' => $aItem[$CNF['FIELD_PRICE_SINGLE']],
  669. 'price_recurring' => $aItem[$CNF['FIELD_PRICE_RECURRING']],
  670. 'period_recurring' => 1,
  671. 'period_unit_recurring' => $aItem[$CNF['FIELD_DURATION_RECURRING']],
  672. 'trial_recurring' => $aItem[$CNF['FIELD_TRIAL_RECURRING']]
  673. );
  674. return $aResult;
  675. }
  676. /**
  677. * @page service Service Calls
  678. * @section bx_market Market
  679. * @subsection bx_market-payments Payments
  680. * @subsubsection bx_market-register_cart_item register_cart_item
  681. *
  682. * @code bx_srv('bx_market', 'register_cart_item', [...]); @endcode
  683. *
  684. * Register a processed single time payment inside the Market module. Is called with payment processing module after the payment was registered there.
  685. *
  686. * @param $iClientId client ID.
  687. * @param $iSellerId seller ID
  688. * @param $iItemId item ID.
  689. * @param $iItemCount the number of purchased items.
  690. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  691. * @param $sLicense license number genereted with payment processing module for internal usage
  692. * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
  693. *
  694. * @see BxMarketModule::serviceRegisterCartItem
  695. */
  696. /**
  697. * @ref bx_market-register_cart_item "register_cart_item"
  698. */
  699. public function serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  700. {
  701. return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, BX_MARKET_LICENSE_TYPE_SINGLE);
  702. }
  703. /**
  704. * @page service Service Calls
  705. * @section bx_market Market
  706. * @subsection bx_market-payments Payments
  707. * @subsubsection bx_market-register_subscription_item register_subscription_item
  708. *
  709. * @code bx_srv('bx_market', 'register_subscription_item', [...]); @endcode
  710. *
  711. * Register a processed subscription (recurring payment) inside the Market module. Is called with payment processing module after the subscription was registered there.
  712. *
  713. * @param $iClientId client ID.
  714. * @param $iSellerId seller ID
  715. * @param $iItemId item ID.
  716. * @param $iItemCount the number of purchased items.
  717. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  718. * @param $sLicense license number genereted with payment processing module for internal usage
  719. * @return an array with subscribed prodict's description. Empty array is returned if something is wrong.
  720. *
  721. * @see BxMarketModule::serviceRegisterSubscriptionItem
  722. */
  723. /**
  724. * @ref bx_market-register_subscription_item "register_subscription_item"
  725. */
  726. public function serviceRegisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  727. {
  728. return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, BX_MARKET_LICENSE_TYPE_RECURRING);
  729. }
  730. /**
  731. * @page service Service Calls
  732. * @section bx_market Market
  733. * @subsection bx_market-payments Payments
  734. * @subsubsection bx_market-reregister_cart_item reregister_cart_item
  735. *
  736. * @code bx_srv('bx_market', 'reregister_cart_item', [...]); @endcode
  737. *
  738. * Reregister a single time payment inside the Market module. Is called with payment processing module after the payment was reregistered there.
  739. *
  740. * @param $iClientId client ID.
  741. * @param $iSellerId seller ID
  742. * @param $iItemIdOld old item ID.
  743. * @param $iItemIdNew new item ID.
  744. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  745. * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
  746. *
  747. * @see BxMarketModule::serviceReregisterCartItem
  748. */
  749. /**
  750. * @ref bx_market-reregister_cart_item "reregister_cart_item"
  751. */
  752. public function serviceReregisterCartItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  753. {
  754. return $this->_serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder, BX_MARKET_LICENSE_TYPE_SINGLE);
  755. }
  756. /**
  757. * @page service Service Calls
  758. * @section bx_market Market
  759. * @subsection bx_market-payments Payments
  760. * @subsubsection bx_market-reregister_subscription_item reregister_subscription_item
  761. *
  762. * @code bx_srv('bx_market', 'reregister_subscription_item', [...]); @endcode
  763. *
  764. * Reregister a subscription (recurring payment) inside the Market module. Is called with payment processing module after the subscription was reregistered there.
  765. *
  766. * @param $iClientId client ID.
  767. * @param $iSellerId seller ID
  768. * @param $iItemIdOld old item ID.
  769. * @param $iItemIdNew new item ID.
  770. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  771. * @return an array with subscribed prodict's description. Empty array is returned if something is wrong.
  772. *
  773. * @see BxMarketModule::serviceReregisterSubscriptionItem
  774. */
  775. /**
  776. * @ref bx_market-reregister_subscription_item "reregister_subscription_item"
  777. */
  778. public function serviceReregisterSubscriptionItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  779. {
  780. return $this->_serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder, BX_MARKET_LICENSE_TYPE_RECURRING);
  781. }
  782. /**
  783. * @page service Service Calls
  784. * @section bx_market Market
  785. * @subsection bx_market-payments Payments
  786. * @subsubsection bx_market-unregister_cart_item unregister_cart_item
  787. *
  788. * @code bx_srv('bx_market', 'unregister_cart_item', [...]); @endcode
  789. *
  790. * Unregister an earlier processed single time payment inside the Market module. Is called with payment processing module after the payment was unregistered there.
  791. *
  792. * @param $iClientId client ID.
  793. * @param $iSellerId seller ID
  794. * @param $iItemId item ID.
  795. * @param $iItemCount the number of purchased items.
  796. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  797. * @param $sLicense license number genereted with payment processing module for internal usage
  798. * @return boolean value determining where the payment was unregistered or not.
  799. *
  800. * @see BxMarketModule::serviceUnregisterCartItem
  801. */
  802. /**
  803. * @ref bx_market-unregister_cart_item "unregister_cart_item"
  804. */
  805. public function serviceUnregisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  806. {
  807. return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, BX_MARKET_LICENSE_TYPE_SINGLE);
  808. }
  809. /**
  810. * @page service Service Calls
  811. * @section bx_market Market
  812. * @subsection bx_market-payments Payments
  813. * @subsubsection bx_market-unregister_subscription_item unregister_subscription_item
  814. *
  815. * @code bx_srv('bx_market', 'unregister_subscription_item', [...]); @endcode
  816. *
  817. * Unregister an earlier processed subscription (recurring payment) inside the Market module. Is called with payment processing module after the subscription was unregistered there.
  818. *
  819. * @param $iClientId client ID.
  820. * @param $iSellerId seller ID
  821. * @param $iItemId item ID.
  822. * @param $iItemCount the number of purchased items.
  823. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  824. * @param $sLicense license number genereted with payment processing module for internal usage
  825. * @return boolean value determining where the subscription was unregistered or not.
  826. *
  827. * @see BxMarketModule::serviceUnregisterSubscriptionItem
  828. */
  829. /**
  830. * @ref bx_market-unregister_subscription_item "unregister_subscription_item"
  831. */
  832. public function serviceUnregisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  833. {
  834. return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, BX_MARKET_LICENSE_TYPE_RECURRING);
  835. }
  836. /**
  837. * @page service Service Calls
  838. * @section bx_market Market
  839. * @subsection bx_market-payments Payments
  840. * @subsubsection bx_market-cancel_subscription_item cancel_subscription_item
  841. *
  842. * @code bx_srv('bx_market', 'cancel_subscription_item', [...]); @endcode
  843. *
  844. * Cancel an earlier processed subscription (recurring payment) inside the Market module. Is called with payment processing module after the subscription was canceled there.
  845. *
  846. * @param $iClientId client ID.
  847. * @param $iSellerId seller ID
  848. * @param $iItemId item ID.
  849. * @param $iItemCount the number of purchased items.
  850. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  851. * @return boolean value determining where the subscription was canceled or not.
  852. *
  853. * @see BxMarketModule::serviceCancelSubscriptionItem
  854. */
  855. /**
  856. * @ref bx_market-cancel_subscription_item "cancel_subscription_item"
  857. */
  858. public function serviceCancelSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  859. {
  860. //TODO: Do something if it's necessary.
  861. return true;
  862. }
  863. protected function _serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, $sType)
  864. {
  865. $aItem = $this->serviceGetCartItem($iItemId);
  866. if(empty($aItem) || !is_array($aItem))
  867. return array();
  868. $iTrial = 0;
  869. $sDuration = '';
  870. if($sType == BX_MARKET_LICENSE_TYPE_RECURRING) {
  871. $aProduct = $this->_oDb->getContentInfoById($iItemId);
  872. $iTrial = $aProduct[$this->_oConfig->CNF['FIELD_TRIAL_RECURRING']];
  873. $sDuration = $aProduct[$this->_oConfig->CNF['FIELD_DURATION_RECURRING']];
  874. }
  875. $sAction = $this->_oDb->hasLicenseByOrder($iClientId, $iItemId, $sOrder) ? 'prolong' : 'register';
  876. if(!$this->_oDb->{$sAction . 'License'}($iClientId, $iItemId, $iItemCount, $sOrder, $sLicense, $sType, $sDuration, $iTrial))
  877. return array();
  878. bx_alert($this->getName(), 'license_' . $sAction, 0, false, array(
  879. 'product_id' => $iItemId,
  880. 'profile_id' => $iClientId,
  881. 'order' => $sOrder,
  882. 'license' => $sLicense,
  883. 'type' => $sType,
  884. 'count' => $iItemCount,
  885. 'duration' => $sDuration,
  886. 'trial' => $iTrial
  887. ));
  888. return $aItem;
  889. }
  890. protected function _serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder, $sType)
  891. {
  892. $aItemNew = $this->serviceGetCartItem($iItemIdNew);
  893. if(empty($aItemNew) || !is_array($aItemNew))
  894. return array();
  895. if(!$this->_oDb->hasLicenseByOrder($iClientId, $iItemIdOld, $sOrder))
  896. return array();
  897. if(!$this->_oDb->updateLicense(array('product_id' => $iItemIdNew), array('profile_id' => $iClientId, 'product_id' => $iItemIdOld, 'order' => $sOrder)))
  898. return array();
  899. bx_alert($this->getName(), 'license_reregister', 0, false, array(
  900. 'product_id_old' => $iItemIdOld,
  901. 'product_id_new' => $iItemIdNew,
  902. 'profile_id' => $iClientId,
  903. 'order' => $sOrder,
  904. 'type' => $sType
  905. ));
  906. return $aItemNew;
  907. }
  908. protected function _serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, $sType)
  909. {
  910. if(!$this->_oDb->unregisterLicense($iClientId, $iItemId, $sOrder, $sLicense, $sType))
  911. return false;
  912. bx_alert($this->getName(), 'license_unregister', 0, false, array(
  913. 'product_id' => $iItemId,
  914. 'profile_id' => $iClientId,
  915. 'order' => $sOrder,
  916. 'license' => $sLicense,
  917. 'type' => $sType,
  918. 'count' => $iItemCount
  919. ));
  920. return true;
  921. }
  922. public function getGhostTemplateVars($aFile, $iProfileId, $iContentId, $oStorage, $oImagesTranscoder)
  923. {
  924. $CNF = &$this->_oConfig->CNF;
  925. $sMethod = '';
  926. $sStorage = $oStorage->getObject();
  927. switch($sStorage) {
  928. case $CNF['OBJECT_STORAGE']:
  929. $sMethod = 'getPhoto';
  930. break;
  931. case $CNF['OBJECT_STORAGE_FILES']:
  932. $sMethod = 'getFile';
  933. break;
  934. }
  935. $aFileInfo = $this->_oDb->$sMethod(array('type' => 'file_id', 'file_id' => $aFile['id']));
  936. $bFileInfo = !empty($aFileInfo) && is_array($aFileInfo);
  937. $bFileInfoTitle = $bFileInfo && isset($aFileInfo['title']);
  938. $aTmplVars = array(
  939. 'file_title' => $bFileInfoTitle ? $aFileInfo['title'] : '',
  940. 'file_title_attr' => $bFileInfoTitle ? bx_html_attribute($aFileInfo['title']) : '',
  941. );
  942. if($sStorage == $CNF['OBJECT_STORAGE'])
  943. return $aTmplVars;
  944. $bFileInfoVersion = $bFileInfo && isset($aFileInfo['version']);
  945. $bFileInfoTypeVersion = !$bFileInfo || ($bFileInfo && isset($aFileInfo['type']) && $aFileInfo['type'] == BX_MARKET_FILE_TYPE_VERSION);
  946. $bFileInfoTypeUpdate = $bFileInfo && isset($aFileInfo['type']) && $aFileInfo['type'] == BX_MARKET_FILE_TYPE_UPDATE;
  947. $aVersions = $this->_oDb->$sMethod(array('type' => 'content_id', 'content_id' => $iContentId));
  948. $aTmplVars = array_merge($aTmplVars, array(
  949. 'file_version' => $bFileInfoVersion ? $aFileInfo['version'] : '',
  950. 'file_version_attr' => $bFileInfoVersion ? bx_html_attribute($aFileInfo['version']) : '',
  951. 'file_type_version_selected' => $bFileInfoTypeVersion ? ' selected="selected"' : '',
  952. 'file_type_update_selected' => $bFileInfoTypeUpdate ? ' selected="selected"' : '',
  953. 'file_type_version_elements' => !$bFileInfoTypeVersion ? ' style="display:none;"' : '',
  954. 'file_type_update_elements' => !$bFileInfoTypeUpdate ? ' style="display:none;"' : '',
  955. 'file_version_from_options' => $this->_oTemplate->getGhostTemplateFileOptions('version', $aFileInfo, $aVersions),
  956. 'file_version_to_options' => $this->_oTemplate->getGhostTemplateFileOptions('version_to', $aFileInfo, $aVersions)
  957. ));
  958. return $aTmplVars;
  959. }
  960. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  961. {
  962. $CNF = &$this->_oConfig->CNF;
  963. if($aDataEntry[$CNF['FIELD_AUTHOR']] == $this->_iProfileId) {
  964. $aLicenses = $this->_oDb->getLicense(array('type' => 'product_id', 'product_id' => $aDataEntry[$CNF['FIELD_ID']]));
  965. if(is_array($aLicenses) && count($aLicenses) > 0)
  966. return _t('_sys_txt_access_denied');
  967. }
  968. return parent::checkAllowedDelete($aDataEntry, $isPerformAction);
  969. }
  970. public function checkAllowedSetCover ()
  971. {
  972. $aCheck = checkActionModule($this->_iProfileId, 'set cover', $this->getName(), false);
  973. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  974. return $aCheck[CHECK_ACTION_MESSAGE];
  975. return CHECK_ACTION_RESULT_ALLOWED;
  976. }
  977. public function checkAllowedSetSubentries ()
  978. {
  979. $aCheck = checkActionModule($this->_iProfileId, 'set subentries', $this->getName(), false);
  980. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  981. return $aCheck[CHECK_ACTION_MESSAGE];
  982. return CHECK_ACTION_RESULT_ALLOWED;
  983. }
  984. public function checkAllowedDownload($aDataEntry, $isPerformAction = false)
  985. {
  986. $CNF = &$this->_oConfig->CNF;
  987. // moderator and owner always have access
  988. if ($aDataEntry[$CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  989. return CHECK_ACTION_RESULT_ALLOWED;
  990. // check ACL
  991. $aCheck = checkActionModule($this->_iProfileId, 'download entry', $this->getName(), $isPerformAction);
  992. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  993. return $aCheck[CHECK_ACTION_MESSAGE];
  994. if((float)$aDataEntry[$CNF['FIELD_PRICE_SINGLE']] == 0 && (float)$aDataEntry[$CNF['FIELD_PRICE_RECURRING']] == 0)
  995. return CHECK_ACTION_RESULT_ALLOWED;
  996. if(!$this->_oDb->hasLicense($this->_iProfileId, $aDataEntry[$CNF['FIELD_ID']]))
  997. return CHECK_ACTION_RESULT_NOT_ALLOWED;
  998. return CHECK_ACTION_RESULT_ALLOWED;
  999. }
  1000. public function checkAllowedHide($aDataEntry, $isPerformAction = false)
  1001. {
  1002. $CNF = &$this->_oConfig->CNF;
  1003. if($aDataEntry[$CNF['FIELD_STATUS']] != 'active')
  1004. return CHECK_ACTION_RESULT_NOT_ALLOWED;
  1005. // moderator and owner always have access
  1006. if ($aDataEntry[$CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  1007. return CHECK_ACTION_RESULT_ALLOWED;
  1008. return CHECK_ACTION_RESULT_NOT_ALLOWED;
  1009. }
  1010. public function checkAllowedUnhide($aDataEntry, $isPerformAction = false)
  1011. {
  1012. $CNF = &$this->_oConfig->CNF;
  1013. if($aDataEntry[$CNF['FIELD_STATUS']] == 'active')
  1014. return CHECK_ACTION_RESULT_NOT_ALLOWED;
  1015. // moderator and owner always have access
  1016. if ($aDataEntry[$CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  1017. return CHECK_ACTION_RESULT_ALLOWED;
  1018. return CHECK_ACTION_RESULT_NOT_ALLOWED;
  1019. }
  1020. public function checkAllowedViewMoreMenu (&$aDataEntry, $isPerformAction = false)
  1021. {
  1022. $CNF = &$this->_oConfig->CNF;
  1023. $oMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  1024. $oMenu->setContentId($aDataEntry[$CNF['FIELD_ID']]);
  1025. if(!$oMenu || !$oMenu->isVisible())
  1026. return CHECK_ACTION_RESULT_NOT_ALLOWED;
  1027. return CHECK_ACTION_RESULT_ALLOWED;
  1028. }
  1029. protected function _getContentInfo($iContentId = 0)
  1030. {
  1031. if(!$iContentId)
  1032. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1033. if(!$iContentId)
  1034. return false;
  1035. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1036. if(!$aContentInfo)
  1037. return false;
  1038. return $aContentInfo;
  1039. }
  1040. protected function _performHideProduct($aDataEntry) {
  1041. $CNF = &$this->_oConfig->CNF;
  1042. if(!$this->_oDb->updateContentInfoBy(array($CNF['FIELD_STATUS'] => 'hidden'), array($CNF['FIELD_ID'] => $aDataEntry[$CNF['FIELD_ID']])))
  1043. return echoJson(array());
  1044. $this->checkAllowedHide($aDataEntry, true);
  1045. return echoJson(array('reload' => 1));
  1046. }
  1047. protected function _performUnhideProduct($aDataEntry) {
  1048. $CNF = &$this->_oConfig->CNF;
  1049. if(!$this->_oDb->updateContentInfoBy(array($CNF['FIELD_STATUS'] => 'active'), array($CNF['FIELD_ID'] => $aDataEntry[$CNF['FIELD_ID']])))
  1050. return echoJson(array());
  1051. $this->checkAllowedHide($aDataEntry, true);
  1052. return echoJson(array('reload' => 1));
  1053. }
  1054. protected function _entitySocialSharing ($iId, $aParams = array())
  1055. {
  1056. $CNF = &$this->_oConfig->CNF;
  1057. return parent::_entitySocialSharing($iId, array_merge($aParams, array(
  1058. 'object_vote' => ''
  1059. )));
  1060. }
  1061. }
  1062. /** @} */