1 | <?php |
||
14 | class AchievementsStorage implements AchievementsStorageInterface |
||
15 | { |
||
16 | const MODEL_ACHIEVEMENT = 'achievement'; |
||
17 | const MODEL_CRITERIA = 'criteria'; |
||
18 | |||
19 | /** |
||
20 | * @var Repository |
||
21 | */ |
||
22 | protected $config; |
||
23 | |||
24 | /** |
||
25 | * AchievementsStorage constructor. |
||
26 | * |
||
27 | * @param Repository $config |
||
28 | */ |
||
29 | public function __construct(Repository $config) |
||
33 | |||
34 | /** |
||
35 | * Returns actual class name from config. |
||
36 | * |
||
37 | * @param string $section |
||
38 | * @param string $type |
||
39 | * |
||
40 | * @return string |
||
41 | */ |
||
42 | protected function getConfigurableClassName(string $section, string $type) |
||
46 | |||
47 | /** |
||
48 | * Injects model class name into given callback. |
||
49 | * |
||
50 | * @param string $type |
||
51 | * @param callable $callback |
||
52 | * |
||
53 | * @return mixed|string |
||
54 | */ |
||
55 | protected function getModelClass(string $type, callable $callback) |
||
59 | |||
60 | /** |
||
61 | * Dispatches new Achievements event. |
||
62 | * |
||
63 | * @param string $type |
||
64 | * @param array $args |
||
65 | * @return mixed |
||
66 | */ |
||
67 | protected function dispatchEvent(string $type, array $args = []) |
||
73 | |||
74 | /** |
||
75 | * Fetches given owner's criterias by given type. |
||
76 | * |
||
77 | * @param mixed $owner |
||
78 | * @param string $type |
||
79 | * @param mixed $data = null |
||
80 | * |
||
81 | * @return array |
||
82 | */ |
||
83 | public function getOwnerCriteriasByType($owner, string $type, $data = null) |
||
101 | |||
102 | /** |
||
103 | * Loads criteria progress for given owner, applies given query callback |
||
104 | * and returns array of AchievementCriteria objects transformed from AchievementCriteriaModels. |
||
105 | * |
||
106 | * @param mixed $owner |
||
107 | * @param callable $callback |
||
108 | * |
||
109 | * @return \Illuminate\Support\Collection |
||
110 | */ |
||
111 | protected function getOwnerCriteriasProgress($owner, callable $callback) |
||
119 | |||
120 | /** |
||
121 | * Loads achievement criterias with given type. |
||
122 | * |
||
123 | * @param string $type |
||
124 | * @param mixed $data = null |
||
125 | * |
||
126 | * @return \Illuminate\Database\Eloquent\Collection |
||
127 | */ |
||
128 | protected function getCriteriasByType(string $type, $data = null) |
||
134 | |||
135 | /** |
||
136 | * Transforms AchievementCriteriaModel collection int AchievementCriteriaProgress collection. |
||
137 | * |
||
138 | * @param Collection $criterias |
||
139 | * |
||
140 | * @return \Illuminate\Support\Collection |
||
141 | */ |
||
142 | protected function transformOwnerCriteriasToProgress(Collection $criterias) |
||
155 | |||
156 | /** |
||
157 | * Transforms AchievementCriteriaModel to AchievementCriteria object and attaches progress data. |
||
158 | * |
||
159 | * @param AchievementCriteriaModel $criteria |
||
160 | * @param AchievementCriteriaProgress|null $progress |
||
161 | * |
||
162 | * @return AchievementCriteria |
||
163 | */ |
||
164 | protected function transformCriteriaWithProgress($criteria, AchievementCriteriaProgress $progress = null) |
||
186 | |||
187 | /** |
||
188 | * Returns list of criterias' achievements. |
||
189 | * |
||
190 | * @param array $criterias |
||
191 | * |
||
192 | * @return array |
||
193 | */ |
||
194 | public function getAchievementsByCriterias(array $criterias) |
||
208 | |||
209 | /** |
||
210 | * Loads collection of achievements by IDs. |
||
211 | * |
||
212 | * @param array $achievementIds |
||
213 | * |
||
214 | * @return mixed |
||
215 | */ |
||
216 | public function getAchievementsByIds(array $achievementIds) |
||
222 | |||
223 | /** |
||
224 | * Converts collection of AchievementModel objects to array of Achievement objects. |
||
225 | * |
||
226 | * @param Collection $achievements |
||
227 | * @param bool $reloadCriteriasRelation = true |
||
228 | * |
||
229 | * @return array |
||
230 | */ |
||
231 | public function convertAchievementModelsWithCriterias(Collection $achievements, bool $reloadCriteriasRelation = true) |
||
239 | |||
240 | /** |
||
241 | * Converts single AchievementModel to Achievement object. |
||
242 | * |
||
243 | * @param AchievementModel $achievement |
||
244 | * |
||
245 | * @return Achievement |
||
246 | */ |
||
247 | public function convertAchievementModelWithCriterias($achievement) |
||
257 | |||
258 | /** |
||
259 | * Transforms AchievementModel collection to Achievement collection and applies appropriate criterias. |
||
260 | * |
||
261 | * @param Collection $achievements |
||
262 | * @param array $criterias |
||
263 | * |
||
264 | * @return \Illuminate\Support\Collection |
||
265 | */ |
||
266 | protected function transformAchievements(Collection $achievements, array $criterias) |
||
274 | |||
275 | /** |
||
276 | * Transforms single AchievementModel object to Achievement object with appropriate criterias. |
||
277 | * |
||
278 | * @param AchievementModel $achievement |
||
279 | * @param array $criterias |
||
280 | * |
||
281 | * @return Achievement |
||
282 | */ |
||
283 | protected function transformSingleAchievement($achievement, array $criterias) |
||
306 | |||
307 | /** |
||
308 | * Extracts single Achievement from given list for given criteria. |
||
309 | * |
||
310 | * @param AchievementCriteria $criteria |
||
311 | * @param array $achievements |
||
312 | * |
||
313 | * @return Achievement |
||
314 | */ |
||
315 | public function getAchievementForCriteria(AchievementCriteria $criteria, array $achievements) |
||
329 | |||
330 | /** |
||
331 | * Loads achievements with progresses for given owner. |
||
332 | * |
||
333 | * @param mixed $owner |
||
334 | * @param array $achievementIds |
||
335 | * |
||
336 | * @return array |
||
337 | */ |
||
338 | public function getAchievementsWithProgressFor($owner, array $achievementIds) |
||
358 | |||
359 | /** |
||
360 | * Loads criterias by achievement IDs. |
||
361 | * |
||
362 | * @param array $achievementIds |
||
363 | * |
||
364 | * @return \Illuminate\Database\Eloquent\Collection |
||
365 | */ |
||
366 | public function getCriteriasByAchievementIds(array $achievementIds) |
||
372 | |||
373 | /** |
||
374 | * Saves criteria progress for given owner. |
||
375 | * |
||
376 | * @param mixed $owner |
||
377 | * @param AchievementCriteria $criteria |
||
378 | * @param Achievement $achievement |
||
379 | * @param AchievementCriteriaProgress $progress |
||
380 | * |
||
381 | * @return mixed |
||
382 | */ |
||
383 | public function setCriteriaProgressUpdated($owner, AchievementCriteria $criteria, Achievement $achievement, AchievementCriteriaProgress $progress) |
||
397 | |||
398 | /** |
||
399 | * Saves given achievements completeness state for given owner. |
||
400 | * |
||
401 | * @param mixed $owner |
||
402 | * @param array $achievements |
||
403 | * |
||
404 | * @return mixed |
||
405 | */ |
||
406 | public function setAchievementsCompleted($owner, array $achievements) |
||
421 | } |
||
422 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.