6521 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace LeadersLinked\Library;
|
|
|
6 |
|
|
|
7 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
8 |
use LeadersLinked\Mapper\MyCoachCategoryMapper;
|
|
|
9 |
use LeadersLinked\Mapper\MyCoachCategoryUserMapper;
|
|
|
10 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
11 |
use LeadersLinked\Model\MyCoachCategory;
|
|
|
12 |
use LeadersLinked\Mapper\MyCoachQuestionMapper;
|
|
|
13 |
use LeadersLinked\Mapper\MyCoachQuestionCategoryMapper;
|
|
|
14 |
use LeadersLinked\Model\MyCoachCategoryUser;
|
|
|
15 |
use LeadersLinked\Mapper\MyCoachAnswerMapper;
|
|
|
16 |
|
|
|
17 |
class MyCoachAccessControl
|
|
|
18 |
{
|
|
|
19 |
|
|
|
20 |
/**
|
|
|
21 |
*
|
|
|
22 |
* @var MyCoachAccessControl
|
|
|
23 |
*/
|
|
|
24 |
private static $_instance;
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
*
|
|
|
29 |
* @var AdapterInterface
|
|
|
30 |
*/
|
|
|
31 |
private $adapter;
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
*
|
|
|
35 |
* @param AdapterInterface $adapter
|
|
|
36 |
*/
|
|
|
37 |
public function __construct($adapter)
|
|
|
38 |
{
|
|
|
39 |
$this->adapter = $adapter;
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
*
|
|
|
44 |
* @param AdapterInterface $adapter
|
|
|
45 |
* @return MyCoachAccessControl
|
|
|
46 |
*/
|
|
|
47 |
public static function getInstance($adapter)
|
|
|
48 |
{
|
|
|
49 |
if(self::$_instance == null) {
|
|
|
50 |
self::$_instance = new MyCoachAccessControl($adapter);
|
|
|
51 |
}
|
|
|
52 |
return self::$_instance;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
/**
|
|
|
56 |
*
|
|
|
57 |
* @param int $user_id
|
|
|
58 |
* @param int $network_id
|
|
|
59 |
* @return int[]
|
|
|
60 |
*/
|
|
|
61 |
public function getCategoryIdsWithAccess($user_id, $network_id)
|
|
|
62 |
{
|
|
|
63 |
$category_ids = [];
|
|
|
64 |
|
|
|
65 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
$selectPublic = $queryMapper->getSql()->select();
|
|
|
69 |
$selectPublic->columns(['id']);
|
|
|
70 |
$selectPublic->from(['c' => MyCoachCategoryMapper::_TABLE]);
|
|
|
71 |
$selectPublic->where->equalTo('c.network_id', $network_id);
|
|
|
72 |
$selectPublic->where->equalTo('c.privacy', MyCoachCategory::PRIVACY_PUBLIC);
|
|
|
73 |
$selectPublic->where->equalTo('c.status', MyCoachCategory::STATUS_ACTIVE);
|
|
|
74 |
|
|
|
75 |
$select = $queryMapper->getSql()->select();
|
|
|
76 |
$select->columns(['id']);
|
|
|
77 |
$select->from(['c' => MyCoachCategoryMapper::_TABLE]);
|
|
|
78 |
$select->join(['cu' => MyCoachCategoryUserMapper::_TABLE], 'c.id = cu.category_id', []);
|
|
|
79 |
$select->where->equalTo('cu.user_id', $user_id);
|
|
|
80 |
$select->where->equalTo('c.privacy', MyCoachCategory::PRIVACY_COMPANY);
|
|
|
81 |
$select->where->equalTo('c.status', MyCoachCategory::STATUS_ACTIVE);
|
|
|
82 |
$select->combine( $selectPublic );
|
|
|
83 |
|
|
|
84 |
// echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
$records = $queryMapper->fetchAll($select);
|
|
|
88 |
foreach($records as $record)
|
|
|
89 |
{
|
|
|
90 |
array_push($category_ids, $record['id']);
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
return array_unique($category_ids);
|
|
|
94 |
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
/**
|
|
|
98 |
*
|
|
|
99 |
* @param int $user_id
|
|
|
100 |
* @param int $network_id
|
|
|
101 |
* @return array
|
|
|
102 |
*/
|
|
|
103 |
public function getCategoriesWithAccessToFormSelect($user_id, $network_id)
|
|
|
104 |
{
|
|
|
105 |
$categories = [];
|
|
|
106 |
|
|
|
107 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
$selectPublic = $queryMapper->getSql()->select();
|
|
|
111 |
$selectPublic->columns(['uuid', 'name']);
|
|
|
112 |
$selectPublic->from(['c' => MyCoachCategoryMapper::_TABLE]);
|
|
|
113 |
$selectPublic->where->equalTo('c.network_id', $network_id);
|
|
|
114 |
$selectPublic->where->equalTo('c.privacy', MyCoachCategory::PRIVACY_PUBLIC);
|
|
|
115 |
$selectPublic->where->equalTo('c.status', MyCoachCategory::STATUS_ACTIVE);
|
|
|
116 |
|
|
|
117 |
$select = $queryMapper->getSql()->select();
|
|
|
118 |
$select->columns(['uuid', 'name']);
|
|
|
119 |
$select->from(['c' => MyCoachCategoryMapper::_TABLE]);
|
|
|
120 |
$select->join(['cu' => MyCoachCategoryUserMapper::_TABLE], 'c.id = cu.category_id', []);
|
|
|
121 |
$select->where->equalTo('cu.user_id', $user_id);
|
|
|
122 |
$select->combine( $selectPublic );
|
|
|
123 |
|
|
|
124 |
// echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
$records = $queryMapper->fetchAll($select);
|
|
|
128 |
foreach($records as $record)
|
|
|
129 |
{
|
|
|
130 |
$categories[ $record['uuid'] ] = $record['name'];
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
uksort($categories, function ($a, $b) {
|
|
|
135 |
return $a <=> $b;
|
|
|
136 |
});
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
return $categories;
|
|
|
140 |
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
/**
|
|
|
145 |
*
|
|
|
146 |
* @param int $user_id
|
|
|
147 |
* @return int[]
|
|
|
148 |
*/
|
|
|
149 |
public function getCategoryIdsWithEdition($user_id)
|
|
|
150 |
{
|
|
|
151 |
$category_ids = [];
|
|
|
152 |
|
|
|
153 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
154 |
|
|
|
155 |
|
|
|
156 |
$select = $queryMapper->getSql()->select();
|
|
|
157 |
$select->columns(['id']);
|
|
|
158 |
$select->from(['c' => MyCoachCategoryMapper::_TABLE]);
|
|
|
159 |
$select->join(['cu' => MyCoachCategoryUserMapper::_TABLE], 'c.id = cu.category_id', []);
|
|
|
160 |
$select->where->equalTo('cu.user_id', $user_id);
|
6547 |
efrain |
161 |
//$select->where->equalTo('c.privacy', MyCoachCategory::PRIVACY_COMPANY);
|
6521 |
efrain |
162 |
$select->where->equalTo('c.status', MyCoachCategory::STATUS_ACTIVE);
|
|
|
163 |
$select->where->in('cu.role', [MyCoachCategoryUser::ROLE_EDITOR, MyCoachCategoryUser::ROLE_ADMINISTRATOR]);
|
|
|
164 |
|
|
|
165 |
|
6547 |
efrain |
166 |
//echo $select->getSqlString($this->adapter->platform); exit;
|
6521 |
efrain |
167 |
|
|
|
168 |
|
|
|
169 |
$records = $queryMapper->fetchAll($select);
|
|
|
170 |
foreach($records as $record)
|
|
|
171 |
{
|
|
|
172 |
array_push($category_ids, $record['id']);
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
return array_unique($category_ids);
|
|
|
176 |
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
/**
|
|
|
180 |
*
|
|
|
181 |
* @param int $user_id
|
|
|
182 |
* @param int|string $category_id
|
|
|
183 |
* @param int $network_id
|
|
|
184 |
* @param string $message_error
|
|
|
185 |
* return boolean
|
|
|
186 |
*/
|
|
|
187 |
public function hasAccessForCategory($user_id, $category_id, $network_id, &$message_error)
|
|
|
188 |
{
|
|
|
189 |
$myCoachCategoryMapper = MyCoachCategoryMapper::getInstance($this->adapter);
|
|
|
190 |
|
|
|
191 |
if(is_numeric($category_id)) {
|
|
|
192 |
$myCoachCategory = $myCoachCategoryMapper->fetchOneByIdAndNetworkId($category_id, $network_id);
|
|
|
193 |
} else {
|
|
|
194 |
$myCoachCategory = $myCoachCategoryMapper->fetchOneByUuidAndNetworkId($category_id, $network_id);
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
if(!$myCoachCategory) {
|
|
|
198 |
$message_error ='ERROR_MY_COACH_CATEGORY_NOT_FOUND';
|
|
|
199 |
return false;
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
if($myCoachCategory->status == MyCoachCategory::STATUS_INACTIVE) {
|
|
|
203 |
$message_error = 'ERROR_MY_COACH_CATEGORY_IS_INACTIVE';
|
|
|
204 |
return false;
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
if($myCoachCategory->privacy == MyCoachCategory::PRIVACY_COMPANY) {
|
|
|
208 |
|
|
|
209 |
$myCoachCategoryUserMapper = MyCoachCategoryUserMapper::getInstance($this->adapter);
|
|
|
210 |
$myCoachCategoryUser = $myCoachCategoryUserMapper->fetchOneByCategoryIdAndUserId($myCoachCategory->id, $user_id);
|
|
|
211 |
|
|
|
212 |
if(!$myCoachCategoryUser) {
|
|
|
213 |
$message_error = 'ERROR_MY_COACH_CATEGORY_UNAUTHORIZED';
|
|
|
214 |
return false;
|
|
|
215 |
}
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
return true;
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
/**
|
|
|
222 |
*
|
|
|
223 |
* @param int $user_id
|
|
|
224 |
* @param int|string $question_id
|
|
|
225 |
* @param int $network_id
|
|
|
226 |
* @param string $message_error
|
|
|
227 |
* return boolean
|
|
|
228 |
*/
|
|
|
229 |
public function hasAccessViewQuestion($user_id, $question_id, $network_id, &$message_error)
|
|
|
230 |
{
|
|
|
231 |
|
|
|
232 |
$myCoachQuestionMapper = MyCoachQuestionMapper::getInstance($this->adapter);
|
|
|
233 |
|
|
|
234 |
if(is_numeric($question_id)) {
|
|
|
235 |
$myCoachQuestion = $myCoachQuestionMapper->fetchOneByIdAndNetworkId($question_id, $network_id);
|
|
|
236 |
|
|
|
237 |
} else {
|
|
|
238 |
$myCoachQuestion = $myCoachQuestionMapper->fetchOneByUuidAndNetworkId($question_id, $network_id);
|
|
|
239 |
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
|
|
|
243 |
|
|
|
244 |
if(!$myCoachQuestion) {
|
|
|
245 |
$message_error = 'ERROR_MY_COACH_QUESTION_NOT_FOUND';
|
|
|
246 |
return false;
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
|
|
|
250 |
$category_ids = $this->getCategoryIdsWithAccess($user_id, $network_id);
|
|
|
251 |
|
|
|
252 |
$myCoachQuestionCategoryMapper = MyCoachQuestionCategoryMapper::getInstance($this->adapter);
|
|
|
253 |
$records = $myCoachQuestionCategoryMapper->fetchAllByQuestionId($myCoachQuestion->id);
|
|
|
254 |
|
|
|
255 |
foreach($records as $record)
|
|
|
256 |
{
|
|
|
257 |
if(in_array($record->category_id, $category_ids)) {
|
|
|
258 |
return true;
|
|
|
259 |
}
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
|
|
|
263 |
$message_error = 'ERROR_MY_COACH_QUESTION_UNAUTHORIZED';
|
|
|
264 |
return false;
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
|
|
|
268 |
/**
|
|
|
269 |
*
|
|
|
270 |
* @param int $user_id
|
|
|
271 |
* @param int|string $question_id
|
|
|
272 |
* @param int $network_id
|
|
|
273 |
* @param string $message_error
|
|
|
274 |
* return boolean
|
|
|
275 |
*/
|
|
|
276 |
public function hasAccessEditQuestion($user_id, $question_id, $network_id, &$message_error)
|
|
|
277 |
{
|
|
|
278 |
|
|
|
279 |
$myCoachQuestionMapper = MyCoachQuestionMapper::getInstance($this->adapter);
|
|
|
280 |
|
|
|
281 |
if(is_numeric($question_id)) {
|
|
|
282 |
$myCoachQuestion = $myCoachQuestionMapper->fetchOneByIdAndNetworkId($question_id, $network_id);
|
|
|
283 |
} else {
|
|
|
284 |
$myCoachQuestion = $myCoachQuestionMapper->fetchOneByUuidAndNetworkId($question_id, $network_id);
|
|
|
285 |
}
|
|
|
286 |
|
|
|
287 |
|
|
|
288 |
|
|
|
289 |
|
|
|
290 |
if(!$myCoachQuestion) {
|
|
|
291 |
$message_error = 'ERROR_MY_COACH_QUESTION_NOT_FOUND';
|
|
|
292 |
return false;
|
|
|
293 |
}
|
|
|
294 |
|
|
|
295 |
|
|
|
296 |
if($myCoachQuestion->user_id == $user_id) {
|
|
|
297 |
|
|
|
298 |
$myCoachAnswerMapper = MyCoachAnswerMapper::getInstance($this->adapter);
|
|
|
299 |
$total = $myCoachAnswerMapper->fetchCountByMyCoachQuestionId($myCoachQuestion->id);
|
|
|
300 |
|
|
|
301 |
return $total == 0 ? true : false;
|
|
|
302 |
}
|
|
|
303 |
|
|
|
304 |
$message_error = 'ERROR_MY_COACH_QUESTION_UNAUTHORIZED';
|
|
|
305 |
return false;
|
|
|
306 |
}
|
|
|
307 |
|
|
|
308 |
|
|
|
309 |
/**
|
|
|
310 |
*
|
|
|
311 |
* @param int $user_id
|
|
|
312 |
* @param int|string $question_id
|
|
|
313 |
* @param int $network_id
|
|
|
314 |
* @param string $message_error
|
|
|
315 |
* return boolean
|
|
|
316 |
*/
|
|
|
317 |
public function hasAccessDeleteQuestion($user_id, $question_id, $network_id, &$message_error)
|
|
|
318 |
{
|
|
|
319 |
|
|
|
320 |
$myCoachQuestionMapper = MyCoachQuestionMapper::getInstance($this->adapter);
|
|
|
321 |
|
|
|
322 |
if(is_numeric($question_id)) {
|
|
|
323 |
$myCoachQuestion = $myCoachQuestionMapper->fetchOneByIdAndNetworkId($question_id, $network_id);
|
|
|
324 |
} else {
|
|
|
325 |
$myCoachQuestion = $myCoachQuestionMapper->fetchOneByUuidAndNetworkId($question_id, $network_id);
|
|
|
326 |
}
|
|
|
327 |
|
|
|
328 |
|
|
|
329 |
|
|
|
330 |
|
|
|
331 |
if(!$myCoachQuestion) {
|
|
|
332 |
$message_error = 'ERROR_MY_COACH_QUESTION_NOT_FOUND';
|
|
|
333 |
return false;
|
|
|
334 |
}
|
|
|
335 |
|
|
|
336 |
$category_ids = $this->getCategoryIdsWithEdition($user_id);
|
|
|
337 |
|
|
|
338 |
$myCoachQuestionCategoryMapper = MyCoachQuestionCategoryMapper::getInstance($this->adapter);
|
|
|
339 |
$records = $myCoachQuestionCategoryMapper->fetchAllByQuestionId($myCoachQuestion->id);
|
|
|
340 |
|
|
|
341 |
foreach($records as $record)
|
|
|
342 |
{
|
|
|
343 |
if(in_array($record->category_id, $category_ids)) {
|
|
|
344 |
return true;
|
|
|
345 |
}
|
|
|
346 |
}
|
|
|
347 |
|
|
|
348 |
if($myCoachQuestion->user_id == $user_id) {
|
|
|
349 |
$myCoachAnswerMapper = MyCoachAnswerMapper::getInstance($this->adapter);
|
|
|
350 |
$total = $myCoachAnswerMapper->fetchCountByMyCoachQuestionId($myCoachQuestion->id);
|
|
|
351 |
|
|
|
352 |
return $total == 0 ? true : false;
|
|
|
353 |
}
|
|
|
354 |
|
|
|
355 |
|
|
|
356 |
|
|
|
357 |
|
|
|
358 |
$message_error = 'ERROR_MY_COACH_QUESTION_UNAUTHORIZED';
|
|
|
359 |
return false;
|
|
|
360 |
}
|
6547 |
efrain |
361 |
|
6521 |
efrain |
362 |
|
6547 |
efrain |
363 |
|
|
|
364 |
|
6521 |
efrain |
365 |
/**
|
|
|
366 |
*
|
|
|
367 |
* @param int $user_id
|
|
|
368 |
* @param int|string $question_id
|
|
|
369 |
* @param int $network_id
|
|
|
370 |
* @param string $message_error
|
|
|
371 |
* return boolean
|
|
|
372 |
*/
|
|
|
373 |
public function hasAccessAnswerQuestion($user_id, $question_id, $network_id, &$message_error)
|
|
|
374 |
{
|
|
|
375 |
|
|
|
376 |
|
|
|
377 |
$myCoachQuestionMapper = MyCoachQuestionMapper::getInstance($this->adapter);
|
|
|
378 |
|
|
|
379 |
if(is_numeric($question_id)) {
|
|
|
380 |
$myCoachQuestion = $myCoachQuestionMapper->fetchOneByIdAndNetworkId($question_id, $network_id);
|
|
|
381 |
} else {
|
|
|
382 |
$myCoachQuestion = $myCoachQuestionMapper->fetchOneByUuidAndNetworkId($question_id, $network_id);
|
|
|
383 |
|
|
|
384 |
}
|
|
|
385 |
|
6547 |
efrain |
386 |
|
|
|
387 |
|
|
|
388 |
|
6521 |
efrain |
389 |
if(!$myCoachQuestion) {
|
|
|
390 |
$message_error = 'ERROR_MY_COACH_QUESTION_NOT_FOUND';
|
|
|
391 |
return false;
|
|
|
392 |
}
|
|
|
393 |
|
|
|
394 |
|
|
|
395 |
$category_ids = $this->getCategoryIdsWithEdition($user_id);
|
|
|
396 |
|
|
|
397 |
|
|
|
398 |
$myCoachQuestionCategoryMapper = MyCoachQuestionCategoryMapper::getInstance($this->adapter);
|
|
|
399 |
$records = $myCoachQuestionCategoryMapper->fetchAllByQuestionId($myCoachQuestion->id);
|
|
|
400 |
|
6547 |
efrain |
401 |
|
6521 |
efrain |
402 |
foreach($records as $record)
|
|
|
403 |
{
|
|
|
404 |
if(in_array($record->category_id, $category_ids)) {
|
|
|
405 |
return true;
|
|
|
406 |
}
|
|
|
407 |
}
|
|
|
408 |
|
|
|
409 |
|
|
|
410 |
$message_error = 'ERROR_MY_COACH_QUESTION_UNAUTHORIZED';
|
|
|
411 |
return false;
|
|
|
412 |
}
|
|
|
413 |
|
|
|
414 |
/**
|
|
|
415 |
*
|
|
|
416 |
* @param int $user_id
|
|
|
417 |
* @param int|string $answer_id
|
|
|
418 |
* @param int $network_id
|
|
|
419 |
* @param string $message_error
|
|
|
420 |
* return boolean
|
|
|
421 |
*/
|
|
|
422 |
public function hasAccessViewAnswer($user_id, $answer_id, $network_id, &$message_error)
|
|
|
423 |
{
|
|
|
424 |
|
|
|
425 |
$myCoachAnswerMapper = MyCoachAnswerMapper::getInstance($this->adapter);
|
|
|
426 |
if(is_numeric($answer_id)) {
|
|
|
427 |
$myCoachAnswer = $myCoachAnswerMapper->fetchOne($answer_id);
|
|
|
428 |
} else {
|
|
|
429 |
$myCoachAnswer = $myCoachAnswerMapper->fetchOneByUuid($answer_id);
|
|
|
430 |
|
|
|
431 |
}
|
|
|
432 |
|
|
|
433 |
|
|
|
434 |
|
|
|
435 |
if(!$myCoachAnswer) {
|
|
|
436 |
$message_error = 'ERROR_MY_COACH_ANSWER_NOT_FOUND';
|
|
|
437 |
return false;
|
|
|
438 |
}
|
|
|
439 |
|
|
|
440 |
$category_ids = $this->getCategoryIdsWithAccess($user_id, $network_id);
|
|
|
441 |
|
|
|
442 |
|
|
|
443 |
|
|
|
444 |
$myCoachQuestionCategoryMapper = MyCoachQuestionCategoryMapper::getInstance($this->adapter);
|
|
|
445 |
$records = $myCoachQuestionCategoryMapper->fetchAllByQuestionId($myCoachAnswer->question_id);
|
|
|
446 |
|
|
|
447 |
foreach($records as $record)
|
|
|
448 |
{
|
|
|
449 |
if(in_array($record->category_id, $category_ids)) {
|
|
|
450 |
return true;
|
|
|
451 |
}
|
|
|
452 |
}
|
|
|
453 |
|
|
|
454 |
|
|
|
455 |
$message_error = 'ERROR_MY_COACH_QUESTION_UNAUTHORIZED';
|
|
|
456 |
return false;
|
|
|
457 |
}
|
|
|
458 |
|
|
|
459 |
|
|
|
460 |
/**
|
|
|
461 |
*
|
|
|
462 |
* @param int $user_id
|
|
|
463 |
* @param int|string $answer_id
|
|
|
464 |
* @param int $network_id
|
|
|
465 |
* @param string $message_error
|
|
|
466 |
* return boolean
|
|
|
467 |
*/
|
|
|
468 |
public function hasAccessEditOrDeleteAnswer($user_id, $answer_id, $network_id, &$message_error)
|
|
|
469 |
{
|
|
|
470 |
$myCoachAnswerMapper = MyCoachAnswerMapper::getInstance($this->adapter);
|
|
|
471 |
|
|
|
472 |
if(is_numeric($answer_id)) {
|
|
|
473 |
$myCoachAnswer = $myCoachAnswerMapper->fetchOne($answer_id);
|
|
|
474 |
} else {
|
|
|
475 |
$myCoachAnswer = $myCoachAnswerMapper->fetchOneByUuid($answer_id);
|
|
|
476 |
}
|
6547 |
efrain |
477 |
|
6521 |
efrain |
478 |
|
|
|
479 |
if(!$myCoachAnswer) {
|
|
|
480 |
$message_error = 'ERROR_MY_COACH_ANSWER_NOT_FOUND';
|
|
|
481 |
return false;
|
|
|
482 |
}
|
|
|
483 |
|
|
|
484 |
|
|
|
485 |
$myCoachQuestionMapper = MyCoachQuestionMapper::getInstance($this->adapter);
|
6547 |
efrain |
486 |
$myCoachQuestion = $myCoachQuestionMapper->fetchOneByIdAndNetworkId($myCoachAnswer->question_id, $network_id);
|
6521 |
efrain |
487 |
|
|
|
488 |
|
|
|
489 |
$category_ids = $this->getCategoryIdsWithEdition($user_id);
|
|
|
490 |
|
|
|
491 |
$myCoachCategoryUserMapper = MyCoachCategoryUserMapper::getInstance($this->adapter);
|
|
|
492 |
$myCoachQuestionCategoryMapper = MyCoachQuestionCategoryMapper::getInstance($this->adapter);
|
|
|
493 |
$records = $myCoachQuestionCategoryMapper->fetchAllByQuestionId($myCoachQuestion->id);
|
6547 |
efrain |
494 |
|
6521 |
efrain |
495 |
$ok = false;
|
|
|
496 |
$role = MyCoachCategoryUser::ROLE_USER;
|
|
|
497 |
foreach($records as $record)
|
|
|
498 |
{
|
|
|
499 |
if(in_array($record->category_id, $category_ids)) {
|
|
|
500 |
$ok = true;
|
|
|
501 |
|
|
|
502 |
$myCoachCategoryUser = $myCoachCategoryUserMapper->fetchOneByCategoryIdAndUserId($record->category_id, $user_id);
|
|
|
503 |
if($myCoachCategoryUser) {
|
|
|
504 |
|
|
|
505 |
if($myCoachCategoryUser->role == MyCoachCategoryUser::ROLE_EDITOR && $role == MyCoachCategoryUser::ROLE_USER)
|
|
|
506 |
{
|
|
|
507 |
$role = MyCoachCategoryUser::ROLE_EDITOR;
|
|
|
508 |
}
|
|
|
509 |
if($myCoachCategoryUser->role == MyCoachCategoryUser::ROLE_ADMINISTRATOR && $role != MyCoachCategoryUser::ROLE_ADMINISTRATOR)
|
|
|
510 |
{
|
|
|
511 |
$role = MyCoachCategoryUser::ROLE_ADMINISTRATOR;
|
|
|
512 |
}
|
|
|
513 |
}
|
|
|
514 |
|
|
|
515 |
}
|
|
|
516 |
}
|
|
|
517 |
|
6547 |
efrain |
518 |
if(!$ok) {
|
6521 |
efrain |
519 |
$message_error = 'ERROR_MY_COACH_QUESTION_UNAUTHORIZED';
|
|
|
520 |
return false;
|
|
|
521 |
}
|
|
|
522 |
|
|
|
523 |
if($myCoachAnswer->user_id == $user_id || $role == MyCoachCategoryUser::ROLE_ADMINISTRATOR) {
|
|
|
524 |
return true;
|
|
|
525 |
} else {
|
|
|
526 |
$message_error = 'ERROR_MY_COACH_ANSWER_UNAUTHORIZED';
|
|
|
527 |
return false;
|
|
|
528 |
|
|
|
529 |
}
|
|
|
530 |
}
|
|
|
531 |
}
|