types.inc.php
5.5 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/**
* Type access functions for CMIS AtomPub
*/
include 'services/cmis/RepositoryService.inc.php';
$RepositoryService = new RepositoryService();
// technically do not need to log in to access this information
// TODO consider requiring authentication even to access basic repository information
$RepositoryService->startSession($username, $password);
// fetch repository id
$repositories = $RepositoryService->getRepositories();
$repositoryId = $repositories[0]['repositoryId'];
switch($arg)
{
case 'type':
{
if (!isset($query[3]))
{
$type = ucwords($query[2]);
$types = $RepositoryService->getTypes($repositoryId, $type);
$output = CMISTypeFeed::getTypeFeed($type, $types);
}
else
{
// TODO dynamic dates, as needed everywhere
// NOTE children of types not yet implemented and we don't support any non-basic types at this time
$output = CMISTypeFeed::getTypeChildrenFeed($query[2]);
}
}
break;
case 'types':
$types = $RepositoryService->getTypes($repositoryId);
$type = (($query[2] == '') ? 'all' : $query[2]);
$output = CMISTypeFeed::getTypeFeed($type, $types);
break;
}
/**
* Class to generate CMIS AtomPub feeds for Type responses
*/
class CMISTypeFeed {
/**
* Retrieves the list of types as a CMIS AtomPub feed
*
* @param string $typeDef Type requested - 'All Types' indicates a listing, else only a specific type
* @param array $types The types found
* @return string CMIS AtomPub feed
*/
static public function getTypeFeed($typeDef, $types)
{
$typesString = '';
$typesHeading = '';
switch($typeDef)
{
case 'all':
case 'children':
case 'descendants':
$typesString = 'types-' . $typeDef;
$typesHeading = 'All Types';
break;
default:
$typesString = 'type-' . $typeDef;
$typesHeading = $typeDef;
break;
}
$feed = new KTCMISAPPFeed(KT_APP_BASE_URI, $typesHeading, null, null, null, 'urn:uuid:' . $typesString);
foreach($types as $type)
{
$entry = $feed->newEntry();
$feed->newId('urn:uuid:type-' . strtolower($type['typeId']), $entry);
// links
$link = $feed->newElement('link');
$link->appendChild($feed->newAttr('rel','self'));
$link->appendChild($feed->newAttr('href', CMIS_BASE_URI . 'type/' . strtolower($type['typeId'])));
$entry->appendChild($link);
$link = $feed->newElement('link');
$link->appendChild($feed->newAttr('rel','cmis-type'));
$link->appendChild($feed->newAttr('href', CMIS_BASE_URI . 'type/' . strtolower($type['typeId'])));
$entry->appendChild($link);
$link = $feed->newElement('link');
$link->appendChild($feed->newAttr('rel','cmis-children'));
$link->appendChild($feed->newAttr('href', CMIS_BASE_URI . 'type/' . strtolower($type['typeId']) . '/children'));
$entry->appendChild($link);
$link = $feed->newElement('link');
$link->appendChild($feed->newAttr('rel','cmis-descendants'));
$link->appendChild($feed->newAttr('href', CMIS_BASE_URI . 'type/' . strtolower($type['typeId']) . '/descendants'));
$entry->appendChild($link);
$link = $feed->newElement('link');
$link->appendChild($feed->newAttr('rel','cmis-repository'));
$link->appendChild($feed->newAttr('href', CMIS_BASE_URI . 'repository'));
$entry->appendChild($link);
$entry->appendChild($feed->newElement('summary', $type['typeId'] . ' Type'));
$entry->appendChild($feed->newElement('title', $type['typeId']));
// main CMIS entry
$feedElement = $feed->newElement('cmis:' . strtolower($type['typeId']) . 'Type');
foreach($type as $property => $value)
{
$feed->newField($property, CMISUtil::boolToString($value), $feedElement);
}
$entry->appendChild($feedElement);
}
$output = $feed->getAPPdoc();
return $output;
}
/**
* Retrieves a list of child types for the supplied type
*
* NOTE this currently returns a hard coded empty list, since we do not currently support child types
* TODO make dynamic if/when we support checking for child types (we don't actually need to support child types themselves)
*
* @param string $type
* @return string CMIS AtomPub feed
*/
static public function getTypeChildrenFeed($type)
{
$output = '<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns:cmis="http://www.cmis.org/2008/05">
<id>urn:uuid:type-' . $type . '-children</id>
<link rel="self" href="' . CMIS_BASE_URI . 'type/document/children"/>
<link rel="first" href="' . CMIS_BASE_URI . 'type/document/children?pageNo=1&pageSize=0&guest=" type="application/atom+xml;type=feed"/>
<link rel="last" href="' . CMIS_BASE_URI . 'type/document/children?pageNo=1&pageSize=0&guest=" type="application/atom+xml;type=feed"/>
<title>Child types of ' . $type . '</title>
<updated>2009-06-23T13:40:32.786+02:00</updated>
<cmis:hasMoreItems>false</cmis:hasMoreItems>
</feed>';
return $output;
}
}
?>