BxAclModule.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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 PaidLevels Paid Levels
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolAcl');
  12. define('BX_ACL_LICENSE_TYPE_SINGLE', 'single'); //--- one-time payment license
  13. define('BX_ACL_LICENSE_TYPE_RECURRING', 'recurring'); //--- recurring payment license
  14. class BxAclModule extends BxDolModule
  15. {
  16. /**
  17. * Constructor
  18. */
  19. function __construct($aModule)
  20. {
  21. parent::__construct($aModule);
  22. $this->_oConfig->init($this->_oDb);
  23. }
  24. /**
  25. * ACTION METHODS
  26. */
  27. public function actionCheckName()
  28. {
  29. $CNF = &$this->_oConfig->CNF;
  30. $sName = bx_process_input(bx_get('name'));
  31. if(empty($sName))
  32. return echoJson(array());
  33. $sResult = '';
  34. $iId = (int)bx_get('id');
  35. if(!empty($iId)) {
  36. $aPrice = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iId));
  37. if(strcmp($sName, $aPrice[$CNF['FIELD_NAME']]) == 0)
  38. $sResult = $sName;
  39. }
  40. echoJson(array(
  41. 'name' => !empty($sResult) ? $sResult : $this->_oConfig->getPriceName($sName)
  42. ));
  43. }
  44. /**
  45. * SERVICE METHODS
  46. */
  47. public function serviceGetSafeServices()
  48. {
  49. return array (
  50. 'GetViewUrl' => '',
  51. 'GetBlockView' => '',
  52. 'GetMembershipActions' => '',
  53. );
  54. }
  55. /**
  56. * @page service Service Calls
  57. * @section bx_acl Paid Levels
  58. * @subsection bx_acl-other Other
  59. * @subsubsection bx_acl-get_view_url get_view_url
  60. *
  61. * @code bx_srv('bx_acl', 'get_view_url', [...]); @endcode
  62. *
  63. * Get page URL with membership levels list.
  64. *
  65. * @return string with page URL.
  66. *
  67. * @see BxAclModule::serviceGetViewUrl
  68. */
  69. /**
  70. * @ref bx_acl-get_view_url "get_view_url"
  71. */
  72. public function serviceGetViewUrl()
  73. {
  74. $CNF = &$this->_oConfig->CNF;
  75. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_VIEW']);
  76. }
  77. /**
  78. * @page service Service Calls
  79. * @section bx_acl Paid Levels
  80. * @subsection bx_acl-page_blocks Page Blocks
  81. * @subsubsection bx_acl-get_block_view get_block_view
  82. *
  83. * @code bx_srv('bx_acl', 'get_block_view', [...]); @endcode
  84. *
  85. * Get page block with a list of available ACL levels to purchase or get for Free. List is represented as table.
  86. *
  87. * @return HTML string with a list of ACL levels to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML. On error empty string is returned.
  88. *
  89. * @see BxAclModule::serviceGetBlockView
  90. */
  91. /**
  92. * @ref bx_acl-get_block_view "get_block_view"
  93. */
  94. public function serviceGetBlockView()
  95. {
  96. bx_require_authentication(false, false, $this->serviceGetViewUrl());
  97. $sGrid = $this->_oConfig->getGridObject('view');
  98. $oGrid = BxDolGrid::getObjectInstance($sGrid);
  99. if(!$oGrid)
  100. return '';
  101. $this->_oTemplate->addCss(array('view.css'));
  102. return array(
  103. 'content' => $oGrid->getCode()
  104. );
  105. }
  106. /**
  107. * @page service Service Calls
  108. * @section bx_acl Paid Levels
  109. * @subsection bx_acl-page_blocks Page Blocks
  110. * @subsubsection bx_acl-get_membership_actions get_membership_actions
  111. *
  112. * @code bx_srv('bx_acl', 'get_membership_actions', [...]); @endcode
  113. *
  114. * Get page block with a list of current membership level's actions.
  115. *
  116. * @return HTML string with a list of actions to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML. On error empty string is returned.
  117. *
  118. * @see BxAclModule::serviceGetMembershipActions
  119. */
  120. /**
  121. * @ref bx_acl-get_membership_actions "get_membership_actions"
  122. */
  123. public function serviceGetMembershipActions($iProfileId)
  124. {
  125. if($iProfileId != $this->getUserId())
  126. return '';
  127. return $this->_oTemplate->displayMembershipActions($iProfileId);
  128. }
  129. /**
  130. * @page service Service Calls
  131. * @section bx_acl Paid Levels
  132. * @subsection bx_acl-payments Payments
  133. * @subsubsection bx_acl-get_payment_data get_payment_data
  134. *
  135. * @code bx_srv('bx_acl', 'get_payment_data', [...]); @endcode
  136. *
  137. * Get an array with module's description. Is needed for payments processing module.
  138. *
  139. * @return an array with module's description.
  140. *
  141. * @see BxAclModule::serviceGetPaymentData
  142. */
  143. /**
  144. * @ref bx_acl-get_payment_data "get_payment_data"
  145. */
  146. public function serviceGetPaymentData()
  147. {
  148. return $this->_aModule;
  149. }
  150. /**
  151. * @page service Service Calls
  152. * @section bx_acl Paid Levels
  153. * @subsection bx_acl-payments Payments
  154. * @subsubsection bx_acl-get_cart_item get_cart_item
  155. *
  156. * @code bx_srv('bx_acl', 'get_cart_item', [...]); @endcode
  157. *
  158. * Get an array with level's description. Is used in Shopping Cart in payments processing module.
  159. *
  160. * @param $mixedItemId level's ID or Unique Name.
  161. * @return an array with level's description. Empty array is returned if something is wrong.
  162. *
  163. * @see BxAclModule::serviceGetCartItem
  164. */
  165. /**
  166. * @ref bx_acl-get_cart_item "get_cart_item"
  167. */
  168. public function serviceGetCartItem($mixedItemId)
  169. {
  170. $CNF = &$this->_oConfig->CNF;
  171. if(!$mixedItemId)
  172. return array();
  173. if(is_numeric($mixedItemId))
  174. $aItem = $this->_oDb->getPrices(array('type' => 'by_id_full', 'value' => (int)$mixedItemId));
  175. else
  176. $aItem = $this->_oDb->getPrices(array('type' => 'by_name_full', 'value' => $mixedItemId));
  177. if(empty($aItem) || !is_array($aItem))
  178. return array();
  179. $sTitle = '';
  180. if((int)$aItem['period'] == 0)
  181. $sTitle = _t('_bx_acl_txt_cart_item_title_lifetime', _t($aItem['level_name']));
  182. else
  183. $sTitle = _t('_bx_acl_txt_cart_item_title', _t($aItem['level_name']), $aItem['period'], $aItem['period_unit']);
  184. $sDescription = _t($aItem['level_description']);
  185. if(empty($sDescription))
  186. $sDescription = _t('_bx_acl_txt_cart_item_description', getParam('site_title'));
  187. return array (
  188. 'id' => $aItem['id'],
  189. 'author_id' => $this->_oConfig->getOwner(),
  190. 'name' => $aItem['name'],
  191. 'title' => $sTitle,
  192. 'description' => $sDescription,
  193. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_VIEW']),
  194. 'price_single' => $aItem['price'],
  195. 'price_recurring' => $aItem['price'],
  196. 'period_recurring' => $aItem['period'],
  197. 'period_unit_recurring' => $aItem['period_unit'],
  198. 'trial_recurring' => $aItem['trial']
  199. );
  200. }
  201. /**
  202. * @page service Service Calls
  203. * @section bx_acl Paid Levels
  204. * @subsection bx_acl-payments Payments
  205. * @subsubsection bx_acl-get_cart_items get_cart_items
  206. *
  207. * @code bx_srv('bx_acl', 'get_cart_items', [...]); @endcode
  208. *
  209. * Get an array with levels' descriptions by seller. Is used in Manual Order Processing in payments processing module.
  210. *
  211. * @param $iSellerId seller ID.
  212. * @return an array with levels' descriptions. Empty array is returned if something is wrong or seller doesn't have any paid level.
  213. *
  214. * @see BxAclModule::serviceGetCartItems
  215. */
  216. /**
  217. * @ref bx_acl-get_cart_items "get_cart_items"
  218. */
  219. public function serviceGetCartItems($iSellerId)
  220. {
  221. $CNF = &$this->_oConfig->CNF;
  222. $iSellerIdSetting = $this->_oConfig->getOwner();
  223. if(empty($iSellerId) || ($iSellerId != $iSellerIdSetting && !isAdmin()))
  224. return array();
  225. $aItems = $this->_oDb->getPrices(array('type' => 'all_full'));
  226. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_VIEW']);
  227. $aResult = array();
  228. foreach($aItems as $aItem) {
  229. $sTitle = '';
  230. if((int)$aItem['period'] == 0)
  231. $sTitle = _t('_bx_acl_txt_cart_item_title_lifetime', _t($aItem['level_name']));
  232. else
  233. $sTitle = _t('_bx_acl_txt_cart_item_title', _t($aItem['level_name']), $aItem['period'], $aItem['period_unit']);
  234. $sDescription = _t($aItem['level_description']);
  235. if(empty($sDescription))
  236. $sDescription = _t('_bx_acl_txt_cart_item_description', getParam('site_title'));
  237. $aResult[] = array(
  238. 'id' => $aItem['id'],
  239. 'author_id' => $iSellerIdSetting,
  240. 'name' => $aItem['name'],
  241. 'title' => $sTitle,
  242. 'description' => $sDescription,
  243. 'url' => $sUrl,
  244. 'price_single' => $aItem['price'],
  245. 'price_recurring' => $aItem['price'],
  246. 'period_recurring' => $aItem['period'],
  247. 'period_unit_recurring' => $aItem['period_unit'],
  248. 'trial_recurring' => $aItem['trial']
  249. );
  250. }
  251. return $aResult;
  252. }
  253. /**
  254. * @page service Service Calls
  255. * @section bx_acl Paid Levels
  256. * @subsection bx_acl-payments Payments
  257. * @subsubsection bx_acl-register_cart_item register_cart_item
  258. *
  259. * @code bx_srv('bx_acl', 'register_cart_item', [...]); @endcode
  260. *
  261. * Register a processed single time payment inside the Paid Levels module. Is called with payment processing module after the payment was registered there.
  262. *
  263. * @param $iClientId client ID.
  264. * @param $iSellerId seller ID
  265. * @param $iItemId item ID.
  266. * @param $iItemCount the number of purchased items.
  267. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  268. * @param $sLicense license number genereted with payment processing module for internal usage
  269. * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
  270. *
  271. * @see BxAclModule::serviceRegisterCartItem
  272. */
  273. /**
  274. * @ref bx_acl-register_cart_item "register_cart_item"
  275. */
  276. public function serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  277. {
  278. return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, BX_ACL_LICENSE_TYPE_SINGLE);
  279. }
  280. /**
  281. * @page service Service Calls
  282. * @section bx_acl Paid Levels
  283. * @subsection bx_acl-payments Payments
  284. * @subsubsection bx_acl-register_subscription_item register_subscription_item
  285. *
  286. * @code bx_srv('bx_acl', 'register_subscription_item', [...]); @endcode
  287. *
  288. * Register a processed subscription (recurring payment) inside the Paid Levels module. Is called with payment processing module after the subscription was registered there.
  289. *
  290. * @param $iClientId client ID.
  291. * @param $iSellerId seller ID
  292. * @param $iItemId item ID.
  293. * @param $iItemCount the number of purchased items.
  294. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  295. * @param $sLicense license number genereted with payment processing module for internal usage
  296. * @return an array with subscribed prodict's description. Empty array is returned if something is wrong.
  297. *
  298. * @see BxAclModule::serviceRegisterSubscriptionItem
  299. */
  300. /**
  301. * @ref bx_acl-register_subscription_item "register_subscription_item"
  302. */
  303. public function serviceRegisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  304. {
  305. return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, BX_ACL_LICENSE_TYPE_RECURRING);
  306. }
  307. /**
  308. * @page service Service Calls
  309. * @section bx_acl Paid Levels
  310. * @subsection bx_acl-payments Payments
  311. * @subsubsection bx_acl-reregister_cart_item reregister_cart_item
  312. *
  313. * @code bx_srv('bx_acl', 'reregister_cart_item', [...]); @endcode
  314. *
  315. * Reregister a single time payment inside the Paid Levels module. Is called with payment processing module after the payment was reregistered there.
  316. *
  317. * @param $iClientId client ID.
  318. * @param $iSellerId seller ID
  319. * @param $iItemIdOld old item ID.
  320. * @param $iItemIdNew new item ID.
  321. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  322. * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
  323. *
  324. * @see BxAclModule::serviceReregisterCartItem
  325. */
  326. /**
  327. * @ref bx_acl-reregister_cart_item "reregister_cart_item"
  328. */
  329. public function serviceReregisterCartItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  330. {
  331. return $this->_serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder, BX_ACL_LICENSE_TYPE_SINGLE);
  332. }
  333. /**
  334. * @page service Service Calls
  335. * @section bx_acl Paid Levels
  336. * @subsection bx_acl-payments Payments
  337. * @subsubsection bx_acl-reregister_subscription_item reregister_subscription_item
  338. *
  339. * @code bx_srv('bx_acl', 'reregister_subscription_item', [...]); @endcode
  340. *
  341. * Reregister a subscription (recurring payment) inside the Paid Levels module. Is called with payment processing module after the subscription was reregistered there.
  342. *
  343. * @param $iClientId client ID.
  344. * @param $iSellerId seller ID
  345. * @param $iItemIdOld old item ID.
  346. * @param $iItemIdNew new item ID.
  347. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  348. * @return an array with subscribed prodict's description. Empty array is returned if something is wrong.
  349. *
  350. * @see BxAclModule::serviceReregisterSubscriptionItem
  351. */
  352. /**
  353. * @ref bx_acl-reregister_subscription_item "reregister_subscription_item"
  354. */
  355. public function serviceReregisterSubscriptionItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  356. {
  357. return $this->_serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder, BX_ACL_LICENSE_TYPE_RECURRING);
  358. }
  359. /**
  360. * @page service Service Calls
  361. * @section bx_acl Paid Levels
  362. * @subsection bx_acl-payments Payments
  363. * @subsubsection bx_acl-unregister_cart_item unregister_cart_item
  364. *
  365. * @code bx_srv('bx_acl', 'unregister_cart_item', [...]); @endcode
  366. *
  367. * Unregister an earlier processed single time payment inside the Paid Levels module. Is called with payment processing module after the payment was unregistered there.
  368. *
  369. * @param $iClientId client ID.
  370. * @param $iSellerId seller ID
  371. * @param $iItemId item ID.
  372. * @param $iItemCount the number of purchased items.
  373. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  374. * @param $sLicense license number genereted with payment processing module for internal usage
  375. * @return boolean value determining where the payment was unregistered or not.
  376. *
  377. * @see BxAclModule::serviceUnregisterCartItem
  378. */
  379. /**
  380. * @ref bx_acl-unregister_cart_item "unregister_cart_item"
  381. */
  382. public function serviceUnregisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  383. {
  384. return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, BX_ACL_LICENSE_TYPE_SINGLE);
  385. }
  386. /**
  387. * @page service Service Calls
  388. * @section bx_acl Paid Levels
  389. * @subsection bx_acl-payments Payments
  390. * @subsubsection bx_acl-unregister_subscription_item unregister_subscription_item
  391. *
  392. * @code bx_srv('bx_acl', 'unregister_subscription_item', [...]); @endcode
  393. *
  394. * Unregister an earlier processed subscription (recurring payment) inside the Paid Levels module. Is called with payment processing module after the subscription was unregistered there.
  395. *
  396. * @param $iClientId client ID.
  397. * @param $iSellerId seller ID
  398. * @param $iItemId item ID.
  399. * @param $iItemCount the number of purchased items.
  400. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  401. * @param $sLicense license number genereted with payment processing module for internal usage
  402. * @return boolean value determining where the subscription was unregistered or not.
  403. *
  404. * @see BxAclModule::serviceUnregisterSubscriptionItem
  405. */
  406. /**
  407. * @ref bx_acl-unregister_subscription_item "unregister_subscription_item"
  408. */
  409. public function serviceUnregisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  410. {
  411. return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, BX_ACL_LICENSE_TYPE_RECURRING);
  412. }
  413. /**
  414. * @page service Service Calls
  415. * @section bx_acl Paid Levels
  416. * @subsection bx_acl-payments Payments
  417. * @subsubsection bx_acl-cancel_subscription_item cancel_subscription_item
  418. *
  419. * @code bx_srv('bx_acl', 'cancel_subscription_item', [...]); @endcode
  420. *
  421. * Cancel an earlier processed subscription (recurring payment) inside the Paid Levels module. Is called with payment processing module after the subscription was canceled there.
  422. *
  423. * @param $iClientId client ID.
  424. * @param $iSellerId seller ID
  425. * @param $iItemId item ID.
  426. * @param $iItemCount the number of purchased items.
  427. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  428. * @return boolean value determining where the subscription was canceled or not.
  429. *
  430. * @see BxAclModule::serviceCancelSubscriptionItem
  431. */
  432. /**
  433. * @ref bx_acl-cancel_subscription_item "cancel_subscription_item"
  434. */
  435. public function serviceCancelSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  436. {
  437. //TODO: Do something if it's necessary.
  438. return true;
  439. }
  440. /**
  441. * @page service Service Calls
  442. * @section bx_acl Paid Levels
  443. * @subsection bx_acl-other Other
  444. * @subsubsection bx_acl-get_prices get_prices
  445. *
  446. * @code bx_srv('bx_acl', 'get_prices', [...]); @endcode
  447. *
  448. * Get array of available price options for membership levels
  449. *
  450. * @param $iLevelId membership level id
  451. * @param $bFreeUnlimitedOnly get unlimited free pricing options only
  452. * @return array of levels, or empty array of there are no any pricing options avaiulable
  453. *
  454. * @see BxAclModule::serviceGetPrices
  455. */
  456. /**
  457. * @ref bx_acl-get_prices "get_prices"
  458. */
  459. public function serviceGetPrices($iLevelId = 0, $bFreeUnlimitedOnly = false)
  460. {
  461. $aParams = array(
  462. 'type' => $iLevelId ? 'by_level_id' : 'all_full',
  463. 'value' => $iLevelId,
  464. );
  465. $aPrices = $this->_oDb->getPrices($aParams, false);
  466. return array_filter($aPrices, function ($r) use ($bFreeUnlimitedOnly) {
  467. return $bFreeUnlimitedOnly ? !$r['price'] && !$r['period'] : true;
  468. });
  469. }
  470. /**
  471. * @page service Service Calls
  472. * @section bx_acl Paid Levels
  473. * @subsection bx_acl-other Other
  474. * @subsubsection bx_acl-get_products_names get_products_names
  475. *
  476. * @code bx_srv('bx_acl', 'get_products_names', [...]); @endcode
  477. *
  478. * Get an array of products names.
  479. *
  480. * @param $iVendorId return products of 1 vendor only
  481. * @param $iLimit limit the result artay
  482. * @return an array of products names
  483. *
  484. * @see BxAclModule::serviceGetProductsNames
  485. */
  486. /**
  487. * @ref bx_acl-get_products_names "get_products_names"
  488. */
  489. public function serviceGetProductsNames($iVendorId = 0, $iLimit = 1000)
  490. {
  491. return $this->_oDb->getProductsNames($iVendorId, $iLimit);
  492. }
  493. protected function _serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, $sType)
  494. {
  495. $CNF = &$this->_oConfig->CNF;
  496. $aItem = $this->serviceGetCartItem($iItemId);
  497. if(empty($aItem) || !is_array($aItem))
  498. return array();
  499. $oAcl = BxDolAcl::getInstance();
  500. $aItemInfo = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemId));
  501. $aMembershipInfo = $oAcl->getMemberMembershipInfo($iClientId);
  502. $aPeriod = array('period' => (int)$aItemInfo['period'], 'period_unit' => $aItemInfo['period_unit']);
  503. if($sType == BX_ACL_LICENSE_TYPE_RECURRING && (int)$aItemInfo['trial'] > 0 && (int)$aItemInfo['level_id'] != (int)$aMembershipInfo['id'])
  504. $aPeriod = array('period' => (int)$aItemInfo['trial'], 'period_unit' => 'day', 'period_trial' => true);
  505. $iReserve = (int)getParam($CNF['PARAM_RECURRING_RESERVE']);
  506. if(!empty($iReserve))
  507. $aPeriod['period_reserve'] = $iReserve;
  508. if(!$oAcl->setMembership($iClientId, $aItemInfo['level_id'], $aPeriod, true, $sLicense))
  509. return array();
  510. return $aItem;
  511. }
  512. protected function _serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder, $sType)
  513. {
  514. $aItemNew = $this->serviceGetCartItem($iItemIdNew);
  515. if(empty($aItemNew) || !is_array($aItemNew))
  516. return array();
  517. /*
  518. * Note. Membership level cannot be reregistered immediately.
  519. * it will be automatically changed in the end of current period.
  520. */
  521. return $aItemNew;
  522. }
  523. protected function _serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, $sType)
  524. {
  525. $aItemInfo = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemId));
  526. if(empty($aItemInfo) || !is_array($aItemInfo))
  527. return false;
  528. return BxDolAcl::getInstance()->unsetMembership($iClientId, $aItemInfo['level_id'], $sLicense);
  529. }
  530. /**
  531. * COMMON METHODS
  532. */
  533. public function getUserId()
  534. {
  535. return isLogged() ? bx_get_logged_profile_id() : 0;
  536. }
  537. public function getUserInfo($iUserId = 0)
  538. {
  539. $oProfile = BxDolProfile::getInstance($iUserId);
  540. if (!$oProfile)
  541. $oProfile = BxDolProfileUndefined::getInstance();
  542. return array(
  543. $oProfile->getDisplayName(),
  544. $oProfile->getUrl(),
  545. $oProfile->getThumb(),
  546. $oProfile->getUnit()
  547. );
  548. }
  549. }
  550. /** @} */