From 336632fea0a955d74099cd169b3178c01f250ff5 Mon Sep 17 00:00:00 2001 From: Joe7 Date: Mon, 3 Jan 2011 13:21:54 +0100 Subject: Keep view counters of all item types accurate Added common increment_view_count() func in item model for reuse --- modules/gallery/controllers/albums.php | 5 +---- modules/gallery/controllers/movies.php | 3 +-- modules/gallery/controllers/photos.php | 3 +-- 3 files changed, 3 insertions(+), 8 deletions(-) (limited to 'modules/gallery/controllers') diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index b0887195..c0368488 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -71,10 +71,7 @@ class Albums_Controller extends Items_Controller { $template->set_global("parents", $album->parents()->as_array()); // view calls empty() on this $template->content = new View("album.html"); - // We can't use math in ORM or the query builder, so do this by hand. It's important - // that we do this with math, otherwise concurrent accesses will damage accuracy. - db::query("UPDATE {items} SET `view_count` = `view_count` + 1 WHERE `id` = $album->id") - ->execute(); + $album->increment_view_count(); print $template; } diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index 717eb8aa..15d4f950 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -49,8 +49,7 @@ class Movies_Controller extends Items_Controller { $template->content = new View("movie.html"); - $movie->view_count++; - $movie->save(); + $movie->increment_view_count(); print $template; } diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index b22ac8e5..2dc22ca4 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -49,8 +49,7 @@ class Photos_Controller extends Items_Controller { $template->content = new View("photo.html"); - $photo->view_count++; - $photo->save(); + $photo->increment_view_count(); print $template; } -- cgit v1.2.3 From cfaa62370ecbdb3badf4ab68bbefa7cfedaea154 Mon Sep 17 00:00:00 2001 From: Joe7 Date: Sun, 2 Jan 2011 18:59:23 +0100 Subject: Reimplemented Kohana 2.3's View::set_global() with array support. Allows for cleaner code and fewer function calls. --- modules/gallery/controllers/albums.php | 17 +++++++++-------- modules/gallery/controllers/movies.php | 17 +++++++++-------- modules/gallery/controllers/photos.php | 17 +++++++++-------- modules/gallery/libraries/MY_View.php | 10 ++++++++-- 4 files changed, 35 insertions(+), 26 deletions(-) (limited to 'modules/gallery/controllers') diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index c0368488..e69f6b6d 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -61,14 +61,15 @@ class Albums_Controller extends Items_Controller { } $template = new Theme_View("page.html", "collection", "album"); - $template->set_global("page", $page); - $template->set_global("page_title", null); - $template->set_global("max_pages", $max_pages); - $template->set_global("page_size", $page_size); - $template->set_global("item", $album); - $template->set_global("children", $album->viewable()->children($page_size, $offset)); - $template->set_global("children_count", $children_count); - $template->set_global("parents", $album->parents()->as_array()); // view calls empty() on this + $template->set_global(array("page" => $page, + "page_title" => null, + "max_pages" => $max_pages, + "page_size" => $page_size, + "item" => $album, + "children" => $album->viewable()->children($page_size, $offset), + "children_count" => $children_count, + "parents" => $album->parents()->as_array())); + // view calls empty() on this $template->content = new View("album.html"); $album->increment_view_count(); diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index 15d4f950..1ae969c7 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -38,14 +38,15 @@ class Movies_Controller extends Items_Controller { } $template = new Theme_View("page.html", "item", "movie"); - $template->set_global("item", $movie); - $template->set_global("children", array()); - $template->set_global("children_count", 0); - $template->set_global("parents", $movie->parents()->as_array()); - $template->set_global("next_item", $next_item); - $template->set_global("previous_item", $previous_item); - $template->set_global("sibling_count", $movie->parent()->viewable()->children_count($where)); - $template->set_global("position", $position); + $template->set_global(array("item" => $movie, + "children" => array(), + "children_count" => 0, + "parents" => $movie->parents()->as_array(), + "next_item" => $next_item, + "previous_item" => $previous_item, + "sibling_count" + => $movie->parent()->viewable()->children_count($where), + "position" => $position)); $template->content = new View("movie.html"); diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index 2dc22ca4..e795f336 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -38,14 +38,15 @@ class Photos_Controller extends Items_Controller { } $template = new Theme_View("page.html", "item", "photo"); - $template->set_global("item", $photo); - $template->set_global("children", array()); - $template->set_global("children_count", 0); - $template->set_global("parents", $photo->parents()->as_array()); - $template->set_global("next_item", $next_item); - $template->set_global("previous_item", $previous_item); - $template->set_global("sibling_count", $photo->parent()->viewable()->children_count($where)); - $template->set_global("position", $position); + $template->set_global(array("item" => $photo, + "children" => array(), + "children_count" => 0, + "parents" => $photo->parents()->as_array(), + "next_item" => $next_item, + "previous_item" => $previous_item, + "sibling_count" + => $photo->parent()->viewable()->children_count($where), + "position" => $position)); $template->content = new View("photo.html"); diff --git a/modules/gallery/libraries/MY_View.php b/modules/gallery/libraries/MY_View.php index ded77792..2230203a 100644 --- a/modules/gallery/libraries/MY_View.php +++ b/modules/gallery/libraries/MY_View.php @@ -23,8 +23,14 @@ class View extends View_Core { /** * Reimplement Kohana 2.3's View::set_global() functionality. */ - public function set_global($key, $value) { - View::$global_data[$key] = $value; + public function set_global($key, $value = NULL) { + if (is_array($key)) { + foreach ($key as $key2 => $value) { + View::$global_data[$key2] = $value; + } + } else { + View::$global_data[$key] = $value; + } } public function is_set($key=null) { -- cgit v1.2.3 From 4a882108259f9542a6c8f2ffe95c9ee0e1c102cd Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 3 Jan 2011 11:41:25 -0800 Subject: Follow on to cfaa62370ecbdb3badf4ab68bbefa7cfedaea154 to fix indentation. Fixes #1569. --- modules/gallery/controllers/albums.php | 18 +++++++++--------- modules/gallery/controllers/movies.php | 18 +++++++++--------- modules/gallery/controllers/photos.php | 18 +++++++++--------- 3 files changed, 27 insertions(+), 27 deletions(-) (limited to 'modules/gallery/controllers') diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index e69f6b6d..25df0da7 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -61,15 +61,15 @@ class Albums_Controller extends Items_Controller { } $template = new Theme_View("page.html", "collection", "album"); - $template->set_global(array("page" => $page, - "page_title" => null, - "max_pages" => $max_pages, - "page_size" => $page_size, - "item" => $album, - "children" => $album->viewable()->children($page_size, $offset), - "children_count" => $children_count, - "parents" => $album->parents()->as_array())); - // view calls empty() on this + $template->set_global( + array("page" => $page, + "page_title" => null, + "max_pages" => $max_pages, + "page_size" => $page_size, + "item" => $album, + "children" => $album->viewable()->children($page_size, $offset), + "parents" => $album->parents()->as_array(), // view calls empty() on this + "children_count" => $children_count)); $template->content = new View("album.html"); $album->increment_view_count(); diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index 1ae969c7..bf50abd5 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -38,15 +38,15 @@ class Movies_Controller extends Items_Controller { } $template = new Theme_View("page.html", "item", "movie"); - $template->set_global(array("item" => $movie, - "children" => array(), - "children_count" => 0, - "parents" => $movie->parents()->as_array(), - "next_item" => $next_item, - "previous_item" => $previous_item, - "sibling_count" - => $movie->parent()->viewable()->children_count($where), - "position" => $position)); + $template->set_global( + array("item" => $movie, + "children" => array(), + "children_count" => 0, + "parents" => $movie->parents()->as_array(), + "next_item" => $next_item, + "previous_item" => $previous_item, + "sibling_count" => $movie->parent()->viewable()->children_count($where), + "position" => $position)); $template->content = new View("movie.html"); diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index e795f336..d500a92e 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -38,15 +38,15 @@ class Photos_Controller extends Items_Controller { } $template = new Theme_View("page.html", "item", "photo"); - $template->set_global(array("item" => $photo, - "children" => array(), - "children_count" => 0, - "parents" => $photo->parents()->as_array(), - "next_item" => $next_item, - "previous_item" => $previous_item, - "sibling_count" - => $photo->parent()->viewable()->children_count($where), - "position" => $position)); + $template->set_global( + array("item" => $photo, + "children" => array(), + "children_count" => 0, + "parents" => $photo->parents()->as_array(), + "next_item" => $next_item, + "previous_item" => $previous_item, + "sibling_count" => $photo->parent()->viewable()->children_count($where), + "position" => $position)); $template->content = new View("photo.html"); -- cgit v1.2.3