-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScoutOrg.php
132 lines (107 loc) · 3.88 KB
/
ScoutOrg.php
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
* Contains ScoutOrg class
* @author Alexander Krantz
*/
namespace Org\Lib;
/**
* Is used for getting structured information about scout groups.
*/
class ScoutOrg {
/** @var IScoutGroupProvider The object that provides a scout group object. */
private $scoutGroupProvider;
/** @var ScoutGroup The cached scout group. */
private $loadedScoutGroup;
/** @var ICustomListsProvider The object that provides a custom list list. */
private $customListsProvider;
/** @var CustomList[] The id indexed cached list of custom lists. */
private $loadedCustomListsIdIndexed;
/** @var CustomList[] The title indexed cached list of custom lists.*/
private $loadedCustomListsTitleIndexed;
/** @var IWaitingListProvider The object that provides a waiting member list. */
private $waitingListProvider;
/** @var WaitingMember[] The cached list of members. */
private $loadedWaitingList;
/**
* Creates a new controller from providers.
* @internal
* @param IScoutGroupProvider $scoutGroupProvider
* @param ICustomListsProvider $customListsProvider
* @param IWaitingListProvider $waitingListProvider
*/
public function __construct(
IScoutGroupProvider $scoutGroupProvider,
ICustomListsProvider $customListsProvider,
IWaitingListProvider $waitingListProvider
) {
$this->scoutGroupProvider = $scoutGroupProvider;
$this->customListsProvider = $customListsProvider;
$this->waitingListProvider = $waitingListProvider;
}
/**
* Gets the scout group structure.
* @return ScoutGroup|false
*/
public function getScoutGroup() {
if ($this->loadedScoutGroup !== null) {
return $this->loadedScoutGroup;
}
$scoutGroup = $this->scoutGroupProvider->getScoutGroup();
if ($scoutGroup === false) {
return false;
}
$this->loadedScoutGroup = $scoutGroup;
return $scoutGroup;
}
/**
* Gets custom lists.
* @param bool $idIndexed Wether to index the list by id or title.
* @return CustomList[]
*/
public function getCustomLists(bool $idIndexed = false) {
if ($this->loadedCustomListsIdIndexed !== null) {
if ($idIndexed) {
return $this->loadedCustomListsIdIndexed;
} else {
return $this->loadedCustomListsTitleIndexed;
}
}
$scoutGroup = $this->getScoutGroup();
$customLists = $this->customListsProvider->getCustomLists($scoutGroup);
if ($customLists === false) {
return false;
}
$idIndexedList = [];
$titleIndexedList = [];
foreach ($customLists as $customList) {
$idIndexedList[$customList->getId()] = $customList;
$titleIndexedList[$customList->getTitle()] = $customList;
}
$this->loadedCustomListsIdIndexed = $idIndexedList;
$this->loadedCustomListsTitleIndexed = $titleIndexedList;
if ($idIndexed) {
return $idIndexedList;
} else {
return $titleIndexedList;
}
}
/**
* Gets the list of members waiting for placement.
* @return WaitingMember[]|false
*/
public function getWaitingList() {
if ($this->loadedWaitingList !== null) {
return $this->loadedWaitingList;
}
$waitingList = $this->waitingListProvider->getWaitingList();
if ($waitingList === false) {
return false;
}
$idIndexedList = [];
foreach ($waitingList as $waitingMember) {
$idIndexedList[$waitingMember->getId()] = $waitingMember;
}
$this->loadedWaitingList = $idIndexedList;
return $idIndexedList;
}
}