public function __construct($options = array())
 {
     common_user_auth_Service::singleton()->startSession(new core_kernel_users_GenerisUser(new core_kernel_classes_Resource(TAO_INSTALLATOR)));
     $this->processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton();
     $this->localNS = common_ext_NamespaceManager::singleton()->getLocalNamespace()->getUri();
     $this->unserialize = isset($options['unserialize']) ? (int) $options['unserialize'] : 0;
 }
 /**
  * Generates a URI based on a serial stored in the database.
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @return string
  * @throws common_UriProviderException
  */
 public function provide()
 {
     $returnValue = (string) '';
     $modelUri = common_ext_NamespaceManager::singleton()->getLocalNamespace()->getUri();
     $uri = $modelUri . uniqid('i') . getmypid() . bin2hex(openssl_random_pseudo_bytes(8));
     return (string) $uri;
 }
 /**
  * Main entry point to retrieve the unique NamespaceManager instance
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @return common_ext_NamespaceManager
  */
 public static function singleton()
 {
     $returnValue = null;
     if (is_null(self::$instance)) {
         $class = __CLASS__;
         //used in case of subclassing
         self::$instance = new $class();
     }
     $returnValue = self::$instance;
     return $returnValue;
 }
 /**
  * test the manager retrieving methods and the namespace setters/getters
  */
 public function testBehaviour()
 {
     $namespaceManager = common_ext_NamespaceManager::singleton();
     $namespaces = $namespaceManager->getAllNamespaces();
     $this->assertTrue(count($namespaces) > 0);
     foreach ($namespaces as $namespace) {
         $this->assertIsA($namespace, 'common_ext_Namespace');
     }
     $localNs = $namespaceManager->getLocalNamespace();
     $this->assertIsA($localNs, 'common_ext_Namespace');
     $otherLocalNs = $namespaceManager->getNamespace($localNs->getModelId());
     $this->assertIsA($otherLocalNs, 'common_ext_Namespace');
     $this->assertEquals((string) $otherLocalNs, (string) $localNs);
 }
Beispiel #5
0
 /**
  * Build and load the item execution environment.
  * 
  * @param core_kernel_classes_Resource $processExecution
  * @param core_kernel_classes_Resource $item
  * @param core_kernel_classes_Resource $test
  * @param core_kernel_classes_Resource $delivery
  * @param core_kernel_classes_Resource $user
  * 
  * @return array
  */
 protected function createExecutionEnvironment(core_kernel_classes_Resource $processExecution, core_kernel_classes_Resource $item, core_kernel_classes_Resource $test, core_kernel_classes_Resource $delivery, core_kernel_classes_Resource $user)
 {
     $executionEnvironment = array();
     foreach (func_get_args() as $arg) {
         if (is_null($arg)) {
             return $executionEnvironment;
         }
     }
     //we build the data to give to the item
     $executionEnvironment = array('token' => $this->createToken(), 'localNamespace' => rtrim(common_ext_NamespaceManager::singleton()->getLocalNamespace()->getUri(), '#'), CLASS_PROCESS_EXECUTIONS => array('uri' => $processExecution->getUri(), RDFS_LABEL => $processExecution->getLabel()), TAO_ITEM_CLASS => array('uri' => $item->getUri(), RDFS_LABEL => $item->getLabel()), TAO_TEST_CLASS => array('uri' => $test->getUri(), RDFS_LABEL => $test->getLabel()), TAO_DELIVERY_CLASS => array('uri' => $delivery->getUri(), RDFS_LABEL => $delivery->getLabel()), TAO_SUBJECT_CLASS => array('uri' => $user->getUri(), RDFS_LABEL => $user->getLabel(), PROPERTY_USER_LOGIN => (string) $user->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_USER_LOGIN)), PROPERTY_USER_FIRSTNAME => (string) $user->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_USER_FIRSTNAME)), PROPERTY_USER_LASTNAME => (string) $user->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_USER_LASTNAME))));
     $session = PHPSession::singleton();
     $session->setAttribute(self::ENV_VAR_NAME . '_' . tao_helpers_Uri::encode($user->getUri()), $executionEnvironment);
     return $executionEnvironment;
 }
 private function add($data)
 {
     $subject = new core_kernel_classes_Resource($data['s']);
     $property = new core_kernel_classes_Property($data['p']);
     $object = $data['o'];
     $lg = is_null($data['l']) ? '' : $data['l'];
     if (!$this->exists($subject, $property, $object, $lg)) {
         $nsPrefix = substr($data['s'], 0, strpos($data['s'], '#') + 1);
         $ns = isset($this->namespaceCache[$nsPrefix]) ? $this->namespaceCache[$nsPrefix]->getModelId() : common_ext_NamespaceManager::singleton()->getLocalNamespace()->getModelId();
         if (!core_kernel_classes_DbWrapper::singleton()->query($this->updateQuery, array($ns, $subject->getUri(), $property->getUri(), $object, $lg))) {
             $this->err('Add query failed');
         }
         if (!$this->exists($subject, $property, $object, $lg)) {
             $this->err('Did not add ' . $subject->getUri() . ':' . $property->getUri() . ':"' . $object . '"@' . $lg);
         }
     } else {
         $this->out('Already existed ' . $subject->getUri() . ':' . $property->getUri() . ':"' . $object . '"@' . $lg);
     }
 }
 /**
  * Import a XML file as is into the ontology
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param  string source
  * @param  Class destination
  * @param  string namespace
  * @return boolean
  */
 public function import($source, core_kernel_classes_Class $destination = null, $namespace = null)
 {
     $returnValue = (bool) false;
     $api = core_kernel_impl_ApiModelOO::singleton();
     $localModel = rtrim(common_ext_NamespaceManager::singleton()->getLocalNamespace()->getUri(), '#');
     if (!is_null($destination) && file_exists($source)) {
         $destModel = substr($destination->getUri(), 0, strpos($destination->getUri(), '#'));
         $returnValue = $api->importXmlRdf($destModel, $source);
     } else {
         if (file_exists($source) && !is_null($namespace)) {
             $returnValue = $api->importXmlRdf($namespace, $source);
         } else {
             if (file_exists($source)) {
                 $returnValue = $api->importXmlRdf($localModel, $source);
             }
         }
     }
     return (bool) $returnValue;
 }
 /**
  * Generates a URI based on the value of PHP microtime() and rand().
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @return string
  */
 public function provide()
 {
     $returnValue = (string) '';
     $modelUri = common_ext_NamespaceManager::singleton()->getLocalNamespace()->getUri();
     $dbWrapper = core_kernel_classes_DbWrapper::singleton();
     $uriExist = false;
     do {
         list($usec, $sec) = explode(" ", microtime());
         $uri = $modelUri . 'i' . str_replace(".", "", $sec . "" . $usec) . rand(0, 1000);
         $sqlResult = $dbWrapper->query("SELECT COUNT(subject) AS num FROM statements WHERE subject = '" . $uri . "'");
         if ($row = $sqlResult->fetch()) {
             $found = (int) $row['num'];
             if ($found > 0) {
                 $uriExist = true;
             }
             $sqlResult->closeCursor();
         }
     } while ($uriExist);
     $returnValue = $uri;
     return (string) $returnValue;
 }
 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;
 }
Beispiel #10
0
 public function testRightModels()
 {
     $namespaces = common_ext_NamespaceManager::singleton()->getAllNamespaces();
     $localNamespace = $namespaces[LOCAL_NAMESPACE . '#'];
     // In tao context, the only one model which is updatable
     $updatableModels = core_kernel_persistence_smoothsql_SmoothModel::getUpdatableModelIds();
     $this->assertEquals(1, count($updatableModels));
     $this->assertEquals(1, $localNamespace->getModelId());
     $readableModels = core_kernel_persistence_smoothsql_SmoothModel::getReadableModelIds();
     $this->assertTrue(count($readableModels) > 3);
     $this->assertTrue(array_search(1, $readableModels) !== false);
     $this->assertTrue(array_search(2, $readableModels) !== false);
     $this->assertTrue(array_search(3, $readableModels) !== false);
     $this->assertTrue(array_search(4, $readableModels) !== false);
     // Try to delete a resource of a locked model
     $property = new core_kernel_classes_Property(RDFS_LABEL);
     $domain = new core_kernel_classes_Property(RDFS_DOMAIN, __METHOD__);
     $this->assertFalse($property->removePropertyValues($domain, array('pattern' => RDFS_LABEL)));
     // Try to remove a property value which is lg dependent of a locked model
     $clazz = new core_kernel_classes_Class('http://www.tao.lu/middleware/Rules.rdf#And');
     $this->assertFalse($clazz->removePropertyValueByLg($property, 'EN'));
 }
Beispiel #11
0
 /**
  * Short description of method run
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @return void
  */
 public function run()
 {
     $userService = tao_models_classes_UserService::singleton();
     $this->outVerbose("Connecting to TAO as '" . $this->options['user'] . "' ...");
     if ($userService->loginUser($this->options['user'], $this->options['password'])) {
         $this->outVerbose("Connected to TAO as '" . $this->options['user'] . "'.");
         $filename = $this->options['input'];
         $action = new ImportRdf();
         $params = array($filename);
         if (!empty($this->options['model'])) {
             $nameSpace = common_ext_NamespaceManager::singleton()->getNamespace($this->options['model']);
             $params[] = $nameSpace->getModelId();
         }
         $report = $action->__invoke($params);
         $string = helpers_Report::renderToCommandline($report);
         foreach (explode(PHP_EOL, $string) as $line) {
             $this->out($line);
         }
     } else {
         $this->err("Unable to connect to TAO as '" . $this->options['user'] . "'.", true);
     }
 }
 public function testGetRootClass()
 {
     $localModel = common_ext_NamespaceManager::singleton()->getLocalNamespace()->getUri();
     $this->assertFalse(empty($localModel));
     $rootClasses = $this->object->getRootClasses();
     $this->assertInstanceOf('common_Collection', $rootClasses);
     $expectedResult = array(WIDGET_CONSTRAINT_TYPE, CLASS_WIDGET, RDFS_RESOURCE, CLASS_WIDGETRENDERER);
     $pattern = "/^" . preg_quote($localModel, '/') . "/";
     foreach ($rootClasses->getIterator() as $rootClass) {
         $this->assertInstanceOf('core_kernel_classes_Class', $rootClass);
         $parentClasses = $rootClass->getParentClasses(true);
         $this->assertEquals(0, count($parentClasses));
         $types = $rootClass->getTypes(true);
         $this->assertEquals(1, count($types));
         foreach ($types as $uri => $parent) {
             $this->assertEquals($uri, RDFS_CLASS);
         }
         //don't check the user root classes
         if (!preg_match($pattern, $rootClass->getUri())) {
             $this->assertTrue(in_array($rootClass->getUri(), $expectedResult));
         }
     }
 }
Beispiel #13
0
 private function getReadableModelIds()
 {
     $extensionManager = \common_ext_ExtensionsManager::singleton();
     \common_ext_NamespaceManager::singleton()->reset();
     $uris = array(LOCAL_NAMESPACE . '#');
     foreach ($extensionManager->getModelsToLoad() as $subModelUri) {
         if (!preg_match("/#\$/", $subModelUri)) {
             $subModelUri .= '#';
         }
         $uris[] = $subModelUri;
     }
     $ids = array();
     foreach (\common_ext_NamespaceManager::singleton()->getAllNamespaces() as $namespace) {
         if (in_array($namespace->getUri(), $uris)) {
             $ids[] = $namespace->getModelId();
         }
     }
     return array_unique($ids);
 }
Beispiel #14
0
 /**
  * Short description of method run
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @return void
  */
 public function run()
 {
     $userService = tao_models_classes_UserService::singleton();
     $this->outVerbose("Connecting to TAO as '" . $this->options['user'] . "' ...");
     if ($userService->loginUser($this->options['user'], $this->options['password'])) {
         $this->outVerbose("Connected to TAO as '" . $this->options['user'] . "'.");
         //determine the target namespace.
         $targetNamespace = rtrim(common_ext_NamespaceManager::singleton()->getLocalNamespace()->getUri(), '#');
         if (!empty($this->options['model'])) {
             $targetNamespace = $this->options['model'];
         } else {
             // Look for XML Base.
             $this->outVerbose("Looking up for the value of xml:base as the model URI.");
             try {
                 $dom = new DOMDocument('1.0', TAO_DEFAULT_ENCODING);
                 if (false !== $dom->load($this->options['input'])) {
                     $this->outVerbose("RDF-XML document loaded.");
                     // try to find the 'xml:base' attribute on the root node.
                     $roots = $dom->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'RDF');
                     if ($roots->length > 0) {
                         $this->outVerbose("Root RDF element found.");
                         $root = $roots->item(0);
                         $node = $root->getAttributeNodeNS('http://www.w3.org/XML/1998/namespace', 'base');
                         if (!empty($node)) {
                             $targetNamespace = $node->value;
                         } else {
                             $this->outVerbose("No xml:base attribute found. The local model will be used.");
                         }
                     }
                 } else {
                     $this->err("RDF-XML could not be loaded.", true);
                 }
             } catch (DOMException $e) {
                 $this->err("RDF-XML parsing error: " . $e->getMessage(), true);
             }
         }
         //validate the file to import
         $parser = new tao_models_classes_Parser($this->options['input'], array('extension' => 'rdf'));
         $parser->validate();
         $this->outVerbose("Model URI is '{$targetNamespace}'.");
         if (!$parser->isValid()) {
             foreach ($parser->getErrors() as $error) {
                 $this->outVerbose("RDF-XML parsing error in '" . $error['file'] . "' at line '" . $error['line'] . "': '" . $error['message'] . "'.");
             }
             $userService->logout();
             $this->err("RDF-XML parsing error.", true);
         } else {
             //initialize the adapter (no target class but a target namespace)
             $adapter = new tao_helpers_data_GenerisAdapterRdf();
             if ($adapter->import($this->options['input'], null, $targetNamespace)) {
                 $this->outVerbose("RDF 'input' file successfully imported.");
                 $userService->logout();
             } else {
                 $userService->logout();
                 $this->err("An error occured during RDF-XML import.", true);
             }
         }
     } else {
         $this->err("Unable to connect to TAO as '" . $this->options['user'] . "'.", true);
     }
 }
 public function getData(Revision $revision)
 {
     $localModel = \common_ext_NamespaceManager::singleton()->getLocalNamespace();
     // retrieve data
     $query = 'SELECT * FROM ' . self::DATA_TABLE_NAME . ' WHERE ' . self::DATA_RESOURCE . ' = ? AND ' . self::DATA_VERSION . ' = ?';
     $result = $this->getPersistence()->query($query, array($revision->getResourceId(), $revision->getVersion()));
     $triples = array();
     while ($statement = $result->fetch()) {
         $triple = new \core_kernel_classes_Triple();
         $triple->modelid = $localModel->getModelId();
         $triple->subject = $statement[self::DATA_SUBJECT];
         $triple->predicate = $statement[self::DATA_PREDICATE];
         $triple->object = $statement[self::DATA_OBJECT];
         $triple->lg = $statement[self::DATA_LANGUAGE];
         $triples[] = $triple;
     }
     return $triples;
 }
Beispiel #16
0
 /**
  * (non-PHPdoc)
  * @see core_kernel_persistence_ClassInterface::createInstance()
  */
 public function createInstance(core_kernel_classes_Class $resource, $label = '', $comment = '', $uri = '')
 {
     $returnValue = null;
     $subject = '';
     if ($uri == '') {
         $subject = common_Utils::getNewUri();
     } else {
         if ($uri[0] == '#') {
             //$uri should start with # and be well formed
             $modelUri = common_ext_NamespaceManager::singleton()->getLocalNamespace()->getUri();
             $subject = rtrim($modelUri, '#') . $uri;
         } else {
             $subject = $uri;
         }
     }
     $returnValue = new core_kernel_classes_Resource($subject, __METHOD__);
     if (!$returnValue->hasType($resource)) {
         $returnValue->setType($resource);
     } else {
         common_Logger::e('already had type ' . $resource);
     }
     if (!empty($label)) {
         $returnValue->setLabel($label);
     }
     if (!empty($comment)) {
         $returnValue->setComment($comment);
     }
     return $returnValue;
 }
 /**
  * Get the long name (full URI) by providing a short name.
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param  string shortName
  * @return string
  */
 public static function getLongName($shortName)
 {
     $returnValue = (string) '';
     if (!empty($shortName) && strlen($shortName) > 2) {
         $shortName = preg_replace("/^_/", '', $shortName);
         $modelid = intval(substr($shortName, 0, 2));
         if ($modelid != null && $modelid > 0) {
             $nsUri = \common_ext_NamespaceManager::singleton()->getNamespace($modelid);
             $returnValue = $nsUri . substr($shortName, 2);
         }
     }
     return (string) $returnValue;
 }
Beispiel #18
0
 /**
  * Get the local namespace (model) in use by the authenticated user.
  *
  * @access public
  * @author Cédric Alfonsi, <*****@*****.**>
  * @return string
  * @deprecated
  */
 public function getNameSpace()
 {
     return common_ext_NamespaceManager::singleton()->getLocalNamespace()->getUri();
 }
 /**
  * (non-PHPdoc)
  * @see core_kernel_persistence_ClassInterface::createInstance()
  */
 public function createInstance(\core_kernel_classes_Class $resource, $label = '', $comment = '', $uri = '')
 {
     $returnValue = null;
     $dbWrapper = \core_kernel_classes_DbWrapper::singleton();
     $subject = '';
     if ($uri == '') {
         $subject = \common_Utils::getNewUri();
     } else {
         if ($uri[0] == '#') {
             //$uri should start with # and be well formed
             $modelUri = \common_ext_NamespaceManager::singleton()->getLocalNamespace()->getUri();
             $subject = rtrim($modelUri, '#') . $uri;
         } else {
             $subject = $uri;
         }
     }
     $returnValue = new \core_kernel_classes_Resource($subject, __METHOD__);
     try {
         $table = '_' . HardapiUtils::getShortName($resource);
         $query = 'INSERT INTO "' . $table . '" ("uri") VALUES (?)';
         $result = $dbWrapper->exec($query, array($subject));
         // reference the newly created instance
         ResourceReferencer::singleton()->referenceResource($returnValue, $table, array($resource), true);
         if (!empty($label)) {
             $returnValue->setPropertyValue(new \core_kernel_classes_Property(RDFS_LABEL), $label);
         }
         if (!empty($comment)) {
             $returnValue->setPropertyValue(new \core_kernel_classes_Property(RDFS_COMMENT), $comment);
         }
     } catch (\PDOException $e) {
         throw new Exception("Unable to create instance for the resource {$resource->getUri()} in the table {$table} : " . $e->getMessage());
     }
     return $returnValue;
 }
Beispiel #20
0
 /**
  * add a new statment to the knowledge base
  *
  * @access public
  * @author patrick.plichart@tudor.lu
  * @param  string subject
  * @param  string predicate
  * @param  string object
  * @param  string language
  * @return boolean
  */
 public function setStatement($subject, $predicate, $object, $language)
 {
     $returnValue = (bool) false;
     $dbWrapper = core_kernel_classes_DbWrapper::singleton();
     $platform = $dbWrapper->getPlatForm();
     $localNs = common_ext_NamespaceManager::singleton()->getLocalNamespace();
     $mask = 'yyy[admin,administrators,authors]';
     //now it's the default right mode
     $query = 'INSERT INTO statements (modelid,subject,predicate,object,l_language,author,epoch)
     			VALUES  (?, ?, ?, ?, ?, ? , ?);';
     try {
         $returnValue = $dbWrapper->exec($query, array($localNs->getModelId(), $subject, $predicate, $object, $language, \common_session_SessionManager::getSession()->getUserUri(), $platform->getNowExpression()));
     } catch (PDOException $e) {
         if ($e->getCode() !== '00000') {
             throw new common_Exception("Unable to setStatement (SPO) {$subject}, {$predicate}, {$object} : " . $e->getMessage());
         }
     }
     return (bool) $returnValue;
 }
Beispiel #21
0
 /**
  * Initialize the form elements
  *
  * @access protected
  * @author Bertrand Chevrier, <*****@*****.**>
  * @return mixed
  */
 protected function initElements()
 {
     $clazz = $this->getClassInstance();
     //add a group form for the class edition
     $elementNames = array();
     foreach (tao_helpers_form_GenerisFormFactory::getDefaultProperties() as $property) {
         //map properties widgets to form elements
         $element = tao_helpers_form_GenerisFormFactory::elementMap($property);
         if (!is_null($element)) {
             //take property values to populate the form
             $values = $clazz->getPropertyValues($property);
             if (!$property->isMultiple()) {
                 if (count($values) > 1) {
                     $values = array_slice($values, 0, 1);
                 }
             }
             foreach ($values as $value) {
                 if (!is_null($value)) {
                     $element->setValue($value);
                 }
             }
             $element->setName('class_' . $element->getName());
             //set label validator
             if ($property->getUri() == RDFS_LABEL) {
                 $element->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty')));
                 $ns = substr($clazz->getUri(), 0, strpos($clazz->getUri(), '#'));
                 if ($ns != LOCAL_NAMESPACE) {
                     $readonly = tao_helpers_form_FormFactory::getElement($element->getName(), 'Readonly');
                     $readonly->setDescription($element->getDescription());
                     $readonly->setValue($element->getRawValue());
                     $element = $readonly;
                 }
             }
             $element->addClass('global');
             $this->form->addElement($element);
             $elementNames[] = $element->getName();
         }
     }
     //add an hidden elt for the class uri
     $classUriElt = tao_helpers_form_FormFactory::getElement('classUri', 'Hidden');
     $classUriElt->setValue(tao_helpers_Uri::encode($clazz->getUri()));
     $classUriElt->addClass('global');
     $this->form->addElement($classUriElt);
     $hiddenId = tao_helpers_form_FormFactory::getElement('id', 'Hidden');
     $hiddenId->setValue($clazz->getUri());
     $hiddenId->addClass('global');
     $this->form->addElement($hiddenId);
     $localNamespace = common_ext_NamespaceManager::singleton()->getLocalNamespace()->getUri();
     //class properties edition: add a group form for each property
     $classProperties = tao_helpers_form_GenerisFormFactory::getClassProperties($clazz, $this->getTopClazz());
     $i = 0;
     $systemProperties = $this->getSystemProperties();
     foreach ($classProperties as $classProperty) {
         $i++;
         $useEditor = (bool) preg_match("/^" . preg_quote($localNamespace, '/') . "/", $classProperty->getUri());
         $parentProp = true;
         $domains = $classProperty->getDomain();
         foreach ($domains->getIterator() as $domain) {
             if (array_search($classProperty->getUri(), $systemProperties) !== false || $domain->getUri() == $clazz->getUri()) {
                 $parentProp = false;
                 //@todo use the getPrivileges method once implemented
                 break;
             }
         }
         if ($useEditor) {
             $propData = array();
             if (isset($this->propertyData[$classProperty->getUri()])) {
                 foreach ($this->propertyData[$classProperty->getUri()] as $key => $value) {
                     $propData[$i . '_' . $key] = $value;
                 }
             }
             $propForm = $this->getPropertyForm($classProperty, $i, $parentProp, $propData);
             //and get its elements and groups
             $this->form->setElements(array_merge($this->form->getElements(), $propForm->getElements()));
             $this->form->setGroups(array_merge($this->form->getGroups(), $propForm->getGroups()));
             unset($propForm);
         } else {
             $roElement = tao_helpers_form_FormFactory::getElement('roProperty' . $i, 'Free');
             $roElement->setValue(__('Cannot be edited'));
             $this->form->addElement($roElement);
             $groupTitle = '<span class="property-heading-label">' . _dh($classProperty->getLabel()) . '</span>';
             $this->form->createGroup("ro_property_{$i}", $groupTitle, array('roProperty' . $i));
         }
     }
 }
Beispiel #22
0
    }
} else {
    //from a browser
    if (isset($_GET['exportDir'])) {
        $exportDir = $_GET['exportDir'];
    }
    if (isset($_GET['nameMode'])) {
        $_GET['nameMode'] == 'long' ? $nameMode = 'long' : ($nameMode = 'short');
    }
}
if (!is_dir($exportDir)) {
    out("{$exportDir} is not a directory");
    exit;
}
$api = core_kernel_impl_ApiModelOO::singleton();
$nsManager = common_ext_NamespaceManager::singleton();
$namespaces = $nsManager->getAllNamespaces();
//$namespaces = array(LOCAL_NAMESPACE);
foreach ($namespaces as $namespace) {
    out("Exporting {$namespace}");
    $rdfData = core_kernel_api_ModelExporter::exportModelByUri($namespace);
    if (empty($rdfData)) {
        out("Nothing exported!");
        continue;
    }
    if ($nameMode == 'long') {
        $filename = str_replace('/', '_', str_replace('#', '', $namespace));
    } else {
        $filename = str_replace('#', '', strtolower(basename($namespace)));
    }
    if (!preg_match("/\\.rdf\$/", $filename)) {
 public function getData(Revision $revision)
 {
     if (!$revision instanceof RdsRevision) {
         throw new \common_exception_InconsistentData('Unexpected Revision class ' . get_class($revision) . ' in ' . __CLASS__);
     }
     $localModel = \common_ext_NamespaceManager::singleton()->getLocalNamespace();
     // retrieve data
     $query = 'SELECT * FROM ' . self::DATA_TABLE_NAME . ' WHERE ' . self::DATA_REVISION . ' = ?';
     $result = $this->getPersistence()->query($query, array($revision->getId()));
     $triples = array();
     while ($statement = $result->fetch()) {
         $triple = new \core_kernel_classes_Triple();
         $triple->modelid = $localModel->getModelId();
         $triple->subject = $statement[self::DATA_SUBJECT];
         $triple->predicate = $statement[self::DATA_PREDICATE];
         $triple->object = $statement[self::DATA_OBJECT];
         $triple->lg = $statement[self::DATA_LANGUAGE];
         $triples[] = $triple;
     }
     return $triples;
 }
 public function exportDiffToSql()
 {
     $sql = "";
     foreach ($this->comments as $comment) {
         $sql .= '-- ' . $comment . "\n";
     }
     foreach ($this->toRemove as $line) {
         $sql .= 'DELETE FROM statements WHERE subject = ' . $this->escape($line['s']) . ' AND predicate = ' . $this->escape($line['p']) . ' AND object = ' . $this->escape($line['o']) . ' AND l_language = ' . $this->escape($line['l']) . ";\n";
     }
     $namespaces = common_ext_NamespaceManager::singleton()->getAllNamespaces();
     foreach ($this->toAdd as $line) {
         $nsPrefix = substr($line['s'], 0, strpos($line['s'], '#') + 1);
         $ns = isset($namespaces[$nsPrefix]) ? $namespaces[$nsPrefix]->getModelId() : common_ext_NamespaceManager::singleton()->getLocalNamespace()->getModelId();
         $sql .= 'INSERT INTO statements (modelid,subject,predicate,object,l_language,author,epoch) VALUES ' . '(' . $ns . ',' . $this->escape($line['s']) . ',' . $this->escape($line['p']) . ',' . $this->escape($line['o']) . ',' . $this->escape($line['l']) . ',' . "'updateScript','" . date("m/d/y g:i A", time()) . "');\n";
     }
     return $sql;
 }
 /**
  * Returns the ids of all models
  * 
  * @return array
  */
 private static function getAllModelIds()
 {
     $nsManager = \common_ext_NamespaceManager::singleton();
     $modelIds = array();
     foreach ($nsManager->getAllNamespaces() as $m) {
         $modelIds[] = $m->getModelId();
     }
     return $modelIds;
 }