|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the xAPI package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Christian Flothmann <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Xabbuh\XApi\Model; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* A group of {@link Agent Agents} of a {@link Statement}. |
|
16
|
|
|
* |
|
17
|
|
|
* @author Christian Flothmann <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
|
final class Group extends Actor |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var Agent[] The members of the Group |
|
23
|
|
|
*/ |
|
24
|
|
|
private $members = array(); |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param string $mbox |
|
28
|
|
|
* @param string $mboxSha1Sum |
|
29
|
|
|
* @param string $openId |
|
30
|
|
|
* @param Account $account |
|
31
|
|
|
* @param string $name |
|
32
|
|
|
* @param Agent[] $members |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct($mbox = null, $mboxSha1Sum = null, $openId = null, Account $account = null, $name = null, array $members = array()) |
|
35
|
|
|
{ |
|
36
|
|
|
parent::__construct($mbox, $mboxSha1Sum, $openId, $account, $name); |
|
37
|
|
|
|
|
38
|
|
|
$this->members = $members; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Returns the members of this group. |
|
43
|
|
|
* |
|
44
|
|
|
* @return Agent[] The members |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getMembers() |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->members; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritdoc} |
|
53
|
|
|
*/ |
|
54
|
|
|
public function equals(Actor $actor) |
|
55
|
|
|
{ |
|
56
|
|
|
if (!parent::equals($actor)) { |
|
57
|
|
|
return false; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
if ('Xabbuh\XApi\Model\Group' !== get_class($actor)) { |
|
61
|
|
|
return false; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** @var Group $actor */ |
|
65
|
|
|
|
|
66
|
|
|
if (count($this->members) !== count($actor->members)) { |
|
67
|
|
|
return false; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
foreach ($this->members as $member) { |
|
71
|
|
|
if (!in_array($member, $actor->members)) { |
|
72
|
|
|
return false; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return true; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|