private function getRdfTriples(\core_kernel_classes_Resource $resource, $usingRestrictionOn = "object") { $returnValue = null; $dbWrapper = \core_kernel_classes_DbWrapper::singleton(); $namespaces = \common_ext_NamespaceManager::singleton()->getAllNamespaces(); $namespace = $namespaces[substr($resource->getUri(), 0, strpos($resource->getUri(), '#') + 1)]; $query = 'SELECT * FROM "statements" WHERE "' . $usingRestrictionOn . '" = ? order by modelid '; $result = $dbWrapper->query($query, array($resource->getUri())); $returnValue = new \core_kernel_classes_ContainerCollection(new \common_Object(__METHOD__)); while ($statement = $result->fetch()) { $triple = new \core_kernel_classes_Triple(); $triple->modelid = $statement["modelid"]; $triple->subject = $statement["subject"]; $triple->predicate = $statement["predicate"]; $triple->object = $statement["object"]; $triple->id = $statement["id"]; $triple->lg = $statement["l_language"]; $returnValue->add($triple); } return $returnValue; }
/** * Return a collection of values associated to $property * * @param core_kernel_classes_Property $property * @param array $options * @return core_kernel_classes_ContainerCollection */ public function getPropertyValuesCollection(core_kernel_classes_Property $property, $options = array()) { $returnValue = new core_kernel_classes_ContainerCollection($this); foreach ($this->getPropertyValues($property, $options) as $value) { $returnValue->add(common_Utils::toResource($value)); } return $returnValue; }
/** * Short description of method evaluateSet * * @access protected * @author firstname and lastname of author, <*****@*****.**> * @return mixed */ protected function evaluateSet() { common_Logger::d('Constructed Set TYPE', array('Generis Term evaluateSet')); $operator = $this->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_SET_OPERATOR)); $subSets = $this->getPropertyValuesCollection(new core_kernel_classes_Property(PROPERTY_SUBSET)); $returnValue = new core_kernel_classes_ContainerCollection($this); foreach ($subSets->getIterator() as $aSet) { if ($aSet instanceof core_kernel_classes_Resource) { $newSet = new core_kernel_rules_Term($aSet->getUri()); $resultSet = $newSet->evaluate(); if ($resultSet instanceof core_kernel_classes_ContainerCollection) { $returnValue = $this->evalutateSetOperation($operator, $returnValue, $resultSet); } else { $collection = new core_kernel_classes_ContainerCollection($this); $collection->add($resultSet); $returnValue = $this->evalutateSetOperation($operator, $returnValue, $collection); } } else { throw new common_Exception('Bad Type , waiting for a Resource '); } } return $returnValue; }
/** * returns the triples having as subject the current resource * * @access public * @author Joel Bout, <*****@*****.**> * @param core_kernel_classes_Resource resource * @return core_kernel_classes_ContainerCollection */ public function getRdfTriples(core_kernel_classes_Resource $resource) { $returnValue = null; $query = 'SELECT * FROM statements WHERE subject = ? AND ' . $this->getModelReadSqlCondition() . ' ORDER BY predicate'; $result = $this->getPersistence()->query($query, array($resource->getUri())); $returnValue = new core_kernel_classes_ContainerCollection(new common_Object(__METHOD__)); while ($statement = $result->fetch()) { $triple = new core_kernel_classes_Triple(); $triple->modelid = $statement["modelid"]; $triple->subject = $statement["subject"]; $triple->predicate = $statement["predicate"]; $triple->object = $statement["object"]; $triple->id = $statement["id"]; $triple->lg = $statement["l_language"]; $returnValue->add($triple); } return $returnValue; }
/** * Short description of method getRdfTriples * * @access public * @author Joel Bout, <*****@*****.**> * @param Resource resource * @return \core_kernel_classes_ContainerCollection */ public function getRdfTriples(\core_kernel_classes_Resource $resource) { $returnValue = null; $returnValue = new \core_kernel_classes_ContainerCollection(new \common_Object(__METHOD__)); $referencer = ResourceReferencer::singleton(); $tableName = $referencer->resourceLocation($resource); if (!empty($tableName)) { try { $tblmgr = new TableManager($tableName); $propertiesTableName = $tblmgr->getPropertiesTable(); $dbWrapper = \core_kernel_classes_DbWrapper::singleton(); // We get the triples for cardinality = multiple or lg dependent properties // as usual... $quotedUri = $dbWrapper->quote($resource->getUri()); $propsQuery = 'SELECT "b"."id", "b"."uri", "p"."property_uri" AS "property_uri", COALESCE("p"."property_value", "p"."property_foreign_uri") as "property_value", "p"."l_language" FROM "' . $tableName . '" "b" '; $propsQuery .= 'INNER JOIN "' . $propertiesTableName . '" "p" ON ("b"."id" = "p"."instance_id") WHERE "b"."uri" = ' . $quotedUri; $propertyColumns = $tblmgr->getPropertyColumns(); $baseQuery = ''; if (!empty($propertyColumns)) { // But if we have properties as columns in the 'base table' we // have to be crafty... $baseQueries = array(); foreach ($propertyColumns as $k => $pC) { $quotedPropUri = $dbWrapper->quote($pC); $baseQueries[] = 'SELECT "b"."id", "b"."uri", ' . $quotedPropUri . ' AS "property_uri", "b"."' . $k . '" AS "property_value", \'\' AS "l_language" FROM "' . $tableName . '" "b" WHERE "b"."uri" = ' . $quotedUri . ' AND "b"."' . $k . '" IS NOT NULL'; } $baseQuery = implode(' UNION ', $baseQueries); } $query = $propsQuery . ' UNION ' . $baseQuery . ' ORDER BY "property_uri"'; try { $result = $dbWrapper->query($query); while ($row = $result->fetch()) { if ($row['property_value'] != null) { $triple = new \core_kernel_classes_Triple(); $triple->subject = $row['uri']; $triple->predicate = $row['property_uri']; $triple->object = $row['property_value']; $triple->lg = $row['l_language']; $returnValue->add($triple); } } // In hard mode, the rdf:type given to resources is defined by // 'the table' their are belonging to. In this case, we need to // manually add these triples to the end result. $types = $resource->getTypes(); foreach ($types as $class) { $triple = new \core_kernel_classes_Triple(); $triple->subject = $resource->getUri(); $triple->predicate = RDF_TYPE; $triple->object = $class->getUri(); $triple->lg = ''; $returnValue->add($triple); } } catch (\PDOException $e) { $uri = $resource->getUri(); throw new Exception("Unable to retrieve RDF triples of resource '{$uri}': " . $e->getMessage()); } } catch (HardapiException $e) { throw new Exception("Unable to access data from table '{$tableName}: " . $e->getMessage()); } } return $returnValue; }
protected static function getCallOfServiceParameterElements(core_kernel_classes_Resource $serviceDefinition, core_kernel_classes_Resource $callOfService, $paramType) { $returnValue = array(); //array(); if (empty($paramType) || empty($serviceDefinition)) { return $returnValue; } $formalParameterType = ''; $actualParameterInOutType = ''; $formalParameterName = ''; $formalParameterSuffix = ''; if (strtolower($paramType) == "formalparameterin") { $formalParameterType = PROPERTY_SERVICESDEFINITION_FORMALPARAMIN; $actualParameterInOutType = PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN; $formalParameterName = __('Input Parameters'); $formalParameterSuffix = '_IN'; } elseif (strtolower($paramType) == "formalparameterout") { $formalParameterType = PROPERTY_SERVICESDEFINITION_FORMALPARAMOUT; $actualParameterInOutType = PROPERTY_CALLOFSERVICES_ACTUALPARAMETEROUT; $formalParameterName = __('Output Parameters'); $formalParameterSuffix = '_OUT'; } else { throw new Exception("unsupported formalParameter type : {$paramType}"); } //get the other parameter input elements $collection = null; $collection = $serviceDefinition->getPropertyValuesCollection(new core_kernel_classes_Property($formalParameterType)); if ($collection->count() > 0) { //start creating the BLOC of form element $descriptionElement = tao_helpers_form_FormFactory::getElement($paramType, 'Free'); $descriptionElement->setValue("<b>{$formalParameterName} :</b>"); $returnValue[$paramType] = $descriptionElement; } $actualParamClass = new core_kernel_classes_Class(CLASS_ACTUALPARAMETER); foreach ($collection->getIterator() as $formalParam) { if ($formalParam instanceof core_kernel_classes_Resource) { //create a form element: $inputName = $formalParam->getLabel(); //which will be equal to $actualParam->getLabel(); $inputUri = $formalParam->getUri(); // $inputUri = ""; $inputValue = ""; //get current value: //find actual param first! $actualParamValue = ''; $actualParamFromFormalParam = new core_kernel_classes_ContainerCollection(new common_Object(__METHOD__)); $actualParamFromFormalParamArray = $actualParamClass->searchInstances(array(PROPERTY_ACTUALPARAMETER_FORMALPARAMETER => $formalParam->getUri()), array('like' => false, 'recursive' => 0)); foreach ($actualParamFromFormalParamArray as $actualParam) { $actualParamFromFormalParam->add($actualParam); } $actualParamFromCallOfServices = $callOfService->getPropertyValuesCollection(new core_kernel_classes_Property($actualParameterInOutType)); //make an intersect with $collection = $callOfService->getPropertyValuesCollection(new core_kernel_classes_Property(PROPERTY_CALLOFSERVICES_ACTUALPARAMETEROUT)); $actualParamCollection = $actualParamFromFormalParam->intersect($actualParamFromCallOfServices); if (!$actualParamCollection->isEmpty()) { foreach ($actualParamCollection->getIterator() as $actualParam) { if ($actualParam instanceof core_kernel_classes_Resource) { //the actual param associated to the formal parameter of THE call of services has been found! //check the type of actual parameter: $inParameterProcessVariable = $actualParam->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_ACTUALPARAMETER_PROCESSVARIABLE)); //a resource $inParameterConstant = $actualParam->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_ACTUALPARAMETER_CONSTANTVALUE)); if (!is_null($inParameterProcessVariable)) { //the type is a processvariable so must be a resource: if (!$inParameterProcessVariable instanceof core_kernel_classes_Resource) { throw new common_Exception("the process variable set as the value of the parameter '" . $actualParam->getLabel() . "' is not a resource"); } $paramType = 'processvariable'; $inputValue = $inParameterProcessVariable->getUri(); } elseif (!is_null($inParameterConstant)) { //the type is a constant: $paramType = 'constant'; if ($inParameterConstant instanceof core_kernel_classes_Literal) { $inputValue = $inParameterConstant->literal; } else { if ($inParameterConstant instanceof core_kernel_classes_Resource) { $inputValue = $inParameterConstant->getUri(); //encode?? } } } else { //the type is not specified yet: } break; //stop as one iteration: there normally should be only one actual parameter set for a given formal parameter } } } if (empty($inputValue)) { //if no value set yet, try finding the default value (literal only! or url that are considered as a literal) $defaultConstantValue = $formalParam->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_FORMALPARAMETER_DEFAULTCONSTANTVALUE)); $defaultProcessVariable = $formalParam->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_FORMALPARAMETER_DEFAULTPROCESSVARIABLE)); $defaultValue = ''; if (!is_null($defaultProcessVariable)) { if ($defaultProcessVariable instanceof core_kernel_classes_Resource) { $defaultValue = $defaultProcessVariable->getUri(); //the case a url } else { throw new Exception('the process variable must be a resource'); } if (!empty($defaultValue)) { //the input value has been set as the default one: $paramType = 'processvariable'; $inputValue = $defaultValue; } } elseif (!is_null($defaultConstantValue)) { if ($defaultConstantValue instanceof core_kernel_classes_Literal) { $defaultValue = $defaultConstantValue->literal; } else { if ($defaultConstantValue instanceof core_kernel_classes_Resource) { $defaultValue = $defaultConstantValue->getUri(); //the case a url } } if (!empty($defaultValue)) { //the input value has been set as the default one: $paramType = 'constant'; $inputValue = $defaultValue; } } } $elementId = tao_helpers_Uri::encode($inputUri) . $formalParameterSuffix; $elementChoiceId = $elementId . '_choice'; $elementInputId = $elementId . '_constant'; $elementVarId = $elementId . '_var'; //element of type "free": $element = tao_helpers_form_FormFactory::getElement($elementId, 'Free'); $element->setValue($inputName . ': '); //set the choice element (radiobox: constant/processVariable: $elementChoice = tao_helpers_form_FormFactory::getElement($elementChoiceId, 'Radiobox'); $elementChoice->setDescription(' '); $options = array("constant" => __("Constant"), "processvariable" => __("Process Variable")); $elementChoice->setOptions($options); $elementChoice->setValue($paramType); //element input: $elementInput = tao_helpers_form_FormFactory::getElement($elementInputId, 'Textbox'); $elementInput->setDescription(' '); //element choice of process var (range: all or selected only?): $elementVar = tao_helpers_form_FormFactory::getElement($elementVarId, 'ComboBox'); $elementVar->setDescription(' '); $processVariables = array(); $processVariables = array('none' => ' '); $range = new core_kernel_classes_Class(CLASS_PROCESSVARIABLES); foreach ($range->getInstances(true) as $rangeInstance) { $processVariables[tao_helpers_Uri::encode($rangeInstance->getUri())] = $rangeInstance->getLabel(); } $elementVar->setOptions($processVariables); //set value here: if ($paramType == 'constant') { $elementInput->setValue($inputValue); } elseif ($paramType == 'processvariable') { $elementVar->setValue($inputValue); } $returnValue[$elementId] = $element; $returnValue[$elementChoiceId] = $elementChoice; $returnValue[$elementInputId] = $elementInput; $returnValue[$elementVarId] = $elementVar; } } return $returnValue; }
/** * Short description of method getObject * * @access public * @author firstname and lastname of author, <*****@*****.**> * @param string subject * @param string predicate * @return core_kernel_classes_ContainerCollection */ public function getObject($subject, $predicate) { $returnValue = null; $sqlQuery = "SELECT object FROM statements WHERE subject = ? AND predicate = ?"; $dbWrapper = core_kernel_classes_DbWrapper::singleton(); $sqlResult = $dbWrapper->query($sqlQuery, array($subject, $predicate)); $returnValue = new core_kernel_classes_ContainerCollection(new common_Object(__METHOD__)); while ($row = $sqlResult->fetch()) { $value = $row['object']; if (!common_Utils::isUri($value)) { $container = new core_kernel_classes_Literal($value); } else { $container = new core_kernel_classes_Resource($value); } $container->debug = __METHOD__; $returnValue->add($container); } return $returnValue; }