Exemple #1
0
 /**
  * Create a new index
  * 
  * @param \core_kernel_classes_Property $property
  * @param unknown $identifier
  * @param \core_kernel_classes_Resource $tokenizer
  * @param unknown $isFuzzyMatching
  * @param unknown $isDefaultSearchable
  * @return \oat\tao\model\search\Index
  */
 public static function createIndex(\core_kernel_classes_Property $property, $identifier, \core_kernel_classes_Resource $tokenizer, $isFuzzyMatching, $isDefaultSearchable)
 {
     $class = new \core_kernel_classes_Class(Index::RDF_TYPE);
     $existingIndex = self::getIndexById($identifier);
     if (!is_null($existingIndex)) {
         throw new \common_Exception('Index ' . $identifier . ' already in use');
     }
     // verify identifier is unused
     $resource = $class->createInstanceWithProperties(array(RDFS_LABEL => $identifier, INDEX_PROPERTY_IDENTIFIER => $identifier, INDEX_PROPERTY_TOKENIZER => $tokenizer, INDEX_PROPERTY_FUZZY_MATCHING => $isFuzzyMatching ? GENERIS_TRUE : GENERIS_FALSE, INDEX_PROPERTY_DEFAULT_SEARCH => $isDefaultSearchable ? GENERIS_TRUE : GENERIS_FALSE));
     $property->setPropertyValue(new \core_kernel_classes_Property(INDEX_PROPERTY), $resource);
     return new Index($resource);
 }
 /**
  * Expose or not a property
  *
  * @param RdfProperty $property the property to check
  * @param bool        $value    true if exposed
  *
  * @return void
  */
 public function exposeCategory(RdfProperty $property, $value)
 {
     $exposeProperty = new RdfProperty(self::EXPOSE_PROP_URI);
     if ($value == true) {
         $property->setPropertyValue($exposeProperty, GENERIS_TRUE);
     } else {
         $property->removePropertyValue($exposeProperty, GENERIS_TRUE);
     }
 }
 /**
  * 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 createProcessVariable
  *
  * @access public
  * @author Somsack Sipasseuth, <*****@*****.**>
  * @param  string label
  * @param  string code
  * @return core_kernel_classes_Resource
  */
 public function createProcessVariable($label = '', $code = '')
 {
     $returnValue = null;
     if (!empty($code) && $this->getProcessVariable($code)) {
         throw new Exception("A process variable with the code '{$code}' already exists");
     }
     if (empty($label)) {
         $label = "Process variable";
         if (!empty($code)) {
             $label .= " " . $code;
         }
     }
     $returnValue = $this->createInstance($this->processVariablesClass, $label);
     if (!empty($code)) {
         $returnValue->setPropertyValue($this->codeProperty, $code);
     }
     //set the new instance of process variable as a property of the class process instance:
     $ok = $returnValue->setType(new core_kernel_classes_Class(RDF_PROPERTY));
     if ($ok) {
         $newTokenProperty = new core_kernel_classes_Property($returnValue->getUri());
         $newTokenProperty->setDomain(new core_kernel_classes_Class(CLASS_ACTIVITY_EXECUTION));
         $newTokenProperty->setRange(new core_kernel_classes_Class(RDFS_LITERAL));
         //literal only!
         $newTokenProperty->setPropertyValue(new core_kernel_classes_Property(PROPERTY_MULTIPLE), GENERIS_TRUE);
     } else {
         throw new Exception("the newly created process variable {$label} ({$returnValue->getUri()}) cannot be set as a property of the class Activity Execution");
     }
     return $returnValue;
 }