|
1
|
|
|
<?php |
|
2
|
|
|
namespace keeko\core\model; |
|
3
|
|
|
|
|
4
|
|
|
use keeko\core\model\Base\User as BaseUser; |
|
5
|
|
|
use keeko\core\serializer\UserSerializer; |
|
6
|
|
|
use keeko\framework\model\ActivityObjectInterface; |
|
7
|
|
|
use keeko\framework\model\ApiModelInterface; |
|
8
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Skeleton subclass for representing a row from the 'kk_user' table. |
|
12
|
|
|
* |
|
13
|
|
|
* You should add additional methods to this class to meet the |
|
14
|
|
|
* application requirements. This class will only be generated as |
|
15
|
|
|
* long as it does not already exist in the output directory. |
|
16
|
|
|
*/ |
|
17
|
|
|
class User extends BaseUser implements ApiModelInterface { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
*/ |
|
21
|
|
|
private static $serializer; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @return UserSerializer |
|
25
|
|
|
*/ |
|
26
|
|
|
public static function getSerializer() { |
|
27
|
|
|
if (self::$serializer === null) { |
|
28
|
|
|
self::$serializer = new UserSerializer(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
return self::$serializer; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Returns whether this user is a guest |
|
36
|
|
|
* |
|
37
|
|
|
* @return boolean |
|
38
|
|
|
*/ |
|
39
|
|
|
public function isGuest() { |
|
40
|
|
|
return $this->getId() == -1; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param array $activity |
|
45
|
|
|
*/ |
|
46
|
|
|
public function newActivity(array $activity) { |
|
47
|
|
|
$resolver = new OptionsResolver(); |
|
48
|
|
|
$resolver->setRequired(['verb', 'object']); |
|
49
|
|
|
$resolver->setDefined(['target']); |
|
50
|
|
|
$resolver->setAllowedTypes('target', ['keeko\\framework\\model\\ActivityObjectInterface', 'keeko\\core\\model\\ActivityObject']); |
|
51
|
|
|
$resolver->setAllowedTypes('object', ['keeko\\framework\\model\\ActivityObjectInterface', 'keeko\\core\\model\\ActivityObject']); |
|
52
|
|
|
$options = $resolver->resolve($activity); |
|
53
|
|
|
$obj = new Activity(); |
|
54
|
|
|
$obj->setActor($this); |
|
55
|
|
|
$obj->setVerb($options['verb']); |
|
56
|
|
|
$obj->setObject($this->getActivityObject($options['object'], true)); |
|
57
|
|
|
if (isset($options['target'])) { |
|
58
|
|
|
$obj->setTarget($this->getActivityObject($options['target'])); |
|
59
|
|
|
} |
|
60
|
|
|
$obj->save(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param ActivityObject $ao |
|
65
|
|
|
* @return ActivityObject |
|
66
|
|
|
*/ |
|
67
|
|
|
private function findActivityObject(ActivityObject $ao, $isObject) { |
|
68
|
|
|
$q = ActivityObjectQuery::create() |
|
69
|
|
|
->filterByClassName($ao->getClassName()) |
|
70
|
|
|
->filterByType($ao->getType()) |
|
71
|
|
|
->filterByReferenceId($ao->getReferenceId()); |
|
72
|
|
|
|
|
73
|
|
|
if (method_exists($ao, 'getVersion') && $isObject) { |
|
74
|
|
|
$version = $ao->getVersion(); |
|
75
|
|
|
if (!empty($version)) { |
|
76
|
|
|
$q = $q->filterByVersion($version); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
$result = $q->findOne(); |
|
80
|
|
|
if ($result) { |
|
81
|
|
|
$result->setDisplayName($ao->getDisplayName()); |
|
82
|
|
|
return $result; |
|
83
|
|
|
} |
|
84
|
|
|
return $ao; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param mixed $obj |
|
89
|
|
|
* @return ActivityObject |
|
90
|
|
|
*/ |
|
91
|
|
|
private function getActivityObject($obj, $isObject = false) { |
|
92
|
|
|
if ($obj instanceof ActivityObject) { |
|
93
|
|
|
return $obj; |
|
94
|
|
|
} |
|
95
|
|
|
if ($obj instanceof ActivityObjectInterface) { |
|
96
|
|
|
return $this->findActivityObject($obj->toActivityObject(), $isObject); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|