Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
63.64% |
7 / 11 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| HasFileEntityDecorator | |
63.64% |
7 / 11 |
|
66.67% |
2 / 3 |
6.20 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| jsonSerialize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
50.00% |
4 / 8 |
|
0.00% |
0 / 1 |
4.12 | |||
| 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 (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoTaskQueue\model\Entity\Decorator; |
| 23 | |
| 24 | use oat\oatbox\filesystem\Directory; |
| 25 | use oat\oatbox\filesystem\FileSystemService; |
| 26 | use oat\tao\model\taskQueue\QueueDispatcherInterface; |
| 27 | use oat\tao\model\taskQueue\TaskLog\Decorator\TaskLogEntityDecorator; |
| 28 | use oat\tao\model\taskQueue\TaskLog\Entity\EntityInterface; |
| 29 | |
| 30 | /** |
| 31 | * @deprecated Use \oat\tao\model\taskQueue\TaskLog\Decorator\HasFileEntityDecorator |
| 32 | * |
| 33 | * @author Gyula Szucs <gyula@taotesting.com> |
| 34 | */ |
| 35 | class HasFileEntityDecorator extends TaskLogEntityDecorator |
| 36 | { |
| 37 | /** |
| 38 | * @var FileSystemService |
| 39 | */ |
| 40 | private $fileSystemService; |
| 41 | |
| 42 | public function __construct(EntityInterface $entity, FileSystemService $fileSystemService) |
| 43 | { |
| 44 | parent::__construct($entity); |
| 45 | |
| 46 | $this->fileSystemService = $fileSystemService; |
| 47 | } |
| 48 | |
| 49 | public function jsonSerialize(): array |
| 50 | { |
| 51 | return $this->toArray(); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Add 'hasFile' to the result. Required by our frontend. |
| 56 | * |
| 57 | * @return array |
| 58 | */ |
| 59 | public function toArray() |
| 60 | { |
| 61 | $result = parent::toArray(); |
| 62 | |
| 63 | $result['hasFile'] = false; |
| 64 | |
| 65 | if ($this->getFileNameFromReport()) { |
| 66 | /** @var Directory $queueStorage */ |
| 67 | $queueStorage = $this->fileSystemService |
| 68 | ->getDirectory(QueueDispatcherInterface::FILE_SYSTEM_ID); |
| 69 | |
| 70 | if ($queueStorage->getFile($this->getFileNameFromReport())->exists()) { |
| 71 | $result['hasFile'] = true; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | return $result; |
| 76 | } |
| 77 | } |