public static function validateWSUsage($wsId, $wsReturnValues, $wsParameters)
 {
     $ws = WebService::newFromId($wsId);
     //validate subparameters and construct appropriate parameters
     $subParameters = array();
     foreach ($wsParameters as $name => $value) {
         $name = explode(".", $name);
         if (count($name) > 1) {
             unset($wsParameters[$name[0] . "." . $name[1]]);
             if (array_key_exists($name[0], $wsParameters)) {
                 unset($wsParameters[$name[0]]);
             }
             $subParameters[$name[0]][$name[1]] = $value;
         }
     }
     $result = $ws->validateSpecifiedSubParameters($subParameters);
     $mSP = $result[0];
     if (!is_null($result[1])) {
         foreach ($result[1] as $key => $value) {
             if (strlen($value) > 0) {
                 $wsParameters[$key] = $value;
             }
         }
     }
     if (count($mSP) == 0) {
         $mSP = array();
     }
     $mP = $ws->validateSpecifiedParameters($wsParameters);
     $mR = $ws->validateSpecifiedResults($wsReturnValues);
     return array(array_merge($mSP, $mP, $mR), $wsParameters);
 }
Example #2
0
 private function createTriples($wsResult, $subjectCreationPattern, $wsId, $unwantedPropertys, $previewTitle)
 {
     $unwantedPropertys = array_flip($unwantedPropertys);
     global $wgParser, $IP;
     require_once $IP . "/extensions/SMWHalo/includes/storage/SMW_TS_Helper.php";
     $subjects = array();
     //get number of rows and property types
     $lineCount = 0;
     $types = array();
     foreach ($wsResult as $propertyName => $resultPart) {
         $lineCount = max($lineCount, count($resultPart));
         $title = Title::newFromText($propertyName, SMW_NS_PROPERTY);
         $semData = smwfGetStore()->getSemanticData(SMWWikiPageValue::makePageFromTitle($title));
         $property = SMWPropertyValue::makeProperty('Has_type');
         $value = $semData->getPropertyValues($property);
         if (count($value) > 0) {
             $fK = array_keys($value);
             $fK = $fK[0];
             @($types[$propertyName] = '' . $value[$fK]->getShortWikiText());
             $types[$propertyName] = str_replace('http://www.w3.org/2001/XMLSchema#', 'xsd:', $types[$propertyName]);
             //@ $types[$propertyName] = SMWDataValueFactory::findTypeID($value[$fK]->getShortWikiText());
         } else {
             $types[$propertyName] = '';
         }
     }
     $triples = array();
     $allAliases = WebService::newFromId($wsId)->getAllResultPartAliases();
     $subjectCreationPatternParts = array();
     foreach ($allAliases as $alias => $dc) {
         if (strpos($subjectCreationPattern, "?" . $alias . "?") !== false) {
             $alias = explode(".", $alias);
             $subjectCreationPatternParts[$alias[1]] = $alias[0] . "." . $alias[1];
         }
     }
     for ($i = 0; $i < $lineCount; $i++) {
         $tempTriples = array();
         $subject = $subjectCreationPattern;
         foreach ($wsResult as $property => $objects) {
             if (array_key_exists($i, $objects) && strlen($objects[$i]) > 0) {
                 if (array_key_exists($property, $subjectCreationPatternParts)) {
                     $subject = str_replace("?" . $subjectCreationPatternParts[$property] . "?", $objects[$i], $subject);
                 }
                 $triple = array();
                 $triple['property'] = $property;
                 $triple['object'] = $objects[$i];
                 if (!array_key_exists($property, $types) || strlen($types[$property]) == 0) {
                     $triple['type'] = '__objectURI';
                     $triple['object'] = trim($triple['object']);
                 } else {
                     //$typeDataValue = SMWDataValueFactory::newTypeIDValue($types[$property], $triple['object']);
                     //if($typeDataValue->isValid()){
                     //	$triple['type'] = WikiTypeToXSD::getXSDType($types[$property]);
                     //} else {
                     //	$triple['type'] = null;
                     //}
                     $triple['type'] = $types[$property];
                 }
                 if (!array_key_exists($property, $unwantedPropertys)) {
                     $tempTriples[] = $triple;
                 }
             } else {
                 if (array_key_exists($property, $subjectCreationPatternParts)) {
                     $subject = str_replace("?" . $subjectCreationPatternParts[$property] . "?", '', $subject);
                 }
             }
         }
         if (is_string($previewTitle)) {
             //we are in preview mode
             $t = Title::makeTitleSafe(0, $previewTitle);
             $popts = new ParserOptions();
             $wgParser->startExternalParse($t, $popts, Parser::OT_HTML);
             $subject = $wgParser->internalParse($subject);
             //$subject = $wgParser->doBlockLevels($subject, true);
             $subject = trim($subject);
         } else {
             $subject = trim($wgParser->replaceVariables($subject));
         }
         if (strlen($subject) > 0) {
             foreach ($tempTriples as $triple) {
                 $triple['subject'] = $subject;
                 $triples[] = $triple;
             }
         }
         if (strlen($subject) > 0 && !is_string($previewTitle)) {
             $subject = "[[" . $subject . "]]";
         }
         $subjects[] = $subject;
     }
     return array($triples, $subjects);
 }