/**
  * 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);
 }
Example #2
0
 /**
  * protected constructor to ensure singleton pattern
  */
 protected function __construct()
 {
     parent::__construct();
     $this->persistence = common_persistence_KeyValuePersistence::getPersistence(self::PERSISTENCE_ID);
 }
 /**
  * Entry point to get an instance of a service 
  * by it's short name.
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @deprecated
  * @param  string serviceName The name of the service you want to retrieve. You can set the complete class name, the interface name or only the ressource name managed by the service.
  * @return tao_models_classes_GenerisService
  */
 public static function get($serviceName)
 {
     $returnValue = null;
     $returnValue = tao_models_classes_Service::getServiceByName($serviceName);
     return $returnValue;
 }
 protected function __construct()
 {
     parent::__construct();
     $config = $this->getConfig();
     $this->register($config);
 }