summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/docs/technical/code-snippets/store.subobject.md
blob: 6d96773790cf90769450cfdd026bdcd97c46acea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
);
```