* @package oat\taoTestTaker\actions */ class TestTakerGenerisTree extends tao_actions_GenerisTree { /** * @see tao_actions_GenerisTree::setValues() */ public function setValues() { $parentResult = parent::setValues(); $this->getEventManager()->trigger(new TestTakerUpdatedEvent($this->getRequestParameter('resourceUri'), [])); return $parentResult; } /** * @see tao_actions_GenerisTree::setReverseValues() */ public function setReverseValues() { if (!$this->isXmlHttpRequest()) { throw new common_exception_IsAjaxAction(__FUNCTION__); } $values = tao_helpers_form_GenerisTreeForm::getSelectedInstancesFromPost(); $resource = $this->getResource($this->getRequestParameter('resourceUri')); $property = $this->getProperty($this->getRequestParameter('propertyUri')); $ttClass = $this->getClass('http://www.tao.lu/Ontologies/TAOSubject.rdf#Subject'); $instances = $ttClass->searchInstances([ $property->getUri() => $resource ], ['recursive' => true, 'like' => false]); $currentValues = array_merge([], array_keys($instances)); $toAdd = array_diff($values, $currentValues); $toRemove = array_diff($currentValues, $values); $success = true; foreach ($toAdd as $uri) { $subject = $this->getResource($uri); $success = $success && $subject->setPropertyValue($property, $resource); } foreach ($toRemove as $uri) { $subject = $this->getResource($uri); $success = $success && $subject->removePropertyValue($property, $resource); } $touchedValues = array_merge_recursive($toRemove, $values); foreach ($touchedValues as $uri) { $this->getEventManager()->trigger(new TestTakerUpdatedEvent($uri, [])); } return $this->returnJson(['saved' => $success]); } /** * @return EventManager */ private function getEventManager(): EventManager { return $this->getServiceLocator()->get(EventManager::SERVICE_ID); } }