| Code Coverage | ||||||||||
| Lines | Functions and Methods | Classes and Traits | ||||||||
| Total |  | 93.33% | 14 / 15 |  | 80.00% | 4 / 5 | CRAP |  | 0.00% | 0 / 1 | 
| DeliveryCreatedEvent |  | 93.33% | 14 / 15 |  | 80.00% | 4 / 5 | 6.01 |  | 0.00% | 0 / 1 | 
| __construct |  | 100.00% | 2 / 2 |  | 100.00% | 1 / 1 | 1 | |||
| getName |  | 100.00% | 1 / 1 |  | 100.00% | 1 / 1 | 1 | |||
| jsonSerialize |  | 100.00% | 3 / 3 |  | 100.00% | 1 / 1 | 1 | |||
| getWebhookEventName |  | 100.00% | 1 / 1 |  | 100.00% | 1 / 1 | 1 | |||
| serializeForWebhook |  | 87.50% | 7 / 8 |  | 0.00% | 0 / 1 | 2.01 | |||
| 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) 2016 (original work) Open Assessment Technologies SA | 
| 19 | * | 
| 20 | */ | 
| 21 | |
| 22 | namespace oat\taoDeliveryRdf\model\event; | 
| 23 | |
| 24 | use core_kernel_classes_Resource; | 
| 25 | use oat\tao\model\webhooks\WebhookSerializableEventInterface; | 
| 26 | use oat\taoDeliveryRdf\model\DeliveryAssemblyService; | 
| 27 | |
| 28 | class DeliveryCreatedEvent extends AbstractDeliveryEvent implements WebhookSerializableEventInterface | 
| 29 | { | 
| 30 | /** | 
| 31 | * @var core_kernel_classes_Resource | 
| 32 | */ | 
| 33 | private $delivery; | 
| 34 | |
| 35 | /** | 
| 36 | * @param core_kernel_classes_Resource $delivery | 
| 37 | */ | 
| 38 | public function __construct(core_kernel_classes_Resource $delivery) | 
| 39 | { | 
| 40 | $this->deliveryUri = $delivery->getUri(); | 
| 41 | $this->delivery = $delivery; | 
| 42 | } | 
| 43 | |
| 44 | /** | 
| 45 | * Return a unique name for this event | 
| 46 | * @see \oat\oatbox\event\Event::getName() | 
| 47 | */ | 
| 48 | public function getName() | 
| 49 | { | 
| 50 | return self::class; | 
| 51 | } | 
| 52 | |
| 53 | /** | 
| 54 | * Specify data which should be serialized to JSON | 
| 55 | * @link http://php.net/manual/en/jsonserializable.jsonserialize.php | 
| 56 | * @return mixed data which can be serialized by <b>json_encode</b>, | 
| 57 | * which is a value of any type other than a resource. | 
| 58 | * @since 5.4.0 | 
| 59 | */ | 
| 60 | public function jsonSerialize() | 
| 61 | { | 
| 62 | return [ | 
| 63 | 'delivery' => $this->delivery->getUri(), | 
| 64 | ]; | 
| 65 | } | 
| 66 | |
| 67 | /** | 
| 68 | * @return string | 
| 69 | */ | 
| 70 | public function getWebhookEventName() | 
| 71 | { | 
| 72 | return 'DeliveryCreatedEvent'; | 
| 73 | } | 
| 74 | |
| 75 | /** | 
| 76 | * @return array | 
| 77 | */ | 
| 78 | public function serializeForWebhook(): array | 
| 79 | { | 
| 80 | $testUri = null; | 
| 81 | try { | 
| 82 | $testProperty = new \core_kernel_classes_Property(DeliveryAssemblyService::PROPERTY_ORIGIN); | 
| 83 | $testUri = $this->delivery->getOnePropertyValue($testProperty)->getUri(); | 
| 84 | } catch (\Throwable $e) { | 
| 85 | } | 
| 86 | |
| 87 | return [ | 
| 88 | 'deliveryId' => $this->deliveryUri, | 
| 89 | 'testId' => $testUri, | 
| 90 | ]; | 
| 91 | } | 
| 92 | } |