Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
DeliverySyncService
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 4
90
0.00% covered (danger)
0.00%
0 / 1
 onDeliveryCreated
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
 onDeliveryUpdated
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
20
 setProctoredByDefault
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 isProctoredByDefault
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
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
22namespace oat\taoProctoring\model\delivery;
23
24use oat\generis\model\OntologyAwareTrait;
25use oat\oatbox\service\ConfigurableService;
26use oat\taoDeliveryRdf\model\event\DeliveryCreatedEvent;
27use oat\taoDeliveryRdf\model\event\DeliveryUpdatedEvent;
28use oat\taoProctoring\model\authorization\TestTakerAuthorizationService;
29use oat\taoProctoring\model\ProctorService;
30
31/**
32 * Listen service for delivery events.
33 * Checking current state of http://www.tao.lu/Ontologies/TAODelivery.rdf#ProctorAccessible and setting correct value.
34 *
35 * @author Aleksej Tikhanovich <aleksej@taotesting.com>
36 */
37class DeliverySyncService extends ConfigurableService
38{
39    use OntologyAwareTrait;
40
41    public const SERVICE_ID = 'taoProctoring/DeliverySync';
42
43    public const PROCTORED_BY_DEFAULT = 'proctored_by_default';
44
45    /**
46     * Listen create event for delivery
47     * @param DeliveryCreatedEvent $event
48     */
49    public function onDeliveryCreated(DeliveryCreatedEvent $event)
50    {
51        $delivery = $this->getResource($event->getDeliveryUri());
52
53        $proctoredByDefault = $this->isProctoredByDefault();
54
55        $delivery->editPropertyValues($this->getProperty(ProctorService::ACCESSIBLE_PROCTOR), (
56            $proctoredByDefault
57                ? ProctorService::ACCESSIBLE_PROCTOR_ENABLED
58                : ProctorService::ACCESSIBLE_PROCTOR_DISABLED
59        ));
60    }
61
62    /**
63     * Listen update event for delivery
64     * @param DeliveryUpdatedEvent $event
65     */
66    public function onDeliveryUpdated(DeliveryUpdatedEvent $event)
67    {
68        $data = $event->jsonSerialize();
69        $deliveryData = !empty($data['data']) ? $data['data'] : [];
70        $delivery = $this->getResource($event->getDeliveryUri());
71
72        if (
73            isset($deliveryData[ProctorService::ACCESSIBLE_PROCTOR])
74            && !$deliveryData[ProctorService::ACCESSIBLE_PROCTOR]
75        ) {
76            $delivery->editPropertyValues(
77                $this->getProperty(ProctorService::ACCESSIBLE_PROCTOR),
78                ProctorService::ACCESSIBLE_PROCTOR_DISABLED
79            );
80        }
81    }
82
83    /**
84     * Whenever or not new deliveries should be proctored by default
85     * @param boolean $proctored
86     * @return $this
87     */
88    public function setProctoredByDefault($proctored)
89    {
90        $this->setOption(self::PROCTORED_BY_DEFAULT, $proctored);
91        return $this;
92    }
93
94    /**
95     * @return boolean
96     */
97    public function isProctoredByDefault()
98    {
99        return $this->hasOption(self::PROCTORED_BY_DEFAULT)
100            ? $this->getOption(self::PROCTORED_BY_DEFAULT)
101            : true;
102    }
103}