public static function getIndexes(\core_kernel_classes_Property $property)
 {
     $indexUris = $property->getPropertyValues(new \core_kernel_classes_Property('http://www.tao.lu/Ontologies/TAO.rdf#PropertyIndex'));
     $indexes = array();
     foreach ($indexes as $indexUri) {
         $indexes[] = new Index($indexUri);
     }
 }
Exemplo n.º 2
0
 /**
  * Get all indexes of a property
  * 
  * @param \core_kernel_classes_Property $property
  * @return multitype:\oat\tao\model\search\Index
  */
 public static function getIndexes(\core_kernel_classes_Property $property)
 {
     $indexUris = $property->getPropertyValues(new \core_kernel_classes_Property(INDEX_PROPERTY));
     $indexes = array();
     foreach ($indexUris as $indexUri) {
         $indexes[] = new Index($indexUri);
     }
     return $indexes;
 }
Exemplo n.º 3
0
 /**
  * remove a class property
  * 
  * @param core_kernel_classes_Property $property            
  * @return bool
  */
 public function deleteClassProperty(core_kernel_classes_Property $property)
 {
     $indexes = $property->getPropertyValues(new core_kernel_classes_Property(INDEX_PROPERTY));
     //delete property and the existing values of this property
     if ($returnValue = $property->delete(true)) {
         //delete index linked to the property
         foreach ($indexes as $indexUri) {
             $index = new core_kernel_classes_Resource($indexUri);
             $returnValue = $this->deletePropertyIndex($index);
         }
     }
     return $returnValue;
 }
Exemplo n.º 4
0
 public function getValidators(\core_kernel_classes_Property $property)
 {
     $validationProp = $this->getProperty(self::PROPERTY_VALIDATION_RULE);
     $rules = [];
     foreach ($property->getPropertyValues($validationProp) as $ruleId) {
         $rule = $this->get($ruleId);
         if ($rule == '') {
             throw new \common_exception_NotFound('No validation rule found with id "' . $ruleId . '"');
         }
         $rules[] = $rule;
     }
     return $rules;
 }
 /**
  * Imports the currently loaded CsvFile into the destination Class.
  * The map should be set in the options before executing it.
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param  string $source
  * @param  core_kernel_classes_Class $destination
  * @return common_report_Report
  */
 public function import($source, core_kernel_classes_Class $destination = null)
 {
     if (!isset($this->options['map'])) {
         throw new BadFunctionCallException("import map not set");
     }
     if (is_null($destination)) {
         throw new InvalidArgumentException("{$destination} must be a valid core_kernel_classes_Class");
     }
     $csvData = $this->load($source);
     $createdResources = 0;
     $rangeProperty = new core_kernel_classes_Property(RDFS_RANGE);
     for ($rowIterator = 0; $rowIterator < $csvData->count(); $rowIterator++) {
         helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::SHORT);
         common_Logger::d("CSV - Importing CSV row {$rowIterator}.");
         $resource = null;
         $csvRow = $csvData->getRow($rowIterator);
         //create the instance with the label defined in the map
         $label = $this->options['map'][RDFS_LABEL];
         if ($label != 'csv_select' && $label != 'csv_null') {
             if (isset($csvRow[$label])) {
                 $resource = $destination->createInstance($csvRow[$label]);
                 common_Logger::t("CSV - Resource creation with label");
             }
         }
         if (is_null($resource)) {
             $resource = $destination->createInstance();
             common_Logger::t("CSV - Resource creation without label");
         }
         if ($resource instanceof core_kernel_classes_Resource) {
             common_Logger::t("CSV - Resource successfully created");
             //import the value of each column into the property defined in the map
             foreach ($this->options['map'] as $propUri => $csvColumn) {
                 if ($propUri != RDFS_LABEL) {
                     // Already set at resource instantiation
                     $targetProperty = new core_kernel_classes_Property($propUri);
                     $ranges = $targetProperty->getPropertyValues($rangeProperty);
                     if (count($ranges) > 0) {
                         // @todo support multi-valued ranges in CSV import.
                         common_Logger::t("CSV - Target property has " . $ranges[0] . " for range");
                         $range = new core_kernel_classes_Resource($ranges[0]);
                     } else {
                         common_Logger::t("CSV - Target property has no range");
                         $range = null;
                     }
                     //stop future action if validation was not passed
                     $valid = $this->validate($destination, $propUri, $csvRow, $csvColumn);
                     if (!$valid) {
                         break;
                     }
                     if ($range == null || $range->getUri() == RDFS_LITERAL) {
                         // Deal with the column value as a literal.
                         common_Logger::t("CSV - Importing Literal from CSV");
                         $this->importLiteral($targetProperty, $resource, $csvRow, $csvColumn);
                     } else {
                         // Deal with the column value as a resource existing in the Knowledge Base.
                         common_Logger::t("CSV - Importing Resource from CSV");
                         $this->importResource($targetProperty, $resource, $csvRow, $csvColumn);
                     }
                 }
             }
             if ($valid) {
                 // Deal with default values.
                 $this->importStaticData($this->options['staticMap'], $this->options['map'], $resource);
                 // Apply 'resourceImported' callbacks.
                 foreach ($this->resourceImported as $callback) {
                     $callback($resource);
                 }
                 $createdResources++;
             } else {
                 $resource->delete();
             }
         }
         helpers_TimeOutHelper::reset();
     }
     $this->addOption('to_import', count($csvData));
     $this->addOption('imported', $createdResources);
     $report = $this->getResult($createdResources);
     return $report;
 }
Exemplo n.º 6
0
 protected function getIndexes(\core_kernel_classes_Property $property)
 {
     if (!isset($this->indexMap[$property->getUri()])) {
         $this->indexMap[$property->getUri()] = array();
         $indexes = $property->getPropertyValues($this->getProperty(INDEX_PROPERTY));
         foreach ($indexes as $indexUri) {
             $this->indexMap[$property->getUri()][] = new Index($indexUri);
         }
     }
     return $this->indexMap[$property->getUri()];
 }
Exemplo n.º 7
0
 /**
  * Initialize the form elements
  *
  * @access protected
  * @author Bertrand Chevrier, <*****@*****.**>
  * @return mixed
  */
 protected function initElements()
 {
     $property = new core_kernel_classes_Property($this->instance->getUri());
     isset($this->options['index']) ? $index = $this->options['index'] : ($index = 1);
     $propertyProperties = array_merge(tao_helpers_form_GenerisFormFactory::getDefaultProperties(), array(new core_kernel_classes_Property(PROPERTY_IS_LG_DEPENDENT), new core_kernel_classes_Property(TAO_GUIORDER_PROP)));
     $elementNames = array();
     foreach ($propertyProperties as $propertyProperty) {
         //map properties widgets to form elements
         $element = tao_helpers_form_GenerisFormFactory::elementMap($propertyProperty);
         if (!is_null($element)) {
             //take property values to populate the form
             $values = $property->getPropertyValuesCollection($propertyProperty);
             foreach ($values->getIterator() as $value) {
                 if (!is_null($value)) {
                     if ($value instanceof core_kernel_classes_Resource) {
                         $element->setValue($value->getUri());
                     }
                     if ($value instanceof core_kernel_classes_Literal) {
                         $element->setValue((string) $value);
                     }
                 }
             }
             $element->setName("{$index}_{$element->getName()}");
             $element->addClass('property');
             if ($propertyProperty->getUri() == TAO_GUIORDER_PROP) {
                 $element->addValidator(tao_helpers_form_FormFactory::getValidator('Integer'));
             }
             if ($propertyProperty->getUri() == RDFS_LABEL) {
                 $element->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
             }
             $this->form->addElement($element);
             $elementNames[] = $element->getName();
         }
     }
     //build the type list from the "widget/range to type" map
     $typeElt = tao_helpers_form_FormFactory::getElement("{$index}_type", 'Combobox');
     $typeElt->setDescription(__('Type'));
     $typeElt->addAttribute('class', 'property-type property');
     $typeElt->setEmptyOption(' --- ' . __('select') . ' --- ');
     $options = array();
     $checkRange = false;
     foreach (tao_helpers_form_GenerisFormFactory::getPropertyMap() as $typeKey => $map) {
         $options[$typeKey] = $map['title'];
         $widget = $property->getWidget();
         if ($widget instanceof core_kernel_classes_Resource) {
             if ($widget->getUri() == $map['widget']) {
                 $typeElt->setValue($typeKey);
                 $checkRange = is_null($map['range']);
             }
         }
     }
     $typeElt->setOptions($options);
     $this->form->addElement($typeElt);
     $elementNames[] = $typeElt->getName();
     //list drop down
     $listService = tao_models_classes_ListService::singleton();
     $listElt = tao_helpers_form_FormFactory::getElement("{$index}_range", 'Combobox');
     $listElt->setDescription(__('List values'));
     $listElt->addAttribute('class', 'property-listvalues property');
     $listElt->setEmptyOption(' --- ' . __('select') . ' --- ');
     $listOptions = array();
     foreach ($listService->getLists() as $list) {
         $listOptions[tao_helpers_Uri::encode($list->getUri())] = $list->getLabel();
         $range = $property->getRange();
         if (!is_null($range)) {
             if ($range->getUri() == $list->getUri()) {
                 $listElt->setValue($list->getUri());
             }
         }
     }
     $listOptions['new'] = ' + ' . __('Add / Edit lists');
     $listElt->setOptions($listOptions);
     if ($checkRange) {
         $listElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     }
     $this->form->addElement($listElt);
     $elementNames[] = $listElt->getName();
     //index part
     $indexes = $property->getPropertyValues(new \core_kernel_classes_Property(INDEX_PROPERTY));
     foreach ($indexes as $i => $indexUri) {
         $indexProperty = new \oat\tao\model\search\Index($indexUri);
         $indexFormContainer = new tao_actions_form_IndexProperty($this->getClazz(), $indexProperty, array('property' => $property->getUri(), 'propertyindex' => $index, 'index' => $i));
         /** @var tao_helpers_form_Form $indexForm */
         $indexForm = $indexFormContainer->getForm();
         foreach ($indexForm->getElements() as $element) {
             $this->form->addElement($element);
             $elementNames[] = $element->getName();
         }
     }
     //add this element only when the property is defined (type)
     if (!is_null($property->getRange())) {
         $addIndexElt = tao_helpers_form_FormFactory::getElement("index_{$index}_add", 'Free');
         $addIndexElt->setValue("<a href='#' class='btn-info index-adder small index'><span class='icon-add'></span> " . __('Add index') . "</a><div class='clearfix'></div>");
         $this->form->addElement($addIndexElt);
         $elementNames[] = $addIndexElt;
     } else {
         $addIndexElt = tao_helpers_form_FormFactory::getElement("index_{$index}_p", 'Free');
         $addIndexElt->setValue("<p class='index' >" . __('Choose a type for your property first') . "</p>");
         $this->form->addElement($addIndexElt);
         $elementNames[] = $addIndexElt;
     }
     //add an hidden elt for the property uri
     $encodedUri = tao_helpers_Uri::encode($property->getUri());
     $propUriElt = tao_helpers_form_FormFactory::getElement("{$index}_uri", 'Hidden');
     $propUriElt->addAttribute('class', 'property-uri property');
     $propUriElt->setValue($encodedUri);
     $this->form->addElement($propUriElt);
     $elementNames[] = $propUriElt;
     if (count($elementNames) > 0) {
         $groupTitle = $this->getGroupTitle($property);
         $this->form->createGroup("property_{$encodedUri}", $groupTitle, $elementNames);
     }
 }
Exemplo n.º 8
0
 protected function getIndexes(\core_kernel_classes_Property $property)
 {
     if (!isset($this->indexMap[$property->getUri()])) {
         $this->indexMap[$property->getUri()] = array();
         $indexes = $property->getPropertyValues(new \core_kernel_classes_Property('http://www.tao.lu/Ontologies/TAO.rdf#PropertyIndex'));
         foreach ($indexes as $indexUri) {
             $this->indexMap[$property->getUri()][] = new SolrIndex($indexUri);
         }
     }
     return $this->indexMap[$property->getUri()];
 }
 protected function indexProperty(Document $document, \core_kernel_classes_Property $property)
 {
     $indexes = $property->getPropertyValues(new \core_kernel_classes_Property('http://www.tao.lu/Ontologies/TAO.rdf#PropertyIndex'));
     foreach ($indexes as $indexUri) {
         $index = new Index($indexUri);
         $id = $index->getIdentifier();
         $strings = $index->tokenize($this->resource->getPropertyValues($property));
         if (!empty($strings)) {
             if ($index->isFuzzyMatching()) {
                 // cannot store multiple fuzzy strings
                 $string = implode(' ', $strings);
                 $field = Document\Field::Text($index->getIdentifier(), $string);
                 $field->isStored = $index->isStored();
                 $document->addField($field);
             } else {
                 $value = count($strings) > 1 ? $strings : reset($strings);
                 $field = Document\Field::Keyword($index->getIdentifier(), $value);
                 $field->isStored = $index->isStored() && !is_array($value);
                 // storage of arrays not supported
                 $document->addField($field);
             }
         }
     }
 }