blob: b288d08cb54e0693f00343c81c18ac91c4210a13 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
<?php
namespace JsonApi\Routes\Avatar;
use JsonApi\Errors\RecordNotFoundException;
trait AvatarHelpers
{
protected static function getAvatarClass(String $range_id, String $range_type, \User $user): Array
{
$has_perm = false;
$class = null;
if ($range_type === 'users') {
$has_perm = Authority::canUpdateAvatarOfUser($user);
$class = \Avatar::class;
} else if ($range_type === 'institutes') {
$inst = \Institute::find($range_id);
if ($inst) {
$has_perm = Authority::canUpdateAvatarOfInstitute($user, $inst);
$class = \InstituteAvatar::class;
}
} else if ($range_type === 'courses') {
$course = \Course::find($range_id);
if ($course) {
$has_perm = Authority::canUpdateAvatarOfSeminar($user, $course);
if ($course->isStudygroup()) {
$class = \StudygroupAvatar::class;
} else {
$class = \CourseAvatar::class;
}
}
} else {
throw new RecordNotFoundException();
}
return ['class' => $class, 'has_perm' => $has_perm];
}
}
|