Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
62.50% covered (warning)
62.50%
20 / 32
75.00% covered (warning)
75.00%
12 / 16
CRAP
0.00% covered (danger)
0.00%
0 / 1
RdsDeliveryExecution
62.50% covered (warning)
62.50%
20 / 32
75.00% covered (warning)
75.00%
12 / 16
44.26
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getIdentifier
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getOriginalIdentifier
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setIdentifier
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLabel
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setLabel
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDelivery
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 setDelivery
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getState
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 setState
44.44% covered (danger)
44.44%
4 / 9
0.00% covered (danger)
0.00%
0 / 1
2.69
 getUserIdentifier
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setUserIdentifier
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getStartTime
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 setStartTime
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFinishTime
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 setFinishTime
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
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) 2013-2017 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
19 *
20 */
21
22namespace oat\taoDelivery\model\execution\rds;
23
24use core_kernel_classes_Resource;
25use oat\generis\model\OntologyAwareTrait;
26use oat\taoDelivery\model\execution\DeliveryExecutionInterface;
27use oat\taoDelivery\model\execution\OriginalIdAwareDeliveryExecutionInterface;
28
29/**
30 * RDS Delivery Execution model
31 *
32 * @author Péter Halász <peter@taotesting.com>
33 */
34class RdsDeliveryExecution implements DeliveryExecutionInterface, OriginalIdAwareDeliveryExecutionInterface
35{
36    use OntologyAwareTrait;
37
38    /** @var string */
39    private $identifier;
40
41    /** @var string */
42    private $label;
43
44    /** @var string */
45    private $delivery;
46
47    /** @var string */
48    private $state;
49
50    /** @var string */
51    private $userIdentifier;
52
53    /** @var \DateTime */
54    private $startTime;
55
56    /** @var \DateTime */
57    private $finishTime;
58
59    /** @var RdsDeliveryExecutionService */
60    private $service;
61
62    public function __construct(RdsDeliveryExecutionService $service)
63    {
64        $this->service = $service;
65    }
66
67    /**
68     * @return string
69     */
70    public function getIdentifier()
71    {
72        return $this->identifier;
73    }
74
75    /**
76     * @inheritDoc
77     */
78    public function getOriginalIdentifier(): string
79    {
80        return substr($this->identifier, strlen(RdsDeliveryExecutionService::ID_PREFIX));
81    }
82
83    /**
84     * @param int $identifier
85     */
86    public function setIdentifier($identifier)
87    {
88        $this->identifier = $identifier;
89    }
90
91    /**
92     * @return string
93     */
94    public function getLabel()
95    {
96        return $this->label;
97    }
98
99    /**
100     * @param string $label
101     */
102    public function setLabel($label)
103    {
104        $this->label = $label;
105    }
106
107    /**
108     * @return core_kernel_classes_Resource|null
109     * @throws \common_exception_Error
110     */
111    public function getDelivery()
112    {
113        if (!is_null($this->delivery)) {
114            return $this->getResource($this->delivery);
115        } else {
116            return null;
117        }
118    }
119
120    /**
121     * @param string $delivery
122     */
123    public function setDelivery($delivery)
124    {
125        $this->delivery = $delivery;
126    }
127
128    /**
129     * @return core_kernel_classes_Resource|null
130     * @throws \common_exception_Error
131     */
132    public function getState()
133    {
134        if (!is_null($this->state)) {
135            return $this->getResource($this->state);
136        } else {
137            return null;
138        }
139    }
140
141    /**
142     * @param string $state
143     * @return bool
144     */
145    public function setState($state)
146    {
147        $isUpdated = true;
148
149        // Avoid any update in database when mapping the value
150        if ($this->state !== null) {
151            $isUpdated = $this->service->updateDeliveryExecutionState(
152                $this->identifier,
153                $this->state,
154                $state
155            );
156        }
157
158        $this->state = $state;
159
160        return $isUpdated;
161    }
162
163    /**
164     * @return string
165     */
166    public function getUserIdentifier()
167    {
168        return $this->userIdentifier;
169    }
170
171    /**
172     * @param string $userIdentifier
173     */
174    public function setUserIdentifier($userIdentifier)
175    {
176        $this->userIdentifier = $userIdentifier;
177    }
178
179    /**
180     * @return int
181     */
182    public function getStartTime()
183    {
184        if (!empty($this->startTime)) {
185            return $this->startTime->getTimestamp();
186        } else {
187            return null;
188        }
189    }
190
191    /**
192     * @param \DateTime $startTime
193     */
194    public function setStartTime($startTime)
195    {
196        $this->startTime = $startTime;
197    }
198
199    /**
200     * @return int
201     */
202    public function getFinishTime()
203    {
204        if (!empty($this->finishTime)) {
205            return $this->finishTime->getTimestamp();
206        } else {
207            return null;
208        }
209    }
210
211    /**
212     * @param \DateTime $finishTime
213     */
214    public function setFinishTime($finishTime)
215    {
216        $this->finishTime = $finishTime;
217    }
218}