9095 |
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;
|
16768 |
efrain |
9 |
|
9095 |
nelberth |
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;
|
9136 |
nelberth |
16 |
use LeadersLinked\Model\Feed;
|
|
|
17 |
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsViewTopicMapper;
|
|
|
18 |
use LeadersLinked\Model\HighPerformanceTeamsGroupsMembers;
|
|
|
19 |
use LeadersLinked\Model\HighPerformanceTeamsGroups;
|
|
|
20 |
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMembersMapper;
|
|
|
21 |
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMapper;
|
9149 |
nelberth |
22 |
use LeadersLinked\Mapper\FeedMapper;
|
9290 |
nelberth |
23 |
use LeadersLinked\Mapper\UserMapper;
|
9095 |
nelberth |
24 |
|
9298 |
nelberth |
25 |
use LeadersLinked\Library\Functions;
|
|
|
26 |
|
9136 |
nelberth |
27 |
|
16701 |
efrain |
28 |
|
9095 |
nelberth |
29 |
class HighPerformanceTeamsGroupsViewCalendarController extends AbstractActionController
|
|
|
30 |
{
|
|
|
31 |
/**
|
|
|
32 |
*
|
16769 |
efrain |
33 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
9095 |
nelberth |
34 |
*/
|
|
|
35 |
private $adapter;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
*
|
16769 |
efrain |
39 |
* @var \LeadersLinked\Cache\CacheInterface
|
9095 |
nelberth |
40 |
*/
|
16769 |
efrain |
41 |
private $cache;
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
*
|
|
|
46 |
* @var \Laminas\Log\LoggerInterface
|
|
|
47 |
*/
|
9095 |
nelberth |
48 |
private $logger;
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
*
|
|
|
52 |
* @var array
|
|
|
53 |
*/
|
|
|
54 |
private $config;
|
|
|
55 |
|
16769 |
efrain |
56 |
|
9095 |
nelberth |
57 |
/**
|
|
|
58 |
*
|
16769 |
efrain |
59 |
* @var \Laminas\Mvc\I18n\Translator
|
|
|
60 |
*/
|
|
|
61 |
private $translator;
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
*
|
|
|
66 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
67 |
* @param \LeadersLinked\Cache\CacheInterface $cache
|
|
|
68 |
* @param \Laminas\Log\LoggerInterface LoggerInterface $logger
|
9095 |
nelberth |
69 |
* @param array $config
|
16769 |
efrain |
70 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
9095 |
nelberth |
71 |
*/
|
16769 |
efrain |
72 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
9095 |
nelberth |
73 |
{
|
16769 |
efrain |
74 |
$this->adapter = $adapter;
|
|
|
75 |
$this->cache = $cache;
|
|
|
76 |
$this->logger = $logger;
|
|
|
77 |
$this->config = $config;
|
|
|
78 |
$this->translator = $translator;
|
9095 |
nelberth |
79 |
}
|
9135 |
nelberth |
80 |
|
|
|
81 |
|
9095 |
nelberth |
82 |
public function indexAction()
|
|
|
83 |
{
|
9135 |
nelberth |
84 |
|
9095 |
nelberth |
85 |
|
9135 |
nelberth |
86 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
87 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
88 |
$currentCompany = $currentUserPlugin->getCompany();
|
11084 |
nelberth |
89 |
$group_uuid = $this->params()->fromRoute('group_id');
|
|
|
90 |
$feed_uuid = $this->params()->fromRoute('feed_id');
|
9135 |
nelberth |
91 |
|
9095 |
nelberth |
92 |
$request = $this->getRequest();
|
|
|
93 |
if($request->isGet()) {
|
|
|
94 |
|
|
|
95 |
|
9135 |
nelberth |
96 |
$headers = $request->getHeaders();
|
9095 |
nelberth |
97 |
|
9135 |
nelberth |
98 |
$isJson = false;
|
|
|
99 |
if($headers->has('Accept')) {
|
|
|
100 |
$accept = $headers->get('Accept');
|
|
|
101 |
|
|
|
102 |
$prioritized = $accept->getPrioritized();
|
|
|
103 |
|
|
|
104 |
foreach($prioritized as $key => $value) {
|
|
|
105 |
$raw = trim($value->getRaw());
|
|
|
106 |
|
|
|
107 |
if(!$isJson) {
|
|
|
108 |
$isJson = strpos($raw, 'json');
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
}
|
|
|
112 |
}
|
9141 |
nelberth |
113 |
|
9318 |
nelberth |
114 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
|
|
115 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
|
11184 |
nelberth |
116 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
117 |
$viewModel = new ViewModel();
|
9318 |
nelberth |
118 |
if (!$highPerformanceTeamsGroups) {
|
11184 |
nelberth |
119 |
$viewModel->setTemplate('leaders-linked/no-access/index.phtml');
|
|
|
120 |
return $viewModel ;
|
9318 |
nelberth |
121 |
}
|
|
|
122 |
|
|
|
123 |
if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
|
|
|
124 |
|
11184 |
nelberth |
125 |
$viewModel->setTemplate('leaders-linked/no-access/index.phtml');
|
|
|
126 |
return $viewModel ;
|
9318 |
nelberth |
127 |
|
|
|
128 |
}
|
11184 |
nelberth |
129 |
|
11136 |
nelberth |
130 |
$highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
131 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
|
|
132 |
if(!$highPerformanceTeamsGroupsMember) {
|
11184 |
nelberth |
133 |
$viewModel->setTemplate('leaders-linked/no-access/index.phtml');
|
|
|
134 |
return $viewModel ;
|
11136 |
nelberth |
135 |
}
|
|
|
136 |
if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
|
11184 |
nelberth |
137 |
$viewModel->setTemplate('leaders-linked/no-access/index.phtml');
|
|
|
138 |
return $viewModel ;
|
11136 |
nelberth |
139 |
}
|
|
|
140 |
$addTopicBoton=true;
|
|
|
141 |
if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
|
|
|
142 |
$addTopicBoton=false;
|
|
|
143 |
}
|
9922 |
nelberth |
144 |
|
|
|
145 |
|
|
|
146 |
$viewModel->setTemplate('leaders-linked/high-performance-teams-groups-view-calendar/index.phtml');
|
|
|
147 |
$viewModel->setVariables([
|
|
|
148 |
'group_uuid' => $group_uuid,
|
|
|
149 |
'group_title'=>$highPerformanceTeamsGroups->title,
|
|
|
150 |
]);
|
|
|
151 |
return $viewModel ;
|
|
|
152 |
|
|
|
153 |
} else {
|
|
|
154 |
return new JsonModel([
|
|
|
155 |
'success' => false,
|
|
|
156 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
157 |
]);
|
|
|
158 |
}
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
public function viewAction()
|
|
|
162 |
{
|
|
|
163 |
|
16701 |
efrain |
164 |
|
14740 |
efrain |
165 |
$now = $utilMapper->getDatebaseNow();
|
9922 |
nelberth |
166 |
|
|
|
167 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
168 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
169 |
$currentCompany = $currentUserPlugin->getCompany();
|
11084 |
nelberth |
170 |
$group_uuid = $this->params()->fromRoute('group_id');
|
|
|
171 |
$feed_uuid = $this->params()->fromRoute('feed_id');
|
9922 |
nelberth |
172 |
|
|
|
173 |
$request = $this->getRequest();
|
|
|
174 |
if($request->isGet()) {
|
9142 |
nelberth |
175 |
|
9922 |
nelberth |
176 |
|
|
|
177 |
$headers = $request->getHeaders();
|
|
|
178 |
|
|
|
179 |
$isJson = false;
|
|
|
180 |
if($headers->has('Accept')) {
|
|
|
181 |
$accept = $headers->get('Accept');
|
|
|
182 |
|
|
|
183 |
$prioritized = $accept->getPrioritized();
|
|
|
184 |
|
|
|
185 |
foreach($prioritized as $key => $value) {
|
|
|
186 |
$raw = trim($value->getRaw());
|
|
|
187 |
|
|
|
188 |
if(!$isJson) {
|
|
|
189 |
$isJson = strpos($raw, 'json');
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
}
|
|
|
193 |
}
|
|
|
194 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
16701 |
efrain |
195 |
$now = $highPerformanceTeamsGroupsMapper->getDatebaseNow();
|
|
|
196 |
|
9922 |
nelberth |
197 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
|
|
|
198 |
|
|
|
199 |
if (!$highPerformanceTeamsGroups) {
|
|
|
200 |
$data = [
|
|
|
201 |
'success' => false,
|
|
|
202 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
203 |
];
|
|
|
204 |
|
|
|
205 |
return new JsonModel($data);
|
|
|
206 |
}
|
|
|
207 |
|
|
|
208 |
if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
|
|
|
209 |
|
|
|
210 |
return new JsonModel([
|
|
|
211 |
'success' => false,
|
|
|
212 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
213 |
]);
|
|
|
214 |
|
|
|
215 |
}
|
11136 |
nelberth |
216 |
|
|
|
217 |
$highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
218 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
|
|
219 |
if(!$highPerformanceTeamsGroupsMember) {
|
|
|
220 |
return new JsonModel([
|
|
|
221 |
'success' => false,
|
|
|
222 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
223 |
]);
|
|
|
224 |
}
|
|
|
225 |
if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
|
|
|
226 |
return new JsonModel([
|
|
|
227 |
'success' => false,
|
|
|
228 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
|
|
|
229 |
]);
|
|
|
230 |
}
|
|
|
231 |
$addTopicBoton=true;
|
|
|
232 |
if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
|
|
|
233 |
$addTopicBoton=false;
|
|
|
234 |
}
|
9922 |
nelberth |
235 |
|
9135 |
nelberth |
236 |
if($isJson) {
|
9255 |
nelberth |
237 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
9256 |
nelberth |
238 |
$allowView = $acl->isAllowed($currentUser->usertype_id,'high-performance-teams/groups/view/calendar');
|
9135 |
nelberth |
239 |
|
9144 |
nelberth |
240 |
|
9281 |
nelberth |
241 |
$items = [];
|
9156 |
nelberth |
242 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
9264 |
nelberth |
243 |
if(isset($feed_uuid)){
|
14740 |
efrain |
244 |
$record = $feedMapper->fetchOneByUuid($feed_uuid);
|
9269 |
nelberth |
245 |
|
14740 |
efrain |
246 |
if($record->high_performance_group_id!=$highPerformanceTeamsGroups->id){
|
9264 |
nelberth |
247 |
return new JsonModel([
|
|
|
248 |
'success' => false,
|
9276 |
nelberth |
249 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
9264 |
nelberth |
250 |
]);
|
9281 |
nelberth |
251 |
}
|
9290 |
nelberth |
252 |
|
14740 |
efrain |
253 |
$items = $this->renderFeed($record, $now);
|
9264 |
nelberth |
254 |
}else{
|
|
|
255 |
$records = $feedMapper->fetchAllTypeCalendar($highPerformanceTeamsGroups->id);
|
9282 |
nelberth |
256 |
$contador=1;
|
9271 |
nelberth |
257 |
foreach($records as $record)
|
|
|
258 |
{
|
|
|
259 |
$item = [
|
|
|
260 |
'id' => $record->uuid,
|
|
|
261 |
'title' => 'Reunion #'.$contador,
|
|
|
262 |
'start' => $record->date.'T'.$record->time,
|
|
|
263 |
'color'=>'#00000'.$contador,
|
11084 |
nelberth |
264 |
'link_feed'=> $allowView ? $this->url()->fromRoute('high-performance-teams/groups/view/calendar/view', ['group_id' => $highPerformanceTeamsGroups->uuid, 'feed_id'=>$record->uuid]) : '',
|
9271 |
nelberth |
265 |
];
|
|
|
266 |
$contador++;
|
|
|
267 |
array_push($items, $item);
|
|
|
268 |
}
|
9281 |
nelberth |
269 |
}
|
9273 |
nelberth |
270 |
|
9179 |
nelberth |
271 |
return new JsonModel([
|
|
|
272 |
'success' => true,
|
|
|
273 |
'data' => [
|
|
|
274 |
'items' => $items,
|
|
|
275 |
]
|
|
|
276 |
]);
|
9135 |
nelberth |
277 |
|
|
|
278 |
}
|
9095 |
nelberth |
279 |
} else {
|
9179 |
nelberth |
280 |
return new JsonModel([
|
|
|
281 |
'success' => false,
|
|
|
282 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
283 |
]);
|
9095 |
nelberth |
284 |
}
|
|
|
285 |
}
|
9135 |
nelberth |
286 |
|
14740 |
efrain |
287 |
private function renderFeed($feed, $now)
|
9290 |
nelberth |
288 |
{
|
|
|
289 |
|
15351 |
efrain |
290 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
291 |
$network = $currentNetworkPlugin->getNetwork();
|
|
|
292 |
|
9290 |
nelberth |
293 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
294 |
$user = $userMapper->fetchOne($feed->user_id);
|
14740 |
efrain |
295 |
|
|
|
296 |
$item['owner_time_elapse'] = Functions::timeAgo( $feed->added_on, $now);
|
9290 |
nelberth |
297 |
$item['feed_priority'] = $feed->priority;
|
15351 |
efrain |
298 |
$item['owner_url'] = 'https://'. $network->main_hostname . '/profile/view/' . $user->uuid;
|
9290 |
nelberth |
299 |
$item['owner_image'] = $this->url()->fromRoute('storage', ['code' => $user->uuid, 'type' => 'user', 'filename' => $user->image]);
|
|
|
300 |
$item['owner_name'] = $user->first_name . ' ' . $user->last_name;
|
|
|
301 |
$item['owner_description'] = strip_tags($feed->description, 'p');
|
|
|
302 |
$dt = \DateTime::createFromFormat('Y-m-d', $feed->date);
|
|
|
303 |
$dt2 = \DateTime::createFromFormat('H:i:s', $feed->time);
|
|
|
304 |
$item['owner_meeting_date'] = $dt->format('d/m/Y');
|
|
|
305 |
$item['owner_meeting_time'] = $dt2->format('h:i a');
|
|
|
306 |
$item['owner_meeting_link_type'] = $feed->link_type;
|
|
|
307 |
$item['owner_meeting_link_name'] = $feed->link_name;
|
|
|
308 |
|
|
|
309 |
return $item;
|
|
|
310 |
}
|
|
|
311 |
|
9095 |
nelberth |
312 |
}
|