|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace keeko\core\model; |
|
4
|
|
|
|
|
5
|
|
|
use keeko\core\model\Base\User as BaseUser; |
|
6
|
|
|
use keeko\core\model\types\ActivityObjectInterface; |
|
7
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
8
|
|
|
use keeko\core\model\types\APIModelInterface; |
|
9
|
|
|
use keeko\core\model\serializer\UserSerializer; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Skeleton subclass for representing a row from the 'kk_user' table. |
|
13
|
|
|
* |
|
14
|
|
|
* |
|
15
|
|
|
* |
|
16
|
|
|
* You should add additional methods to this class to meet the |
|
17
|
|
|
* application requirements. This class will only be generated as |
|
18
|
|
|
* long as it does not already exist in the output directory. |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
class User extends BaseUser implements APIModelInterface { |
|
22
|
|
|
|
|
23
|
|
|
private static $serializer = null; |
|
24
|
|
|
|
|
25
|
|
|
public static function getSerializer() { |
|
26
|
|
|
if (self::$serializer === null) { |
|
27
|
|
|
self::$serializer = new UserSerializer(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
return self::$serializer; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function newActivity(array $activity) { |
|
34
|
|
|
$resolver = new OptionsResolver(); |
|
35
|
|
|
$resolver->setRequired(['verb', 'object']); |
|
36
|
|
|
$resolver->setOptional(['target']); |
|
|
|
|
|
|
37
|
|
|
$resolver->setAllowedTypes([ |
|
|
|
|
|
|
38
|
|
|
'target' => ['keeko\core\model\types\ActivityObjectInterface', 'keeko\core\model\ActivityObject'], |
|
39
|
|
|
'object' => ['keeko\core\model\types\ActivityObjectInterface', 'keeko\core\model\ActivityObject'] |
|
40
|
|
|
]); |
|
41
|
|
|
$options = $resolver->resolve($activity); |
|
42
|
|
|
|
|
43
|
|
|
$obj = new Activity(); |
|
44
|
|
|
$obj->setActor($this); |
|
45
|
|
|
$obj->setVerb($options['verb']); |
|
46
|
|
|
$obj->setObject($this->getActivityObject($options['object'])); |
|
47
|
|
|
|
|
48
|
|
|
if (isset($options['target'])) { |
|
49
|
|
|
$obj->setTarget($this->getActivityObject($options['target'])); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$obj->save(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
private function getActivityObject($obj) { |
|
|
|
|
|
|
56
|
|
|
if ($obj instanceof ActivityObject) { |
|
57
|
|
|
return $obj; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
if ($obj instanceof ActivityObjectInterface) { |
|
61
|
|
|
return $this->findActivityObject($obj->toActivityObject()); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
private function findActivityObject(ActivityObject $ao) { |
|
|
|
|
|
|
66
|
|
|
$q = ActivityObjectQuery::create() |
|
67
|
|
|
->filterByClassName($ao->getClassName()) |
|
68
|
|
|
->filterByType($ao->getType()) |
|
69
|
|
|
->filterByReferenceId($ao->getId()); |
|
70
|
|
|
|
|
71
|
|
|
if (method_exists($ao, 'getVersion')) { |
|
72
|
|
|
$version = $ao->getVersion(); |
|
73
|
|
|
if (!empty($version)) { |
|
74
|
|
|
$q = $q->filterByVersion($version); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$result = $q->findOne(); |
|
79
|
|
|
|
|
80
|
|
|
if ($result) { |
|
81
|
|
|
$result->setDisplayName($ao->getDisplayName()); |
|
82
|
|
|
return $result; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return $ao; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.