Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
76.47% |
13 / 17 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| OntoLockData | |
76.47% |
13 / 17 |
|
66.67% |
2 / 3 |
6.47 | |
0.00% |
0 / 1 |
| getLockData | |
55.56% |
5 / 9 |
|
0.00% |
0 / 1 |
5.40 | |||
| getOwner | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toJson | |
100.00% |
7 / 7 |
|
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 Open Assessment Technologies S.A. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\tao\model\lock\implementation; |
| 23 | |
| 24 | use oat\tao\model\lock\Lock; |
| 25 | use core_kernel_classes_Resource; |
| 26 | use common_exception_InconsistentData; |
| 27 | |
| 28 | /** |
| 29 | * Implements Lock using a simple property in the ontology for the lock storage |
| 30 | * |
| 31 | **/ |
| 32 | class OntoLockData extends SimpleLock |
| 33 | { |
| 34 | /** |
| 35 | * |
| 36 | * @param string $json |
| 37 | * @throws common_exception_InconsistentData |
| 38 | * @return tao_models_classes_LockData |
| 39 | */ |
| 40 | public static function getLockData($json) |
| 41 | { |
| 42 | $array = json_decode($json, true); |
| 43 | if (isset($array['resource']) && isset($array['owner']) && isset($array['epoch'])) { |
| 44 | $resource = new core_kernel_classes_Resource($array['resource']); |
| 45 | $ownerId = $array['owner']; |
| 46 | $epoch = $array['epoch']; |
| 47 | return new self($resource, $ownerId, $epoch); |
| 48 | } else { |
| 49 | throw new common_exception_InconsistentData( |
| 50 | 'LockData should contain a resource, owner and epoch, one data is missing' |
| 51 | ); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @author "Patrick Plichart, <patrick@taotesting.com>" |
| 57 | * @return core_kernel_classes_Resource |
| 58 | */ |
| 59 | public function getOwner() |
| 60 | { |
| 61 | return new core_kernel_classes_Resource($this->getOwnerId()); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @author "Patrick Plichart, <patrick@taotesting.com>" |
| 66 | * @return string |
| 67 | */ |
| 68 | public function toJson() |
| 69 | { |
| 70 | return json_encode( |
| 71 | [ |
| 72 | 'resource' => $this->getResource()->getUri(), |
| 73 | 'owner' => $this->getOwnerId(), |
| 74 | 'epoch' => $this->getCreationTime() |
| 75 | ] |
| 76 | ); |
| 77 | } |
| 78 | } |