Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 38 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
MonitorService | |
0.00% |
0 / 38 |
|
0.00% |
0 / 2 |
110 | |
0.00% |
0 / 1 |
breadcrumbs | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
breadcrumbsIndex | |
0.00% |
0 / 33 |
|
0.00% |
0 / 1 |
56 |
1 | <?php |
2 | |
3 | /** |
4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU General Public License |
6 | * as published by the Free Software Foundation; under version 2 |
7 | * of the License (non-upgradable). |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | * |
18 | * Copyright (c) 2017 (original work) Open Assessment Technologies SA ; |
19 | * |
20 | */ |
21 | |
22 | namespace oat\taoProctoring\model\breadcrumbs; |
23 | |
24 | use oat\oatbox\service\ConfigurableService; |
25 | use oat\tao\model\mvc\Breadcrumbs; |
26 | use oat\taoProctoring\model\ProctorService; |
27 | |
28 | /** |
29 | * Provides breadcrumbs for the Monitor controller. |
30 | * @author Jean-Sébastien Conan <jean-sebastien@taotesting.com> |
31 | */ |
32 | class MonitorService extends ConfigurableService implements Breadcrumbs |
33 | { |
34 | public const SERVICE_ID = 'taoProctoring/Monitor/breadcrumbs'; |
35 | |
36 | /** |
37 | * Builds breadcrumbs for a particular route. |
38 | * @param string $route - The route URL |
39 | * @param array $parsedRoute - The parsed URL (@see parse_url), augmented with extension, controller and action |
40 | * @return array|null - The breadcrumb related to the route, or `null` if none. Must contains: |
41 | * - id: the route id |
42 | * - url: the route url |
43 | * - label: the label displayed for the breadcrumb |
44 | * - entries: a list of related links, using the same format as above |
45 | */ |
46 | public function breadcrumbs($route, $parsedRoute) |
47 | { |
48 | if (isset($parsedRoute['action'])) { |
49 | switch ($parsedRoute['action']) { |
50 | case 'index': |
51 | return $this->breadcrumbsIndex($route, $parsedRoute); |
52 | } |
53 | } |
54 | return null; |
55 | } |
56 | |
57 | /** |
58 | * Gets the breadcrumbs for the index page |
59 | * @param string $route |
60 | * @param array $parsedRoute |
61 | * @return array |
62 | */ |
63 | protected function breadcrumbsIndex($route, $parsedRoute) |
64 | { |
65 | $routeContext = null; |
66 | $routeDelivery = null; |
67 | |
68 | if (isset($parsedRoute['params'])) { |
69 | if (isset($parsedRoute['params']['delivery'])) { |
70 | $routeDelivery = $parsedRoute['params']['delivery']; |
71 | } |
72 | if (isset($parsedRoute['params']['context'])) { |
73 | $routeContext = $parsedRoute['params']['context']; |
74 | } |
75 | } |
76 | |
77 | $service = $this->getServiceManager()->get(ProctorService::SERVICE_ID); |
78 | $proctor = \common_session_SessionManager::getSession()->getUser(); |
79 | $deliveries = $service->getProctorableDeliveries($proctor, $routeContext); |
80 | $entries = array(); |
81 | $main = null; |
82 | foreach ($deliveries as $delivery) { |
83 | $deliveryId = $delivery->getUri(); |
84 | $crumb = [ |
85 | 'id' => $deliveryId, |
86 | 'url' => _url( |
87 | 'index', |
88 | 'Monitor', |
89 | 'taoProctoring', |
90 | [ |
91 | 'delivery' => $deliveryId, |
92 | 'context' => $routeContext, |
93 | ] |
94 | ), |
95 | 'label' => $delivery->getLabel(), |
96 | ]; |
97 | |
98 | if ($deliveryId == $routeDelivery) { |
99 | $main = $crumb; |
100 | } else { |
101 | $entries[] = $crumb; |
102 | } |
103 | } |
104 | |
105 | if ($main) { |
106 | $main['entries'] = $entries; |
107 | } |
108 | |
109 | return $main; |
110 | } |
111 | } |