302 |
www |
1 |
<?php
|
|
|
2 |
declare(strict_types=1);
|
|
|
3 |
|
|
|
4 |
namespace LeadersLinked\Controller;
|
|
|
5 |
|
|
|
6 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
7 |
|
|
|
8 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
9 |
use Laminas\View\Model\ViewModel;
|
|
|
10 |
use Laminas\View\Model\JsonModel;
|
|
|
11 |
|
|
|
12 |
use LeadersLinked\Library\Functions;
|
|
|
13 |
use LeadersLinked\Model\HabitValue;
|
|
|
14 |
use LeadersLinked\Mapper\HabitValueMapper;
|
|
|
15 |
use LeadersLinked\Form\Habit\HabitValueForm;
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
class HabitController extends AbstractActionController
|
|
|
19 |
{
|
|
|
20 |
/**
|
|
|
21 |
*
|
|
|
22 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
|
|
23 |
*/
|
|
|
24 |
private $adapter;
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
*
|
|
|
28 |
* @var \LeadersLinked\Cache\CacheInterface
|
|
|
29 |
*/
|
|
|
30 |
private $cache;
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
*
|
|
|
35 |
* @var \Laminas\Log\LoggerInterface
|
|
|
36 |
*/
|
|
|
37 |
private $logger;
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
*
|
|
|
41 |
* @var array
|
|
|
42 |
*/
|
|
|
43 |
private $config;
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
*
|
|
|
48 |
* @var \Laminas\Mvc\I18n\Translator
|
|
|
49 |
*/
|
|
|
50 |
private $translator;
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
*
|
|
|
55 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
56 |
* @param \LeadersLinked\Cache\CacheInterface $cache
|
|
|
57 |
* @param \Laminas\Log\LoggerInterface LoggerInterface $logger
|
|
|
58 |
* @param array $config
|
|
|
59 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
|
|
60 |
*/
|
|
|
61 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
|
|
62 |
{
|
|
|
63 |
$this->adapter = $adapter;
|
|
|
64 |
$this->cache = $cache;
|
|
|
65 |
$this->logger = $logger;
|
|
|
66 |
$this->config = $config;
|
|
|
67 |
$this->translator = $translator;
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
public function indexAction()
|
|
|
71 |
{
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
|
75 |
$request = $this->getRequest();
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
$request = $this->getRequest();
|
|
|
79 |
if($request->isGet()) {
|
|
|
80 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
81 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
82 |
|
|
|
83 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
84 |
$allowValues = $acl->isAllowed($currentUser->usertype_id, 'habits/values');
|
|
|
85 |
$allowParadigms = $acl->isAllowed($currentUser->usertype_id, 'habits/paradigms');
|
|
|
86 |
$allowPurposes = $acl->isAllowed($currentUser->usertype_id, 'habits/purposes');
|
307 |
www |
87 |
$allowSkills = $acl->isAllowed($currentUser->usertype_id, 'habits/skills');
|
|
|
88 |
$allowGoals = $acl->isAllowed($currentUser->usertype_id, 'habits/goals');
|
302 |
www |
89 |
|
|
|
90 |
return new JsonModel([
|
|
|
91 |
'success' => true,
|
|
|
92 |
'data' => [
|
|
|
93 |
'link_values' => $allowValues ? $this->url()->fromRoute('habits/values', [], ['force_canonical' => true]) : '',
|
|
|
94 |
'link_paradigms' => $allowParadigms ? $this->url()->fromRoute('habits/paradigms', [], ['force_canonical' => true]) : '',
|
|
|
95 |
'link_purposes' => $allowPurposes ? $this->url()->fromRoute('habits/purposes', [], ['force_canonical' => true]) : '',
|
307 |
www |
96 |
'link_skills' => $allowSkills ? $this->url()->fromRoute('habits/skills', [], ['force_canonical' => true]) : '',
|
|
|
97 |
'link_goals' => $allowGoals ? $this->url()->fromRoute('habits/goals', [], ['force_canonical' => true]) : '',
|
302 |
www |
98 |
]
|
|
|
99 |
]);
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
} else {
|
|
|
103 |
return new JsonModel([
|
|
|
104 |
'success' => false,
|
|
|
105 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
106 |
]);;
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
}
|