| 4388 |
nelberth |
1 |
<?php
|
|
|
2 |
declare(strict_types=1);
|
|
|
3 |
|
|
|
4 |
namespace LeadersLinked\Controller;
|
|
|
5 |
|
|
|
6 |
use Laminas\Authentication\AuthenticationService;
|
|
|
7 |
use Laminas\Authentication\Result as AuthResult;
|
|
|
8 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
9 |
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
|
|
|
10 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
11 |
use Laminas\Mvc\I18n\Translator;
|
|
|
12 |
use Laminas\Log\LoggerInterface;
|
|
|
13 |
use Laminas\View\Model\ViewModel;
|
|
|
14 |
use Laminas\View\Model\JsonModel;
|
|
|
15 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
16 |
|
| 4396 |
nelberth |
17 |
use LeadersLinked\Mapper\IndustryMapper;
|
|
|
18 |
use LeadersLinked\Mapper\GroupTypeMapper;
|
|
|
19 |
use LeadersLinked\Mapper\GroupMemberMapper;
|
|
|
20 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
21 |
use LeadersLinked\Model\GroupMember;
|
|
|
22 |
|
| 4401 |
nelberth |
23 |
|
|
|
24 |
|
|
|
25 |
use LeadersLinked\Form\HighPerformanceTeamsMyGroupsForm;
|
|
|
26 |
|
| 4388 |
nelberth |
27 |
class HighPerformanceTeamsMyGroupsController extends AbstractActionController
|
|
|
28 |
{
|
|
|
29 |
/**
|
|
|
30 |
*
|
|
|
31 |
* @var AdapterInterface
|
|
|
32 |
*/
|
|
|
33 |
private $adapter;
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
*
|
|
|
38 |
* @var AbstractAdapter
|
|
|
39 |
*/
|
|
|
40 |
private $cache;
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
*
|
|
|
44 |
* @var LoggerInterface
|
|
|
45 |
*/
|
|
|
46 |
private $logger;
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
*
|
|
|
50 |
* @var array
|
|
|
51 |
*/
|
|
|
52 |
private $config;
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
*
|
|
|
58 |
* @param AdapterInterface $adapter
|
|
|
59 |
* @param AbstractAdapter $cache
|
|
|
60 |
* @param LoggerInterface $logger
|
|
|
61 |
* @param array $config
|
|
|
62 |
*/
|
|
|
63 |
public function __construct($adapter, $cache , $logger, $config)
|
|
|
64 |
{
|
|
|
65 |
$this->adapter = $adapter;
|
|
|
66 |
$this->cache = $cache;
|
|
|
67 |
$this->logger = $logger;
|
|
|
68 |
$this->config = $config;
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
}
|
|
|
72 |
public function indexAction()
|
|
|
73 |
{
|
| 4396 |
nelberth |
74 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
75 |
$currentUser = $currentUserPlugin->getUser();
|
| 4388 |
nelberth |
76 |
|
|
|
77 |
$request = $this->getRequest();
|
|
|
78 |
if($request->isGet()) {
|
|
|
79 |
|
|
|
80 |
|
| 4396 |
nelberth |
81 |
$headers = $request->getHeaders();
|
| 4388 |
nelberth |
82 |
|
| 4396 |
nelberth |
83 |
$isJson = false;
|
|
|
84 |
if($headers->has('Accept')) {
|
|
|
85 |
$accept = $headers->get('Accept');
|
|
|
86 |
|
|
|
87 |
$prioritized = $accept->getPrioritized();
|
|
|
88 |
|
|
|
89 |
foreach($prioritized as $key => $value) {
|
|
|
90 |
$raw = trim($value->getRaw());
|
|
|
91 |
|
|
|
92 |
if(!$isJson) {
|
|
|
93 |
$isJson = strpos($raw, 'json');
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
if($isJson) {
|
|
|
100 |
$search = trim(filter_var($this->params()->fromQuery('search', ''), FILTER_SANITIZE_STRING));
|
|
|
101 |
|
|
|
102 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
103 |
$allowView = $acl->isAllowed($currentUser->usertype_id, 'group/view');
|
|
|
104 |
$allowEdit = $acl->isAllowed($currentUser->usertype_id, 'group/my-groups/edit');
|
|
|
105 |
$allowDelete = $acl->isAllowed($currentUser->usertype_id, 'group/my-groups/delete');
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
109 |
|
|
|
110 |
$select = $queryMapper->getSql()->select(GroupMapper::_TABLE);
|
|
|
111 |
$select->columns(['id', 'uuid', 'name', 'privacy', 'image', 'status']);
|
|
|
112 |
$select->where->equalTo('status', Group::STATUS_ACTIVE);
|
|
|
113 |
|
|
|
114 |
if($search) {
|
|
|
115 |
$select->where->like('name', '%' . $search . '%');
|
|
|
116 |
}
|
|
|
117 |
$select->where->equalTo('user_id', $currentUser->id);
|
|
|
118 |
$select->order('name ASC');
|
|
|
119 |
|
|
|
120 |
$records = $queryMapper->fetchAll($select);
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
$values = [
|
|
|
124 |
Group::PRIVACY_IS_PRIVATE => 'LABEL_PRIVATE',
|
|
|
125 |
Group::PRIVACY_IS_PUBLIC => 'LABEL_PUBLIC'
|
|
|
126 |
];
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
$items = [];
|
|
|
130 |
foreach($records as $record)
|
|
|
131 |
{
|
|
|
132 |
|
|
|
133 |
$item = [
|
|
|
134 |
'name' => $record['name'],
|
|
|
135 |
'privacy' => $values[$record['privacy']],
|
|
|
136 |
'image' => $this->url()->fromRoute('storage', ['type' => 'group', 'code' => $record['uuid'], 'filename' => $record['image'] ]),
|
|
|
137 |
'link_view' => $allowView ? $this->url()->fromRoute('group/view', ['id' => $record['uuid'] ]) : '',
|
|
|
138 |
'link_edit' => $allowEdit ? $this->url()->fromRoute('group/my-groups/edit', ['id' => $record['uuid'] ]) : '',
|
|
|
139 |
'link_delete' => $allowDelete ? $this->url()->fromRoute('group/my-groups/delete', ['id' => $record['uuid'] ]) : '',
|
|
|
140 |
|
|
|
141 |
];
|
|
|
142 |
|
|
|
143 |
array_push($items, $item);
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
$response = [
|
|
|
149 |
'success' => true,
|
|
|
150 |
'data' => $items
|
|
|
151 |
];
|
|
|
152 |
|
|
|
153 |
return new JsonModel($response);
|
|
|
154 |
|
|
|
155 |
|
|
|
156 |
} else {
|
|
|
157 |
$industries = [];
|
|
|
158 |
$industryMapper = IndustryMapper::getInstance($this->adapter);
|
|
|
159 |
$records = $industryMapper->fetchAllActives();
|
|
|
160 |
foreach($records as $record)
|
|
|
161 |
{
|
|
|
162 |
$industries[$record->uuid] = $record->name;
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
$groupTypes = [];
|
|
|
166 |
$groupTypeMapper = GroupTypeMapper::getInstance($this->adapter);
|
|
|
167 |
$records = $groupTypeMapper->fetchAllActives();
|
|
|
168 |
foreach($records as $record)
|
|
|
169 |
{
|
|
|
170 |
$groupTypes[$record->uuid] = $record->name;
|
|
|
171 |
}
|
|
|
172 |
|
| 4401 |
nelberth |
173 |
$formAdd = new HighPerformanceTeamsMyGroupsForm($this->adapter);
|
| 4396 |
nelberth |
174 |
|
|
|
175 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
176 |
$viewModel = new ViewModel();
|
|
|
177 |
$viewModel->setTemplate('leaders-linked/high-performance-teams-my-groups/index.phtml');
|
|
|
178 |
$viewModel->setVariables([
|
|
|
179 |
'industries' => $industries,
|
|
|
180 |
'types' => $groupTypes,
|
|
|
181 |
'formAdd' => $formAdd
|
|
|
182 |
]);
|
|
|
183 |
return $viewModel ;
|
|
|
184 |
}
|
|
|
185 |
|
| 4388 |
nelberth |
186 |
} else {
|
|
|
187 |
return new JsonModel([
|
|
|
188 |
'success' => false,
|
|
|
189 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
| 4396 |
nelberth |
190 |
]);
|
| 4388 |
nelberth |
191 |
}
|
|
|
192 |
}
|
| 4396 |
nelberth |
193 |
|
| 4388 |
nelberth |
194 |
}
|