Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezurlaliasquery.php
Go to the documentation of this file.
1 <?php
33 class eZURLAliasQuery
34 {
39 public $actions;
44 public $actionTypes;
49 public $actionTypesEx;
53 public $paren;
57 public $text;
61 public $type = 'alias';
65 public $languages = true;
70 public $offset = 0;
75 public $limit = 15;
80 public $order = 'text';
81
86 public $query;
91 public $count;
96 public $items;
97
98 function hasAttribute( $name )
99 {
100 return $name !== "query" && array_key_exists( $name, get_object_vars( $this ) );
101 }
102
103 function attribute( $name )
104 {
105 switch ( $name )
106 {
107 case 'count':
108 {
109 return $this->count();
110 } break;
111 case 'items':
112 {
113 return $this->fetchAll();
114 } break;
115 default:
116 {
117 return $this->$name;
118 } break;
119 }
120 }
121
122 function setAttribute( $name, $value )
123 {
124 $this->$name = $value;
125 $this->query = null;
126 $this->count = null;
127 $this->items = null;
128 }
129
135 function prepare()
136 {
137 $this->query = null;
138 $this->count = null;
139 $this->items = null;
140 }
141
147 function count()
148 {
149 if ( $this->count !== null )
150 return $this->count;
151
152 if ( $this->query === null )
153 {
154 $this->query = $this->generateSQL();
155 }
156 if ( $this->query === false )
157 return 0;
158 $query = "SELECT count(*) AS count {$this->query}";
159 $db = eZDB::instance();
160 $rows = $db->arrayQuery( $query );
161 if ( count( $rows ) == 0 )
162 $this->count = 0;
163 else
164 $this->count = $rows[0]['count'];
165 return $this->count;
166 }
167
173 function fetchAll()
174 {
175 if ( $this->items !== null )
176 return $this->items;
177
178 if ( $this->query === null )
179 {
180 $this->query = $this->generateSQL();
181 }
182 if ( $this->query === false )
183 return array();
184 $query = "SELECT * {$this->query} ORDER BY {$this->order}";
185 $params = array( 'offset' => $this->offset,
186 'limit' => $this->limit );
187 $db = eZDB::instance();
188 $rows = $db->arrayQuery( $query, $params );
189 if ( count( $rows ) == 0 )
190 $this->items = array();
191 else
192 $this->items = eZURLAliasQuery::makeList( $rows );
193 return $this->items;
194 }
195
200 protected function generateSQL()
201 {
202 if ( !in_array( $this->type, array( 'name', 'alias', 'all' ) ) )
203 {
204 eZDebug::writeError( "Parameter \$type must be one of name, alias or all. The value which was used was '{$this->type}'." );
205 return null;
206 }
207
208 $db = eZDB::instance();
209 if ( $this->languages === true )
210 {
211 $langMask = trim( eZContentLanguage::languagesSQLFilter( 'ezurlalias_ml', 'lang_mask' ) );
212 $conds[] = "($langMask)";
213 }
214
215 if ( $this->paren !== null )
216 {
217 $conds[] = "parent = {$this->paren}";
218 }
219
220 if ( $this->text !== null )
221 {
222 $conds[] = "text_md5 = " . $db->md5( "'" . $db->escapeString( $this->text ) . "'" );
223 }
224
225 if ( $this->actions !== null )
226 {
227 // Check for conditions which will return no rows.
228 if ( count( $this->actions ) == 0 )
229 return false;
230
231 if ( count( $this->actions ) == 1 )
232 {
233 $action = $this->actions[0];
234 $actionStr = $db->escapeString( $action );
235 $conds[] = "action = '$actionStr'";
236 }
237 else
238 {
239 $actions = array();
240 foreach ( $this->actions as $action )
241 {
242 $actions[] = "'" . $db->escapeString( $action ) . "'";
243 }
244 $conds[] = "action IN (" . join( ", ", $actions ) . ")";
245 }
246 }
247 $actionTypes = null;
248 if ( $this->actionTypes !== null )
249 {
250 $actionTypes = $this->actionTypes;
251 }
252 if ( $this->actionTypesEx !== null )
253 {
254 if ( $actionTypes == null )
255 {
256 $rows = $db->arrayQuery( "SELECT DISTINCT action_type FROM ezurlalias_ml" );
257 $actionTypes = array();
258 foreach ( $rows as $row )
259 {
260 $actionTypes[] = $row['action_type'];
261 }
262 }
263 $actionTypes = array_values( array_diff( $actionTypes, $this->actionTypesEx ) );
264 }
265 if ( $actionTypes !== null )
266 {
267 // Check for conditions which will return no rows.
268 if ( count( $actionTypes ) == 0 )
269 return false;
270
271 if ( count( $actionTypes ) == 1 )
272 {
273 $action = $actionTypes[0];
274 $actionStr = $db->escapeString( $action );
275 $conds[] = "action_type = '$actionStr'";
276 }
277 else
278 {
279 $actions = array();
280 foreach ( $actionTypes as $action )
281 {
282 $actions[] = "'" . $db->escapeString( $action ) . "'";
283 }
284 $conds[] = "action_type IN (" . join( ", ", $actions ) . ")";
285 }
286 }
287
288 $conds[] = 'is_original = 1';
289 if ( $this->type == 'name' )
290 {
291 $conds[] = 'is_alias = 0';
292 }
293 else if ( $this->type == 'alias' )
294 {
295 $conds[] = 'is_alias = 1';
296 }
297 else // 'all'
298 {
299 }
300
301 return "FROM ezurlalias_ml WHERE " . join( " AND ", $conds );
302 }
303
309 static public function makeList( $rows )
310 {
311 if ( !is_array( $rows ) || count( $rows ) == 0 )
312 return array();
313 $list = array();
314 $maxNumberOfLanguages = eZContentLanguage::maxCount();
315 foreach ( $rows as $row )
316 {
317 $row['always_available'] = $row['lang_mask'] % 2;
318 $mask = $row['lang_mask'] & ~1;
319 for ( $i = 1; $i < $maxNumberOfLanguages; ++$i )
320 {
321 $newMask = (1 << $i);
322 if ( ($newMask & $mask) > 0 )
323 {
324 $row['lang_mask'] = (1 << $i);
325 $list[] = $row;
326 }
327 }
328 }
329 $objectList = eZPersistentObject::handleRows( $list, 'eZPathElement', true );
330 return $objectList;
331 }
332 }
333
334 ?>
eZContentLanguage\maxCount
static maxCount()
Definition: ezcontentlanguage.php:940
eZContentLanguage\languagesSQLFilter
static languagesSQLFilter( $languageListTable, $languageListAttributeName='language_mask')
Definition: ezcontentlanguage.php:659
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZPersistentObject\handleRows
static handleRows( $rows, $class_name, $asObject)
Definition: ezpersistentobject.php:963
eZURLAliasQuery
Handles querying of URL aliases with different filters.
Definition: ezurlaliasquery.php:34
eZURLAliasQuery\$languages
$languages
Definition: ezurlaliasquery.php:65
eZURLAliasQuery\attribute
attribute( $name)
Definition: ezurlaliasquery.php:103
eZURLAliasQuery\hasAttribute
hasAttribute( $name)
Definition: ezurlaliasquery.php:98
eZURLAliasQuery\makeList
static makeList( $rows)
Definition: ezurlaliasquery.php:309
eZURLAliasQuery\$actions
$actions
Definition: ezurlaliasquery.php:39
eZURLAliasQuery\$items
$items
Definition: ezurlaliasquery.php:96
eZURLAliasQuery\count
count()
Definition: ezurlaliasquery.php:147
eZURLAliasQuery\$limit
$limit
Definition: ezurlaliasquery.php:75
eZURLAliasQuery\prepare
prepare()
Definition: ezurlaliasquery.php:135
eZURLAliasQuery\$type
$type
Definition: ezurlaliasquery.php:61
eZURLAliasQuery\setAttribute
setAttribute( $name, $value)
Definition: ezurlaliasquery.php:122
eZURLAliasQuery\$actionTypes
$actionTypes
Definition: ezurlaliasquery.php:44
eZURLAliasQuery\$actionTypesEx
$actionTypesEx
Definition: ezurlaliasquery.php:49
eZURLAliasQuery\$count
$count
Definition: ezurlaliasquery.php:91
eZURLAliasQuery\$offset
$offset
Definition: ezurlaliasquery.php:70
eZURLAliasQuery\$text
$text
Definition: ezurlaliasquery.php:57
eZURLAliasQuery\$paren
$paren
Definition: ezurlaliasquery.php:53
eZURLAliasQuery\$order
$order
Definition: ezurlaliasquery.php:80
eZURLAliasQuery\$query
$query
Definition: ezurlaliasquery.php:86
eZURLAliasQuery\generateSQL
generateSQL()
Definition: ezurlaliasquery.php:200
eZURLAliasQuery\fetchAll
fetchAll()
Definition: ezurlaliasquery.php:173
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.