Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
LtiDeliveryExecutionService
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 3
42
0.00% covered (danger)
0.00%
0 / 1
 getLinkedDeliveryExecutions
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
12
 createDeliveryExecutionLink
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 deleteDeliveryExecutionData
0.00% covered (danger)
0.00%
0 / 11
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\ltiDeliveryProvider\model\execution\implementation;
23
24use oat\taoDelivery\model\execution\Delete\DeliveryExecutionDeleteRequest;
25use oat\taoDelivery\model\execution\DeliveryExecution;
26use oat\taoDelivery\model\execution\ServiceProxy;
27
28/**
29 * Class LtiDeliveryExecutionService
30 * @author Aleh Hutnikau, <hutnikau@1pt.com>
31 * @package oat\ltiDeliveryProvider\model\execution
32 */
33class LtiDeliveryExecutionService extends AbstractLtiDeliveryExecutionService
34{
35    /**
36     * Returns an array of DeliveryExecution
37     *
38     * @param \core_kernel_classes_Resource $delivery
39     * @param \core_kernel_classes_Resource $link
40     * @param string $userId
41     * @throws
42     * @return DeliveryExecution[]
43     */
44    public function getLinkedDeliveryExecutions(
45        \core_kernel_classes_Resource $delivery,
46        \core_kernel_classes_Resource $link,
47        $userId
48    ) {
49        $class = new \core_kernel_classes_Class(OntologyLTIDeliveryExecutionLink::CLASS_LTI_DELIVERYEXECUTION_LINK);
50        $links = $class->searchInstances([
51            OntologyLTIDeliveryExecutionLink::PROPERTY_LTI_DEL_EXEC_LINK_USER => $userId,
52            OntologyLTIDeliveryExecutionLink::PROPERTY_LTI_DEL_EXEC_LINK_LINK => $link,
53        ], [
54            'like' => false
55        ]);
56        $result = [];
57        foreach ($links as $link) {
58            $execId = $link->getUniquePropertyValue(
59                new \core_kernel_classes_Property(
60                    OntologyLTIDeliveryExecutionLink::PROPERTY_LTI_DEL_EXEC_LINK_EXEC_ID
61                )
62            );
63            $deliveryExecution = ServiceProxy::singleton()->getDeliveryExecution($execId);
64            if ($delivery->equals($deliveryExecution->getDelivery())) {
65                $result[] = $deliveryExecution;
66            }
67        }
68        return $result;
69    }
70
71     /**
72     * @inheritdoc
73     */
74    public function createDeliveryExecutionLink($userUri, $link, $deliveryExecutionUri)
75    {
76        $class = new \core_kernel_classes_Class(OntologyLTIDeliveryExecutionLink::CLASS_LTI_DELIVERYEXECUTION_LINK);
77        $link = $class->createInstanceWithProperties([
78            OntologyLTIDeliveryExecutionLink::PROPERTY_LTI_DEL_EXEC_LINK_USER => $userUri,
79            OntologyLTIDeliveryExecutionLink::PROPERTY_LTI_DEL_EXEC_LINK_LINK => $link,
80            OntologyLTIDeliveryExecutionLink::PROPERTY_LTI_DEL_EXEC_LINK_EXEC_ID => $deliveryExecutionUri
81        ]);
82
83        return $link;
84    }
85
86    /**
87     * @inheritdoc
88     */
89    public function deleteDeliveryExecutionData(DeliveryExecutionDeleteRequest $request)
90    {
91        $removed = [];
92        $deliveryExecutionUri = $request->getDeliveryExecution()->getIdentifier();
93        $userUri = $request->getDeliveryExecution()->getUserIdentifier();
94        $class = new \core_kernel_classes_Class(OntologyLTIDeliveryExecutionLink::CLASS_LTI_DELIVERYEXECUTION_LINK);
95
96        $resources = $class->searchInstances([
97            OntologyLTIDeliveryExecutionLink::PROPERTY_LTI_DEL_EXEC_LINK_USER => $userUri,
98            OntologyLTIDeliveryExecutionLink::PROPERTY_LTI_DEL_EXEC_LINK_EXEC_ID => $deliveryExecutionUri
99        ]);
100
101        /** @var \core_kernel_classes_Resource $resource */
102        foreach ($resources as $resource) {
103            $removed[] = $resource->delete();
104        }
105
106        return !in_array(false, $removed);
107    }
108}