/**
  * Enable you to map an rdf property to a form element using the Widget
  *
  * @access public
  * @author Bertrand Chevrier, <*****@*****.**>
  * @param  Property property
  * @return tao_helpers_form_FormElement
  */
 public static function elementMap(core_kernel_classes_Property $property)
 {
     $returnValue = null;
     //create the element from the right widget
     $property->feed();
     $widgetResource = $property->getWidget();
     if (is_null($widgetResource)) {
         return null;
     }
     //authoring widget is not used in standalone mode
     if ($widgetResource->getUri() == 'http://www.tao.lu/datatypes/WidgetDefinitions.rdf#Authoring' && tao_helpers_Context::check('STANDALONE_MODE')) {
         return null;
     }
     // horrible hack to fix file widget
     if ($widgetResource->getUri() == 'http://www.tao.lu/datatypes/WidgetDefinitions.rdf#AsyncFile') {
         $widgetResource = new core_kernel_classes_Resource('http://www.tao.lu/datatypes/WidgetDefinitions.rdf#GenerisAsyncFile');
     }
     $element = tao_helpers_form_FormFactory::getElementByWidget(tao_helpers_Uri::encode($property->getUri()), $widgetResource);
     if (!is_null($element)) {
         if ($element->getWidget() != $widgetResource->getUri()) {
             common_Logger::w('Widget definition differs from implementation: ' . $element->getWidget() . ' != ' . $widgetResource->getUri());
             return null;
         }
         //use the property label as element description
         $propDesc = strlen(trim($property->getLabel())) > 0 ? $property->getLabel() : str_replace(LOCAL_NAMESPACE, '', $property->getUri());
         $element->setDescription($propDesc);
         //multi elements use the property range as options
         if (method_exists($element, 'setOptions')) {
             $range = $property->getRange();
             if ($range != null) {
                 $options = array();
                 if ($element instanceof tao_helpers_form_elements_Treeview) {
                     if ($property->getUri() == RDFS_RANGE) {
                         $options = self::rangeToTree(new core_kernel_classes_Class(RDFS_RESOURCE));
                     } else {
                         $options = self::rangeToTree($range);
                     }
                 } else {
                     foreach ($range->getInstances(true) as $rangeInstance) {
                         $options[tao_helpers_Uri::encode($rangeInstance->getUri())] = $rangeInstance->getLabel();
                     }
                     //set the default value to an empty space
                     if (method_exists($element, 'setEmptyOption')) {
                         $element->setEmptyOption(' ');
                     }
                 }
                 //complete the options listing
                 $element->setOptions($options);
             }
         }
         $returnValue = $element;
     }
     return $returnValue;
 }
 protected function data_dump($data, $sortProperty = null)
 {
     if ($data instanceof core_kernel_classes_Resource) {
         $propertyValues = array();
         $epoch = '';
         foreach ($data->getRdfTriples()->getIterator() as $triple) {
             $key = $triple->predicate;
             if (!is_null($sortProperty) && $sortProperty->getUri() == $key) {
                 $epoch = $triple->epoch;
             }
             if ($this->diplayPropertyLabels) {
                 if (!isset($this->propertyLabels[$key])) {
                     $property = new core_kernel_classes_Property($key);
                     $this->propertyLabels[$key] = trim(strip_tags($property->getLabel()));
                 }
                 if (!empty($this->propertyLabels[$key])) {
                     $key = $this->propertyLabels[$key];
                 }
             }
             $value = $triple->object;
             if ($this->unserialize && preg_match('/^a:[0-9]{1,2}:{/i', $value)) {
                 $unserializedValue = unserialize($value);
                 if (!is_null($unserializedValue)) {
                     $desc = is_array($unserializedValue) ? 'array ' . count($unserializedValue) . ': ' . implode(', ', array_keys($unserializedValue)) : 'object';
                     if ($this->unserialize == 2) {
                         $value = array("unserialized ({$desc})" => $unserializedValue);
                     } else {
                         $value = array("unserialized ({$desc})" => $value);
                     }
                 }
             }
             if (isset($propertyValues[$key])) {
                 if (is_array($propertyValues[$key])) {
                     $propertyValues[$key][] = $value;
                 } else {
                     $propertyValues[$key] = array($propertyValues[$key], $value);
                 }
             } else {
                 $propertyValues[$key] = $value;
             }
         }
         $returnValue = array('resource' => "{$data->getLabel()} ({$data->getUri()})", 'properties' => $propertyValues);
         if (!empty($epoch)) {
             $returnValue['epoch'] = $epoch;
         }
         var_dump($returnValue);
     } else {
         var_dump($data);
     }
 }
 /**
  * Short description of method createSPX
  *
  * @access public
  * @author firstname and lastname of author, <*****@*****.**>
  * @param  Resource $subject
  * @param  Property $predicate
  * @return core_kernel_rules_Term
  */
 public static function createSPX(core_kernel_classes_Resource $subject, core_kernel_classes_Property $predicate)
 {
     $returnValue = null;
     $termSPXClass = new core_kernel_classes_Class(CLASS_TERM_SUJET_PREDICATE_X, __METHOD__);
     $label = 'Def Term SPX Label : ' . $subject->getLabel() . ' - ' . $predicate->getLabel();
     $comment = 'Def Term SPX Label : ' . $subject->getUri() . ' ' . $predicate->getUri();
     $SPXResource = core_kernel_classes_ResourceFactory::create($termSPXClass, $label, $comment);
     $returnValue = new core_kernel_rules_Term($SPXResource->getUri());
     $subjectProperty = new core_kernel_classes_Property(PROPERTY_TERM_SPX_SUBJET, __METHOD__);
     $predicateProperty = new core_kernel_classes_Property(PROPERTY_TERM_SPX_PREDICATE, __METHOD__);
     $returnValue->setPropertyValue($subjectProperty, $subject->getUri());
     $returnValue->setPropertyValue($predicateProperty, $predicate->getUri());
     return $returnValue;
 }
 /**
  * Enable you to map an rdf property to a form element using the Widget
  *
  * @access public
  * @author Bertrand Chevrier, <*****@*****.**>
  * @param  core_kernel_classes_Property $property
  * @return tao_helpers_form_FormElement
  */
 public static function elementMap(core_kernel_classes_Property $property)
 {
     $returnValue = null;
     //create the element from the right widget
     $property->feed();
     $widgetResource = $property->getWidget();
     if (is_null($widgetResource)) {
         return null;
     }
     //authoring widget is not used in standalone mode
     if ($widgetResource->getUri() === 'http://www.tao.lu/datatypes/WidgetDefinitions.rdf#Authoring' && tao_helpers_Context::check('STANDALONE_MODE')) {
         return null;
     }
     // horrible hack to fix file widget
     if ($widgetResource->getUri() === 'http://www.tao.lu/datatypes/WidgetDefinitions.rdf#AsyncFile') {
         $widgetResource = new core_kernel_classes_Resource('http://www.tao.lu/datatypes/WidgetDefinitions.rdf#GenerisAsyncFile');
     }
     $element = tao_helpers_form_FormFactory::getElementByWidget(tao_helpers_Uri::encode($property->getUri()), $widgetResource);
     if (!is_null($element)) {
         if ($element->getWidget() !== $widgetResource->getUri()) {
             common_Logger::w('Widget definition differs from implementation: ' . $element->getWidget() . ' != ' . $widgetResource->getUri());
             return null;
         }
         //use the property label as element description
         $propDesc = strlen(trim($property->getLabel())) > 0 ? $property->getLabel() : str_replace(LOCAL_NAMESPACE, '', $property->getUri());
         $element->setDescription($propDesc);
         //multi elements use the property range as options
         if (method_exists($element, 'setOptions')) {
             $range = $property->getRange();
             if ($range !== null) {
                 $options = array();
                 if ($element instanceof TreeAware) {
                     $sortedOptions = $element->rangeToTree($property->getUri() === RDFS_RANGE ? new core_kernel_classes_Class(RDFS_RESOURCE) : $range);
                 } else {
                     /** @var core_kernel_classes_Resource $rangeInstance */
                     foreach ($range->getInstances(true) as $rangeInstance) {
                         $level = $rangeInstance->getOnePropertyValue(new core_kernel_classes_Property(TAO_LIST_LEVEL_PROP));
                         if (is_null($level)) {
                             $options[tao_helpers_Uri::encode($rangeInstance->getUri())] = array(tao_helpers_Uri::encode($rangeInstance->getUri()), $rangeInstance->getLabel());
                         } else {
                             $level = $level instanceof core_kernel_classes_Resource ? $level->getUri() : (string) $level;
                             $options[$level] = array(tao_helpers_Uri::encode($rangeInstance->getUri()), $rangeInstance->getLabel());
                         }
                     }
                     ksort($options);
                     $sortedOptions = array();
                     foreach ($options as $id => $values) {
                         $sortedOptions[$values[0]] = $values[1];
                     }
                     //set the default value to an empty space
                     if (method_exists($element, 'setEmptyOption')) {
                         $element->setEmptyOption(' ');
                     }
                 }
                 //complete the options listing
                 $element->setOptions($sortedOptions);
             }
         }
         foreach (ValidationRuleRegistry::getRegistry()->getValidators($property) as $validator) {
             $element->addValidator($validator);
         }
         $returnValue = $element;
     }
     return $returnValue;
 }
 /**
  * Get array of user specific extra fields to be displayed in the monitoring data table
  * 
  * @return array
  */
 private static function _getUserExtraFields()
 {
     if (!self::$extraFields) {
         $proctoringExtension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoProctoring');
         $userExtraFields = $proctoringExtension->getConfig('monitoringUserExtraFields');
         if (!empty($userExtraFields) && is_array($userExtraFields)) {
             foreach ($userExtraFields as $name => $uri) {
                 $property = new \core_kernel_classes_Property($uri);
                 self::$extraFields[] = array('id' => $name, 'property' => $property, 'label' => $property->getLabel());
             }
         }
     }
     return self::$extraFields;
 }
 /**
  * Short description of method evaluateSPX
  *
  * @access protected
  * @author firstname and lastname of author, <*****@*****.**>
  * @param  array $variable
  * @return mixed
  */
 protected function evaluateSPX($variable = array())
 {
     common_Logger::d('SPX TYPE', array('Generis Term evaluateSPX'));
     $resource = $this->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_TERM_SPX_SUBJET));
     if ($resource instanceof core_kernel_classes_Resource) {
         if (array_key_exists($resource->getUri(), $variable)) {
             common_Logger::d('Variable uri : ' . $resource->getUri() . ' found', array('Generis Term evaluateSPX'));
             common_Logger::d('Variable name : ' . $resource->getLabel() . ' found', array('Generis Term evaluateSPX'));
             $resource = new core_kernel_classes_Resource($variable[$resource->getUri()]);
             common_Logger::d('Variable repaced uri : ' . $resource->getUri(), array('Generis Term evaluateSPX'));
             common_Logger::d('Variable repaced name : ' . $resource->getLabel(), array('Generis Term evaluateSPX'));
         }
         try {
             $propertyInstance = $this->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_TERM_SPX_PREDICATE));
         } catch (common_Exception $e) {
             echo $e;
             var_dump($this);
             die('unable to get property value in Term');
         }
         //    		if(array_key_exists($propertyInstance->getUri(),$variable)) {
         //				$logger->debug('Variable uri : ' .  $propertyInstance->getUri() . ' found' , __FILE__, __LINE__);
         //    			$logger->debug('Variable name : ' .  $propertyInstance->getLabel() . ' found' , __FILE__, __LINE__);
         //				$propertyInstance = new core_kernel_classes_Resource($variable[$resource->getUri()]);
         //    			$logger->debug('Variable repaced uri : ' .  $propertyInstance->getUri() , __FILE__, __LINE__);
         //    			$logger->debug('Variable repaced name : ' .  $propertyInstance->getLabel() , __FILE__, __LINE__);
         //    	    }
         $property = new core_kernel_classes_Property($propertyInstance->getUri());
         common_Logger::d('Property uri ' . $property->getUri(), array('Generis Term evaluateSPX'));
         common_Logger::d('Property name ' . $property->getLabel(), array('Generis Term evaluateSPX'));
         $returnValue = $resource->getPropertyValuesCollection($property);
         common_Logger::d($returnValue->count() . ' values returned ', array('Generis Term evaluateSPX'));
         if ($returnValue->isEmpty()) {
             $newEmptyTerm = new core_kernel_rules_Term(INSTANCE_TERM_IS_NULL, __METHOD__);
             common_Logger::d('Empty Term Created', array('Generis Term evaluateSPX'));
             $property = new core_kernel_classes_Property(PROPERTY_TERM_VALUE);
             $returnValue = $newEmptyTerm->getUniquePropertyValue($property);
         } else {
             if ($returnValue->count() == 1) {
                 $returnValue = $returnValue->get(0);
             }
         }
     }
     return $returnValue;
 }
 /**
  * Render the add index sub form.
  * @throws Exception
  * @return void
  */
 public function addPropertyIndex()
 {
     if (!tao_helpers_Request::isAjax()) {
         throw new Exception("wrong request mode");
     }
     if (!$this->hasRequestParameter('uri')) {
         throw new Exception("wrong request Parameter");
     }
     $uri = $this->getRequestParameter('uri');
     $clazz = $this->getCurrentClass();
     $index = 1;
     if ($this->hasRequestParameter('index')) {
         $index = $this->getRequestParameter('index');
     }
     $propertyIndex = 1;
     if ($this->hasRequestParameter('propertyIndex')) {
         $propertyIndex = $this->getRequestParameter('propertyIndex');
     }
     //create and attach the new index property to the property
     $property = new core_kernel_classes_Property(tao_helpers_Uri::decode($uri));
     $class = new \core_kernel_classes_Class("http://www.tao.lu/Ontologies/TAO.rdf#Index");
     //get property range to select a default tokenizer
     /** @var core_kernel_classes_Class $range */
     $range = $property->getRange();
     //range is empty select item content
     $tokenizer = null;
     if (is_null($range)) {
         $tokenizer = new core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAO.rdf#RawValueTokenizer');
     } else {
         $tokenizer = $range->getUri() === RDFS_LITERAL ? new core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAO.rdf#RawValueTokenizer') : new core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAO.rdf#LabelTokenizer');
     }
     $indexClass = new core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAO.rdf#Index');
     $i = 0;
     $indexIdentifierBackup = preg_replace('/[^a-z_0-9]/', '_', strtolower($property->getLabel()));
     $indexIdentifierBackup = ltrim(trim($indexIdentifierBackup, '_'), '0..9');
     $indexIdentifier = $indexIdentifierBackup;
     do {
         if ($i !== 0) {
             $indexIdentifier = $indexIdentifierBackup . '_' . $i;
         }
         $resources = $indexClass->searchInstances(array(INDEX_PROPERTY_IDENTIFIER => $indexIdentifier), array('like' => false));
         $count = count($resources);
         $i++;
     } while ($count !== 0);
     $indexProperty = $class->createInstanceWithProperties(array(RDFS_LABEL => preg_replace('/_/', ' ', ucfirst($indexIdentifier)), INDEX_PROPERTY_IDENTIFIER => $indexIdentifier, INDEX_PROPERTY_TOKENIZER => $tokenizer, INDEX_PROPERTY_FUZZY_MATCHING => GENERIS_TRUE, INDEX_PROPERTY_DEFAULT_SEARCH => GENERIS_FALSE));
     $property->setPropertyValue(new core_kernel_classes_Property(INDEX_PROPERTY), $indexProperty);
     //generate form
     $indexFormContainer = new tao_actions_form_IndexProperty($clazz, $indexProperty, array('index' => $index, 'propertyindex' => $propertyIndex));
     $myForm = $indexFormContainer->getForm();
     $form = trim(preg_replace('/\\s+/', ' ', $myForm->renderElements()));
     echo json_encode(array('form' => $form));
 }
 /**
  * Short description of method __construct
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Property property
  * @return mixed
  */
 public function __construct(core_kernel_classes_Property $property)
 {
     $this->property = $property;
     parent::__construct($property->getLabel());
 }
 /**
  * search the instances of an ontology
  * @return
  */
 public function search()
 {
     $found = false;
     try {
         $clazz = $this->getCurrentClass();
     } catch (Exception $e) {
         common_Logger::i('Search : could not find current class switch to root class');
         $clazz = $this->getRootClass();
     }
     $formContainer = $this->getSearchForm($clazz);
     $myForm = $formContainer->getForm();
     if (tao_helpers_Context::check('STANDALONE_MODE')) {
         $standAloneElt = tao_helpers_form_FormFactory::getElement('standalone', 'Hidden');
         $standAloneElt->setValue(true);
         $myForm->addElement($standAloneElt);
     }
     if ($myForm->isSubmited()) {
         if ($myForm->isValid()) {
             $filters = $myForm->getValues('filters');
             $model = array();
             foreach ($filters as $propUri => $filter) {
                 if (preg_match("/^http/", $propUri) && !empty($filter)) {
                     $property = new core_kernel_classes_Property($propUri);
                     $model[$property->getUri()] = array('id' => $property->getUri(), 'label' => $property->getLabel(), 'sortable' => true);
                 } else {
                     unset($filters[$propUri]);
                 }
             }
             $clazz = new core_kernel_classes_Class($myForm->getValue('clazzUri'));
             if (!array_key_exists(RDFS_LABEL, $model)) {
                 $labelProp = new core_kernel_classes_Property(RDFS_LABEL);
                 $model = array_merge(array($labelProp->getUri() => array('id' => $labelProp->getUri(), 'label' => $labelProp->getLabel(), 'sortable' => true)), $model);
             }
             $params = $myForm->getValues('params');
             if (!isset($params['recursive'])) {
                 // 0 => Current class + sub-classes, 10 => Current class only
                 $params['recursive'] = true;
             } else {
                 $params['recursive'] = false;
             }
             $params['like'] = false;
             return $this->returnJson(array('url' => _url('searchResults', null, null, array('classUri' => $clazz->getUri())), 'params' => $params, 'model' => $model, 'filters' => $filters, 'result' => true));
         }
     }
     $this->setData('myForm', $myForm->render());
     $this->setData('formTitle', __('Search'));
     $this->setView('form/search.tpl', 'tao');
 }
Exemple #10
0
 /**
  * Generate a key for the property to use during export
  * 
  * @param string $uri
  * @return string
  */
 protected function generateId($uri)
 {
     $property = new \core_kernel_classes_Property($uri);
     $label = strtolower(trim($property->getLabel()));
     $label = preg_replace(array('/\\s/', '[^a-z\\-]'), array('-', ''), $label);
     return empty($label) ? 'key' : $label;
 }
 /**
  * Should not be called directly but is public
  * since Renderer is public
  * 
  * @param core_kernel_classes_Resource $resource
  * @param core_kernel_classes_Property $property
  */
 public function __construct(core_kernel_classes_Resource $resource, core_kernel_classes_Property $property)
 {
     $tpl = Template::getTemplate('form' . DIRECTORY_SEPARATOR . 'generis_tree_form.tpl', 'tao');
     parent::__construct($tpl);
     $this->setData('id', 'uid' . md5($property->getUri() . $resource->getUri()));
     $this->setData('title', $property->getLabel());
     $this->setData('resourceUri', $resource->getUri());
     $this->setData('propertyUri', $property->getUri());
 }
 public static function getChoiceElement(core_kernel_classes_Resource $instance, core_kernel_classes_Property $property, $options, $widget = 'Radiobox')
 {
     $elementChoice = null;
     $elementChoice = tao_helpers_form_FormFactory::getElement(tao_helpers_Uri::encode($property->getUri()), $widget);
     $elementChoice->setDescription($property->getLabel());
     //check the validity of the widget type
     if (!in_array($widget, array('Radiobox', 'Checkbox', 'Combobox'))) {
         return $elementChoice;
     }
     //set the options:
     $elementChoice->setOptions($options);
     //set the value:
     $propertyValuesCollection = $instance->getPropertyValuesCollection($property);
     foreach ($propertyValuesCollection->getIterator() as $propertyValue) {
         if ($propertyValue instanceof core_kernel_classes_Resource) {
             $elementChoice->setValue($propertyValue->getUri());
         } elseif ($propertyValue instanceof core_kernel_classes_Literal) {
             $elementChoice->setValue($propertyValue->literal);
         }
     }
     return $elementChoice;
 }