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