5 * @author Benjamin Nowack <bnowack@semsol.com>
6 * @license http://arc.semsol.org/license
7 * @homepage <http://arc.semsol.org/>
14 class ARC2_Resource extends ARC2_Class {
16 function __construct($a = '', &$caller) {
17 parent::__construct($a, $caller);
20 function ARC2_Resource($a = '', &$caller) {
21 $this->__construct($a, $caller);
27 $this->index = array();
28 $this->fetched = array();
34 function setURI($uri) {
38 function setIndex($index) {
39 $this->index = $index;
42 function setProps($props, $s = '') {
43 if (!$s) $s = $this->uri;
44 $this->index[$s] = $props;
47 function setProp($p, $os, $s = '') {
48 if (!$s) $s = $this->uri;
49 /* single plain value */
50 if (!is_array($os)) $os = array('value' => $os, 'type' => 'literal');
51 /* single array value */
52 if (isset($os['value'])) $os = array($os);
54 foreach ($os as $i => $o) {
55 if (!is_array($o)) $os[$i] = array('value' => $o, 'type' => 'literal');
57 $this->index[$s][$this->expandPName($p)] = $os;
60 function setStore($store) {
61 $this->store = $store;
66 function fetchData($uri = '') {
67 if (!$uri) $uri = $this->uri;
69 if (in_array($uri, $this->fetched)) return 0;
70 $this->index[$uri] = array();
72 $index = $this->store->query('DESCRIBE <' . $uri . '>', 'raw');
75 $index = $this->toIndex($uri);
77 $this->index = ARC2::getMergedIndex($this->index, $index);
78 $this->fetched[] = $uri;
83 function getProps($p = '', $s = '') {
84 if (!$s) $s = $this->uri;
85 if (!$s) return array();
86 if (!isset($this->index[$s])) $this->fetchData($s);
87 if (!$p) return $this->index[$s];
88 return $this->v($this->expandPName($p), array(), $this->index[$s]);
91 function getProp($p, $s = '') {
92 $props = $this->getProps($p, $s);
93 return $props ? $props[0] : '';
96 function getPropValue($p, $s = '') {
97 $prop = $this->getProp($p, $s);
98 return $prop ? $prop['value'] : '';
101 function getPropValues($p, $s = '') {
103 $props = $this->getProps($p, $s);
104 foreach ($props as $prop) {
105 $r[] = $prop['value'];
110 function hasPropValue($p, $o, $s = '') {
111 $props = $this->getProps($p, $s);
112 $o = $this->expandPName($o);
113 foreach ($props as $prop) {
114 if ($prop['value'] == $o) return 1;