Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
15.38% |
4 / 26 |
|
26.67% |
4 / 15 |
CRAP | |
0.00% |
0 / 1 |
| DeliveryExecution | |
15.38% |
4 / 26 |
|
26.67% |
4 / 15 |
171.09 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setImplementation | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getImplementation | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getIdentifier | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getOriginalIdentifier | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getLabel | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| getStartTime | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getFinishTime | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getState | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setState | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getDelivery | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUserIdentifier | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| __call | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDeliveryIdSessionKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| jsonSerialize | |
0.00% |
0 / 5 |
|
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) 2015 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoDelivery\model\execution; |
| 24 | |
| 25 | use common_exception_NoImplementation; |
| 26 | use core_kernel_classes_Resource; |
| 27 | use JsonSerializable; |
| 28 | use oat\oatbox\service\ServiceManagerAwareInterface; |
| 29 | use oat\oatbox\service\ServiceManagerAwareTrait; |
| 30 | use oat\taoDelivery\model\fields\DeliveryFieldsService; |
| 31 | |
| 32 | class DeliveryExecution implements |
| 33 | DeliveryExecutionInterface, |
| 34 | ServiceManagerAwareInterface, |
| 35 | JsonSerializable, |
| 36 | OriginalIdAwareDeliveryExecutionInterface |
| 37 | { |
| 38 | use ServiceManagerAwareTrait; |
| 39 | |
| 40 | /** |
| 41 | * @var DeliveryExecutionInterface |
| 42 | */ |
| 43 | private $implementation; |
| 44 | |
| 45 | public function __construct(DeliveryExecutionInterface $implementation) |
| 46 | { |
| 47 | $this->setImplementation($implementation); |
| 48 | } |
| 49 | |
| 50 | public function setImplementation(DeliveryExecutionInterface $implementation) |
| 51 | { |
| 52 | $this->implementation = $implementation; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @return DeliveryExecutionInterface |
| 57 | */ |
| 58 | public function getImplementation() |
| 59 | { |
| 60 | return $this->implementation; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Returns the identifier of the delivery execution |
| 65 | * |
| 66 | * @return string |
| 67 | */ |
| 68 | public function getIdentifier() |
| 69 | { |
| 70 | return $this->getImplementation()->getIdentifier(); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @inheritDoc |
| 75 | */ |
| 76 | public function getOriginalIdentifier(): string |
| 77 | { |
| 78 | return $this->getImplementation()->getOriginalIdentifier(); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Returns a human readable test representation of the delivery execution |
| 83 | * Should respect the current user's language |
| 84 | * |
| 85 | * @return string |
| 86 | * @throws \common_exception_NotFound |
| 87 | */ |
| 88 | public function getLabel() |
| 89 | { |
| 90 | /** @var DeliveryFieldsService $deliveryFieldsService */ |
| 91 | $deliveryFieldsService = $this->getServiceLocator()->get(DeliveryFieldsService::SERVICE_ID); |
| 92 | $label = $deliveryFieldsService->getLabel( |
| 93 | $this->getImplementation()->getDelivery(), |
| 94 | $this->getImplementation()->getLabel() |
| 95 | ); |
| 96 | return $label; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Returns when the delivery execution was started |
| 101 | * @throws \common_exception_NotFound |
| 102 | */ |
| 103 | public function getStartTime() |
| 104 | { |
| 105 | return $this->getImplementation()->getStartTime(); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Returns when the delivery execution was finished |
| 110 | * or null if not yet finished |
| 111 | * @throws \common_exception_NotFound |
| 112 | */ |
| 113 | public function getFinishTime() |
| 114 | { |
| 115 | return $this->getImplementation()->getFinishTime(); |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Returns the delivery execution state as resource |
| 120 | * @throws \common_exception_NotFound |
| 121 | */ |
| 122 | public function getState() |
| 123 | { |
| 124 | return $this->getImplementation()->getState(); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * |
| 129 | * @param string $state |
| 130 | * @return boolean success |
| 131 | */ |
| 132 | public function setState($state) |
| 133 | { |
| 134 | /** @var \oat\taoDelivery\model\execution\AbstractStateService $stateService */ |
| 135 | $stateService = $this->getServiceLocator()->get(StateServiceInterface::SERVICE_ID); |
| 136 | $result = $stateService->legacyTransition($this, $state); |
| 137 | return $result; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Returns the delivery execution delivery as resource |
| 142 | * |
| 143 | * @return core_kernel_classes_Resource |
| 144 | * @throws \common_exception_NotFound |
| 145 | */ |
| 146 | public function getDelivery() |
| 147 | { |
| 148 | return $this->getImplementation()->getDelivery(); |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Returns the delivery executions user identifier |
| 153 | * |
| 154 | * @return string |
| 155 | * @throws \common_exception_NotFound |
| 156 | */ |
| 157 | public function getUserIdentifier() |
| 158 | { |
| 159 | return $this->getImplementation()->getUserIdentifier(); |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Calls the named method which is not a class method. |
| 164 | * Do not call this method. |
| 165 | * @param string $name the method name |
| 166 | * @param array $parameters method parameters |
| 167 | * @return mixed the method return value |
| 168 | */ |
| 169 | public function __call($name, $parameters) |
| 170 | { |
| 171 | return call_user_func_array([$this->getImplementation(), $name], $parameters); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Returns the delivery id session key. |
| 176 | * |
| 177 | * @param $deliveryExecutionId |
| 178 | * |
| 179 | * @return string |
| 180 | */ |
| 181 | public static function getDeliveryIdSessionKey($deliveryExecutionId) |
| 182 | { |
| 183 | return 'deliveryIdForDeliveryExecution:' . $deliveryExecutionId; |
| 184 | } |
| 185 | |
| 186 | public function jsonSerialize(): array |
| 187 | { |
| 188 | if ($this->getImplementation() instanceof JsonSerializable) { |
| 189 | return $this->getImplementation()->jsonSerialize(); |
| 190 | } |
| 191 | |
| 192 | throw new common_exception_NoImplementation( |
| 193 | 'Delivery Execution model does not implement json serialise method' |
| 194 | ); |
| 195 | } |
| 196 | } |