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