1
|
|
|
<?php |
2
|
|
|
namespace keeko\core\model; |
3
|
|
|
|
4
|
|
|
use keeko\core\model\Base\User as BaseUser; |
5
|
|
|
use keeko\core\model\serializer\UserSerializer; |
6
|
|
|
use keeko\framework\model\ApiModelInterface; |
7
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Skeleton subclass for representing a row from the 'kk_user' table. |
11
|
|
|
* |
12
|
|
|
* You should add additional methods to this class to meet the |
13
|
|
|
* application requirements. This class will only be generated as |
14
|
|
|
* long as it does not already exist in the output directory. |
15
|
|
|
*/ |
16
|
|
|
class User extends BaseUser implements ApiModelInterface { |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
*/ |
20
|
|
|
private static $serializer; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
*/ |
24
|
|
|
public static function getSerializer() { |
|
|
|
|
25
|
|
|
if (self::$serializer === null) { |
26
|
|
|
self::$serializer = new UserSerializer(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
return self::$serializer; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function newActivity(array $activity) { |
33
|
|
|
$resolver = new OptionsResolver(); |
34
|
|
|
$resolver->setRequired(['verb', 'object']); |
35
|
|
|
$resolver->setOptional(['target']); |
|
|
|
|
36
|
|
|
$resolver->setAllowedTypes([ |
|
|
|
|
37
|
|
|
'target' => ['keeko\framework\model\ActivityObjectInterface', 'keeko\core\model\ActivityObject'], |
38
|
|
|
'object' => ['keeko\framework\model\ActivityObjectInterface', 'keeko\core\model\ActivityObject'] |
39
|
|
|
]); |
40
|
|
|
$options = $resolver->resolve($activity); |
41
|
|
|
|
42
|
|
|
$obj = new Activity(); |
43
|
|
|
$obj->setActor($this); |
44
|
|
|
$obj->setVerb($options['verb']); |
45
|
|
|
$obj->setObject($this->getActivityObject($options['object'])); |
46
|
|
|
if (isset($options['target'])) { |
47
|
|
|
$obj->setTarget($this->getActivityObject($options['target'])); |
48
|
|
|
} |
49
|
|
|
$obj->save(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
private function getActivityObject($obj) { |
|
|
|
|
53
|
|
|
if ($obj instanceof ActivityObject) { |
54
|
|
|
return $obj; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if ($obj instanceof ActivityObjectInterface) { |
|
|
|
|
58
|
|
|
return $this->findActivityObject($obj->toActivityObject()); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
private function findActivityObject(ActivityObject $ao) { |
|
|
|
|
63
|
|
|
$q = ActivityObjectQuery::create() |
64
|
|
|
->filterByClassName($ao->getClassName()) |
65
|
|
|
->filterByType($ao->getType()) |
66
|
|
|
->filterByReferenceId($ao->getId()); |
67
|
|
|
|
68
|
|
|
if (method_exists($ao, 'getVersion')) { |
69
|
|
|
$version = $ao->getVersion(); |
70
|
|
|
if (!empty($version)) { |
71
|
|
|
$q = $q->filterByVersion($version); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$result = $q->findOne(); |
76
|
|
|
if ($result) { |
77
|
|
|
$result->setDisplayName($ao->getDisplayName()); |
78
|
|
|
return $result; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $ao; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.