/** * Generis API searchInstances function as an action * Developed for the facet based filter ... * @todo Is it a dangerous action ? */ public function searchInstances() { $returnValue = array(); $filter = array(); $properties = array(); if (!tao_helpers_Request::isAjax()) { //throw new Exception("wrong request mode"); } // Get the class paramater if ($this->hasRequestParameter('classUri')) { $clazz = $this->getCurrentClass(); } else { $clazz = $this->getRootClass(); } // Get filter parameter if ($this->hasRequestParameter('filter')) { $filter = $this->getFilterState('filter'); } $properties = tao_helpers_form_GenerisFormFactory::getClassProperties($clazz); // ADD Label property if (!array_key_exists(RDFS_LABEL, $properties)) { $new_properties = array(); $new_properties[RDFS_LABEL] = new core_kernel_classes_Property(RDFS_LABEL); $properties = array_merge($new_properties, $properties); } // Remove item content property if (array_key_exists(TAO_ITEM_CONTENT_PROPERTY, $properties)) { unset($properties[TAO_ITEM_CONTENT_PROPERTY]); } $instances = $this->service->searchInstances($filter, $clazz, array('recursive' => true)); $index = 0; foreach ($instances as $instance) { $returnValue[$index]['uri'] = $instance->getUri(); $formatedProperties = array(); foreach ($properties as $property) { //$formatedProperties[] = (string)$instance->getOnePropertyValue (new core_kernel_classes_Property($property)); $value = $instance->getOnePropertyValue($property); if ($value instanceof core_kernel_classes_Resource) { $value = $value->getLabel(); } else { $value = (string) $value; } $formatedProperties[] = $value; } $returnValue[$index]['properties'] = (object) $formatedProperties; $index++; } echo json_encode($returnValue); }