depage-xmldb
v2.3.1
XML documents in a relational database
Toggle main menu visibility
Loading...
Searching...
No Matches
XmlDbHistory.php
Go to the documentation of this file.
1
<?php
2
12
13
namespace
Depage\XmlDb;
14
15
class
XmlDbHistory
implements
Interfaces\XmlGetter
16
{
17
protected
$pdo
;
18
protected
$xmlDb
;
19
protected
$dbNs
;
20
protected
$tableHistory
;
21
22
protected
$docIds
= [];
23
24
protected
$tablePrefix
=
'dp_'
;
25
protected
$tableDocs
;
26
27
protected
$options
;
28
29
public
$timestamp
=
null
;
30
39
public
function
__construct
(
$tablePrefix
,
$pdo
, $cache,
$options
= [])
40
{
41
$this->pdo =
$pdo
;
42
$this->pdo->setAttribute(\PDO::ATTR_ORACLE_NULLS, \PDO::NULL_NATURAL);
43
44
$this->xmlDb =
new
XmlDb
(
$tablePrefix
,
$pdo
, $cache,
$options
);
45
$this->dbNs =
new
XmlNs
(
'db'
,
'http://cms.depagecms.net/ns/database'
);
46
47
$this->tablePrefix =
$tablePrefix
;
48
$this->tableDocs =
$tablePrefix
.
'_xmldocs'
;
49
$this->tableHistory =
$tablePrefix
.
'_history'
;
50
}
51
61
public
function
docExists
($docIdOrName)
62
{
63
$result =
false
;
64
65
$id = $this->xmlDb->docExists($docIdOrName);
66
67
$query = $this->pdo->prepare(
"
68
SELECT doc_id
69
FROM {$this->tableHistory}
70
WHERE doc_id = :id
71
LIMIT 1
72
"
);
73
74
$query->execute([
75
'id'
=> $id,
76
]);
77
78
if
($query->fetch()) {
79
$result = $id;
80
}
81
82
return
$result;
83
}
84
92
public
function
getDocInfo
($docIdOrName)
93
{
94
return
$this->xmlDb->getDocInfo($docIdOrName);
95
}
96
107
public
function
getDocXml
($docIdOrName, $addIdAttribute =
true
)
108
{
109
$xml =
false
;
110
111
if
($docId = $this->
docExists
($docIdOrName)) {
112
$doc =
new
Document
($this, $docId);
113
$history = $doc->getHistory();
114
115
if
(!is_null($this->timestamp)) {
116
$xml = $history->getXml($this->timestamp, $addIdAttribute);
117
}
else
{
118
$xml = $history->getLastPublishedXml($addIdAttribute);
119
}
120
}
121
122
return
$xml;
123
}
124
134
public
function
getDocXmlXpath
($docIdOrName, $xpath, $addIdAttribute =
true
)
135
{
136
$xml =
false
;
137
138
if
($docId = $this->
docExists
($docIdOrName)) {
139
$xmlFull = $this->
getDocXml
($docIdOrName, $addIdAttribute);
140
if
($xmlFull ===
false
) {
141
throw
new \Exception(
"Document could not be read from history"
);
142
}
143
144
$domXpath = new \DomXpath($xmlFull);
145
$list = $domXpath->query($xpath);
146
147
if
($list->length > 0) {
148
$xml = new \Depage\Xml\Document();
149
$xml->appendChild($xml->importNode($list->item(0),
true
));
150
151
return
$xml;
152
}
153
}
154
155
return
$xml;
156
}
157
164
public
function
__get
($property)
165
{
166
if
(property_exists($this, $property)) {
167
return
$this->$property;
168
}
169
}
170
173
public
function
__sleep
()
174
{
175
return
[
176
'pdo'
,
177
'xmlDb'
,
178
'dbNs'
,
179
'tablePrefix'
,
180
'tableDocs'
,
181
'tableHistory'
,
182
'options'
,
183
];
184
}
185
}
186
187
/* vim:set ft=php sw=4 sts=4 fdm=marker et : */
Depage\XmlDb\Document
Definition
Document.php:16
Depage\XmlDb\XmlDbHistory
Definition
XmlDbHistory.php:16
Depage\XmlDb\XmlDbHistory\$options
$options
Definition
XmlDbHistory.php:27
Depage\XmlDb\XmlDbHistory\$tableHistory
$tableHistory
Definition
XmlDbHistory.php:20
Depage\XmlDb\XmlDbHistory\$tablePrefix
$tablePrefix
Definition
XmlDbHistory.php:24
Depage\XmlDb\XmlDbHistory\$timestamp
$timestamp
Definition
XmlDbHistory.php:29
Depage\XmlDb\XmlDbHistory\$docIds
$docIds
Definition
XmlDbHistory.php:22
Depage\XmlDb\XmlDbHistory\$xmlDb
$xmlDb
Definition
XmlDbHistory.php:18
Depage\XmlDb\XmlDbHistory\$pdo
$pdo
Definition
XmlDbHistory.php:17
Depage\XmlDb\XmlDbHistory\docExists
docExists($docIdOrName)
gets the doc-id of a xml-document by name or id and checks if the document has at least one version i...
Definition
XmlDbHistory.php:61
Depage\XmlDb\XmlDbHistory\$dbNs
$dbNs
Definition
XmlDbHistory.php:19
Depage\XmlDb\XmlDbHistory\__get
__get($property)
Get properties (basically read-only).
Definition
XmlDbHistory.php:164
Depage\XmlDb\XmlDbHistory\getDocXml
getDocXml($docIdOrName, $addIdAttribute=true)
gets a published version of a document as a DOMDocument
Definition
XmlDbHistory.php:107
Depage\XmlDb\XmlDbHistory\getDocXmlXpath
getDocXmlXpath($docIdOrName, $xpath, $addIdAttribute=true)
gets the first node of a published version of a document that matches an xpath query
Definition
XmlDbHistory.php:134
Depage\XmlDb\XmlDbHistory\$tableDocs
$tableDocs
Definition
XmlDbHistory.php:25
Depage\XmlDb\XmlDbHistory\__construct
__construct($tablePrefix, $pdo, $cache, $options=[])
creates an instance of the read only view on the published versions
Definition
XmlDbHistory.php:39
Depage\XmlDb\XmlDbHistory\__sleep
__sleep()
allows Depage\Db\Pdo-object to be serialized
Definition
XmlDbHistory.php:173
Depage\XmlDb\XmlDbHistory\getDocInfo
getDocInfo($docIdOrName)
gets the info of a document
Definition
XmlDbHistory.php:92
Depage\XmlDb\XmlDb
Definition
XmlDb.php:19
Depage\XmlDb\XmlNs
A namespace prefix and the URI it is bound to.
Definition
XmlNs.php:9
Depage\XmlDb\Interfaces\XmlGetter
Interface of a read only accessor for xml documents.
Definition
XmlGetter.php:12
XmlDbHistory.php
Generated on
for depage-xmldb by
doxygen
1.18.0
For an overview of all docs, go to
docs.depage.net