* @license GPLv2 http://www.opensource.org/licenses/gpl-2.0.php * @package tao */ use oat\tao\model\Tree\GetTreeRequest; use oat\tao\model\Tree\GetTreeService; use oat\generis\model\OntologyAwareTrait; class tao_actions_GenerisTree extends tao_actions_CommonModule { use OntologyAwareTrait; const DEFAULT_LIMIT = 10; public function getData() { /** @var GetTreeService $service */ $service = $this->getServiceLocator()->get(GetTreeService::SERVICE_ID); $response = $service->handle(GetTreeRequest::create($this->getRequest())); return $this->returnJson($response->getTreeArray()); } public function setValues() { 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')); $success = $resource->editPropertyValues($property, $values); return $this->returnJson(['saved' => $success ]); } 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')); $currentValues = []; foreach ($property->getDomain() as $domain) { $instances = $domain->searchInstances([ $property->getUri() => $resource ], ['recursive' => true, 'like' => false]); $currentValues = array_merge($currentValues, 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); } return $this->returnJson(['saved' => $success]); } }