*/ class DeliverySyncService extends ConfigurableService { use OntologyAwareTrait; const SERVICE_ID = 'taoProctoring/DeliverySync'; const PROCTORED_BY_DEFAULT = 'proctored_by_default'; /** * Listen create event for delivery * @param DeliveryCreatedEvent $event */ public function onDeliveryCreated(DeliveryCreatedEvent $event) { $delivery = $this->getResource($event->getDeliveryUri()); $proctoredByDefault = $this->isProctoredByDefault(); $delivery->editPropertyValues($this->getProperty(ProctorService::ACCESSIBLE_PROCTOR), ( $proctoredByDefault ? ProctorService::ACCESSIBLE_PROCTOR_ENABLED : ProctorService::ACCESSIBLE_PROCTOR_DISABLED )); } /** * Listen update event for delivery * @param DeliveryUpdatedEvent $event */ public function onDeliveryUpdated(DeliveryUpdatedEvent $event) { $data = $event->jsonSerialize(); $deliveryData = !empty($data['data']) ? $data['data'] : []; $delivery = $this->getResource($event->getDeliveryUri()); if (isset($deliveryData[ProctorService::ACCESSIBLE_PROCTOR]) && !$deliveryData[ProctorService::ACCESSIBLE_PROCTOR]) { $delivery->editPropertyValues($this->getProperty(ProctorService::ACCESSIBLE_PROCTOR), ProctorService::ACCESSIBLE_PROCTOR_DISABLED); } } /** * Whenever or not new deliveries should be proctored by default * @param boolean $proctored * @return $this */ public function setProctoredByDefault($proctored) { $this->setOption(self::PROCTORED_BY_DEFAULT, $proctored); return $this; } /** * @return boolean */ public function isProctoredByDefault() { return $this->hasOption(self::PROCTORED_BY_DEFAULT) ? $this->getOption(self::PROCTORED_BY_DEFAULT) : true; } }