From d0630c42404402354bef5350bbe4ec320637a865 Mon Sep 17 00:00:00 2001 From: pzinovkin Date: Sun, 14 Mar 2010 12:12:17 +0000 Subject: [PATCH] ViewAction functional merged to Action, Model::inset now returns last insert id if returned or affected rows count, #16 git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@125 4cb57b5f-5bbd-dd11-951b-001d605cbbc5 --- app/Action.php | 22 ++++++++++++++++++++ app/ErrorAction.php | 2 +- app/PagerAction.php | 18 +---------------- app/{StaticViewAction.php => StaticAction.php} | 2 +- app/ViewAction.php | 28 +------------------------- cache/MemcacheCache.php | 2 +- layout/Layout.php | 4 ++-- model/Model.php | 4 ++-- view/PHPView.php | 2 +- 9 files changed, 32 insertions(+), 52 deletions(-) rename app/{StaticViewAction.php => StaticAction.php} (90%) diff --git a/app/Action.php b/app/Action.php index 457f9bf..dc56f40 100644 --- a/app/Action.php +++ b/app/Action.php @@ -12,8 +12,16 @@ abstract class Action { + protected $template; + + /** + * @var PHPView + */ + protected $view; + public function __construct() { + $this->view = FrontController::getInstance()->getView(); $this->extractParams(); $this->execute(); } @@ -45,4 +53,18 @@ abstract class Action header('Location: ' . $url); exit(); } + + protected function getTemplate() + { + $class = get_class($this); + $template = ($this->template) ? $this->template : substr($class, 0, -6/*strlen('Action')*/); + $dir = array_slice(explode('/', Load::getFilePath($class)), -2, 1); + return '/actions/' . array_pop($dir) . '/' . $template; + } + + public function fetch() + { + $this->view->assignObject($this); + return $this->view->fetch($this->getTemplate()); + } } \ No newline at end of file diff --git a/app/ErrorAction.php b/app/ErrorAction.php index d71d8f9..cf79500 100644 --- a/app/ErrorAction.php +++ b/app/ErrorAction.php @@ -9,7 +9,7 @@ * @filesource $URL$ */ -class ErrorAction extends ViewAction +class ErrorAction extends Action { /** diff --git a/app/PagerAction.php b/app/PagerAction.php index 44bf076..a632dc7 100644 --- a/app/PagerAction.php +++ b/app/PagerAction.php @@ -9,13 +9,10 @@ * @filesource $URL$ */ -class PagerAction extends ViewAction +class PagerAction extends Action { public $page; public $last_page; - - //protected $num_rows; - protected $offset = 0; protected $count = 0; protected $limit; @@ -33,7 +30,6 @@ class PagerAction extends ViewAction $this->last_page = ceil($this->count/$this->limit); $this->page = ($page <= $this->last_page && $page > 0) ? $page : 1; $this->offset = $this->limit * ($this->page - 1); - //$this->num_rows = ($this->limit + $this->offset) <= $this->count ? ($this->limit + $this->offset) : $this->count; } public function getOffset() @@ -51,16 +47,4 @@ class PagerAction extends ViewAction $template = ($this->template) ? $this->template : substr(get_class($this), 0, -6/*strlen('Action')*/); return '/actions/' . $template; } - - -/* public function setNumRows($num_rows) - { - $this->num_rows = $num_rows; - } -*/ - /*function prepare() - { - $this->templater->assign('page', $this->page); - $this->templater->assign('page_max', $this->max_page_num); - }*/ } \ No newline at end of file diff --git a/app/StaticViewAction.php b/app/StaticAction.php similarity index 90% rename from app/StaticViewAction.php rename to app/StaticAction.php index 768f1cd..ec858be 100644 --- a/app/StaticViewAction.php +++ b/app/StaticAction.php @@ -9,7 +9,7 @@ * @filesource $URL$ */ -abstract class StaticViewAction extends ViewAction +abstract class StaticAction extends Action { protected function getTemplate() diff --git a/app/ViewAction.php b/app/ViewAction.php index a86c0a2..cb23ea5 100644 --- a/app/ViewAction.php +++ b/app/ViewAction.php @@ -9,33 +9,7 @@ * @filesource $URL$ */ -abstract class ViewAction extends Action +abstract class Action extends Action { - protected $template; - - /** - * @var PHPView - */ - protected $view; - - public function __construct() - { - $this->view = FrontController::getInstance()->getView(); - parent::__construct(); - } - - protected function getTemplate() - { - $class = get_class($this); - $template = ($this->template) ? $this->template : substr($class, 0, -6/*strlen('Action')*/); - $dir = array_slice(explode('/', Load::getFilePath($class)), -2, 1); - return '/actions/' . array_pop($dir) . '/' . $template; - } - - public function fetch() - { - $this->view->assignObject($this); - return $this->view->fetch($this->getTemplate()); - } } \ No newline at end of file diff --git a/cache/MemcacheCache.php b/cache/MemcacheCache.php index 8daabf2..7caa6e7 100644 --- a/cache/MemcacheCache.php +++ b/cache/MemcacheCache.php @@ -82,7 +82,7 @@ class MemcacheCache extends Cache */ public function del($key) { - return $this->connection->delete($this->getKey($key)); + return $this->connection->delete($this->getKey($key), 0); } /** diff --git a/layout/Layout.php b/layout/Layout.php index 3d291d8..03952f2 100644 --- a/layout/Layout.php +++ b/layout/Layout.php @@ -26,7 +26,7 @@ abstract class Layout /** * @param string $name - * @param ViewAction $action + * @param Action $action */ protected function assign($name, $action) { @@ -36,7 +36,7 @@ abstract class Layout abstract protected function execute(); /** - * @param ViewAction $action + * @param Action $action */ public function fetch($action) { diff --git a/model/Model.php b/model/Model.php index 7be95a8..49e7de4 100644 --- a/model/Model.php +++ b/model/Model.php @@ -97,10 +97,10 @@ abstract class Model implements iCacheable */ public function insert($data, $on_duplicate = array()) { - if (!$res = $this->db->insert($this->table(false), $data, $on_duplicate)) { + if (!$affected = $this->db->insert($this->table(false), $data, $on_duplicate)) { return false; } - return ($on_duplicate) ? $res : $this->getInsertId(); + return ($this->getInsertId()) ? $this->getInsertId() : $affected; } /** diff --git a/view/PHPView.php b/view/PHPView.php index 815c5ff..32c3634 100644 --- a/view/PHPView.php +++ b/view/PHPView.php @@ -40,7 +40,7 @@ class PHPView implements iView } /** - * @param ViewAction $object + * @param Action $object */ public function assignObject($object) {