1 | <?php |
||
12 | class ValidContent implements \Anax\DI\IInjectionAware |
||
13 | { |
||
14 | use \Anax\DI\TInjectable; |
||
15 | |||
16 | private $miniLength; // Minimum length on text-fields (ex. ingress, title etc) |
||
17 | private $urlPrefix; |
||
18 | private $filters; |
||
19 | private $types; |
||
20 | |||
21 | /** |
||
22 | * Initialize the controller |
||
23 | * |
||
24 | * @return void |
||
25 | */ |
||
26 | 16 | public function initialize(){ |
|
27 | 16 | $this->miniLength = CHP_TC_MINILENGTH; // Minimum length on text-fields (ex. ingress, title etc) |
|
28 | 16 | $this->urlPrefix = CHP_TC_URLPREFIX; |
|
29 | $this->filters = unserialize(CHP_TC_FILTERS); |
||
30 | $this->types = unserialize(CHP_TC_TYPES); |
||
31 | 16 | } |
|
32 | |||
33 | /** |
||
34 | * Create a link to the content, based on its type. |
||
35 | * |
||
36 | * @param object $content Content to link to |
||
37 | * @return string With url for content |
||
38 | */ |
||
39 | 1 | public function getUrlToContent($content) { |
|
40 | if(isset($this->types[$content->type])){ |
||
41 | 1 | $type = $this->types[$content->type]; // Get type from type index |
|
42 | |||
43 | return $this->url->create("{$this->urlPrefix}{$type['url']}{$type['prefix']}{$content->{$type['field']}}"); |
||
44 | } |
||
45 | |||
46 | 1 | return null; |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * Return array with all content types title and keys (Use for content-type select) |
||
51 | * |
||
52 | * @return array $types Array with the types title and keys |
||
53 | */ |
||
54 | 1 | public function getTypes(){ |
|
55 | 1 | $types = array(); |
|
56 | |||
57 | // Loop through and save types key as key and title as value in a new array |
||
58 | 1 | foreach($this->types AS $key => $value){ |
|
59 | $types[$key] = $value['title']; |
||
60 | } |
||
61 | |||
62 | 1 | return $types; |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * Return array with all filters |
||
67 | * |
||
68 | * @return array $this->filters Array with the filters |
||
69 | */ |
||
70 | 1 | public function getFilters(){ |
|
73 | |||
74 | /** |
||
75 | * Return name of one specific type |
||
76 | * |
||
77 | * @params string $type Type key |
||
78 | * @return string $this->types[{key}]['title'] Type title |
||
79 | */ |
||
80 | public function getTypeTitle($type){ |
||
83 | |||
84 | /** |
||
85 | * Create a slug of a string, to be used as url. |
||
86 | * |
||
87 | * @param string $str String to format as slug. |
||
88 | * @return string $str Formatted slug. |
||
89 | */ |
||
90 | public function slugify($str) { |
||
100 | |||
101 | /** |
||
102 | * Check if content is published |
||
103 | * |
||
104 | * @param string $datetime When it will be published |
||
105 | * @return boolean True/false Validate result |
||
106 | */ |
||
107 | public function checkIfAvailable($datetime){ |
||
110 | |||
111 | /** |
||
112 | * Check so the choosed type exist. |
||
113 | * |
||
114 | * @param string $type Choosed type on content |
||
115 | * @return boolean True/false Validate result |
||
116 | */ |
||
117 | public function checkType($type = ''){ |
||
120 | |||
121 | /** |
||
122 | * Validate posted datetime so it is correct |
||
123 | * |
||
124 | * @param string $datetime Posted datetime to check |
||
125 | * @return boolean True/false Validate status |
||
126 | */ |
||
127 | 2 | public function checkDatetime($datetime){ |
|
135 | |||
136 | /** |
||
137 | * Minimum length |
||
138 | * |
||
139 | * @param string $value Value from form-element to validate |
||
140 | * @return boolean True/false Validate result |
||
141 | */ |
||
142 | public function minimumLength($value){ |
||
145 | |||
146 | /** |
||
147 | * Validate slug url |
||
148 | * |
||
149 | * @param string $url Url to validate |
||
150 | * @return boolean True/false True if valid otherwish false |
||
151 | */ |
||
152 | public function validateSlug($url){ |
||
155 | |||
156 | /** |
||
157 | * Check so the selected filter exist. |
||
158 | * |
||
159 | * @param string $filter Selected filter |
||
160 | * @return boolean $result Return the result of test |
||
161 | */ |
||
162 | 2 | public function checkFilter($filter = null){ |
|
173 | } |