12829 |
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;
|
16768 |
efrain |
9 |
|
12829 |
nelberth |
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\Library\Functions;
|
|
|
17 |
use LeadersLinked\Mapper\CompanyUserMapper;
|
|
|
18 |
use LeadersLinked\Mapper\UserMapper;
|
12861 |
nelberth |
19 |
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMapper;
|
|
|
20 |
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMembersMapper;
|
|
|
21 |
use LeadersLinked\Model\HighPerformanceTeamsGroupsMembers;
|
|
|
22 |
use LeadersLinked\Model\HighPerformanceTeamsGroups;
|
12829 |
nelberth |
23 |
class HighPerformanceTeamsGroupsViewTaskController extends AbstractActionController
|
|
|
24 |
{
|
|
|
25 |
/**
|
|
|
26 |
*
|
|
|
27 |
* @var AdapterInterface
|
|
|
28 |
*/
|
|
|
29 |
private $adapter;
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
*
|
|
|
33 |
* @var LoggerInterface
|
|
|
34 |
*/
|
|
|
35 |
private $logger;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
*
|
|
|
39 |
* @var array
|
|
|
40 |
*/
|
|
|
41 |
private $config;
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
*
|
|
|
45 |
* @param AdapterInterface $adapter
|
|
|
46 |
* @param LoggerInterface $logger
|
|
|
47 |
* @param array $config
|
|
|
48 |
*/
|
16768 |
efrain |
49 |
public function __construct($adapter, $logger, $config)
|
12829 |
nelberth |
50 |
{
|
16768 |
efrain |
51 |
$this->adapter = $adapter;
|
|
|
52 |
$this->logger = $logger;
|
|
|
53 |
$this->config = $config;
|
12829 |
nelberth |
54 |
}
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
public function indexAction()
|
|
|
59 |
{
|
|
|
60 |
$objective_uuid = $this->params()->fromRoute('objective_id');
|
|
|
61 |
$goal_uuid= $this->params()->fromRoute('goal_id');
|
|
|
62 |
$request = $this->getRequest();
|
|
|
63 |
|
|
|
64 |
if($request->isGet()) {
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
$headers = $request->getHeaders();
|
|
|
68 |
|
|
|
69 |
$isJson = false;
|
|
|
70 |
if($headers->has('Accept')) {
|
|
|
71 |
$accept = $headers->get('Accept');
|
|
|
72 |
|
|
|
73 |
$prioritized = $accept->getPrioritized();
|
|
|
74 |
|
|
|
75 |
foreach($prioritized as $key => $value) {
|
|
|
76 |
$raw = trim($value->getRaw());
|
|
|
77 |
|
|
|
78 |
if(!$isJson) {
|
|
|
79 |
$isJson = strpos($raw, 'json');
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
}
|
|
|
83 |
}
|
12861 |
nelberth |
84 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
12829 |
nelberth |
85 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
86 |
$currentCompany = $currentUserPlugin->getCompany();
|
12861 |
nelberth |
87 |
$group_uuid = $this->params()->fromRoute('group_id');
|
|
|
88 |
if(!$group_uuid) {
|
|
|
89 |
$data = [
|
|
|
90 |
'success' => false,
|
|
|
91 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
92 |
];
|
|
|
93 |
|
|
|
94 |
return new JsonModel($data);
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
|
|
98 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
|
|
|
99 |
|
|
|
100 |
if (!$highPerformanceTeamsGroups) {
|
|
|
101 |
$data = [
|
|
|
102 |
'success' => false,
|
|
|
103 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
104 |
];
|
|
|
105 |
|
|
|
106 |
return new JsonModel($data);
|
|
|
107 |
}
|
|
|
108 |
if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
|
|
|
109 |
|
|
|
110 |
return new JsonModel([
|
|
|
111 |
'success' => false,
|
|
|
112 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
113 |
]);
|
|
|
114 |
|
|
|
115 |
}
|
|
|
116 |
$highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
117 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
|
|
118 |
if(!$highPerformanceTeamsGroupsMember) {
|
|
|
119 |
return new JsonModel([
|
|
|
120 |
'success' => false,
|
|
|
121 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
|
|
|
122 |
]);
|
|
|
123 |
}
|
|
|
124 |
if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
|
|
|
125 |
return new JsonModel([
|
|
|
126 |
'success' => false,
|
|
|
127 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
|
|
|
128 |
]);
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
|
12829 |
nelberth |
132 |
if($isJson) {
|
|
|
133 |
|
|
|
134 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
12913 |
nelberth |
135 |
|
16766 |
efrain |
136 |
$allowAdd = $acl->isAllowed($currentUser->usertype_id, 'planning/objectives/goals/task/add');
|
|
|
137 |
$allowEdit = $acl->isAllowed($currentUser->usertype_id, 'planning/objectives/goals/task/edit');
|
|
|
138 |
$allowDelete = $acl->isAllowed($currentUser->usertype_id, 'planning/objectives/goals/task/delete');
|
|
|
139 |
$allowView = $acl->isAllowed($currentUser->usertype_id, 'planning/objectives/goals/task/view');
|
12829 |
nelberth |
140 |
|
|
|
141 |
$search = $this->params()->fromQuery('search', []);
|
16766 |
efrain |
142 |
$search = empty($search['value']) ? '' : Functions::sanitizeFilterString($search['value']);
|
12829 |
nelberth |
143 |
|
|
|
144 |
$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
|
|
145 |
$page = (intval($this->params()->fromQuery('start', 1), 10)/$records_x_page)+1;
|
|
|
146 |
$order = $this->params()->fromQuery('order', []);
|
|
|
147 |
$order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
|
16766 |
efrain |
148 |
$order_direction = empty($order[0]['dir']) ? 'ASC' : strtoupper(Functions::sanitizeFilterString($order[0]['dir']));
|
12829 |
nelberth |
149 |
|
|
|
150 |
$fields = ['title'];
|
|
|
151 |
$order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'title';
|
|
|
152 |
|
|
|
153 |
if(!in_array($order_direction, ['ASC', 'DESC'])) {
|
|
|
154 |
$order_direction = 'ASC';
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
$planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
|
|
|
158 |
$objective = $planningObjectivesAndGoalsObjectivesMapper->fetchOneByUuid($objective_uuid);
|
|
|
159 |
|
|
|
160 |
if (!$objective) {
|
|
|
161 |
$data = [
|
|
|
162 |
'success' => false,
|
|
|
163 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
164 |
];
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
return new JsonModel($data);
|
|
|
168 |
|
|
|
169 |
}else{
|
|
|
170 |
if($objective->company_id==$currentCompany->id){
|
|
|
171 |
$planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
|
|
|
172 |
$goals = $planningObjectivesAndGoalsGoalsMapper->fetchOneByUuid($goal_uuid);
|
|
|
173 |
|
|
|
174 |
if(!$goals){
|
|
|
175 |
$data = [
|
|
|
176 |
'success' => false,
|
|
|
177 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
178 |
];
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
return new JsonModel($data);
|
|
|
182 |
}
|
|
|
183 |
}else{
|
|
|
184 |
$data = [
|
|
|
185 |
'success' => false,
|
|
|
186 |
'data' => 'ERROR_UNAUTHORIZED',
|
|
|
187 |
];
|
|
|
188 |
|
|
|
189 |
return new JsonModel($data);
|
|
|
190 |
}
|
|
|
191 |
}
|
12861 |
nelberth |
192 |
if($objective->high_performance_team_group_id !=$highPerformanceTeamsGroups->id){
|
|
|
193 |
$data = [
|
|
|
194 |
'success' => false,
|
|
|
195 |
'data' => 'ERROR_UNAUTHORIZED',
|
|
|
196 |
];
|
|
|
197 |
return new JsonModel($data);
|
|
|
198 |
}
|
12829 |
nelberth |
199 |
|
|
|
200 |
$planningObjectivesAndGoalsTaskMapper = PlanningObjectivesAndGoalsTaskMapper::getInstance($this->adapter);
|
|
|
201 |
$paginator = $planningObjectivesAndGoalsTaskMapper->fetchAllDataTable($search, $page, $records_x_page, $order_field, $order_direction, $goals->id);
|
|
|
202 |
|
|
|
203 |
$items = [];
|
|
|
204 |
|
|
|
205 |
$records = $paginator->getCurrentItems();
|
|
|
206 |
|
|
|
207 |
|
|
|
208 |
foreach($records as $record)
|
|
|
209 |
{
|
|
|
210 |
|
|
|
211 |
$item = [
|
|
|
212 |
'title' => $record->title,
|
|
|
213 |
'description' => $record->description,
|
|
|
214 |
'progress'=> $record->indicator,
|
|
|
215 |
'cost'=> $record->cost,
|
|
|
216 |
'status' => $record->status,
|
|
|
217 |
'actions' => [
|
16766 |
efrain |
218 |
'link_edit' => $allowEdit ? $this->url()->fromRoute('planning/objectives/goals/task/edit', ['objective_id' => $objective_uuid,'goal_id' => $goal_uuid,'id' => $record->uuid]) : '',
|
|
|
219 |
'link_delete' => $allowDelete ? $this->url()->fromRoute('planning/objectives/goals/task/delete', ['objective_id' => $objective_uuid,'goal_id' => $goal_uuid,'id' => $record->uuid]) : ''
|
12829 |
nelberth |
220 |
]
|
|
|
221 |
|
|
|
222 |
];
|
|
|
223 |
array_push($items, $item);
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
$recordsTask = $planningObjectivesAndGoalsTaskMapper->fetchAll($goals->id);
|
|
|
227 |
|
|
|
228 |
|
|
|
229 |
$costGoals=0;
|
|
|
230 |
$indicatorGoals=0;
|
|
|
231 |
|
|
|
232 |
foreach($recordsTask as $record)
|
|
|
233 |
{
|
|
|
234 |
$indicatorGoals=$indicatorGoals+$record->indicator;
|
|
|
235 |
$costGoals=$costGoals+$record->cost;
|
|
|
236 |
}
|
|
|
237 |
$countRecordsTask = count($recordsTask);
|
|
|
238 |
if($countRecordsTask >0){
|
|
|
239 |
|
|
|
240 |
$indicatorGoals=round($indicatorGoals/$countRecordsTask, 2);
|
|
|
241 |
}else{
|
|
|
242 |
$indicatorGoals=-1;
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
|
|
|
246 |
|
|
|
247 |
return new JsonModel([
|
|
|
248 |
'success' => true,
|
|
|
249 |
'data' => [
|
|
|
250 |
'items' => $items,
|
|
|
251 |
'total' => $paginator->getTotalItemCount(),
|
|
|
252 |
'goals' => [
|
12869 |
nelberth |
253 |
'titleGoal' =>$goals->title,
|
|
|
254 |
'descriptionGoal' =>$goals->description,
|
|
|
255 |
'costGoal'=>'$'.$costGoals,
|
12873 |
nelberth |
256 |
'indicatorGoal'=> $indicatorGoals,
|
12910 |
nelberth |
257 |
'link_add'=>$allowAdd ? $this->url()->fromRoute('high-performance-teams/groups/view/objectives/goals/task/add', ['group_id'=>$highPerformanceTeamsGroups->uuid,'objective_id' => $objective_uuid,'goal_id' => $goal_uuid,]) : '',
|
12869 |
nelberth |
258 |
'goBackGoal'=> $this->url()->fromRoute('high-performance-teams/groups/view/objectives/goals', ['group_id'=>$highPerformanceTeamsGroups->uuid,'objective_id' => $objective_uuid]),
|
|
|
259 |
'statusGoal'=> $goals->status=='a'?'LABEL_ACTIVE':'LABEL_INACTIVE',
|
12829 |
nelberth |
260 |
|
|
|
261 |
]
|
|
|
262 |
]
|
|
|
263 |
]);
|
|
|
264 |
} else {
|
|
|
265 |
$formAdd = new PlanningObjectivesAndGoalsTaskForm($this->adapter, $currentCompany->id);
|
|
|
266 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
267 |
$viewModel = new ViewModel();
|
16766 |
efrain |
268 |
$viewModel->setTemplate('leaders-linked/planning-task/index.phtml');
|
12829 |
nelberth |
269 |
$viewModel->setVariables([
|
|
|
270 |
'formAdd' => $formAdd,
|
|
|
271 |
'objective_uuid'=> $objective_uuid,
|
|
|
272 |
'goal_uuid'=> $goal_uuid,
|
|
|
273 |
|
|
|
274 |
|
|
|
275 |
]);
|
|
|
276 |
return $viewModel ;
|
|
|
277 |
}
|
|
|
278 |
} else {
|
|
|
279 |
return new JsonModel([
|
|
|
280 |
'success' => false,
|
|
|
281 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
282 |
]);
|
|
|
283 |
}
|
|
|
284 |
}
|
|
|
285 |
public function addAction()
|
|
|
286 |
{
|
12936 |
nelberth |
287 |
|
12829 |
nelberth |
288 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
289 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
290 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
291 |
$objective_uuid = $this->params()->fromRoute('objective_id');
|
|
|
292 |
$goal_uuid = $this->params()->fromRoute('goal_id');
|
12878 |
nelberth |
293 |
$group_uuid = $this->params()->fromRoute('group_id');
|
|
|
294 |
if(!$group_uuid) {
|
|
|
295 |
$data = [
|
|
|
296 |
'success' => false,
|
|
|
297 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
298 |
];
|
|
|
299 |
|
|
|
300 |
return new JsonModel($data);
|
|
|
301 |
}
|
|
|
302 |
|
|
|
303 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
|
|
304 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
|
|
|
305 |
|
|
|
306 |
if (!$highPerformanceTeamsGroups) {
|
|
|
307 |
$data = [
|
|
|
308 |
'success' => false,
|
|
|
309 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
310 |
];
|
|
|
311 |
|
|
|
312 |
return new JsonModel($data);
|
|
|
313 |
}
|
|
|
314 |
if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
|
|
|
315 |
|
|
|
316 |
return new JsonModel([
|
|
|
317 |
'success' => false,
|
|
|
318 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
319 |
]);
|
|
|
320 |
|
|
|
321 |
}
|
|
|
322 |
$highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
323 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
|
|
324 |
if(!$highPerformanceTeamsGroupsMember) {
|
|
|
325 |
return new JsonModel([
|
|
|
326 |
'success' => false,
|
|
|
327 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
|
|
|
328 |
]);
|
|
|
329 |
}
|
|
|
330 |
if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
|
|
|
331 |
return new JsonModel([
|
|
|
332 |
'success' => false,
|
|
|
333 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
|
|
|
334 |
]);
|
|
|
335 |
}
|
|
|
336 |
|
12829 |
nelberth |
337 |
$request = $this->getRequest();
|
|
|
338 |
$planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
|
|
|
339 |
$objective = $planningObjectivesAndGoalsObjectivesMapper->fetchOneByUuid($objective_uuid);
|
|
|
340 |
|
|
|
341 |
if (!$objective) {
|
|
|
342 |
$data = [
|
|
|
343 |
'success' => false,
|
|
|
344 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
345 |
];
|
|
|
346 |
|
|
|
347 |
|
|
|
348 |
return new JsonModel($data);
|
|
|
349 |
|
|
|
350 |
}else{
|
|
|
351 |
if($objective->company_id==$currentCompany->id){
|
|
|
352 |
$planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
|
|
|
353 |
$goals = $planningObjectivesAndGoalsGoalsMapper->fetchOneByUuid($goal_uuid);
|
|
|
354 |
|
|
|
355 |
if(!$goals){
|
|
|
356 |
$data = [
|
|
|
357 |
'success' => false,
|
|
|
358 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
359 |
];
|
|
|
360 |
|
|
|
361 |
|
|
|
362 |
return new JsonModel($data);
|
|
|
363 |
}
|
|
|
364 |
}else{
|
|
|
365 |
$data = [
|
|
|
366 |
'success' => false,
|
|
|
367 |
'data' => 'ERROR_UNAUTHORIZED',
|
|
|
368 |
];
|
|
|
369 |
|
|
|
370 |
return new JsonModel($data);
|
|
|
371 |
}
|
|
|
372 |
|
|
|
373 |
}
|
12878 |
nelberth |
374 |
if($objective->high_performance_team_group_id !=$highPerformanceTeamsGroups->id){
|
|
|
375 |
$data = [
|
|
|
376 |
'success' => false,
|
|
|
377 |
'data' => 'ERROR_UNAUTHORIZED',
|
|
|
378 |
];
|
|
|
379 |
return new JsonModel($data);
|
|
|
380 |
}
|
12829 |
nelberth |
381 |
if($request->isPost()) {
|
12937 |
nelberth |
382 |
|
12829 |
nelberth |
383 |
$form = new PlanningObjectivesAndGoalsTaskForm($this->adapter, $currentCompany->id);
|
|
|
384 |
$dataPost = $request->getPost()->toArray();
|
|
|
385 |
$dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : PlanningObjectivesAndGoalsTask::STATUS_INACTIVE;
|
|
|
386 |
if($dataPost['indicator']!=100){
|
|
|
387 |
$dataPost['evaluation']='';
|
|
|
388 |
$dataPost['detour']='';
|
|
|
389 |
}
|
|
|
390 |
$form->setData($dataPost);
|
12944 |
nelberth |
391 |
|
12829 |
nelberth |
392 |
if($form->isValid()) {
|
|
|
393 |
|
12941 |
nelberth |
394 |
|
12943 |
nelberth |
395 |
|
12829 |
nelberth |
396 |
$dataPost = (array) $form->getData();
|
|
|
397 |
$dataPost['goal_id']=$goals->id;
|
|
|
398 |
|
|
|
399 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
400 |
$planningObjectivesAndGoalsTask = new PlanningObjectivesAndGoalsTask();
|
|
|
401 |
$hydrator->hydrate($dataPost, $planningObjectivesAndGoalsTask);
|
|
|
402 |
|
|
|
403 |
$planningObjectivesAndGoalsTaskMapper = PlanningObjectivesAndGoalsTaskMapper::getInstance($this->adapter);
|
|
|
404 |
$result = $planningObjectivesAndGoalsTaskMapper->insert($planningObjectivesAndGoalsTask);
|
|
|
405 |
|
|
|
406 |
|
|
|
407 |
if($result) {
|
|
|
408 |
$userMapper = UserMapper::getInstance($this->adapter);
|
12939 |
nelberth |
409 |
|
12829 |
nelberth |
410 |
foreach( $dataPost['who'] as $record2){
|
|
|
411 |
$PlanningObjectivesAndGoalsTaskMember = new PlanningObjectivesAndGoalsTaskMembers();
|
|
|
412 |
$datosUser = $userMapper->fetchOneByUuid($record2);
|
|
|
413 |
$PlanningObjectivesAndGoalsTaskMember->task_id = $planningObjectivesAndGoalsTask->id;
|
|
|
414 |
$PlanningObjectivesAndGoalsTaskMember->user_id = $datosUser->id;
|
|
|
415 |
$PlanningObjectivesAndGoalsTaskMember->status = PlanningObjectivesAndGoalsTaskMembers::STATUS_ACTIVE;
|
|
|
416 |
$PlanningObjectivesAndGoalsTaskMemberMapper = PlanningObjectivesAndGoalsTaskMembersMapper::getInstance($this->adapter);
|
|
|
417 |
$PlanningObjectivesAndGoalsTaskMemberMapper->insert($PlanningObjectivesAndGoalsTaskMember);
|
|
|
418 |
}
|
|
|
419 |
|
|
|
420 |
|
|
|
421 |
$this->logger->info('Se agrego la tarea ' . $planningObjectivesAndGoalsTask->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
422 |
|
|
|
423 |
$data = [
|
|
|
424 |
'success' => true,
|
|
|
425 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
426 |
];
|
|
|
427 |
} else {
|
|
|
428 |
$data = [
|
|
|
429 |
'success' => false,
|
|
|
430 |
'data' => $planningObjectivesAndGoalsTaskMapper->getError()
|
|
|
431 |
];
|
|
|
432 |
|
|
|
433 |
}
|
|
|
434 |
|
|
|
435 |
return new JsonModel($data);
|
|
|
436 |
|
|
|
437 |
} else {
|
|
|
438 |
$messages = [];
|
|
|
439 |
$form_messages = (array) $form->getMessages();
|
|
|
440 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
441 |
{
|
|
|
442 |
|
|
|
443 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
444 |
}
|
|
|
445 |
|
|
|
446 |
return new JsonModel([
|
|
|
447 |
'success' => false,
|
|
|
448 |
'data' => $messages
|
|
|
449 |
]);
|
|
|
450 |
}
|
|
|
451 |
|
|
|
452 |
}else if ($request->isGet()) {
|
|
|
453 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
454 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
455 |
$datosCompanyUser = $companyUserMapper->fetchAllByCompanyId($currentCompany->id);
|
|
|
456 |
|
|
|
457 |
$users=[];
|
|
|
458 |
|
|
|
459 |
foreach($datosCompanyUser as $record){
|
|
|
460 |
$datosUser = $userMapper->fetchOne($record->user_id);
|
|
|
461 |
|
|
|
462 |
$user=[
|
|
|
463 |
'uuid'=>$datosUser->uuid,
|
|
|
464 |
'email'=>$datosUser->email,
|
|
|
465 |
'first_name'=>$datosUser->first_name,
|
|
|
466 |
'last_name'=>$datosUser->last_name,
|
|
|
467 |
|
|
|
468 |
];
|
|
|
469 |
array_push($users, $user);
|
|
|
470 |
|
|
|
471 |
}
|
|
|
472 |
|
|
|
473 |
return new JsonModel([
|
|
|
474 |
'success' => true,
|
|
|
475 |
'data' => $users
|
|
|
476 |
|
|
|
477 |
]);
|
|
|
478 |
} else {
|
|
|
479 |
$data = [
|
|
|
480 |
'success' => false,
|
|
|
481 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
482 |
];
|
|
|
483 |
|
|
|
484 |
return new JsonModel($data);
|
|
|
485 |
}
|
|
|
486 |
|
|
|
487 |
return new JsonModel($data);
|
|
|
488 |
|
|
|
489 |
}
|
|
|
490 |
|
|
|
491 |
|
|
|
492 |
|
|
|
493 |
public function editAction(){
|
|
|
494 |
|
|
|
495 |
|
|
|
496 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
497 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
498 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
499 |
$request = $this->getRequest();
|
|
|
500 |
$uuid = $this->params()->fromRoute('id');
|
|
|
501 |
|
|
|
502 |
|
|
|
503 |
if(!$uuid) {
|
|
|
504 |
$data = [
|
|
|
505 |
'success' => false,
|
|
|
506 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
507 |
];
|
|
|
508 |
|
|
|
509 |
return new JsonModel($data);
|
|
|
510 |
}
|
|
|
511 |
|
|
|
512 |
$objective_uuid = $this->params()->fromRoute('objective_id');
|
|
|
513 |
$goal_uuid = $this->params()->fromRoute('goal_id');
|
|
|
514 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
515 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
516 |
$planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
|
|
|
517 |
$objective = $planningObjectivesAndGoalsObjectivesMapper->fetchOneByUuid($objective_uuid);
|
|
|
518 |
|
|
|
519 |
if (!$objective) {
|
|
|
520 |
$data = [
|
|
|
521 |
'success' => false,
|
|
|
522 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
523 |
];
|
|
|
524 |
|
|
|
525 |
|
|
|
526 |
return new JsonModel($data);
|
|
|
527 |
|
|
|
528 |
}else{
|
|
|
529 |
if($objective->company_id==$currentCompany->id){
|
|
|
530 |
$planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
|
|
|
531 |
$goals = $planningObjectivesAndGoalsGoalsMapper->fetchOneByUuid($goal_uuid);
|
|
|
532 |
|
|
|
533 |
if(!$goals){
|
|
|
534 |
$data = [
|
|
|
535 |
'success' => false,
|
|
|
536 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
537 |
];
|
|
|
538 |
|
|
|
539 |
|
|
|
540 |
return new JsonModel($data);
|
|
|
541 |
}
|
|
|
542 |
}else{
|
|
|
543 |
$data = [
|
|
|
544 |
'success' => false,
|
|
|
545 |
'data' => 'ERROR_UNAUTHORIZED',
|
|
|
546 |
];
|
|
|
547 |
|
|
|
548 |
return new JsonModel($data);
|
|
|
549 |
}
|
|
|
550 |
|
|
|
551 |
|
|
|
552 |
|
|
|
553 |
}
|
|
|
554 |
$planningObjectivesAndGoalsTaskMapper = PlanningObjectivesAndGoalsTaskMapper::getInstance($this->adapter);
|
|
|
555 |
$task = $planningObjectivesAndGoalsTaskMapper->fetchOneByUuid($uuid);
|
|
|
556 |
|
|
|
557 |
if (!$task) {
|
|
|
558 |
$data = [
|
|
|
559 |
'success' => false,
|
|
|
560 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
561 |
];
|
|
|
562 |
|
|
|
563 |
return new JsonModel($data);
|
|
|
564 |
}
|
|
|
565 |
|
|
|
566 |
|
|
|
567 |
if($request->isPost()) {
|
|
|
568 |
$form = new PlanningObjectivesAndGoalsTaskForm($this->adapter, $currentCompany->id);
|
|
|
569 |
$dataPost = $request->getPost()->toArray();
|
|
|
570 |
$dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : PlanningObjectivesAndGoalsTask::STATUS_INACTIVE;
|
|
|
571 |
$form->setData($dataPost);
|
|
|
572 |
|
|
|
573 |
if($form->isValid()) {
|
|
|
574 |
$dataPost = (array) $form->getData();
|
|
|
575 |
|
|
|
576 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
577 |
$hydrator->hydrate($dataPost, $task);
|
|
|
578 |
$result = $planningObjectivesAndGoalsTaskMapper->update($task);
|
|
|
579 |
|
|
|
580 |
if($result) {
|
|
|
581 |
|
|
|
582 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
583 |
$PlanningObjectivesAndGoalsTaskMemberMapper = PlanningObjectivesAndGoalsTaskMembersMapper::getInstance($this->adapter);
|
|
|
584 |
$PlanningObjectivesAndGoalsTaskMemberMapper->dissableMembersTask($task->id);
|
|
|
585 |
|
|
|
586 |
foreach( $dataPost['who'] as $record2){
|
|
|
587 |
$PlanningObjectivesAndGoalsTaskMember = new PlanningObjectivesAndGoalsTaskMembers();
|
|
|
588 |
$datosUser = $userMapper->fetchOneByUuid($record2);
|
|
|
589 |
$PlanningObjectivesAndGoalsTaskMember->task_id = $task->id;
|
|
|
590 |
$PlanningObjectivesAndGoalsTaskMember->user_id = $datosUser->id;
|
|
|
591 |
$PlanningObjectivesAndGoalsTaskMember->status = PlanningObjectivesAndGoalsTaskMembers::STATUS_ACTIVE;
|
|
|
592 |
$PlanningObjectivesAndGoalsTaskMemberMapper->insert($PlanningObjectivesAndGoalsTaskMember);
|
|
|
593 |
}
|
|
|
594 |
|
|
|
595 |
|
|
|
596 |
|
|
|
597 |
$this->logger->info('Se actualizo la tarea ' . $task->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
598 |
|
|
|
599 |
$data = [
|
|
|
600 |
'success' => true,
|
|
|
601 |
'data' => 'LABEL_RECORD_UPDATED'
|
|
|
602 |
];
|
|
|
603 |
} else {
|
|
|
604 |
$data = [
|
|
|
605 |
'success' => false,
|
|
|
606 |
'data' => $planningObjectivesAndGoalsTaskMapper->getError()
|
|
|
607 |
];
|
|
|
608 |
}
|
|
|
609 |
|
|
|
610 |
return new JsonModel($data);
|
|
|
611 |
|
|
|
612 |
} else {
|
|
|
613 |
$messages = [];
|
|
|
614 |
$form_messages = (array) $form->getMessages();
|
|
|
615 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
616 |
{
|
|
|
617 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
618 |
}
|
|
|
619 |
|
|
|
620 |
return new JsonModel([
|
|
|
621 |
'success' => false,
|
|
|
622 |
'data' => $messages
|
|
|
623 |
]);
|
|
|
624 |
}
|
|
|
625 |
}else if ($request->isGet()) {
|
|
|
626 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
627 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
628 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
629 |
$datosCompanyUser = $companyUserMapper->fetchAllByCompanyId($currentCompany->id);
|
|
|
630 |
|
|
|
631 |
$allUsers=[];
|
|
|
632 |
|
|
|
633 |
foreach($datosCompanyUser as $record){
|
|
|
634 |
$datosUser = $userMapper->fetchOne($record->user_id);
|
|
|
635 |
|
|
|
636 |
$allUser=[
|
|
|
637 |
'uuid'=>$datosUser->uuid,
|
|
|
638 |
'email'=>$datosUser->email,
|
|
|
639 |
'first_name'=>$datosUser->first_name,
|
|
|
640 |
'last_name'=>$datosUser->last_name,
|
|
|
641 |
|
|
|
642 |
];
|
|
|
643 |
array_push($allUsers, $allUser);
|
|
|
644 |
|
|
|
645 |
}
|
|
|
646 |
$PlanningObjectivesAndGoalsTaskMemberMapper = PlanningObjectivesAndGoalsTaskMembersMapper::getInstance($this->adapter);
|
|
|
647 |
$datosUsuarios = $PlanningObjectivesAndGoalsTaskMemberMapper->fetchAll($task->id);
|
|
|
648 |
$users=[];
|
|
|
649 |
foreach($datosUsuarios as $record){
|
|
|
650 |
$datosUser = $userMapper->fetchOne($record->user_id);
|
|
|
651 |
|
|
|
652 |
$user=[
|
|
|
653 |
'uuid'=>$datosUser->uuid,
|
|
|
654 |
];
|
|
|
655 |
array_push($users, $user);
|
|
|
656 |
}
|
|
|
657 |
|
|
|
658 |
$data = [
|
|
|
659 |
'success' => true,
|
|
|
660 |
'data' => $hydrator->extract($task),
|
|
|
661 |
'all_users'=> $allUsers,
|
|
|
662 |
'users'=> $users
|
|
|
663 |
];
|
|
|
664 |
|
|
|
665 |
return new JsonModel($data);
|
|
|
666 |
} else {
|
|
|
667 |
$data = [
|
|
|
668 |
'success' => false,
|
|
|
669 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
670 |
];
|
|
|
671 |
|
|
|
672 |
return new JsonModel($data);
|
|
|
673 |
}
|
|
|
674 |
|
|
|
675 |
return new JsonModel($data);
|
|
|
676 |
|
|
|
677 |
}
|
|
|
678 |
|
|
|
679 |
|
|
|
680 |
|
|
|
681 |
|
|
|
682 |
public function deleteAction(){
|
|
|
683 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
684 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
685 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
686 |
|
|
|
687 |
$request = $this->getRequest();
|
|
|
688 |
$uuid = $this->params()->fromRoute('id');
|
|
|
689 |
|
|
|
690 |
|
|
|
691 |
if (!$uuid) {
|
|
|
692 |
$data = [
|
|
|
693 |
'success' => false,
|
|
|
694 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
695 |
];
|
|
|
696 |
|
|
|
697 |
return new JsonModel($data);
|
|
|
698 |
}
|
|
|
699 |
$objective_uuid = $this->params()->fromRoute('objective_id');
|
|
|
700 |
$goal_uuid = $this->params()->fromRoute('goal_id');
|
|
|
701 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
702 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
703 |
$planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
|
|
|
704 |
$objective = $planningObjectivesAndGoalsObjectivesMapper->fetchOneByUuid($objective_uuid);
|
|
|
705 |
|
|
|
706 |
if (!$objective) {
|
|
|
707 |
$data = [
|
|
|
708 |
'success' => false,
|
|
|
709 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
710 |
];
|
|
|
711 |
return new JsonModel($data);
|
|
|
712 |
|
|
|
713 |
}else{
|
|
|
714 |
if($objective->company_id==$currentCompany->id){
|
|
|
715 |
$planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
|
|
|
716 |
$goals = $planningObjectivesAndGoalsGoalsMapper->fetchOneByUuid($goal_uuid);
|
|
|
717 |
|
|
|
718 |
if(!$goals){
|
|
|
719 |
$data = [
|
|
|
720 |
'success' => false,
|
|
|
721 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
722 |
];
|
|
|
723 |
|
|
|
724 |
|
|
|
725 |
return new JsonModel($data);
|
|
|
726 |
}
|
|
|
727 |
}else{
|
|
|
728 |
$data = [
|
|
|
729 |
'success' => false,
|
|
|
730 |
'data' => 'ERROR_UNAUTHORIZED',
|
|
|
731 |
];
|
|
|
732 |
|
|
|
733 |
return new JsonModel($data);
|
|
|
734 |
}
|
|
|
735 |
|
|
|
736 |
}
|
|
|
737 |
$planningObjectivesAndGoalsTaskMapper = PlanningObjectivesAndGoalsTaskMapper::getInstance($this->adapter);
|
|
|
738 |
$task = $planningObjectivesAndGoalsTaskMapper->fetchOneByUuid($uuid);
|
|
|
739 |
|
|
|
740 |
if (!$task) {
|
|
|
741 |
$data = [
|
|
|
742 |
'success' => false,
|
|
|
743 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
744 |
];
|
|
|
745 |
|
|
|
746 |
return new JsonModel($data);
|
|
|
747 |
}
|
|
|
748 |
|
|
|
749 |
|
|
|
750 |
if ($request->isPost()) {
|
|
|
751 |
|
|
|
752 |
|
|
|
753 |
$result = $planningObjectivesAndGoalsTaskMapper->delete($task->id);
|
|
|
754 |
if ($result) {
|
|
|
755 |
$this->logger->info('Se borro la tarea con el titulo ' . $task->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
756 |
|
|
|
757 |
$data = [
|
|
|
758 |
'success' => true,
|
|
|
759 |
'data' => 'LABEL_RECORD_DELETED'
|
|
|
760 |
];
|
|
|
761 |
} else {
|
|
|
762 |
|
|
|
763 |
$data = [
|
|
|
764 |
'success' => false,
|
|
|
765 |
'data' => $planningObjectivesAndGoalsTaskMapper->getError()
|
|
|
766 |
];
|
|
|
767 |
|
|
|
768 |
return new JsonModel($data);
|
|
|
769 |
}
|
|
|
770 |
} else {
|
|
|
771 |
$data = [
|
|
|
772 |
'success' => false,
|
|
|
773 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
774 |
];
|
|
|
775 |
|
|
|
776 |
return new JsonModel($data);
|
|
|
777 |
}
|
|
|
778 |
|
|
|
779 |
return new JsonModel($data);
|
|
|
780 |
}
|
|
|
781 |
|
|
|
782 |
|
|
|
783 |
|
|
|
784 |
|
|
|
785 |
}
|