diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/docs/technical/code-snippets/store.subobject.md')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/docs/technical/code-snippets/store.subobject.md | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/docs/technical/code-snippets/store.subobject.md b/www/wiki/extensions/SemanticMediaWiki/docs/technical/code-snippets/store.subobject.md new file mode 100644 index 00000000..6d967737 --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/docs/technical/code-snippets/store.subobject.md @@ -0,0 +1,73 @@ +## Using Subobject + +```php +$subject = new DIWikiPage( 'Foo', NS_MAIN ); + +$subobject = new Subobject( $subject->getTitle() ); +$subobject->setEmptyContainerForId( 'SomeSubobject' ); + +$dataValue = DataValueFactory::getInstance()->newDataValueByText( + 'SomeProperty, + 'SomeValue' +); + +$subobject->addDataValue( + $dataValue +); +``` + +```php +// Create and store SemanticData object and add the subobject +$semanticData = new SemanticData( $subject ); + +$semanticData->addPropertyObjectValue( + $subobject->getProperty(), + $subobject->getContainer() +); + +ApplicationFactory::getInstance()->getStore()->updateData( + $semanticData +); +``` + +## Using DIContainer + +```php +$subject = new DIWikiPage( 'Foo', NS_MAIN ); + +// Internal subobject reference +$subobjectName = 'SomeSubobject'; + +$containerSubject = new DIWikiPage( + $subject->getDBkey(), + $subject->getNamespace(), + $subject->getInterwiki(), + $subobjectName +); + +// Create container to host property values assignments +// for the particular subobjectName +$containerSemanticData = new ContainerSemanticData( $containerSubject ); + +$dataValue = DataValueFactory::getInstance()->newDataValueByText( + 'SomeProperty, + 'SomeValue' +); + +$containerSemanticData->addDataValue( + $dataValue +); +``` +```php +// Create and store SemanticData object and add the subobject +$semanticData = new SemanticData( $subject ); + +$semanticData->addPropertyObjectValue( + new DIProperty( '_SOBJ' ), + new DIContainer( $containerSemanticData ) +); + +ApplicationFactory::getInstance()->getStore()->updateData( + $semanticData +); +```
\ No newline at end of file |