コード例 #1
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()];
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
ファイル: class.TermFactory.php プロジェクト: nagyist/generis
 /**
  * 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;
 }
コード例 #4
0
ファイル: CardinalityTest.php プロジェクト: nagyist/tao-core
 /**
  * Test the service factory: dynamical instantiation and single instance serving
  */
 public function testMultiple()
 {
     $propClass = new core_kernel_classes_Class(RDF_PROPERTY);
     $q = "SELECT subject, count(object)\n                FROM statements\n                    WHERE predicate = ?\n                    GROUP BY subject\n                    HAVING (count(object) > 1)";
     foreach ($propClass->getInstances(true) as $property) {
         $property = new core_kernel_classes_Property($property);
         if (!$property->isMultiple() && !$property->isLgDependent()) {
             // bypass generis
             $result = core_kernel_classes_DbWrapper::singleton()->query($q, array($property->getUri()));
             while ($statement = $result->fetch()) {
                 $this->fail($property->getUri() . ' has multiple values but is not multiple.');
             }
         }
     }
 }
コード例 #5
0
 /**
  * 
  * @param \core_kernel_classes_Property $property
  * @param mixed $value
  * @param string $userMessage
  */
 public function __construct(\core_kernel_classes_Property $property, $value, $userMessage)
 {
     parent::__construct($userMessage . ' ' . $property->getUri() . ' ' . $value);
     $this->property = $property;
     $this->value = $value;
     $this->userMessage = $userMessage;
 }
コード例 #6
0
 public function setReverseValues()
 {
     if (!tao_helpers_Request::isAjax()) {
         throw new common_exception_IsAjaxAction(__FUNCTION__);
     }
     $values = tao_helpers_form_GenerisTreeForm::getSelectedInstancesFromPost();
     $resource = new core_kernel_classes_Resource($this->getRequestParameter('resourceUri'));
     $property = new core_kernel_classes_Property($this->getRequestParameter('propertyUri'));
     $currentValues = array();
     foreach ($property->getDomain() as $domain) {
         $instances = $domain->searchInstances(array($property->getUri() => $resource), array('recursive' => true, 'like' => false));
         $currentValues = array_merge($currentValues, array_keys($instances));
     }
     $toAdd = array_diff($values, $currentValues);
     $toRemove = array_diff($currentValues, $values);
     $success = true;
     foreach ($toAdd as $uri) {
         $subject = new core_kernel_classes_Resource($uri);
         $success = $success && $subject->setPropertyValue($property, $resource);
     }
     foreach ($toRemove as $uri) {
         $subject = new core_kernel_classes_Resource($uri);
         $success = $success && $subject->removePropertyValue($property, $resource);
     }
     echo json_encode(array('saved' => $success));
 }
コード例 #7
0
 /**
  * Get items of a specific model
  * @param string|core_kernel_classes_Resource $itemModel - the item model URI
  * @return core_kernel_classes_Resource[] the found items
  */
 public function getAllByModel($itemModel)
 {
     if (!empty($itemModel)) {
         $uri = $itemModel instanceof core_kernel_classes_Resource ? $itemModel->getUri() : $itemModel;
         return $this->itemClass->searchInstances(array($this->itemModelProperty->getUri() => $uri), array('recursive' => true));
     }
     return array();
 }
コード例 #8
0
 /**
  * Get groups to which delivery is assigned.
  * @param \core_kernel_classes_Resource $delivery
  * @return \core_kernel_classes_Resource[]
  */
 public function getGroups(\core_kernel_classes_Resource $delivery)
 {
     $result = array();
     $groupsProperty = new \core_kernel_classes_Property(PROPERTY_GROUP_DELVIERY);
     $domainCollection = $groupsProperty->getDomain();
     if (!$domainCollection->isEmpty()) {
         $domain = $domainCollection->get(0);
         $result = $domain->searchInstances(array($groupsProperty->getUri() => $delivery), array('recursive' => false, 'like' => false));
     }
     return $result;
 }
コード例 #9
0
 public function lookup(array $metadataValues)
 {
     $lookup = false;
     foreach ($metadataValues as $metadataValue) {
         $path = $metadataValue->getPath();
         $expectedPath = array(RDFS_LABEL);
         if ($path === $expectedPath) {
             // Check for such a value in database...
             $prop = new \core_kernel_classes_Property(RDFS_LABEL);
             $class = new \core_kernel_classes_Class(RDFS_CLASS);
             $instances = $class->searchInstances(array($prop->getUri() => $metadataValue->getValue()), array('like' => false, 'recursive' => true));
             if (count($instances) > 0) {
                 $lookup = new \core_kernel_classes_Class(reset($instances));
                 break;
             }
         }
     }
     return $lookup;
 }
コード例 #10
0
 /**
  * Short description of method initElements
  *
  * @access public
  * @author Bertrand Chevrier, <*****@*****.**>
  * @return mixed
  */
 public 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(PROPERTY_WIDGET), new core_kernel_classes_Property(RDFS_RANGE)));
     $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("property_{$index}_{$element->getName()}");
             $element->addClass('property');
             if ($propertyProperty->getUri() == RDFS_LABEL) {
                 $element->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
             }
             $this->form->addElement($element);
             $elementNames[] = $element->getName();
         }
     }
     $encodedUri = tao_helpers_Uri::encode($property->getUri());
     $modeElt = tao_helpers_form_FormFactory::getElement("{$index}_uri", 'Hidden');
     $modeElt->setValue($encodedUri);
     $modeElt->addClass('property');
     $this->form->addElement($modeElt);
     $elementNames[] = $modeElt->getName();
     if (count($elementNames) > 0) {
         $groupTitle = $this->getGroupTitle($property);
         $this->form->createGroup("property_{$encodedUri}", $groupTitle, $elementNames);
     }
 }
コード例 #11
0
 public function testSetPropertiesValues()
 {
     $this->hardify();
     $instance = $this->targetMovieClass->createInstance("Hard Sub Movie (Unit Test)");
     $instance2 = $this->targetMovieClass->createInstance("Hard Sub Movie2 (Unit Test)");
     $instance->setPropertiesValues(array($this->targetRelatedMoviesProperty->getUri() => $instance2, $this->targetActorsProperty->getUri() => array('I\'m special"! !', 'So special"! !'), RDFS_LABEL => 'I\'m special"! !'));
     $actors = $instance->getPropertyValues($this->targetActorsProperty);
     $this->assertEquals(2, count($actors));
     $this->assertTrue(in_array('I\'m special"! !', $actors));
     $this->assertTrue(in_array('So special"! !', $actors));
     $relateds = $instance->getPropertyValues($this->targetRelatedMoviesProperty);
     $this->assertEquals(1, count($relateds));
     $related = current($relateds);
     $this->assertEquals($instance2->getUri(), $related);
     $labels = $instance->getPropertyValues(new core_kernel_classes_Property(RDFS_LABEL));
     $this->assertEquals(2, count($labels));
     $this->assertTrue(in_array('I\'m special"! !', $labels));
     $this->assertTrue(in_array("Hard Sub Movie (Unit Test)", $labels));
     $instance->delete();
     $instance2->delete();
 }
コード例 #12
0
 public function guard(array $metadataValues)
 {
     $guard = false;
     // Search for a metadataValue with path:
     // http://www.imsglobal.org/xsd/imsmd_v1p2#lom
     // http://www.imsglobal.org/xsd/imsmd_v1p2#general
     // http://www.imsglobal.org/xsd/imsmd_v1p2#identifier
     foreach ($metadataValues as $metadataValue) {
         $path = $metadataValue->getPath();
         $expectedPath = array('http://www.imsglobal.org/xsd/imsmd_v1p2#lom', 'http://www.imsglobal.org/xsd/imsmd_v1p2#general', 'http://www.imsglobal.org/xsd/imsmd_v1p2#identifier');
         if ($path === $expectedPath) {
             // Check for such a value in database...
             $prop = new \core_kernel_classes_Property('http://www.imsglobal.org/xsd/imsmd_v1p2#identifier');
             $class = new \core_kernel_classes_Class(TAO_ITEM_CLASS);
             $instances = $class->searchInstances(array($prop->getUri() => $metadataValue->getValue()), array('like' => false, 'recursive' => true));
             if (count($instances) > 0) {
                 //var_dump($instances);
                 $guard = reset($instances);
                 break;
             }
         }
     }
     return $guard;
 }
コード例 #13
0
 /**
  * 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;
 }
コード例 #14
0
 /**
  * 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;
 }
コード例 #15
0
ファイル: class.Resource.php プロジェクト: nagyist/generis
 /**
  * Short description of method getUsedLanguages
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource resource
  * @param  Property property
  * @return array
  */
 public function getUsedLanguages(core_kernel_classes_Resource $resource, core_kernel_classes_Property $property)
 {
     $returnValue = array();
     $sqlQuery = 'SELECT l_language FROM statements WHERE subject = ? AND predicate = ? ';
     $sqlResult = $this->getPersistence()->query($sqlQuery, array($resource->getUri(), $property->getUri()));
     while ($row = $sqlResult->fetch()) {
         if (!empty($row['l_language'])) {
             $returnValue[] = $row['l_language'];
         }
     }
     return (array) $returnValue;
 }
コード例 #16
0
 /**
  * Return the cached description of the roles
  * that have access to this controller
  * 
  * @param string $controllerClassName
  * @return array
  */
 public static function getControllerAccess($controllerClassName)
 {
     try {
         $returnValue = self::getCacheImplementation()->get(self::SERIAL_PREFIX_MODULE . $controllerClassName);
     } catch (common_cache_Exception $e) {
         $extId = funcAcl_helpers_Map::getExtensionFromController($controllerClassName);
         $extension = funcAcl_helpers_Map::getUriForExtension($extId);
         $module = funcAcl_helpers_Map::getUriForController($controllerClassName);
         $roleClass = new core_kernel_classes_Class(CLASS_ROLE);
         $accessProperty = new core_kernel_classes_Property(funcAcl_models_classes_AccessService::PROPERTY_ACL_GRANTACCESS);
         $returnValue = array('module' => array(), 'actions' => array());
         // roles by extensions
         $roles = $roleClass->searchInstances(array($accessProperty->getUri() => $extension), array('recursive' => true, 'like' => false));
         foreach ($roles as $grantedRole) {
             $returnValue['module'][] = $grantedRole->getUri();
         }
         // roles by controller
         $filters = array($accessProperty->getUri() => $module);
         $options = array('recursive' => true, 'like' => false);
         foreach ($roleClass->searchInstances($filters, $options) as $grantedRole) {
             $returnValue['module'][] = $grantedRole->getUri();
         }
         // roles by action
         foreach (ControllerHelper::getActions($controllerClassName) as $actionName) {
             $actionUri = funcAcl_helpers_Map::getUriForAction($controllerClassName, $actionName);
             $rolesForAction = $roleClass->searchInstances(array($accessProperty->getUri() => $actionUri), array('recursive' => true, 'like' => false));
             if (!empty($rolesForAction)) {
                 $actionName = funcAcl_helpers_Map::getActionFromUri($actionUri);
                 $returnValue['actions'][$actionName] = array();
                 foreach ($rolesForAction as $roleResource) {
                     $returnValue['actions'][$actionName][] = $roleResource->getUri();
                 }
             }
         }
         self::getCacheImplementation()->put($returnValue, self::SERIAL_PREFIX_MODULE . $controllerClassName);
     }
     return $returnValue;
 }
コード例 #17
0
 /**
  * Short description of method deleteConnectorNextActivity
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource connector
  * @param  string connectionType
  * @return mixed
  */
 public function deleteConnectorNextActivity(core_kernel_classes_Resource $connector, $connectionType = 'next')
 {
     $nextActivitiesProp = new core_kernel_classes_Property(PROPERTY_STEP_NEXT);
     $connectorService = wfEngine_models_classes_ConnectorService::singleton();
     switch ($connectionType) {
         case 'next':
             $property = $nextActivitiesProp;
             break;
         case 'then':
             $property = new core_kernel_classes_Property(PROPERTY_TRANSITIONRULES_THEN);
             break;
         case 'else':
             $property = new core_kernel_classes_Property(PROPERTY_TRANSITIONRULES_ELSE);
             break;
         default:
             throw new Exception('Trying to delete the value of an unauthorized connector property');
     }
     $activityRefProp = new core_kernel_classes_Property(PROPERTY_CONNECTORS_ACTIVITYREFERENCE);
     $activityRef = $connector->getUniquePropertyValue($activityRefProp)->getUri();
     if ($property->getUri() == PROPERTY_STEP_NEXT) {
         //manage the connection to the following activities
         $nextActivityCollection = $connector->getPropertyValuesCollection($property);
         foreach ($nextActivityCollection->getIterator() as $nextActivity) {
             if ($connectorService->isConnector($nextActivity)) {
                 $nextActivityRef = $nextActivity->getUniquePropertyValue($activityRefProp)->getUri();
                 if ($nextActivityRef == $activityRef) {
                     //delete following connectors only if they have the same activity reference
                     wfAuthoring_models_classes_ConnectorService::singleton()->delete($nextActivity);
                 }
             }
         }
         $connector->removePropertyValues($nextActivitiesProp);
     } elseif ($property->getUri() == PROPERTY_TRANSITIONRULES_THEN || $property->getUri() == PROPERTY_TRANSITIONRULES_ELSE) {
         //it is a split connector: get the transition rule, if exists
         $transitionRule = $connector->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_CONNECTORS_TRANSITIONRULE));
         if (!is_null($transitionRule)) {
             $nextActivity = $transitionRule->getOnePropertyValue($property);
             if (!is_null($nextActivity)) {
                 if ($connectorService->isConnector($nextActivity)) {
                     $nextActivityRef = $nextActivity->getUniquePropertyValue($activityRefProp)->getUri();
                     if ($nextActivityRef == $activityRef) {
                         //delete following connectors only if they have the same activity reference
                         wfAuthoring_models_classes_ConnectorService::singleton()->delete($nextActivity);
                     }
                 }
                 $connector->removePropertyValues($nextActivitiesProp, array('pattern' => $nextActivity->getUri()));
                 $transitionRule->removePropertyValues($property, array('pattern' => $nextActivity->getUri()));
             }
         }
     }
 }
コード例 #18
0
 private function createSPX(core_kernel_classes_Resource $context, core_kernel_classes_Property $predicate)
 {
     $termClass = new core_kernel_classes_Class(CLASS_TERM_SUJET_PREDICATE_X, __METHOD__);
     $termInstance = $termClass->createInstance("Term : SPX " . $context->getUri() . "-" . $predicate->getUri(), 'generated by Condition Descriptor on ' . date(DATE_ISO8601));
     $subjectProperty = new core_kernel_classes_Property(PROPERTY_TERM_SPX_SUBJET, __METHOD__);
     $predicateProperty = new core_kernel_classes_Property(PROPERTY_TERM_SPX_PREDICATE, __METHOD__);
     $termInstance->setPropertyValue($subjectProperty, $context->getUri());
     $termInstance->setPropertyValue($predicateProperty, $predicate->getUri());
     return $termInstance;
 }
コード例 #19
0
 /**
  * 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());
 }
コード例 #20
0
    /**
     * Short description of method getUsedLanguages
     *
     * @access public
     * @author Joel Bout, <*****@*****.**>
     * @param  Resource resource
     * @param  Property property
     * @return array
     */
    public function getUsedLanguages(\core_kernel_classes_Resource $resource, \core_kernel_classes_Property $property)
    {
        $returnValue = array();
        $tableName = ResourceReferencer::singleton()->resourceLocation($resource);
        $sqlQuery = 'SELECT "' . $tableName . 'props"."l_language" FROM "' . $tableName . 'props" 
			LEFT JOIN "' . $tableName . '" ON "' . $tableName . '".id = "' . $tableName . 'props".instance_id
			WHERE "' . $tableName . '"."uri" = ? 
				AND "' . $tableName . 'props"."property_uri" = ?';
        $dbWrapper = \core_kernel_classes_DbWrapper::singleton();
        $sqlResult = $dbWrapper->query($sqlQuery, array($resource->getUri(), $property->getUri()));
        while ($row = $sqlResult->fetch()) {
            if (!empty($row['l_language'])) {
                $returnValue[] = $row['l_language'];
            }
        }
        return (array) $returnValue;
    }
コード例 #21
0
 /**
  * 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');
 }
コード例 #22
0
 /**
  * Short description of method __construct
  *
  * @access public
  * @param  core_kernel_classes_Resource resource
  * @param  core_kernel_classes_Property property
  * @return mixed
  */
 public function __construct(core_kernel_classes_Resource $resource, core_kernel_classes_Property $property)
 {
     $this->resource = $resource;
     $this->property = $property;
     parent::__construct('Property ( ' . $property->getUri() . ' ) of resource ' . ' ( ' . $resource->getUri() . ' ) has more than one value do not use getUniquePropertyValue but use getPropertyValue instead');
 }
コード例 #23
0
 public function testCreateInstanceWithProperties()
 {
     // simple case, without params
     $class = $this->class;
     $litproperty = new core_kernel_classes_Property(core_kernel_classes_ResourceFactory::create(new core_kernel_classes_Class(RDF_PROPERTY))->getUri());
     $property = new core_kernel_classes_Property(core_kernel_classes_ResourceFactory::create(new core_kernel_classes_Class(RDF_PROPERTY))->getUri());
     $instance = $class->createInstanceWithProperties(array());
     $this->assertTrue($instance->hasType($class));
     // simple literal properties
     $instance1 = $class->createInstanceWithProperties(array(RDFS_LABEL => 'testlabel', RDFS_COMMENT => 'testcomment'));
     $this->assertTrue($instance1->hasType($class));
     $this->assertEquals($instance1->getLabel(), 'testlabel');
     $this->assertEquals($instance1->getComment(), 'testcomment');
     // multiple literal properties
     $instance2 = $class->createInstanceWithProperties(array(RDFS_LABEL => 'testlabel', $litproperty->getUri() => array('testlit1', 'testlit2')));
     $this->assertTrue($instance2->hasType($class));
     $this->assertEquals($instance2->getLabel(), 'testlabel');
     $comments = $instance2->getPropertyValues($litproperty);
     sort($comments);
     $this->assertEquals($comments, array('testlit1', 'testlit2'));
     // single ressource properties
     $propInst = core_kernel_classes_ResourceFactory::create($class);
     $instance3 = $class->createInstanceWithProperties(array(RDFS_LABEL => 'testlabel', RDFS_COMMENT => 'testcomment', $property->getUri() => $propInst));
     $this->assertTrue($instance3->hasType($class));
     $this->assertEquals($instance3->getLabel(), 'testlabel');
     $propActual = $instance3->getUniquePropertyValue($property);
     // returns a ressource
     $this->assertEquals($propInst->getUri(), $propActual->getUri());
     // multiple ressource properties
     $propInst2 = core_kernel_classes_ResourceFactory::create($class);
     $instance4 = $class->createInstanceWithProperties(array(RDFS_LABEL => 'testlabel', RDFS_COMMENT => 'testcomment', $property->getUri() => array($propInst, $propInst2)));
     $this->assertTrue($instance4->hasType($class));
     $this->assertEquals($instance4->getLabel(), 'testlabel');
     $propActual = array_values($instance4->getPropertyValues($property));
     // returns uris
     $propNormative = array($propInst->getUri(), $propInst2->getUri());
     sort($propActual);
     sort($propNormative);
     $this->assertEquals($propActual, $propNormative);
     // multiple classes
     $classres = core_kernel_classes_ResourceFactory::create(new core_kernel_classes_Class(RDFS_CLASS), 'TestClass2');
     $class2 = new core_kernel_classes_Class($classres);
     $classres = core_kernel_classes_ResourceFactory::create(new core_kernel_classes_Class(RDFS_CLASS), 'TestClass3');
     $class3 = new core_kernel_classes_Class($classres);
     // 2 classes (by ressource)
     $instance5 = $class->createInstanceWithProperties(array(RDFS_LABEL => 'testlabel5', RDF_TYPE => $classres));
     $this->assertTrue($instance5->hasType($class));
     $this->assertTrue($instance5->hasType($class3));
     $this->assertEquals($instance5->getLabel(), 'testlabel5');
     // 3 classes (by uri + class)
     $instance6 = $class->createInstanceWithProperties(array(RDFS_LABEL => 'testlabel6', RDF_TYPE => array($class2, $class3->getUri())));
     $this->assertTrue($instance6->hasType($class));
     $this->assertTrue($instance6->hasType($class2));
     $this->assertTrue($instance6->hasType($class3));
     $this->assertEquals($instance6->getLabel(), 'testlabel6');
     $instance->delete();
     $instance1->delete();
     $instance2->delete();
     $propInst->delete();
     $propInst2->delete();
     $property->delete();
     $litproperty->delete();
     $instance5->delete();
     $instance6->delete();
     $class2->delete();
     $class3->delete();
 }
コード例 #24
0
    /**
     * Unhardify a specific class. Unhardifying a class implies that the instances of this
     * class will be transfered from specific optimized tables to the statement table, as RDF
     * triples.
     * 
     * The $options array is an associative array where values are all booleans. The keys that
     * can be used to pass specific unhardify options are the following:
     * 
     * - recursive: Unhardify the target class and its subclasses (default: false).
     *
     * @access public
     * @author Cédric Alfonsi, <*****@*****.**>
     * @param  \core_kernel_classes_Class class
     * @param  array options
     * @return boolean true if the resource was correctly unhardified, false otherwise.
     */
    public function unhardify(\core_kernel_classes_Class $class, $options = array())
    {
        $returnValue = (bool) false;
        $classLabel = $class->getLabel();
        \common_Logger::i("Unhardifying class {$classLabel}", 'GENERIS');
        if (defined("DEBUG_PERSISTENCE") && DEBUG_PERSISTENCE) {
            var_dump('unhardify ' . $class->getUri());
        }
        // Check if the class has been hardened
        if (!ResourceReferencer::singleton()->isClassReferenced($class)) {
            \common_Logger::w("Class {$classLabel} could not be unhardened because it is not hardified.");
            return false;
        }
        //if defined, we take all the properties of the class and it's parents till the topclass
        $classLocations = ResourceReferencer::singleton()->classLocations($class);
        $topclass = null;
        if (count($classLocations) > 1) {
            throw new Exception("Try to unhardify the class {$class->getUri()} which has multiple locations");
        } else {
            $topclass = new \core_kernel_classes_Class($classLocations[0]['topclass']);
        }
        //recursive will unhardify the class and it's subclasses in the same table!
        isset($options['recursive']) ? $recursive = $options['recursive'] : ($recursive = false);
        //removeForeigns will unhardify the class that are range of the properties
        isset($options['removeForeigns']) ? $removeForeigns = $options['removeForeigns'] : ($removeForeigns = false);
        //rmSources will remove the related data from the hard data after
        //transfer to the smooth data.
        $rmSources = true;
        // Get class' properties
        $propertySwitcher = new PropertySwitcher($class);
        $additionalProperties = array();
        $properties = $propertySwitcher->getProperties($additionalProperties);
        $columns = $propertySwitcher->getTableColumns($additionalProperties, self::$blackList);
        // Get all instances of this class
        $startIndex = 0;
        $instancePackSize = 100;
        $instances = $class->getInstances(false, array('offset' => $startIndex, 'limit' => $instancePackSize));
        $count = count($instances);
        $existingInstances = array();
        do {
            //reset timeout:
            \helpers_TimeOutHelper::setTimeOutLimit(\helpers_TimeOutHelper::MEDIUM);
            // lionel did that :d le salop
            PersistenceProxy::forceMode(PERSISTENCE_SMOOTH);
            foreach ($instances as $uri => $instance) {
                if ($instance->exists()) {
                    PersistenceProxy::forceMode(PERSISTENCE_HARD);
                    $instance->delete();
                    PersistenceProxy::restoreImplementation();
                    unset($instances[$uri]);
                    $existingInstances[] = $uri;
                }
            }
            PersistenceProxy::restoreImplementation();
            foreach ($instances as $instance) {
                // Get table name where the resource is located
                $tableName = ResourceReferencer::singleton()->resourceLocation($instance);
                // Get Instance type
                $types = $instance->getTypes();
                // Create instance in the smooth implementation
                PersistenceProxy::forceMode(PERSISTENCE_SMOOTH);
                $class->createInstance('', '', $instance->getUri());
                // set types to the newly created instance
                foreach ($types as $type) {
                    if (!$type->equals($class)) {
                        $instance->setType($type);
                    }
                }
                PersistenceProxy::restoreImplementation();
                // Export properties of the instance
                foreach ($columns as $column) {
                    $property = new \core_kernel_classes_Property(Utils::getLongName($column['name']));
                    // Multiple property
                    if (isset($column['multi']) && $column['multi']) {
                        $sqlQuery = 'SELECT
								"' . $tableName . 'props"."property_value",
								"' . $tableName . 'props"."property_foreign_uri", 
								"' . $tableName . 'props"."l_language" 
							FROM "' . $tableName . 'props"
							LEFT JOIN "' . $tableName . '" ON "' . $tableName . '"."id" = "' . $tableName . 'props"."instance_id"
							WHERE "' . $tableName . '"."uri" = ? 
								AND "' . $tableName . 'props"."property_uri" = ?';
                        $dbWrapper = \core_kernel_classes_DbWrapper::singleton();
                        $sqlResult = $dbWrapper->query($sqlQuery, array($instance->getUri(), $property->getUri()));
                        if ($sqlResult->errorCode() !== '00000') {
                            throw new Exception("unable to unhardify : " . $dbWrapper->errorMessage());
                        }
                        // ENTER IN SMOOTH SQL MODE
                        PersistenceProxy::forceMode(PERSISTENCE_SMOOTH);
                        while ($row = $sqlResult->fetch()) {
                            $value = null;
                            if (!empty($row['property_value'])) {
                                $value = $row['property_value'];
                            } else {
                                $value = $row['property_foreign_uri'];
                            }
                            $lg = $row['l_language'];
                            if (!empty($lg)) {
                                $instance->setPropertyValueByLg($property, $value, $lg);
                            } else {
                                $instance->setPropertyValue($property, $value);
                            }
                        }
                        /// EXIT HARD SQL MODE
                        PersistenceProxy::restoreImplementation();
                    } else {
                        $value = $instance->getOnePropertyValue($property);
                        if ($value != null) {
                            PersistenceProxy::forceMode(PERSISTENCE_SMOOTH);
                            $instance->setPropertyValue($property, $value);
                            PersistenceProxy::restoreImplementation();
                        }
                    }
                }
                // delete instance in the hard implementation
                $instance->delete();
            }
            //record decompiled instances number
            if (isset($this->decompiledClasses[$class->getUri()])) {
                $this->decompiledClasses[$class->getUri()] += $count;
            } else {
                $this->decompiledClasses[$class->getUri()] = $count;
            }
            //update instance array and count value
            $instances = $class->getInstances(false, array('offset' => $startIndex, 'limit' => $instancePackSize));
            foreach ($existingInstances as $uri) {
                unset($instances[$uri]);
            }
            $count = count($instances);
            \helpers_TimeOutHelper::reset();
        } while ($count > 0);
        // Unreference the class
        $returnValue = ResourceReferencer::singleton()->unReferenceClass($class);
        // If recursive, treat the subclasses
        if ($recursive) {
            foreach ($class->getSubClasses(true) as $subClass) {
                if (ResourceReferencer::singleton()->isClassReferenced($subClass)) {
                    $returnValue = $this->unhardify($subClass, $options);
                }
            }
        }
        return (bool) $returnValue;
    }
コード例 #25
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()];
 }
コード例 #26
0
 /**
  * 
  * @author Lionel Lecaque, lionel@taotesting.com
  * @param core_kernel_classes_Resource $source
  * @param core_kernel_classes_Resource $destination
  * @param core_kernel_classes_Property $property
  */
 protected function cloneInstanceProperty(core_kernel_classes_Resource $source, core_kernel_classes_Resource $destination, core_kernel_classes_Property $property)
 {
     $range = $property->getRange();
     // Avoid doublons, the RDF TYPE property will be set by the implementation layer
     if ($property->getUri() != RDF_TYPE) {
         foreach ($source->getPropertyValuesCollection($property)->getIterator() as $propertyValue) {
             if (!is_null($range) && $range->getUri() == CLASS_GENERIS_FILE) {
                 $file = new core_kernel_versioning_File($propertyValue->getUri());
                 $newFile = $file->getRepository()->spawnFile($file->getAbsolutePath(), $file->getLabel());
                 $destination->setPropertyValue($property, $newFile);
             } else {
                 $destination->setPropertyValue($property, $propertyValue);
             }
         }
     }
 }
コード例 #27
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);
     }
 }
コード例 #28
0
ファイル: class.Lists.php プロジェクト: nagyist/tao-core
 /**
  * Save a list and it's elements
  * @return void
  */
 public function saveLists()
 {
     if (!tao_helpers_Request::isAjax()) {
         throw new Exception("wrong request mode");
     }
     $saved = false;
     if ($this->hasRequestParameter('uri')) {
         $listClass = $this->service->getList(tao_helpers_Uri::decode($this->getRequestParameter('uri')));
         if (!is_null($listClass)) {
             // use $_POST instead of getRequestParameters to prevent html encoding
             $listClass->setLabel($_POST['label']);
             $setLevel = false;
             $levelProperty = new core_kernel_classes_Property(TAO_LIST_LEVEL_PROP);
             foreach ($listClass->getProperties(true) as $property) {
                 if ($property->getUri() == $levelProperty->getUri()) {
                     $setLevel = true;
                     break;
                 }
             }
             $elements = $this->service->getListElements($listClass);
             // use $_POST instead of getRequestParameters to prevent html encoding
             foreach ($_POST as $key => $value) {
                 if (preg_match("/^list\\-element_/", $key)) {
                     $key = str_replace('list-element_', '', $key);
                     $l = strpos($key, '_');
                     $level = substr($key, 0, $l);
                     $uri = tao_helpers_Uri::decode(substr($key, $l + 1));
                     $found = false;
                     foreach ($elements as $element) {
                         if ($element->getUri() == $uri && !empty($uri)) {
                             $found = true;
                             $element->setLabel($value);
                             if ($setLevel) {
                                 $element->editPropertyValues($levelProperty, $level);
                             }
                             break;
                         }
                     }
                     if (!$found) {
                         $element = $this->service->createListElement($listClass, $value);
                         if ($setLevel) {
                             $element->setPropertyValue($levelProperty, $level);
                         }
                     }
                 }
             }
             $saved = true;
         }
     }
     echo json_encode(array('saved' => $saved));
 }
コード例 #29
0
 /**
  * Short description of method applyCallbacks
  *
  * @access private
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param  string $value
  * @param  array $options
  * @param  core_kernel_classes_Property $targetProperty
  * @return string
  */
 private function applyCallbacks($value, $options, core_kernel_classes_Property $targetProperty)
 {
     $returnValue = (string) '';
     if (isset($options['callbacks'])) {
         foreach (array('*', $targetProperty->getUri()) as $key) {
             if (isset($options['callbacks'][$key]) && is_array($options['callbacks'][$key])) {
                 foreach ($options['callbacks'][$key] as $callback) {
                     if (is_callable($callback)) {
                         $value = call_user_func($callback, $value);
                     }
                 }
             }
         }
     }
     $returnValue = $value;
     return (string) $returnValue;
 }
コード例 #30
0
 /**
  * Short description of method initElements
  *
  * @access protected
  * @author Joel Bout, <*****@*****.**>
  * @return mixed
  */
 protected function initElements()
 {
     if (!isset($this->options['mode'])) {
         throw new Exception("Please set a mode into container options ");
     }
     parent::initElements();
     //login field
     $loginElement = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_USER_LOGIN));
     $loginElement->setDescription($loginElement->getDescription() . ' *');
     if ($this->options['mode'] == 'add') {
         $loginElement->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty'), tao_helpers_form_FormFactory::getValidator('Callback', array('object' => tao_models_classes_UserService::singleton(), 'method' => 'loginAvailable', 'message' => __('This Login is already in use')))));
     } else {
         $loginElement->setAttributes(array('readonly' => 'readonly', 'disabled' => 'disabled'));
     }
     //set default lang to the languages fields
     $langService = tao_models_classes_LanguageService::singleton();
     $dataLangElt = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_USER_DEFLG));
     $dataLangElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $dataLangElt->setDescription($dataLangElt->getDescription() . ' *');
     $dataUsage = new core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_DATA);
     $dataOptions = array();
     foreach ($langService->getAvailableLanguagesByUsage($dataUsage) as $lang) {
         $dataOptions[tao_helpers_Uri::encode($lang->getUri())] = $lang->getLabel();
     }
     $dataLangElt->setOptions($dataOptions);
     $uiLangElt = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_USER_UILG));
     $uiLangElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $uiLangElt->setDescription($uiLangElt->getDescription() . ' *');
     $guiUsage = new core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_GUI);
     $guiOptions = array();
     foreach ($langService->getAvailableLanguagesByUsage($guiUsage) as $lang) {
         $guiOptions[tao_helpers_Uri::encode($lang->getUri())] = $lang->getLabel();
     }
     $uiLangElt->setOptions($guiOptions);
     // roles field
     $property = new core_kernel_classes_Property(PROPERTY_USER_ROLES);
     $roles = $property->getRange()->getInstances(true);
     $rolesOptions = array();
     foreach ($roles as $r) {
         $rolesOptions[tao_helpers_Uri::encode($r->getUri())] = $r->getLabel();
     }
     asort($rolesOptions);
     $rolesElt = $this->form->getElement(tao_helpers_Uri::encode($property->getUri()));
     $rolesElt->setDescription($rolesElt->getDescription() . ' *');
     $rolesElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $rolesElt->setOptions($rolesOptions);
     // password field
     $this->form->removeElement(tao_helpers_Uri::encode(PROPERTY_USER_PASSWORD));
     if ($this->options['mode'] == 'add') {
         $pass1Element = tao_helpers_form_FormFactory::getElement('password1', 'Hiddenbox');
         $pass1Element->setDescription(__('Password *'));
         $pass1Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty'), tao_helpers_form_FormFactory::getValidator('Length', array('min' => 3))));
         $this->form->addElement($pass1Element);
         $pass2Element = tao_helpers_form_FormFactory::getElement('password2', 'Hiddenbox');
         $pass2Element->setDescription(__('Repeat password *'));
         $pass2Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty'), tao_helpers_form_FormFactory::getValidator('Password', array('password2_ref' => $pass1Element))));
         $this->form->addElement($pass2Element);
     } else {
         if (helpers_PlatformInstance::isDemo()) {
             $warning = tao_helpers_form_FormFactory::getElement('warningpass', 'Label');
             $warning->setValue(__('Unable to change passwords in demo mode'));
             $this->form->addElement($warning);
             $this->form->createGroup("pass_group", __("Change the password"), array('warningpass'));
         } else {
             $pass2Element = tao_helpers_form_FormFactory::getElement('password2', 'Hiddenbox');
             $pass2Element->setDescription(__('New password'));
             $pass2Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('Length', array('min' => 3))));
             $this->form->addElement($pass2Element);
             $pass3Element = tao_helpers_form_FormFactory::getElement('password3', 'Hiddenbox');
             $pass3Element->setDescription(__('Repeat new password'));
             $pass3Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('Password', array('password2_ref' => $pass2Element))));
             $this->form->addElement($pass3Element);
             $this->form->createGroup("pass_group", __("Change the password"), array('password1', 'password2', 'password3'));
             if (empty($_POST[$pass2Element->getName()]) && empty($_POST[$pass3Element->getName()])) {
                 $pass2Element->setForcedValid();
                 $pass3Element->setForcedValid();
             }
         }
     }
     /**/
 }