Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| UpdateDelivery | |
0.00% |
0 / 23 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
| __invoke | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 | |||
| jsonSerialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| createTask | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| 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 | */ |
| 22 | |
| 23 | namespace oat\taoDeliveryRdf\model\tasks; |
| 24 | |
| 25 | use oat\generis\model\OntologyAwareTrait; |
| 26 | use oat\oatbox\extension\AbstractAction; |
| 27 | use oat\oatbox\service\ServiceManager; |
| 28 | use oat\tao\model\taskQueue\QueueDispatcher; |
| 29 | use oat\tao\model\taskQueue\Task\TaskInterface; |
| 30 | use oat\taoDeliveryRdf\model\DeliveryAssemblyService; |
| 31 | use common_report_Report as Report; |
| 32 | |
| 33 | /** |
| 34 | * Class UpdateDelivery |
| 35 | * |
| 36 | * Action to update delivery |
| 37 | * |
| 38 | * @package oat\taoQtiTest\models\tasks |
| 39 | * @author Aleksej Tikhanovich, <aleksej@taotesting.com> |
| 40 | */ |
| 41 | class UpdateDelivery extends AbstractAction implements \JsonSerializable |
| 42 | { |
| 43 | use OntologyAwareTrait; |
| 44 | |
| 45 | public const OPTION_WHERE = 'where'; |
| 46 | public const OPTION_PARAMETERS = 'parameters'; |
| 47 | |
| 48 | /** |
| 49 | * @param $params |
| 50 | * @throws \common_exception_MissingParameter |
| 51 | * @return \common_report_Report |
| 52 | */ |
| 53 | public function __invoke($params) |
| 54 | { |
| 55 | $propertyValues = $params[self::OPTION_PARAMETERS]; |
| 56 | $where = $params[self::OPTION_WHERE]; |
| 57 | |
| 58 | $deliveryModelClass = new \core_kernel_classes_Class(DeliveryAssemblyService::CLASS_URI); |
| 59 | $deliveries = $deliveryModelClass->searchInstances($where, ['like' => false, 'recursive' => true]); |
| 60 | $report = Report::createSuccess(); |
| 61 | |
| 62 | /** @var \core_kernel_classes_Resource $delivery */ |
| 63 | foreach ($deliveries as $key => $delivery) { |
| 64 | foreach ($propertyValues as $rdfKey => $rdfValue) { |
| 65 | $rdfKey = \tao_helpers_Uri::decode($rdfKey); |
| 66 | $property = $this->getProperty($rdfKey); |
| 67 | $delivery->editPropertyValues($property, $rdfValue); |
| 68 | } |
| 69 | |
| 70 | $report->add(Report::createSuccess($delivery->getUri())); |
| 71 | } |
| 72 | return $report; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * @return string |
| 77 | */ |
| 78 | public function jsonSerialize() |
| 79 | { |
| 80 | return __CLASS__; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Create a task to update a delivery |
| 85 | * @param array $where |
| 86 | * @param array $propertyValues |
| 87 | * @return TaskInterface |
| 88 | */ |
| 89 | public static function createTask($where = [], $propertyValues = []) |
| 90 | { |
| 91 | $serviceManager = ServiceManager::getServiceManager(); |
| 92 | $action = new self(); |
| 93 | $action->setServiceLocator($serviceManager); |
| 94 | |
| 95 | $parameters = [ |
| 96 | self::OPTION_WHERE => $where, |
| 97 | self::OPTION_PARAMETERS => $propertyValues |
| 98 | ]; |
| 99 | /** @var QueueDispatcher $queueDispatcher */ |
| 100 | $queueDispatcher = ServiceManager::getServiceManager()->get(QueueDispatcher::SERVICE_ID); |
| 101 | return $queueDispatcher->createTask($action, $parameters, null, null, true); |
| 102 | } |
| 103 | } |