Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
226 | daniel-mar | 1 | <?php |
2 | |||
3 | # if (!interface_exists('OIDPlusFieldExtenders')) throw new Exception('Required interface "OIDPlusFieldExtenders" not found.'); |
||
4 | # if (!class_exists('OIDPlus')) throw new Exception('Required class "OIDPlus" not found.'); |
||
5 | |||
6 | require_once __DIR__ . '/../../core/OIDPlusFieldExtenders.class.php'; |
||
7 | require_once __DIR__ . '/../../includes/oid_utils.inc.php'; |
||
8 | require_once __DIR__ . '/../../includes/uuid_utils.inc.php'; |
||
9 | |||
10 | class IRISearchFieldExtender implements OIDPlusFieldExtenders { |
||
11 | private static function detectDirectIRINotation($x, &$xx, $oidplusobj) { |
||
12 | # At your root, you can define your own iri-notation |
||
13 | # FUT: as alternative, we could have "invisible" OIDs (cannot be queried) which give information about non-root OIDs |
||
14 | $iripath = $oidplusobj->getValuesOf($x, 'iri-notation', true); |
||
15 | if (count($iripath) > 0) { |
||
16 | $oidplusobj->stripAttribs($x, 'iri-notation'); |
||
17 | |||
18 | $iripath = trim($iripath[0]); |
||
19 | if (!iri_valid($iripath)) { |
||
20 | throw new VolcanoException("IRI notation '$iripath' is invalid"); # TODO: source? |
||
21 | } |
||
22 | |||
23 | $iripath = trim($iripath); |
||
24 | assert(substr($iripath, 0, 1) == '/'); |
||
25 | $iripath = substr($iripath, 1); |
||
26 | |||
27 | $xx[] = $iripath; |
||
28 | return true; |
||
29 | } |
||
30 | |||
31 | return false; |
||
32 | } |
||
33 | |||
34 | public static function processOID($oid, &$out, &$oidplusobj) { |
||
35 | $xx = array(); |
||
36 | |||
37 | $x = $oid; |
||
38 | do { |
||
39 | $toparc = oid_toparc($x); |
||
40 | |||
41 | if (self::detectDirectIRINotation($x, $xx, $oidplusobj)) break; |
||
42 | |||
43 | $ids = $oidplusobj->getUnicodeLabels($x); |
||
44 | |||
45 | $id = null; |
||
46 | foreach ($ids as $m) { |
||
47 | if (iri_arc_valid($m)) { |
||
48 | $id = $m; |
||
49 | break; |
||
50 | } |
||
51 | } |
||
52 | |||
53 | if (is_null($id)) { |
||
54 | $xx[] = $toparc; |
||
55 | } else { |
||
56 | $xx[] = $id; |
||
57 | } |
||
58 | } while (($x = oid_up($x)) != '.'); |
||
59 | |||
60 | $xx = array_reverse($xx); |
||
61 | |||
62 | if (count($xx) > 0) { |
||
63 | $iripath = '/'.implode('/', $xx); |
||
64 | |||
65 | if (!iri_valid($iripath)) { |
||
66 | throw new VolcanoException("IRI notation '$iripath' is invalid"); # TODO: source? |
||
67 | } |
||
68 | |||
69 | # TODO: soll das auch für die existierenden "iri-notation" felder angewandt werden? |
||
70 | $iripath = iri_add_longarcs($iripath); |
||
71 | |||
72 | $out[] = "iri-notation: $iripath"; |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | |||
77 | require_once __DIR__ . '/../../core/2_OIDPlus.class.php'; |
||
78 | OIDPlus::registerFieldExtender(new IRISearchFieldExtender()); |