|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* User: Jens |
|
4
|
|
|
* Date: 17-2-2017 |
|
5
|
|
|
* Time: 13:00 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace CloudControl\Cms\storage; |
|
9
|
|
|
use storage\storage\DocumentStorage; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class Document |
|
13
|
|
|
* @package CloudControl\Cms\storage |
|
14
|
|
|
* @property array fields |
|
15
|
|
|
* @property array bricks |
|
16
|
|
|
* @property array dynamicBricks |
|
17
|
|
|
* @property array content |
|
18
|
|
|
* @property-write \PDO dbHandle |
|
19
|
|
|
* @property-write DocumentStorage documentStorage |
|
20
|
|
|
*/ |
|
21
|
|
|
class Document |
|
22
|
|
|
{ |
|
23
|
|
|
public $id; |
|
24
|
|
|
public $path; |
|
25
|
|
|
public $title; |
|
26
|
|
|
public $slug; |
|
27
|
|
|
public $type; |
|
28
|
|
|
public $documentType; |
|
29
|
|
|
public $documentTypeSlug; |
|
30
|
|
|
public $state; |
|
31
|
|
|
public $lastModificationDate; |
|
32
|
|
|
public $creationDate; |
|
33
|
|
|
public $lastModifiedBy; |
|
34
|
|
|
protected $fields; |
|
35
|
|
|
protected $bricks; |
|
36
|
|
|
protected $dynamicBricks; |
|
37
|
|
|
protected $content; |
|
38
|
|
|
|
|
39
|
|
|
protected $dbHandle; |
|
40
|
|
|
|
|
41
|
|
|
protected $jsonEncodedFields = array('fields', 'bricks', 'dynamicBricks'); |
|
42
|
|
|
protected $orderableFields = array('title', 'slug', 'type', 'documentType', 'documentTypeSlug', 'state', 'lastModificationDate', 'creationDate', 'lastModifiedBy'); |
|
43
|
|
|
|
|
44
|
|
|
public static $DOCUMENT_STATES = array('published', 'unpublished'); |
|
45
|
|
|
|
|
46
|
|
|
public function __get($name) { |
|
47
|
|
|
if (in_array($name, $this->jsonEncodedFields)) { |
|
48
|
|
|
if (is_string($this->$name)) { |
|
49
|
|
|
return json_decode($this->$name); |
|
50
|
|
|
} else { |
|
51
|
|
|
return $this->$name; |
|
52
|
|
|
} |
|
53
|
|
|
} elseif ($name === 'content') { |
|
54
|
|
|
if ($this->dbHandle === null) { |
|
55
|
|
|
throw new \Exception('Document doesnt have a dbHandle handle. (path: ' . $this->path . ')'); |
|
56
|
|
|
} else { |
|
57
|
|
|
if ($this->content === null) { |
|
58
|
|
|
return $this->getContent(); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
} elseif ($name === 'dbHandle') { |
|
62
|
|
|
throw new \Exception('Trying to get protected property repository.'); |
|
63
|
|
|
} |
|
64
|
|
|
return $this->$name; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function __set($name, $value) { |
|
68
|
|
|
if (in_array($name, $this->jsonEncodedFields)) { |
|
69
|
|
|
$this->$name = json_encode($value); |
|
70
|
|
|
} elseif ($name === 'content') { |
|
71
|
|
|
// Dont do anything for now.. |
|
72
|
|
|
return; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$this->$name = $value; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param string $orderBy |
|
80
|
|
|
* @param string $order |
|
81
|
|
|
* |
|
82
|
|
|
* @return array |
|
83
|
|
|
* @throws \Exception |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getContent($orderBy = 'title', $order = 'ASC') |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
|
|
if (empty($this->content)) { |
|
88
|
|
|
$docs = $this->documentStorage->getDocumentsWithState($this->path); |
|
89
|
|
|
$this->content = $docs; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return $this->content; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
public function __toString() |
|
99
|
|
|
{ |
|
100
|
|
|
return 'Document:' . $this->title; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.