summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/gallery/controllers/albums.php5
-rw-r--r--modules/gallery/controllers/movies.php3
-rw-r--r--modules/gallery/controllers/photos.php3
-rw-r--r--modules/gallery/models/item.php10
4 files changed, 13 insertions, 8 deletions
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;
}
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index fc5c3ff9..d4df0a78 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -1078,6 +1078,16 @@ class Item_Model_Core extends ORM_MPTT {
return $data;
}
+ /**
+ * Increments the view counter of this item
+ * 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.
+ */
+ public function increment_view_count() {
+ db::query("UPDATE {items} SET `view_count` = `view_count` + 1 WHERE `id` = $this->id")
+ ->execute();
+ }
+
private function _cache_buster($path) {
return "?m=" . (string)(file_exists($path) ? filemtime($path) : 0);
}