10144 |
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 |
use LeadersLinked\Model\Feed;
|
10146 |
nelberth |
17 |
use LeadersLinked\Model\Topic;
|
10144 |
nelberth |
18 |
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsViewTopicMapper;
|
|
|
19 |
use LeadersLinked\Model\HighPerformanceTeamsGroupsMembers;
|
|
|
20 |
use LeadersLinked\Model\HighPerformanceTeamsGroups;
|
|
|
21 |
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMembersMapper;
|
|
|
22 |
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMapper;
|
|
|
23 |
use LeadersLinked\Mapper\FeedMapper;
|
10170 |
nelberth |
24 |
use LeadersLinked\Mapper\TopicMapper;
|
10144 |
nelberth |
25 |
use LeadersLinked\Mapper\UserMapper;
|
10170 |
nelberth |
26 |
|
10144 |
nelberth |
27 |
use Laminas\Db\Sql\Expression;
|
|
|
28 |
|
|
|
29 |
use LeadersLinked\Library\Functions;
|
|
|
30 |
|
|
|
31 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
32 |
|
10145 |
nelberth |
33 |
class HighPerformanceTeamsGroupsViewForoController extends AbstractActionController
|
10144 |
nelberth |
34 |
{
|
|
|
35 |
/**
|
|
|
36 |
*
|
|
|
37 |
* @var AdapterInterface
|
|
|
38 |
*/
|
|
|
39 |
private $adapter;
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
*
|
|
|
44 |
* @var AbstractAdapter
|
|
|
45 |
*/
|
|
|
46 |
private $cache;
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
*
|
|
|
50 |
* @var LoggerInterface
|
|
|
51 |
*/
|
|
|
52 |
private $logger;
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
*
|
|
|
56 |
* @var array
|
|
|
57 |
*/
|
|
|
58 |
private $config;
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
/**
|
|
|
63 |
*
|
|
|
64 |
* @param AdapterInterface $adapter
|
|
|
65 |
* @param AbstractAdapter $cache
|
|
|
66 |
* @param LoggerInterface $logger
|
|
|
67 |
* @param array $config
|
|
|
68 |
*/
|
|
|
69 |
public function __construct($adapter, $cache , $logger, $config)
|
|
|
70 |
{
|
|
|
71 |
$this->adapter = $adapter;
|
|
|
72 |
$this->cache = $cache;
|
|
|
73 |
$this->logger = $logger;
|
|
|
74 |
$this->config = $config;
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
public function indexAction()
|
|
|
81 |
{
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
$request = $this->getRequest();
|
|
|
85 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
86 |
$viewModel = new ViewModel();
|
|
|
87 |
$viewModel->setTemplate('leaders-linked/unknown/index.phtml');
|
|
|
88 |
return $viewModel ;
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
public function viewAction()
|
|
|
93 |
{
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
97 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
98 |
$currentCompany = $currentUserPlugin->getCompany();
|
11086 |
nelberth |
99 |
$group_uuid = $this->params()->fromRoute('group_id');
|
10144 |
nelberth |
100 |
|
|
|
101 |
$request = $this->getRequest();
|
|
|
102 |
if($request->isGet()) {
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
$headers = $request->getHeaders();
|
|
|
106 |
|
|
|
107 |
$isJson = false;
|
|
|
108 |
if($headers->has('Accept')) {
|
|
|
109 |
$accept = $headers->get('Accept');
|
|
|
110 |
|
|
|
111 |
$prioritized = $accept->getPrioritized();
|
|
|
112 |
|
|
|
113 |
foreach($prioritized as $key => $value) {
|
|
|
114 |
$raw = trim($value->getRaw());
|
|
|
115 |
|
|
|
116 |
if(!$isJson) {
|
|
|
117 |
$isJson = strpos($raw, 'json');
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
}
|
|
|
121 |
}
|
|
|
122 |
|
11138 |
nelberth |
123 |
if(!$group_uuid) {
|
|
|
124 |
$data = [
|
|
|
125 |
'success' => false,
|
|
|
126 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
127 |
];
|
|
|
128 |
|
|
|
129 |
return new JsonModel($data);
|
|
|
130 |
}
|
|
|
131 |
|
10144 |
nelberth |
132 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
|
|
133 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
|
|
|
134 |
|
|
|
135 |
if (!$highPerformanceTeamsGroups) {
|
|
|
136 |
$data = [
|
|
|
137 |
'success' => false,
|
|
|
138 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
139 |
];
|
11138 |
nelberth |
140 |
|
10144 |
nelberth |
141 |
return new JsonModel($data);
|
|
|
142 |
}
|
|
|
143 |
if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
|
|
|
144 |
|
|
|
145 |
return new JsonModel([
|
|
|
146 |
'success' => false,
|
|
|
147 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
148 |
]);
|
|
|
149 |
|
|
|
150 |
}
|
11138 |
nelberth |
151 |
$highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
152 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
|
|
153 |
if(!$highPerformanceTeamsGroupsMember) {
|
|
|
154 |
return new JsonModel([
|
|
|
155 |
'success' => false,
|
|
|
156 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
|
|
|
157 |
]);
|
|
|
158 |
}
|
|
|
159 |
if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
|
|
|
160 |
return new JsonModel([
|
|
|
161 |
'success' => false,
|
|
|
162 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
|
|
|
163 |
]);
|
|
|
164 |
}
|
|
|
165 |
|
10144 |
nelberth |
166 |
if($isJson) {
|
|
|
167 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
10166 |
nelberth |
168 |
$allowView = $acl->isAllowed($currentUser->usertype_id,'high-performance-teams/groups/view/foro/categories/articles/view');
|
10144 |
nelberth |
169 |
$items = [];
|
|
|
170 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
10146 |
nelberth |
171 |
$paginator = $feedMapper->fetchFiveForoJoinTopic($highPerformanceTeamsGroups->id, Topic::TYPE_HPTGF);
|
10163 |
nelberth |
172 |
|
|
|
173 |
$records = $paginator->getCurrentItems();
|
10166 |
nelberth |
174 |
$topicMapper = TopicMapper::getInstance($this->adapter);
|
10165 |
nelberth |
175 |
|
10144 |
nelberth |
176 |
foreach($records as $record)
|
|
|
177 |
{
|
10166 |
nelberth |
178 |
|
10188 |
nelberth |
179 |
$topic = $topicMapper->fetchOne($record->topic_id);
|
10192 |
nelberth |
180 |
|
10144 |
nelberth |
181 |
$item = [
|
10146 |
nelberth |
182 |
'title' => $record->title,
|
10193 |
nelberth |
183 |
'category' => $topic->title,
|
11086 |
nelberth |
184 |
'link_foro'=> $allowView ? $this->url()->fromRoute('high-performance-teams/groups/view/foro/categories/articles/view',['group_id' => $highPerformanceTeamsGroups->uuid,'category_id' => $topic->uuid, 'article_id' => $record->uuid]) : '',
|
10144 |
nelberth |
185 |
];
|
|
|
186 |
array_push($items, $item);
|
|
|
187 |
}
|
|
|
188 |
|
10146 |
nelberth |
189 |
|
10144 |
nelberth |
190 |
return new JsonModel([
|
|
|
191 |
'success' => true,
|
|
|
192 |
'data' => [
|
|
|
193 |
'items' => $items,
|
|
|
194 |
]
|
|
|
195 |
]);
|
|
|
196 |
|
|
|
197 |
}
|
|
|
198 |
} else {
|
|
|
199 |
return new JsonModel([
|
|
|
200 |
'success' => false,
|
|
|
201 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
202 |
]);
|
|
|
203 |
}
|
|
|
204 |
}
|
|
|
205 |
|
14740 |
efrain |
206 |
private function renderFeed($feed, $now)
|
10144 |
nelberth |
207 |
{
|
15351 |
efrain |
208 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
209 |
$network = $currentNetworkPlugin->getNetwork();
|
10144 |
nelberth |
210 |
|
|
|
211 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
212 |
$user = $userMapper->fetchOne($feed->user_id);
|
14740 |
efrain |
213 |
|
|
|
214 |
$item['owner_time_elapse'] = Functions::timeAgo( $feed->added_on, $now);
|
10144 |
nelberth |
215 |
$item['feed_priority'] = $feed->priority;
|
15351 |
efrain |
216 |
$item['owner_url'] = 'https://'. $network->main_hostname . '/profile/view/' . $user->uuid,
|
10144 |
nelberth |
217 |
$item['owner_image'] = $this->url()->fromRoute('storage', ['code' => $user->uuid, 'type' => 'user', 'filename' => $user->image]);
|
|
|
218 |
$item['owner_name'] = $user->first_name . ' ' . $user->last_name;
|
|
|
219 |
$item['owner_description'] = strip_tags($feed->description, 'p');
|
|
|
220 |
$dt = \DateTime::createFromFormat('Y-m-d', $feed->date);
|
|
|
221 |
$dt2 = \DateTime::createFromFormat('H:i:s', $feed->time);
|
|
|
222 |
$item['owner_meeting_date'] = $dt->format('d/m/Y');
|
|
|
223 |
$item['owner_meeting_time'] = $dt2->format('h:i a');
|
|
|
224 |
$item['owner_meeting_link_type'] = $feed->link_type;
|
|
|
225 |
$item['owner_meeting_link_name'] = $feed->link_name;
|
|
|
226 |
|
|
|
227 |
return $item;
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
}
|