| 9760 |
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\Model\HighPerformanceTeamsGroups;
|
|
|
16 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
| 9841 |
nelberth |
17 |
use LeadersLinked\Form\CreateFeedForm;
|
| 9760 |
nelberth |
18 |
use LeadersLinked\Library\Functions;
|
|
|
19 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
20 |
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMapper;
|
|
|
21 |
use LeadersLinked\Mapper\CompanyMapper;
|
| 9776 |
nelberth |
22 |
use LeadersLinked\Mapper\TopicMapper;
|
| 9861 |
nelberth |
23 |
use LeadersLinked\Model\Feed;
|
| 9778 |
nelberth |
24 |
use LeadersLinked\Mapper\FeedMapper;
|
| 9760 |
nelberth |
25 |
|
|
|
26 |
use LeadersLinked\Model\HighPerformanceTeamsGroupsMembers;
|
|
|
27 |
use LeadersLinked\Form\HighPerformanceTeamsGroupsMembersForm;
|
|
|
28 |
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMembersMapper;
|
| 9766 |
nelberth |
29 |
class HighPerformanceTeamsGroupsViewForoArticlesController extends AbstractActionController
|
| 9760 |
nelberth |
30 |
{
|
|
|
31 |
/**
|
|
|
32 |
*
|
|
|
33 |
* @var AdapterInterface
|
|
|
34 |
*/
|
|
|
35 |
private $adapter;
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
*
|
|
|
40 |
* @var AbstractAdapter
|
|
|
41 |
*/
|
|
|
42 |
private $cache;
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
*
|
|
|
46 |
* @var LoggerInterface
|
|
|
47 |
*/
|
|
|
48 |
private $logger;
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
*
|
|
|
52 |
* @var array
|
|
|
53 |
*/
|
|
|
54 |
private $config;
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
*
|
|
|
60 |
* @param AdapterInterface $adapter
|
|
|
61 |
* @param AbstractAdapter $cache
|
|
|
62 |
* @param LoggerInterface $logger
|
|
|
63 |
* @param array $config
|
|
|
64 |
*/
|
|
|
65 |
public function __construct($adapter, $cache , $logger, $config)
|
|
|
66 |
{
|
|
|
67 |
$this->adapter = $adapter;
|
|
|
68 |
$this->cache = $cache;
|
|
|
69 |
$this->logger = $logger;
|
|
|
70 |
$this->config = $config;
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
public function indexAction()
|
|
|
79 |
{
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
83 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
84 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 11085 |
nelberth |
85 |
$group_uuid = $this->params()->fromRoute('group_id');
|
|
|
86 |
$category_uuid = $this->params()->fromRoute('category_id');
|
| 9760 |
nelberth |
87 |
|
|
|
88 |
|
|
|
89 |
$request = $this->getRequest();
|
|
|
90 |
if($request->isGet()) {
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
$headers = $request->getHeaders();
|
|
|
94 |
|
|
|
95 |
$isJson = false;
|
|
|
96 |
if($headers->has('Accept')) {
|
|
|
97 |
$accept = $headers->get('Accept');
|
|
|
98 |
|
|
|
99 |
$prioritized = $accept->getPrioritized();
|
|
|
100 |
|
|
|
101 |
foreach($prioritized as $key => $value) {
|
|
|
102 |
$raw = trim($value->getRaw());
|
|
|
103 |
|
|
|
104 |
if(!$isJson) {
|
|
|
105 |
$isJson = strpos($raw, 'json');
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
}
|
|
|
109 |
}
|
| 9775 |
nelberth |
110 |
|
| 9776 |
nelberth |
111 |
if(!$group_uuid) {
|
|
|
112 |
$data = [
|
|
|
113 |
'success' => false,
|
|
|
114 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
115 |
];
|
|
|
116 |
|
|
|
117 |
return new JsonModel($data);
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
if(!$category_uuid) {
|
|
|
121 |
$data = [
|
|
|
122 |
'success' => false,
|
|
|
123 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
124 |
];
|
|
|
125 |
|
|
|
126 |
return new JsonModel($data);
|
|
|
127 |
}
|
|
|
128 |
|
| 9775 |
nelberth |
129 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
|
|
130 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
|
| 11189 |
nelberth |
131 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
132 |
$viewModel = new ViewModel();
|
| 9775 |
nelberth |
133 |
if (!$highPerformanceTeamsGroups) {
|
| 11189 |
nelberth |
134 |
$viewModel->setTemplate('leaders-linked/no-access/index.phtml');
|
|
|
135 |
return $viewModel;
|
| 9775 |
nelberth |
136 |
}
|
| 10377 |
nelberth |
137 |
if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
|
| 11189 |
nelberth |
138 |
$viewModel->setTemplate('leaders-linked/no-access/index.phtml');
|
|
|
139 |
return $viewModel;
|
| 10377 |
nelberth |
140 |
|
|
|
141 |
}
|
|
|
142 |
$highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
143 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
| 9776 |
nelberth |
144 |
if(!$highPerformanceTeamsGroupsMember) {
|
| 11189 |
nelberth |
145 |
$viewModel->setTemplate('leaders-linked/no-access/index.phtml');
|
|
|
146 |
return $viewModel;
|
| 9776 |
nelberth |
147 |
}
|
|
|
148 |
if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
|
| 11189 |
nelberth |
149 |
$viewModel->setTemplate('leaders-linked/no-access/index.phtml');
|
|
|
150 |
return $viewModel;
|
| 9776 |
nelberth |
151 |
}
|
| 10377 |
nelberth |
152 |
|
| 11190 |
nelberth |
153 |
$topicMapper = TopicMapper::getInstance($this->adapter);
|
| 11192 |
nelberth |
154 |
$topic = $topicMapper->fetchOneByUuidAndGroupId($category_uuid,$highPerformanceTeamsGroups->id);
|
| 10377 |
nelberth |
155 |
|
| 11190 |
nelberth |
156 |
if(!$topic){
|
|
|
157 |
$viewModel->setTemplate('leaders-linked/no-access/index.phtml');
|
|
|
158 |
return $viewModel;
|
|
|
159 |
}
|
| 9775 |
nelberth |
160 |
|
| 9760 |
nelberth |
161 |
if($isJson) {
|
|
|
162 |
|
| 9784 |
nelberth |
163 |
|
| 9760 |
nelberth |
164 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
| 9905 |
nelberth |
165 |
$allowEdit = $acl->isAllowed($currentUser->usertype_id, 'high-performance-teams/groups/view/foro/categories/articles/edit');
|
|
|
166 |
$allowDelete = $acl->isAllowed($currentUser->usertype_id,'high-performance-teams/groups/view/foro/categories/articles/delete');
|
|
|
167 |
$allowView = $acl->isAllowed($currentUser->usertype_id,'high-performance-teams/groups/view/foro/categories/articles/view');
|
| 9760 |
nelberth |
168 |
|
| 9776 |
nelberth |
169 |
|
| 9760 |
nelberth |
170 |
|
|
|
171 |
$search = $this->params()->fromQuery('search', []);
|
|
|
172 |
$search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
|
|
|
173 |
|
|
|
174 |
|
|
|
175 |
$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
|
|
176 |
$page = (intval($this->params()->fromQuery('start', 1), 10)/$records_x_page)+1;
|
|
|
177 |
$order = $this->params()->fromQuery('order', []);
|
|
|
178 |
$order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
|
|
|
179 |
$order_direction = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var( $order[0]['dir'], FILTER_SANITIZE_STRING));
|
|
|
180 |
|
| 9886 |
nelberth |
181 |
$fields = ['title', 'added_on'];
|
|
|
182 |
$order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'added_on';
|
| 9760 |
nelberth |
183 |
|
|
|
184 |
if(!in_array($order_direction, ['ASC', 'DESC'])) {
|
| 9888 |
nelberth |
185 |
$order_direction = 'DESC';
|
| 9760 |
nelberth |
186 |
}
|
| 9785 |
nelberth |
187 |
|
| 11190 |
nelberth |
188 |
|
| 9785 |
nelberth |
189 |
|
| 9787 |
nelberth |
190 |
|
|
|
191 |
|
|
|
192 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
| 9792 |
nelberth |
193 |
|
| 9789 |
nelberth |
194 |
$paginator = $feedMapper->fetchAllDataTableForo($search, $page, $records_x_page, $order_field, $order_direction, $topic->id);
|
| 9794 |
nelberth |
195 |
|
| 9760 |
nelberth |
196 |
$items = [];
|
|
|
197 |
|
|
|
198 |
$records = $paginator->getCurrentItems();
|
|
|
199 |
|
| 9877 |
nelberth |
200 |
|
|
|
201 |
$sandbox = $this->config['leaderslinked.runmode.sandbox'];
|
|
|
202 |
if($sandbox) {
|
|
|
203 |
$company_profile_url = $this->config['leaderslinked.frontend.sandbox_company_profile'];
|
|
|
204 |
$user_profile_url = $this->config['leaderslinked.frontend.sandbox_user_profile'];
|
|
|
205 |
|
|
|
206 |
} else {
|
|
|
207 |
$company_profile_url = $this->config['leaderslinked.frontend.production_company_profile'];
|
|
|
208 |
$user_profile_url = $this->config['leaderslinked.frontend.production_user_profile'];
|
|
|
209 |
}
|
| 9760 |
nelberth |
210 |
|
|
|
211 |
foreach($records as $record)
|
|
|
212 |
{
|
|
|
213 |
|
|
|
214 |
|
| 9877 |
nelberth |
215 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
216 |
$user = $userMapper->fetchOne($record->user_id);
|
| 9919 |
nelberth |
217 |
if($record->user_id!=$currentUser->id){
|
| 10380 |
nelberth |
218 |
$contentAllowDelete=$allowDelete;
|
|
|
219 |
$contentAllowEdit=$allowEdit;
|
| 9919 |
nelberth |
220 |
$allowDelete=false;
|
|
|
221 |
$allowEdit=false;
|
|
|
222 |
}
|
| 10389 |
nelberth |
223 |
if($highPerformanceTeamsGroupsMember->type!=HighPerformanceTeamsGroupsMembers::TYPE_USER){
|
| 10377 |
nelberth |
224 |
$allowDelete=true;
|
|
|
225 |
}
|
| 9883 |
nelberth |
226 |
$dt = \DateTime::createFromFormat('Y-m-d H:i:s', $record->added_on);
|
| 9760 |
nelberth |
227 |
$item = [
|
|
|
228 |
'title' => $record->title,
|
| 9877 |
nelberth |
229 |
'author' => [
|
|
|
230 |
'user_name' => $user->first_name . ' ' . $user->last_name,
|
|
|
231 |
'user_url' => str_replace('[uuid]', $user->uuid, $user_profile_url),
|
|
|
232 |
'user_image' => $this->url()->fromRoute('storage', ['code' => $user->uuid, 'type' => 'user', 'filename' => $user->image]),
|
|
|
233 |
],
|
| 9903 |
nelberth |
234 |
'added_on'=> $dt->format('d/m/Y'),
|
| 9760 |
nelberth |
235 |
'actions' => [
|
| 11085 |
nelberth |
236 |
'link_edit' => $allowEdit ? $this->url()->fromRoute('high-performance-teams/groups/view/foro/categories/articles/edit', ['group_id' => $group_uuid,'category_id' => $category_uuid, 'article_id' => $record->uuid]) : '',
|
|
|
237 |
'link_delete' => $allowDelete ? $this->url()->fromRoute('high-performance-teams/groups/view/foro/categories/articles/delete', ['group_id' => $group_uuid,'category_id' => $category_uuid, 'article_id' => $record->uuid]) : '',
|
|
|
238 |
'link_view' => $allowView ? $this->url()->fromRoute('high-performance-teams/groups/view/foro/categories/articles/view', ['group_id' => $group_uuid,'category_id' => $category_uuid, 'article_id' => $record->uuid]) : '',
|
| 9760 |
nelberth |
239 |
]
|
|
|
240 |
|
|
|
241 |
];
|
| 10380 |
nelberth |
242 |
if($record->user_id!=$currentUser->id){
|
|
|
243 |
$allowDelete=$contentAllowDelete;
|
|
|
244 |
$allowEdit=$contentAllowEdit;
|
|
|
245 |
}
|
| 9760 |
nelberth |
246 |
|
|
|
247 |
array_push($items, $item);
|
|
|
248 |
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
return new JsonModel([
|
|
|
252 |
'success' => true,
|
|
|
253 |
'data' => [
|
|
|
254 |
'items' => $items,
|
|
|
255 |
'total' => $paginator->getTotalItemCount(),
|
|
|
256 |
]
|
|
|
257 |
]);
|
|
|
258 |
|
|
|
259 |
} else {
|
| 9841 |
nelberth |
260 |
$formAdd = new CreateFeedForm($this->adapter);
|
| 11189 |
nelberth |
261 |
|
| 9768 |
nelberth |
262 |
$viewModel->setTemplate('leaders-linked/high-performance-teams-groups-view-foro-articles/index.phtml');
|
| 9760 |
nelberth |
263 |
$viewModel->setVariables([
|
| 9770 |
nelberth |
264 |
'formAdd' => $formAdd,
|
| 9772 |
nelberth |
265 |
'group_uuid'=>$group_uuid,
|
| 9775 |
nelberth |
266 |
'group_title'=>$highPerformanceTeamsGroups->title,
|
| 9777 |
nelberth |
267 |
'group_description'=>$highPerformanceTeamsGroups->description,
|
|
|
268 |
'category_uuid'=>$category_uuid
|
| 9760 |
nelberth |
269 |
]);
|
|
|
270 |
return $viewModel ;
|
|
|
271 |
}
|
|
|
272 |
} else {
|
|
|
273 |
return new JsonModel([
|
|
|
274 |
'success' => false,
|
|
|
275 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
276 |
]);
|
|
|
277 |
}
|
|
|
278 |
}
|
|
|
279 |
|
|
|
280 |
public function addAction()
|
|
|
281 |
{
|
| 9850 |
nelberth |
282 |
|
| 9852 |
nelberth |
283 |
|
| 9847 |
nelberth |
284 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
| 9760 |
nelberth |
285 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
286 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 11085 |
nelberth |
287 |
$group_uuid = $this->params()->fromRoute('group_id');
|
|
|
288 |
$category_uuid = $this->params()->fromRoute('category_id');
|
| 9760 |
nelberth |
289 |
|
|
|
290 |
$request = $this->getRequest();
|
|
|
291 |
if($request->isPost()) {
|
|
|
292 |
|
| 9847 |
nelberth |
293 |
|
|
|
294 |
$dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
|
|
|
295 |
|
|
|
296 |
$form = new CreateFeedForm($this->adapter);
|
|
|
297 |
|
| 9760 |
nelberth |
298 |
$form->setData($dataPost);
|
| 9859 |
nelberth |
299 |
|
| 9760 |
nelberth |
300 |
if($form->isValid()) {
|
| 9860 |
nelberth |
301 |
|
| 9847 |
nelberth |
302 |
|
|
|
303 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
304 |
$feed = new Feed();
|
|
|
305 |
$hydrator->hydrate($dataPost, $feed);
|
|
|
306 |
|
| 9862 |
nelberth |
307 |
|
| 9847 |
nelberth |
308 |
|
| 9855 |
nelberth |
309 |
|
| 10379 |
nelberth |
310 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
|
|
311 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
|
|
|
312 |
|
|
|
313 |
if (!$highPerformanceTeamsGroups) {
|
|
|
314 |
$data = [
|
|
|
315 |
'success' => false,
|
|
|
316 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
317 |
];
|
|
|
318 |
|
|
|
319 |
return new JsonModel($data);
|
|
|
320 |
}
|
|
|
321 |
if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
|
| 9847 |
nelberth |
322 |
|
| 10379 |
nelberth |
323 |
return new JsonModel([
|
|
|
324 |
'success' => false,
|
|
|
325 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
326 |
]);
|
|
|
327 |
|
|
|
328 |
}
|
|
|
329 |
$highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
330 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
|
|
331 |
if(!$highPerformanceTeamsGroupsMember) {
|
|
|
332 |
return new JsonModel([
|
|
|
333 |
'success' => false,
|
|
|
334 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
335 |
]);
|
|
|
336 |
}
|
|
|
337 |
|
| 9847 |
nelberth |
338 |
|
|
|
339 |
$highPerformanceTeamsGroupsMemberMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
340 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMemberMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
|
|
341 |
if($highPerformanceTeamsGroupsMember) {
|
|
|
342 |
if($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN ){
|
|
|
343 |
$id = $highPerformanceTeamsGroups->id;
|
|
|
344 |
}else{
|
|
|
345 |
|
|
|
346 |
return new JsonModel([
|
|
|
347 |
'success' => false,
|
|
|
348 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
349 |
]);
|
|
|
350 |
}
|
|
|
351 |
|
|
|
352 |
} else {
|
|
|
353 |
|
|
|
354 |
return new JsonModel([
|
|
|
355 |
'success' => false,
|
|
|
356 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
357 |
]);
|
|
|
358 |
}
|
|
|
359 |
|
| 9864 |
nelberth |
360 |
|
| 9847 |
nelberth |
361 |
|
|
|
362 |
$topicMapper = TopicMapper::getInstance($this->adapter);
|
| 11192 |
nelberth |
363 |
$topic = $topicMapper->fetchOneByUuidAndGroupId($category_uuid,$highPerformanceTeamsGroups->id);
|
| 9847 |
nelberth |
364 |
if($topic){
|
|
|
365 |
$feed->topic_id = $topic->id;
|
|
|
366 |
}else{
|
|
|
367 |
return new JsonModel([
|
|
|
368 |
'success' => false,
|
|
|
369 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
370 |
]);
|
|
|
371 |
}
|
| 9760 |
nelberth |
372 |
|
|
|
373 |
|
| 9865 |
nelberth |
374 |
|
| 9760 |
nelberth |
375 |
|
| 9847 |
nelberth |
376 |
$feed->company_id = $currentCompany->id;
|
|
|
377 |
$feed->group_id = null;
|
|
|
378 |
$feed->high_performance_group_id = $id;
|
|
|
379 |
$feed->user_id = $currentUser->id;
|
|
|
380 |
$feed->type = Feed::TYPE_HPTG;
|
|
|
381 |
$feed->posted_or_shared = Feed::POSTED;
|
|
|
382 |
$feed->shared_with = Feed::SHARE_WITH_CONNECTIONS;
|
|
|
383 |
$feed->total_comments = 0;
|
|
|
384 |
$feed->total_shared = 0;
|
|
|
385 |
|
|
|
386 |
|
| 9866 |
nelberth |
387 |
|
|
|
388 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
389 |
$result = $feedMapper->insert($feed);
|
|
|
390 |
|
| 9867 |
nelberth |
391 |
|
| 9847 |
nelberth |
392 |
if($result) {
|
| 9868 |
nelberth |
393 |
|
|
|
394 |
$this->logger->info('Se agrego el articulo del foro con el titulo ' . $feed->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 9870 |
nelberth |
395 |
|
|
|
396 |
$response = [
|
| 9760 |
nelberth |
397 |
'success' => true,
|
|
|
398 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
399 |
];
|
| 9847 |
nelberth |
400 |
|
| 9760 |
nelberth |
401 |
} else {
|
| 9847 |
nelberth |
402 |
$response = [
|
| 9760 |
nelberth |
403 |
'success' => false,
|
| 9847 |
nelberth |
404 |
'data' => $feedMapper->getError()
|
| 9760 |
nelberth |
405 |
];
|
|
|
406 |
}
|
|
|
407 |
} else {
|
|
|
408 |
$messages = [];
|
|
|
409 |
$form_messages = (array) $form->getMessages();
|
|
|
410 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
411 |
{
|
|
|
412 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
413 |
}
|
|
|
414 |
|
| 9847 |
nelberth |
415 |
$response = [
|
| 9760 |
nelberth |
416 |
'success' => false,
|
|
|
417 |
'data' => $messages
|
| 9847 |
nelberth |
418 |
];
|
| 9760 |
nelberth |
419 |
}
|
|
|
420 |
|
|
|
421 |
} else {
|
| 9847 |
nelberth |
422 |
$response = [
|
| 9760 |
nelberth |
423 |
'success' => false,
|
| 9850 |
nelberth |
424 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
| 9760 |
nelberth |
425 |
];
|
|
|
426 |
}
|
|
|
427 |
|
| 9847 |
nelberth |
428 |
return new JsonModel($response);
|
| 9760 |
nelberth |
429 |
}
|
|
|
430 |
|
|
|
431 |
|
|
|
432 |
public function editAction(){
|
|
|
433 |
|
|
|
434 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
435 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
436 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
437 |
$request = $this->getRequest();
|
| 9915 |
nelberth |
438 |
|
| 11085 |
nelberth |
439 |
$group_uuid = $this->params()->fromRoute('group_id');
|
|
|
440 |
$category_uuid = $this->params()->fromRoute('category_id');
|
| 9760 |
nelberth |
441 |
|
| 11085 |
nelberth |
442 |
$article_uuid = $this->params()->fromRoute('article_id');
|
| 9760 |
nelberth |
443 |
|
| 9915 |
nelberth |
444 |
if(!$group_uuid) {
|
| 9760 |
nelberth |
445 |
$data = [
|
|
|
446 |
'success' => false,
|
|
|
447 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
448 |
];
|
|
|
449 |
|
|
|
450 |
return new JsonModel($data);
|
|
|
451 |
}
|
|
|
452 |
|
| 9915 |
nelberth |
453 |
if(!$category_uuid) {
|
|
|
454 |
$data = [
|
|
|
455 |
'success' => false,
|
|
|
456 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
457 |
];
|
|
|
458 |
|
|
|
459 |
return new JsonModel($data);
|
|
|
460 |
}
|
|
|
461 |
|
|
|
462 |
if(!$article_uuid) {
|
|
|
463 |
$data = [
|
|
|
464 |
'success' => false,
|
|
|
465 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
466 |
];
|
|
|
467 |
|
|
|
468 |
return new JsonModel($data);
|
|
|
469 |
}
|
|
|
470 |
|
| 9760 |
nelberth |
471 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
| 9915 |
nelberth |
472 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
|
| 9760 |
nelberth |
473 |
|
| 9915 |
nelberth |
474 |
if (!$highPerformanceTeamsGroups) {
|
| 9760 |
nelberth |
475 |
$data = [
|
|
|
476 |
'success' => false,
|
|
|
477 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
478 |
];
|
|
|
479 |
|
|
|
480 |
return new JsonModel($data);
|
|
|
481 |
}
|
| 10384 |
nelberth |
482 |
if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
|
|
|
483 |
|
|
|
484 |
return new JsonModel([
|
|
|
485 |
'success' => false,
|
|
|
486 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
487 |
]);
|
|
|
488 |
|
|
|
489 |
}
|
|
|
490 |
|
|
|
491 |
$highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
492 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
| 9915 |
nelberth |
493 |
if(!$highPerformanceTeamsGroupsMember) {
|
| 9760 |
nelberth |
494 |
return new JsonModel([
|
|
|
495 |
'success' => false,
|
| 9915 |
nelberth |
496 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
| 9760 |
nelberth |
497 |
]);
|
| 9915 |
nelberth |
498 |
}
|
|
|
499 |
if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
|
|
|
500 |
return new JsonModel([
|
|
|
501 |
'success' => false,
|
|
|
502 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
|
|
|
503 |
]);
|
|
|
504 |
}
|
| 10388 |
nelberth |
505 |
if($highPerformanceTeamsGroupsMember->user_id!=$currentUser->id){
|
|
|
506 |
|
|
|
507 |
return new JsonModel([
|
|
|
508 |
'success' => false,
|
|
|
509 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
510 |
]);
|
|
|
511 |
|
| 10384 |
nelberth |
512 |
}
|
| 10388 |
nelberth |
513 |
|
| 10384 |
nelberth |
514 |
|
| 9915 |
nelberth |
515 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
516 |
$feed = $feedMapper->fetchOneByUuid($article_uuid);
|
|
|
517 |
|
| 9760 |
nelberth |
518 |
if($request->isPost()) {
|
| 9918 |
nelberth |
519 |
|
|
|
520 |
$form = new CreateFeedForm($this->adapter);
|
| 9760 |
nelberth |
521 |
$dataPost = $request->getPost()->toArray();
|
|
|
522 |
$form->setData($dataPost);
|
|
|
523 |
|
|
|
524 |
if($form->isValid()) {
|
|
|
525 |
$dataPost = (array) $form->getData();
|
|
|
526 |
|
|
|
527 |
$hydrator = new ObjectPropertyHydrator();
|
| 9918 |
nelberth |
528 |
$hydrator->hydrate($dataPost, $feed);
|
|
|
529 |
$result = $feedMapper->update($feed);
|
| 9760 |
nelberth |
530 |
|
|
|
531 |
if($result) {
|
| 9918 |
nelberth |
532 |
$this->logger->info('Se actualizo el articulo del foro con el titulo ' . $feed->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 9760 |
nelberth |
533 |
|
|
|
534 |
$data = [
|
|
|
535 |
'success' => true,
|
|
|
536 |
'data' => 'LABEL_RECORD_UPDATED'
|
|
|
537 |
];
|
|
|
538 |
} else {
|
|
|
539 |
$data = [
|
|
|
540 |
'success' => false,
|
| 9918 |
nelberth |
541 |
'data' => $feedMapper->getError()
|
| 9760 |
nelberth |
542 |
];
|
|
|
543 |
}
|
|
|
544 |
|
|
|
545 |
return new JsonModel($data);
|
|
|
546 |
|
|
|
547 |
} else {
|
|
|
548 |
$messages = [];
|
|
|
549 |
$form_messages = (array) $form->getMessages();
|
|
|
550 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
551 |
{
|
|
|
552 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
553 |
}
|
|
|
554 |
|
|
|
555 |
return new JsonModel([
|
|
|
556 |
'success' => false,
|
|
|
557 |
'data' => $messages
|
|
|
558 |
]);
|
|
|
559 |
}
|
|
|
560 |
}else if ($request->isGet()) {
|
| 9915 |
nelberth |
561 |
|
|
|
562 |
|
|
|
563 |
|
| 9760 |
nelberth |
564 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
565 |
|
|
|
566 |
$data = [
|
|
|
567 |
'success' => true,
|
| 9915 |
nelberth |
568 |
'data' => $hydrator->extract($feed)
|
| 9760 |
nelberth |
569 |
];
|
|
|
570 |
|
|
|
571 |
return new JsonModel($data);
|
|
|
572 |
} else {
|
|
|
573 |
$data = [
|
|
|
574 |
'success' => false,
|
|
|
575 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
576 |
];
|
|
|
577 |
|
|
|
578 |
return new JsonModel($data);
|
|
|
579 |
}
|
|
|
580 |
|
|
|
581 |
return new JsonModel($data);
|
|
|
582 |
|
|
|
583 |
}
|
|
|
584 |
|
|
|
585 |
|
|
|
586 |
|
|
|
587 |
|
| 9904 |
nelberth |
588 |
public function deleteAction()
|
|
|
589 |
{
|
| 9760 |
nelberth |
590 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
| 9904 |
nelberth |
591 |
$currentUser = $currentUserPlugin->getUser();
|
| 9760 |
nelberth |
592 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 11085 |
nelberth |
593 |
$group_uuid = $this->params()->fromRoute('group_id');
|
| 9904 |
nelberth |
594 |
|
| 9760 |
nelberth |
595 |
$request = $this->getRequest();
|
| 10384 |
nelberth |
596 |
|
|
|
597 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
|
|
598 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
|
|
|
599 |
|
|
|
600 |
if (!$highPerformanceTeamsGroups) {
|
|
|
601 |
$data = [
|
|
|
602 |
'success' => false,
|
|
|
603 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
604 |
];
|
|
|
605 |
|
|
|
606 |
return new JsonModel($data);
|
|
|
607 |
}
|
|
|
608 |
if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
|
|
|
609 |
|
|
|
610 |
return new JsonModel([
|
|
|
611 |
'success' => false,
|
|
|
612 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
613 |
]);
|
|
|
614 |
|
|
|
615 |
}
|
|
|
616 |
|
|
|
617 |
$highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
618 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
|
|
619 |
if(!$highPerformanceTeamsGroupsMember) {
|
|
|
620 |
return new JsonModel([
|
|
|
621 |
'success' => false,
|
|
|
622 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
623 |
]);
|
|
|
624 |
}
|
|
|
625 |
if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
|
|
|
626 |
return new JsonModel([
|
|
|
627 |
'success' => false,
|
|
|
628 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
|
|
|
629 |
]);
|
|
|
630 |
}
|
| 10387 |
nelberth |
631 |
if($highPerformanceTeamsGroupsMember->user_id!=$currentUser->id){
|
| 10385 |
nelberth |
632 |
|
| 10388 |
nelberth |
633 |
if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
|
| 10385 |
nelberth |
634 |
return new JsonModel([
|
|
|
635 |
'success' => false,
|
|
|
636 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
637 |
]);
|
|
|
638 |
}
|
|
|
639 |
|
| 10384 |
nelberth |
640 |
}
|
| 10385 |
nelberth |
641 |
|
| 10384 |
nelberth |
642 |
|
| 10385 |
nelberth |
643 |
|
|
|
644 |
|
| 9904 |
nelberth |
645 |
if($request->isPost()) {
|
| 9760 |
nelberth |
646 |
|
| 9904 |
nelberth |
647 |
|
| 11085 |
nelberth |
648 |
$article_uuid = $this->params()->fromRoute('article_id');
|
| 9904 |
nelberth |
649 |
|
|
|
650 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
651 |
$feed = $feedMapper->fetchOneByUuid($article_uuid);
|
|
|
652 |
if(!$feed) {
|
|
|
653 |
$response = [
|
|
|
654 |
'success' => false,
|
|
|
655 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
656 |
];
|
|
|
657 |
return new JsonModel($response);
|
|
|
658 |
}
|
|
|
659 |
|
|
|
660 |
|
| 10384 |
nelberth |
661 |
|
| 9904 |
nelberth |
662 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
663 |
$feed->status = Feed::STATUS_DELETED;
|
|
|
664 |
if($feedMapper->update($feed)) {
|
|
|
665 |
$response = [
|
| 9760 |
nelberth |
666 |
'success' => true,
|
| 9904 |
nelberth |
667 |
'data' => 'LABEL_FEED_WAS_DELETED'
|
| 9760 |
nelberth |
668 |
];
|
| 9904 |
nelberth |
669 |
|
| 9760 |
nelberth |
670 |
} else {
|
| 9904 |
nelberth |
671 |
$response = [
|
| 9760 |
nelberth |
672 |
'success' => false,
|
| 9904 |
nelberth |
673 |
'data' => $feedMapper->getError()
|
| 9760 |
nelberth |
674 |
];
|
| 9904 |
nelberth |
675 |
}
|
| 9760 |
nelberth |
676 |
|
| 9904 |
nelberth |
677 |
|
|
|
678 |
return new JsonModel($response);
|
|
|
679 |
|
| 9760 |
nelberth |
680 |
} else {
|
| 9904 |
nelberth |
681 |
$response = [
|
| 9760 |
nelberth |
682 |
'success' => false,
|
|
|
683 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
684 |
];
|
|
|
685 |
}
|
| 9904 |
nelberth |
686 |
|
|
|
687 |
return new JsonModel($response);
|
| 9760 |
nelberth |
688 |
}
|
|
|
689 |
|
|
|
690 |
|
| 9904 |
nelberth |
691 |
|
| 9760 |
nelberth |
692 |
|
|
|
693 |
|
|
|
694 |
}
|