286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
return $db->simpleStatementFetch(
'SELECT id, revision, uri, titre,
strftime(\'%s\', date_creation) AS date_creation,
strftime(\'%s\', date_modification) AS date_modification
FROM wiki_pages
WHERE parent = ? AND '.$this->_getLectureClause().'
ORDER BY titre LIMIT 500;',
SQLITE3_ASSOC,
(int) $parent
);
}
public function getById($id)
{
|
|
|
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
return $db->simpleStatementFetch(
'SELECT id, revision, uri, titre,
strftime(\'%s\', date_creation) AS date_creation,
strftime(\'%s\', date_modification) AS date_modification
FROM wiki_pages
WHERE parent = ? AND '.$this->_getLectureClause().'
ORDER BY transliterate_to_ascii(titre) COLLATE NOCASE LIMIT 500;',
SQLITE3_ASSOC,
(int) $parent
);
}
public function getById($id)
{
|
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
public function countRecentModifications()
{
$db = Garradin_DB::getInstance();
return $db->simpleQuerySingle('SELECT COUNT(*) FROM wiki_pages WHERE '.$this->_getLectureClause().';');
}
public function listBackParentTree($parent)
{
$db = Garradin_DB::getInstance();
$flat = array((int)$parent);
if ($parent != 0)
{
do
{
$parent = $db->simpleQuerySingle('SELECT parent FROM wiki_pages WHERE id = ? LIMIT 1;', false, (int)$parent);
$flat[] = (int)$parent;
}
while ($parent != 0);
}
foreach ($flat as &$id)
{
$id = array(
'id' => (int)$id,
'children' => $db->simpleStatementFetch('SELECT id, titre
FROM wiki_pages WHERE parent = ? ORDER BY transliterate_to_ascii(titre) COLLATE NOCASE;', SQLITE3_ASSOC, (int)$id),
);
}
$tree = array_reverse($flat);
$tree = $this->_buildBackParentTree($tree);
var_dump($tree);
exit;
return $tree;
}
protected function _buildBackParentTree(&$tree, &$parent = null)
{
foreach ($tree as &$elm)
{
if (empty($elm['id']))
{
$elm['titre'] = 'Racine du site';
}
elseif (!empty($parent['children']))
{
foreach ($parent['children'] as $c)
{
if ($c['id'] == $elm['id'])
$elm['titre'] = $c['titre'];
}
}
if (!empty($elm['children']))
{
$this->_buildBackParentTree($elm['children'], $elm);
}
}
return $tree;
}
}
?>
|
|
|
>
>
>
>
>
>
>
|
|
|
|
|
|
<
|
<
<
<
<
<
|
|
>
>
|
|
>
|
|
<
<
|
<
<
|
<
|
|
<
<
|
|
|
|
|
<
<
>
|
|
<
<
<
|
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
|
public function countRecentModifications()
{
$db = Garradin_DB::getInstance();
return $db->simpleQuerySingle('SELECT COUNT(*) FROM wiki_pages WHERE '.$this->_getLectureClause().';');
}
public function listBackParentTree($id)
{
$db = Garradin_DB::getInstance();
$flat = array(
array(
'id' => 0,
'parent' => null,
'titre' => 'Racine',
'children' => $db->simpleStatementFetchAssocKey('SELECT id, parent, titre FROM wiki_pages
WHERE parent = ? ORDER BY transliterate_to_ascii(titre) COLLATE NOCASE;',
SQLITE3_ASSOC, 0)
)
);
do
{
$parent = $db->simpleQuerySingle('SELECT parent FROM wiki_pages WHERE id = ? LIMIT 1;', false, (int)$id);
$flat[$id] = array(
'id' => $id,
'parent' => $id ? (int)$parent : null,
'titre' => $id ? (string)$db->simpleQuerySingle('SELECT titre FROM wiki_pages WHERE id = ? LIMIT 1;', false, (int)$id) : 'Racine',
'children' => $db->simpleStatementFetchAssocKey('SELECT id, parent, titre FROM wiki_pages
WHERE parent = ? ORDER BY transliterate_to_ascii(titre) COLLATE NOCASE;',
SQLITE3_ASSOC, (int)$id)
);
$id = (int)$parent;
}
while ($id != 0);
$tree = array();
foreach ($flat as $id=>&$node)
{
if (is_null($node['parent']))
{
$tree[$id] = &$node;
}
else
{
if (!isset($flat[$node['parent']]['children']))
{
$flat[$node['parent']]['children'] = array();
}
$flat[$node['parent']]['children'][$id] = &$node;
}
}
return $tree;
}
}
?>
|