This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "quickfw".
The branch, master has been updated
via 28954c12d93a7c8d03e14ca0646f6ebbe6f61e02 (commit)
from f73a62133f91945a849f5b616075bb6bbf91941f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 28954c12d93a7c8d03e14ca0646f6ebbe6f61e02
Author: Ivan Borzenkov <iva...@li...>
Date: Mon May 24 22:53:59 2010 +0400
В скафолдинг добавлена сортировка
diff --git a/lib/Modules/Scafold/ScafoldController.php b/lib/Modules/Scafold/ScafoldController.php
index 8a66a8f..65b3259 100644
--- a/lib/Modules/Scafold/ScafoldController.php
+++ b/lib/Modules/Scafold/ScafoldController.php
@@ -42,7 +42,7 @@ abstract class ScafoldController extends Controller
private $methods;
/** @var boolean Флаг окончания настройки */
private $setup = false;
- /** @var array Порядок сортировки */
+ /** @var array Порядок столбцев */
private $order = array();
/**
@@ -169,10 +169,11 @@ abstract class ScafoldController extends Controller
$foreign = $this->getForeign();
$data = QFW::$db->select('SELECT ?# ?s FROM ?# ?s
- WHERE ?s ?s '.$this->where.' LIMIT ?d, ?d',
+ WHERE ?s ?s '.$this->where.' ?s LIMIT ?d, ?d',
array($this->table=>array_merge($this->order, array('*'))),
$foreign['field'], $this->table, $foreign['join'],
$filter['where'], $parentWhere,
+ $this->getSort(),
$page*$this->pageSize, $this->pageSize);
if (count($filter['form']))
@@ -329,6 +330,33 @@ abstract class ScafoldController extends Controller
QFW::$router->redirect('/'.$this->ControllerUrl.'/index', true);
}
+ /**
+ * Устанавливает порядок сортировки
+ *
+ * @param string $field Имя поля
+ */
+ public function sortAction($field='')
+ {
+ $this->session();
+ //такого поля нету
+ if (!isset($this->fields[$field]))
+ QFW::$router->redirect('/'.$this->ControllerUrl.'/index', true);
+ if (isset($_SESSION['scafold'][$this->table]['sort']) &&
+ $_SESSION['scafold'][$this->table]['sort']['field'] == $field)
+ $r = array(
+ 'field' => $field,
+ 'direction' => $_SESSION['scafold'][$this->table]['sort']['direction'] == 'ASC' ?
+ 'DESC' : 'ASC',
+ );
+ else
+ $r = array(
+ 'field' => $field,
+ 'direction' => 'ASC',
+ );
+ $_SESSION['scafold'][$this->table]['sort'] = $r;
+ QFW::$router->redirect('/'.$this->ControllerUrl.'/index', true);
+ }
+
////////////////////////////////////////////////////////////
//Функции для упращения настройки таблицы - удобные сеттеры
////////////////////////////////////////////////////////////
@@ -560,6 +588,21 @@ abstract class ScafoldController extends Controller
}
/**
+ * Генерирует сортировку
+ *
+ * @return DbSimple_SubQuery Подзапрос сортировки
+ */
+ private function getSort()
+ {
+ if (!isset($_SESSION['scafold'][$this->table]['sort']))
+ return DBSIMPLE_SKIP;
+ $order = $_SESSION['scafold'][$this->table]['sort'];
+ QFW::$view->assign('order', $order);
+ return QFW::$db->subquery('order by ?# '.$order['direction'],
+ array($this->table => $order['field']));
+ }
+
+ /**
* Получает части запроса для связанных полей
*
* @return array два объекта subQuery - список полей и список join
diff --git a/lib/Modules/Scafold/scafold/index.html b/lib/Modules/Scafold/scafold/index.html
index e857452..5f4ede6 100644
--- a/lib/Modules/Scafold/scafold/index.html
+++ b/lib/Modules/Scafold/scafold/index.html
@@ -14,7 +14,10 @@
if ($i->hide)
continue;
?>
- <th><?php echo $i->title ?></th>
+ <th><a href="<?php echo $P->siteUrl($info['ControllerUrl'].
+ '/sort/'.$key) ?>"><?php echo $i->title ?></a>
+ <span class="scafoldSort"><span><?php if (isset($order) && $order['field'] == $key)
+ echo $order['direction']=='ASC' ? 'А->Я' : 'Я->А' ?></span></span></th>
<?php } ?>
<th><a href="<?php echo $P->siteUrl($info['ControllerUrl'].
'/edit/-1') ?>">доб.</a></th>
diff --git a/www/css/buildin/scafold.css b/www/css/buildin/scafold.css
index c1d5f56..5a9c5e7 100644
--- a/www/css/buildin/scafold.css
+++ b/www/css/buildin/scafold.css
@@ -26,6 +26,15 @@ table.scafoldTable
.scafoldTable table.tnone {border: 1px solid black;}
.scafoldTable table.tnone td {background-color:#FFF; border: none; padding: 0; margin: 0;}
+.scafoldTable .scafoldSort {
+ position: relative;
+}
+
+.scafoldTable .scafoldSort span {
+ position: absolute;
+ white-space: nowrap;
+}
+
form.scafoldEdit .err {color: red;}
form.scafoldEdit textarea:focus, input:focus, select:focus {
-----------------------------------------------------------------------
Summary of changes:
lib/Modules/Scafold/ScafoldController.php | 47 +++++++++++++++++++++++++++-
lib/Modules/Scafold/scafold/index.html | 5 ++-
www/css/buildin/scafold.css | 9 +++++
3 files changed, 58 insertions(+), 3 deletions(-)
hooks/post-receive
--
quickfw
|