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