src/Controller/ParentController.php line 627

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\CurrencyPair;
  4. use App\Entity\Customer;
  5. use App\Entity\User;
  6. use Bundles\Portfolios\Controller\PortfolioOptionController;
  7. use Bundles\Settings\Entity\Settings;
  8. use App\Service\Helper;
  9. use App\Service\Messenger;
  10. use App\Service\Sender;
  11. use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController;
  12. use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents;
  13. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  14. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  15. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  16. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  17. use Symfony\Component\Form\Extension\Core\Type\TextType;
  18. use Symfony\Component\Form\FormBuilder;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  21. use App\Service\HedgingCalcs;
  22. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  23. use App\Service\Excel;
  24. use App\Service\GoogleApi;
  25. use App\Models\ForwardPoints;
  26. use Bundles\Settings\Controller\SettingsController;
  27. use Symfony\Component\HttpFoundation\Response;
  28. use Symfony\Component\HttpKernel\Bundle\Bundle;
  29. use Bundles\Messenger\Controller\ActionController;
  30. use Symfony\Contracts\Cache\ItemInterface;
  31. use Symfony\Component\Cache\CacheItem;
  32. use Bundles\Instruments\Base\Model\Calculations;
  33. class ParentController extends EasyAdminController {
  34. protected $systemName = 'CorpHedge';
  35. protected $systemUrl = ''; //is sistemos nustatymo
  36. protected $systemPhone = ''; //is sistemos nustatymo
  37. protected $logger;
  38. protected $cronLogger;
  39. protected $cache;
  40. protected $rootPath;
  41. protected $settings;
  42. protected $sysConfig;
  43. protected $systemCustomer;
  44. protected $session;
  45. protected $connection;
  46. protected $redirect;
  47. protected $data = [];
  48. protected $mailSender = '';
  49. public function initialize(Request $request) {
  50. parent::initialize($request);
  51. if (empty($this->em)) {
  52. $this->em = $this->getDoctrine()->getManagerForClass(Settings::class);
  53. }
  54. $this->getSysConfig();
  55. if (empty($this->systemCustomer)) {
  56. $this->systemCustomer = $this->em->getRepository(Customer::class)->find($this->getSysConfig('systemCustomer'));
  57. }
  58. if (!empty($this->getUser()) && $this->getUser()->getId()) {
  59. if ($this->getCustomer()->getLicence() == 'Trial' && date_create($this->getCustomer()->getTrialExpiresAt()) < date_create()) {
  60. $this->addFlash('warning', 'Your trial period has ended. Please contact your administrator.');
  61. $this->getCustomer()->setLicence('Basic');
  62. $this->updateEntity($this->getCustomer());
  63. }
  64. $this->data['user'] = $this->getUser();
  65. $this->data['licence'] = $this->getCustomer()->getLicence();
  66. }
  67. $this->mailSender = $_ENV['MAIL_SENDER'];
  68. }
  69. protected function listAction() {
  70. $this->initialize($this->request);
  71. $this->dispatch(EasyAdminEvents::PRE_LIST);
  72. $fields = $this->entity['list']['fields'];
  73. $paginator = $this->findAll($this->entity['class'], $this->request->query->get('page', 1), $this->entity['list']['max_results'], $this->request->query->get('sortField'), $this->request->query->get('sortDirection'), $this->entity['list']['dql_filter']);
  74. $this->dispatch(EasyAdminEvents::POST_LIST, ['paginator' => $paginator]);
  75. $parameters = [
  76. 'paginator' => $paginator,
  77. 'fields' => $fields,
  78. 'batch_form' => $this->createBatchForm($this->entity['name'])->createView(),
  79. 'delete_form_template' => $this->createDeleteForm($this->entity['name'], '__id__')->createView(),
  80. 'user' => $this->getUser(),
  81. ];
  82. return $this->executeDynamicMethod('render<EntityName>Template', [
  83. 'list',
  84. $this->entity['templates']['list'],
  85. $parameters,
  86. ]);
  87. }
  88. protected function editAction() {
  89. $this->dispatch(EasyAdminEvents::PRE_EDIT);
  90. $id = $this->request->query->get('id');
  91. $easyadmin = $this->request->attributes->get('easyadmin');
  92. $entity = $easyadmin['item'];
  93. if ($this->request->isXmlHttpRequest() && $property = $this->request->query->get('property')) {
  94. $newValue = 'true' === mb_strtolower($this->request->query->get('newValue'));
  95. $fieldsMetadata = $this->entity['list']['fields'];
  96. if (!isset($fieldsMetadata[$property]) || 'toggle' !== $fieldsMetadata[$property]['dataType']) {
  97. throw new \RuntimeException(sprintf('The type of the "%s" property is not "toggle".', $property));
  98. }
  99. $this->updateEntityProperty($entity, $property, $newValue);
  100. // cast to integer instead of string to avoid sending empty responses for 'false'
  101. return new Response((int)$newValue);
  102. }
  103. $fields = $this->entity['edit']['fields'];
  104. $editForm = $this->executeDynamicMethod('create<EntityName>EditForm', [$entity, $fields]);
  105. $deleteForm = $this->createDeleteForm($this->entity['name'], $id);
  106. $editForm->handleRequest($this->request);
  107. if ($editForm->isSubmitted() && $editForm->isValid()) {
  108. $this->processUploadedFiles($editForm);
  109. $this->dispatch(EasyAdminEvents::PRE_UPDATE, ['entity' => $entity]);
  110. $this->executeDynamicMethod('update<EntityName>Entity', [$entity, $editForm]);
  111. $this->dispatch(EasyAdminEvents::POST_UPDATE, ['entity' => $entity]);
  112. return $this->redirectToReferrer();
  113. }
  114. $this->dispatch(EasyAdminEvents::POST_EDIT);
  115. $parameters = [
  116. 'form' => $editForm->createView(),
  117. 'entity_fields' => $fields,
  118. 'entity' => $entity,
  119. 'delete_form' => $deleteForm->createView(),
  120. 'user' => $this->getUser(),
  121. ];
  122. return $this->executeDynamicMethod('render<EntityName>Template', [
  123. 'edit',
  124. $this->entity['templates']['edit'],
  125. $parameters,
  126. ]);
  127. }
  128. /**
  129. * mano inicijuoti ir aktyvuoti servisai
  130. * @return array
  131. */
  132. public static function getSubscribedServices(): array {
  133. return array_merge(parent::getSubscribedServices(), [
  134. 'messenger' => Messenger::class,
  135. 'sender' => Sender::class,
  136. 'helper' => Helper::class,
  137. 'settings' => SettingsController::class,
  138. 'user' => UserController::class,
  139. 'HedgingCalcs' => HedgingCalcs::class,
  140. 'Excel' => Excel::class,
  141. 'GoogleApi' => GoogleApi::class,
  142. 'messenger_actions' => ActionController::class,
  143. 'optionPortfolio' => PortfolioOptionController::class,
  144. ]);
  145. }
  146. protected function getCurrencyList() {
  147. $list = [];
  148. /**
  149. * @var CurrencyPair[] $pairs
  150. */
  151. $pairs = $this->getDoctrine()->getRepository(CurrencyPair::class)->findBy(['status' => 1]);
  152. if (empty($pairs)) {
  153. return $list;
  154. }
  155. foreach ($pairs as $item) {
  156. $list[$item->getName()] = $item->getId();
  157. }
  158. return $list;
  159. }
  160. protected function getCompanyList() {
  161. $list = [];
  162. /**
  163. * @var Customer[] $customers
  164. */
  165. $customers = $this->getAdminCustomers(false);
  166. if (empty($customers)) {
  167. return $list;
  168. }
  169. foreach ($customers as $item) {
  170. $list[$item->getCompanyName()] = $item->getId();
  171. }
  172. return $list;
  173. }
  174. public function createFilterForm($filters, $requestFilters, $route, $formName = 'filter', $errors = []) {
  175. /** @var FormBuilder $formBuilder */
  176. $formBuilder = $this->get('form.factory')->createNamedBuilder($formName)->setMethod('POST')->setAction($route);
  177. foreach ($filters as $filter) {
  178. if (!empty($filter['roles']['ROLE_ADMIN']) && !$this->getUser()->isAdmin()) {
  179. continue;
  180. }
  181. switch ($filter['type']) {
  182. case 'date':
  183. $formBuilder->add($filter['property'], TextType::class, [
  184. 'translation_domain' => 'messages',
  185. 'required' => false,
  186. 'label' => $filter['label'],
  187. 'attr' => [
  188. 'class' => 'form-control datepicker '.($filter['class'] ?? ''),
  189. 'type' => 'date',
  190. 'widget' => 'single_text',
  191. 'format' => 'yyyy-mm-dd',
  192. 'placeholder' => $filter['placeholder'] ?? '',
  193. 'roles' => $filter['roles'] ?? '',
  194. ],
  195. 'data' => $requestFilters[$filter['property']] ?? $filter['default'] ?? '',
  196. ]);
  197. break;
  198. case 'text':
  199. $formBuilder->add($filter['property'], TextType::class, [
  200. 'translation_domain' => 'messages',
  201. 'required' => false,
  202. 'label' => $filter['label'],
  203. 'label_attr' => ['class' => 'col-sm-2 control-label'],
  204. 'attr' => [
  205. 'class' => 'form-control '.($filter['class'] ?? ''),
  206. 'placeholder' => $filter['placeholder'] ?? '',
  207. 'roles' => $filter['roles'] ?? '',
  208. ],
  209. 'data' => $requestFilters[$filter['property']] ?? $filter['default'] ?? '',
  210. ]);
  211. break;
  212. case 'number':
  213. $formBuilder->add($filter['property'], NumberType::class, [
  214. 'translation_domain' => 'messages',
  215. 'required' => false,
  216. 'label' => $filter['label'],
  217. 'label_attr' => ['class' => 'control-label'],
  218. 'attr' => [
  219. 'class' => 'form-control '.($filter['class'] ?? ''),
  220. 'placeholder' => $filter['placeholder'] ?? '',
  221. 'roles' => $filter['roles'] ?? '',
  222. 'title' => $filter['title'] ?? '',
  223. 'onKeyUp' => 'numberCheck(this)',
  224. ],
  225. 'data' => (!empty($requestFilters[$filter['property']]) ? $requestFilters[$filter['property']] : $filter['default'] ?? 0),
  226. 'help' => $filter['help'] ?? '',
  227. ]);
  228. break;
  229. case 'select':
  230. $formBuilder->add($filter['property'], ChoiceType::class, [
  231. 'translation_domain' => 'messages',
  232. 'required' => false,
  233. 'choices' => $filter['choices'],
  234. 'label' => $filter['label'] ?? '',
  235. 'placeholder' => $filter['placeholder'] ?? '',
  236. 'label_attr' => ['class' => 'col-sm-2 control-label'],
  237. 'attr' => [
  238. 'class' => 'form-control '.($filter['class'] ?? ''),
  239. 'roles' => $filter['roles'] ?? '',
  240. 'onchange' => $filter['onchange'] ?? '',
  241. ],
  242. 'data' => $requestFilters[$filter['property']] ?? $filter['default'] ?? '',
  243. ]);
  244. break;
  245. case 'checkbox':
  246. $formBuilder->add($filter['property'], CheckboxType::class, [
  247. 'translation_domain' => 'messages',
  248. 'required' => false,
  249. 'label' => $filter['label'],
  250. 'label_attr' => ['class' => 'col-sm-2 control-label'],
  251. 'attr' => [
  252. 'class' => 'form-control '.($filter['class'] ?? ''),
  253. 'roles' => $filter['roles'] ?? '',
  254. 'style' => 'width: 20px; box-shadow: none',
  255. ],
  256. 'data' => !empty($requestFilters[$filter['property']]) ? true : false,
  257. ]);
  258. // dump($requestFilters);
  259. // dump($filter);
  260. break;
  261. case 'textarea':
  262. $formBuilder->add($filter['property'], TextareaType::class, [
  263. 'translation_domain' => 'messages',
  264. 'required' => false,
  265. 'label' => $filter['label'],
  266. 'label_attr' => ['class' => 'col-sm-2 control-label'],
  267. 'attr' => [
  268. 'class' => 'form-control '.($filter['class'] ?? ''),
  269. 'roles' => $filter['roles'] ?? '',
  270. ],
  271. 'data' => $requestFilters[$filter['property']] ?? $filter['default'] ?? '',
  272. ]);
  273. break;
  274. case 'hidden':
  275. $formBuilder->add($filter['property'], HiddenType::class, [
  276. 'data' => $filter['default'] ?? '',
  277. ]);
  278. break;
  279. case 'submit':
  280. $formBuilder->add($filter['property'], SubmitType::class, [
  281. 'label' => $filter['label'],
  282. 'attr' => $filter['attributes'] ?? '',
  283. ]);
  284. break;
  285. }
  286. }
  287. return $formBuilder->getForm();
  288. }
  289. public function getEntityConfig($name) {
  290. $backendConfig = $this->get('easyadmin.config.manager')->getBackendConfig();
  291. foreach ($backendConfig['entities'] as $entityName => $entityConfig) {
  292. if ($entityName === $name) {
  293. return $entityConfig;
  294. }
  295. }
  296. return null;
  297. }
  298. public function getConfigValue($name, $type = 'system') {
  299. return $this->getSysConfig($name, $type, 0);
  300. }
  301. public function getCustomer() {
  302. if (!empty($this->getUser()) && !empty($this->getUser()->getCustomer())) {
  303. return $this->getUser()->getCustomer();
  304. }
  305. // Kai prisijungia konsultantas, galima keisti klienta
  306. if (empty($this->session)) {
  307. $this->session = $this->get('session');
  308. }
  309. if (!empty($this->session->get('currentCustomer'))) {
  310. $currentCustomerId = (int)$this->session->get('currentCustomer');
  311. foreach ($this->getUser()->getConsultants() as $consultant) {
  312. if ($consultant->getId() == $currentCustomerId) {
  313. return $consultant;
  314. }
  315. }
  316. $this->session->remove('currentCustomer');
  317. return null;
  318. } elseif (!empty($this->getUser()) && !empty($this->getUser()->getConsultants())) {
  319. $consultants = $this->getUser()->getConsultants();
  320. $this->session->set('currentCustomer', $consultants[0]->getId());
  321. return $consultants[0];
  322. }
  323. return null;
  324. }
  325. protected function updateUserLogin($tokenStorage) {
  326. /** @var User $user */
  327. $user = $this->getUser();
  328. $token = $tokenStorage->getToken();
  329. if ($token && $user && !in_array('ROLE_PREVIOUS_ADMIN', $token->getRoleNames())) {
  330. $user->setLastLoginAt(new \DateTime());
  331. $this->updateEntity($user);
  332. }
  333. }
  334. /**
  335. * @return array
  336. */
  337. protected function getAdmins($all = false, $superAdminsOnly = false) {
  338. $repository = $this->em->getRepository(User::class);
  339. if ($all) {
  340. $admins = $repository->findAllAdmins()->getQuery()->getResult();
  341. $admins = array_merge($admins, $repository->findAllSuperAdmins());
  342. } elseif ($superAdminsOnly) {
  343. $admins = $repository->findAllSuperAdmins();
  344. } else {
  345. $admins = $repository->findAllAdmins()->getQuery()->getResult();
  346. }
  347. $list = [0];
  348. if (!empty($admins)) {
  349. foreach ($admins as $object) {
  350. $list[] = $object->getId();
  351. }
  352. return implode(',', $list);
  353. }
  354. return $list;
  355. }
  356. protected function getAdminCustomers($returnList = true) {
  357. $objects = [];
  358. if ($this->getUser()->isSuperAdmin()) {
  359. $objects = $this->getDoctrine()->getRepository(Customer::class)->findAll();
  360. } elseif ($this->getUser()->isAdmin()) {
  361. $customerRepository = $this->getDoctrine()->getRepository(Customer::class);
  362. $queryBuilder = $customerRepository->createQueryBuilder('c');
  363. $query = $queryBuilder
  364. ->where('c.id = :id')
  365. ->setParameter('id', $this->getCustomer()->getId())
  366. ->getQuery();
  367. $objects = $query->getResult();
  368. } elseif (!empty($this->getUser()->isManager())) {
  369. $objects = $this->getDoctrine()->getRepository(Customer::class)->findBy(['id' => $this->getCustomer()->getId()]);
  370. }
  371. if (!empty($returnList)) {
  372. $list = [0];
  373. foreach ($objects as $object) {
  374. $list[] = $object->getId();
  375. }
  376. return implode(',', $list);
  377. }
  378. return $objects;
  379. }
  380. /**
  381. * @param string $type
  382. * @param int $customerId
  383. * @param string $param
  384. * @return mixed
  385. */
  386. public function getSysConfig($param = '', $type = 'system', $customerId = 0) {
  387. if (empty($this->setting)) {
  388. $settings = $this->getEntityConfig('Settings');
  389. $this->em = $this->getDoctrine()->getManagerForClass($settings['class']);
  390. }
  391. if (empty($this->sysConfig)) {
  392. /**
  393. * @var Settings[] $settingsRecords
  394. */
  395. $settingsRecords = $this->em->getRepository(Settings::class)->findBy([
  396. 'active' => true,
  397. ]);
  398. foreach ($settingsRecords as $item) {
  399. $itemCustomerId = 0;
  400. if (!empty($item->getCustomer())) {
  401. $itemCustomerId = $item->getCustomer()->getId();
  402. }
  403. $this->sysConfig[$item->getType()][$itemCustomerId][$item->getName()] = $item->getValue();
  404. }
  405. }
  406. //dump($this->sysConfig);
  407. //dump($type);
  408. if (!empty($this->sysConfig[$type])) {
  409. $settingConfig = $this->sysConfig[$type];
  410. $this->data['settings'] = $settingConfig[0];
  411. }
  412. if (!empty($settingConfig[$customerId])) {
  413. $settingConfig = $settingConfig[$customerId];
  414. } elseif (!empty($settingConfig[0])) {
  415. $settingConfig = $settingConfig[0];
  416. }
  417. if (!empty($param)) {
  418. if (isset($settingConfig[$param])) {
  419. $settingConfig = $settingConfig[$param];
  420. } else {
  421. $settingConfig = null;
  422. //dump('Setting '.$param.' not found');
  423. }
  424. }
  425. return $settingConfig;
  426. }
  427. protected function getCustomers() {
  428. return $this->getDoctrine()->getRepository(Customer::class)->findAll();
  429. }
  430. protected function getPairs() {
  431. $pairs = $this->getDoctrine()->getRepository(CurrencyPair::class)->findBy(['status' => 1]);
  432. return count($pairs);
  433. }
  434. /**
  435. * @param CurrencyPair $currencyPair
  436. * @param string $date
  437. * @return float
  438. */
  439. protected function getRate($currencyPair, $date = 'now') {
  440. return $this->getModel()->getRate($currencyPair, $date);
  441. }
  442. public function getForwardRate($pair, $period = 30, $action = 'points') {
  443. if (empty($pair)) {
  444. return 0;
  445. }
  446. if (empty($this->forwardRates[$pair->getId()])) {
  447. $this->forwardRates[$pair->getId()] = (new ForwardPoints())->get($pair);
  448. }
  449. if (!empty($this->forwardRates[$pair->getId()][$period][$action])) {
  450. $rate = $this->forwardRates[$pair->getId()][$period][$action];
  451. if ($action == 'points') {
  452. $rate = str_replace(',', '', $rate);
  453. return (int)$rate;
  454. }
  455. return $rate;
  456. }
  457. return 0;
  458. }
  459. protected function getForwardPoints($pairName = '') {
  460. $this->customerId = $this->getCustomer()->getId();
  461. $nextUpdate = $this->session->get('nextUpdate');
  462. $forwards = $this->getCache('forwards_'.$this->customerId);
  463. if (!empty($nextUpdate) && $nextUpdate > date_create() && !empty($forwards)) {
  464. $this->data['forwardPoints'] = $forwards;
  465. $this->data['forwardPointsUpdated'] = $nextUpdate->format('H:i');
  466. if (!empty($pairName) && !empty($this->data['forwardPoints'][$pairName])) {
  467. return $this->data['forwardPoints'][$pairName];
  468. }
  469. return false;
  470. }
  471. $repo = $this->getDoctrine()->getRepository(CurrencyPair::class);
  472. $listNeeded = [];
  473. if (empty($pairName)) {
  474. $list = $this->connection->fetchAllAssociative('
  475. SELECT cp.name
  476. FROM currency_pair cp
  477. LEFT JOIN customer_currency_pair ccp ON(ccp.currency_pair_id = cp.id)
  478. WHERE ccp.customer_id = '.$this->getCustomer()->getId());
  479. foreach ($list as $pair) {
  480. $listNeeded[] = $pair['name'];
  481. }
  482. } else {
  483. $listNeeded = [$pairName];
  484. }
  485. $pairs = $repo->findListByName($listNeeded);
  486. $forwards = [];
  487. $forward = new ForwardPoints();
  488. $needAddEmptyValues = false;
  489. $periodCount = 0;
  490. foreach ($pairs as $pair) {
  491. $forward->setPairSpots([$pair->getName() => $this->getRate($pair)]);
  492. $values = $forward->get($pair->getName());
  493. if (empty($values)) {
  494. //jeigu nerandam reikiamos poros forwardo, sukeiciam valiutas ir bandom rasti atvirkscia
  495. $pairList = explode('/', $pair->getName());
  496. $pairInverted = $pairList[1].'/'.$pairList[0];
  497. $values = $forward->get($pairInverted);
  498. if (!empty($values)) {
  499. //jeigu yra atvirkscias forwardas, tai pakeiciam reiksmes
  500. foreach ($values as $key => $value) {
  501. $values[$key]['bid'] = round(1 / $value['bid'], 4);
  502. $values[$key]['ask'] = round(1 / $value['ask'], 4);
  503. $values[$key]['mid'] = round(1 / $value['mid'], 4);
  504. $values[$key]['points'] = $value['points'];
  505. }
  506. }
  507. }
  508. if (!empty($values)) {
  509. $forwards[$pair->getName()] = $values;
  510. }
  511. if (empty($periodCount) && !empty($values)) {
  512. $periodCount = count($values);
  513. }
  514. if (!empty($values) && count($values) != $periodCount) {
  515. $needAddEmptyValues = true;
  516. }
  517. }
  518. if ($needAddEmptyValues) {
  519. $periods = [30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330, 360];
  520. foreach ($forwards as $pairName => $values) {
  521. foreach ($periods as $period) {
  522. if ($period == 30) {
  523. $oneMonthDiff = floatval(($values[90]['bid'] - $values[30]['bid']) / 2);
  524. }
  525. if (empty($values[$period])) {
  526. $forwards[$pairName][$period] = [
  527. 'name' => $period,
  528. 'ask' => '-',
  529. 'bid' => $lastMonth + $oneMonthDiff,
  530. ];
  531. }
  532. $lastMonth = floatval($forwards[$pairName][$period]['bid']);
  533. }
  534. ksort($forwards[$pairName]);
  535. }
  536. }
  537. $updateInMinutes = 10;
  538. $updated = date_create('+ '.$updateInMinutes.' min'); //todo: padaryti per nustatyma
  539. $this->session->set('nextUpdate', $updated);
  540. $this->setCache('forwards_'.$this->customerId, $forwards, $updateInMinutes * 60);
  541. $this->data['forwardPoints'] = $forwards;
  542. $this->data['forwardPointsUpdated'] = $updated->format('H:i');
  543. if (!empty($pairName) && !empty($this->data['forwardPoints'][$pairName])) {
  544. return $this->data['forwardPoints'][$pairName];
  545. }
  546. }
  547. /**
  548. * @return Calculations
  549. */
  550. protected function getModel($renew = false) {
  551. if (empty($this->model) || $renew) {
  552. $this->model = new Calculations($this->getDoctrine(), $this->logger);
  553. }
  554. return $this->model;
  555. }
  556. public function getCache($name) {
  557. $item = $this->cache->getItem($name);
  558. if ($item->isHit()) {
  559. return $item->get();
  560. }
  561. return false;
  562. }
  563. protected function setCache($name, $value, $expiresAfterSeconds = 3000) {
  564. /** @var CacheItem $item */
  565. $item = $this->cache->getItem($name);
  566. $item->set($value);
  567. if (!empty($expiresAfterSeconds)) {
  568. $item->expiresAfter($expiresAfterSeconds);
  569. }
  570. $this->cache->save($item);
  571. }
  572. public function deleteCache($name) {
  573. $this->cache->deleteItem($name);
  574. }
  575. public function getFunctionalCurrency() {
  576. $this->functionalCurrency = $this->session->get('functionalCurr');
  577. if (empty($this->functionalCurrency)) {
  578. $this->functionalCurrency = $this->getCustomer()->getFunctionalCurrency();
  579. }
  580. return $this->functionalCurrency;
  581. }
  582. public function getCustomerLicence() {
  583. $customer = $this->getCustomer() ?? null;
  584. if (empty($customer)) {
  585. return 'Basic';
  586. }
  587. return $customer->getLicence();
  588. }
  589. }