- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
//из Model_Menu:
public $hierarchy = array(Model_Menu::AUTHOR, Model_Menu::YEAR, Model_Menu::GENRE);
public function get()
{
try {
return
DB::query(Database::SELECT,
'SELECT alias AS '.Model_Menu::ALIAS.',head AS '.Model_Menu::HEAD.',SUBSTRING(body,1,
128) AS '.Model_Menu::LINE.',
'.Model_Menu::AUTHOR.',
YEAR(date) AS '.Model_Menu::YEAR.',genre AS '.Model_Menu::GENRE.' FROM creations ORDER BY ' .
implode(',', $this->hierarchy) . ','.Model_Menu::ALIAS)->execute()->as_array();
} catch (Exception $e) {
return false;
}
}
// views/menu.php:
<?php
$menu = Model::factory('menu');
$hierarchy = $menu->hierarchy;
$size = sizeof($hierarchy);
$currentrow = $menu->creation();
$xml = new MarkupBuilder();
$last = array();
$anchor = -1;
$current = -1;
$num = 0;
$xml->tag('ul');
$rows = $menu->get();
foreach ($rows as $row) {
$num++;
$active=($row[Model_Menu::ALIAS] == $currentrow);
while (true) {
if ($current == $anchor) {
$pass = true;
for ($i = 0; $i < $size; $i++) {
if (empty($last[$i]) || $last[$i] != $row[$hierarchy[$i]]) {
$last[$i] = $row[$hierarchy[$i]];
$anchor = $i;
$pass = false;
for ($i = $anchor + 1; $i < sizeof($last); $i++) {
unset($last[$i]);
}
$anchor--;
break;
}
}
if ($pass) {
$anchor = $size;
}
}
if ($current < $anchor) {
$current++;
if ($current < $size) {
$xml->tag('li');
$xml->tag('span');
$xml->text($row[$hierarchy[$current]]);
$xml->end();
$xml->tag('ul',$active?array('class'=>'active'):array());
}
} elseif ($current > $anchor) {
if ($current < $size) {
$xml->end();
$xml->end();
}
$current--;
}
elseif ($current == $anchor) {
if ($current == $size) {
$tooltip = $menu->tooltip($row);
$xml->tag('li', array(
'class' => 'item' . ($active ? 'highlight' : ''),
'title' => $tooltip
));
$xml->tag('a', array(
'href' => (URL::base() . Route::get('creation')->uri(array('creation' => $row[Model_Menu::ALIAS])
)),
'class' => ($active ? 'highlight' : '')
));
$xml->text($row[Model_Menu::HEAD]);
$xml->end();
$xml->end();
break;
}
}
}
}
$xml->end();
while ($current > -1) {
$xml->end();
$current--;
}
echo $xml->asXML();
?>
смысл данного ужаса в том, чтобы выбрать из таблицы данные (все в строковом формате) и вывести как меню UL\LI с иерархией, указанной в $hierarchy.
guest 06.07.2012 11:32 # 0
Lure Of Chaos 06.07.2012 13:44 # 0
guest 06.07.2012 23:39 # 0
$xml->end();
Это для чего так?
guest 14.05.2013 13:13 # 0
catch (Exception $e) {
return false;
}
Lure Of Chaos 14.05.2013 13:14 # 0