diff options
author | Bharat Mediratta <bharat@menalto.com> | 2008-12-23 04:14:07 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2008-12-23 04:14:07 +0000 |
commit | 2502240ce4ad25e9fb60ee2468764e25346d2917 (patch) | |
tree | 3dab839d1a15b7cfa75dbbc208aef18ad5613845 /core/models | |
parent | 608d0996698716c488318411e10b880796c58805 (diff) |
Add very simple graphics toolkits.
Track a set of rules in Graphics_Rule_Model which specify how we turn
original images into thumbnails and resizes. There's one set of rules
that applies to every image in the Gallery.
Track the state of thumbs and resizes with a "dirty" bit. The new
graphics helper manages the rules and can rebuild the thumbs and
resizes for any images that are considered "dirty".
Introduce the concept of an "album cover" which is an item that an
album points to. We'll use that item as the source for the album's
thumbnail/resize.
Conflated with this change (sorry!) I also changed the Var table to
use module_name instead of module_id. This may be marginally less
efficient, but it's much easier to follow in the database.
Diffstat (limited to 'core/models')
-rw-r--r-- | core/models/graphics_rule.php | 21 | ||||
-rw-r--r-- | core/models/item.php | 58 | ||||
-rw-r--r-- | core/models/module.php | 1 | ||||
-rw-r--r-- | core/models/var.php | 1 |
4 files changed, 37 insertions, 44 deletions
diff --git a/core/models/graphics_rule.php b/core/models/graphics_rule.php new file mode 100644 index 00000000..1554d2fb --- /dev/null +++ b/core/models/graphics_rule.php @@ -0,0 +1,21 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class Graphics_Rule_Model extends ORM { +} diff --git a/core/models/item.php b/core/models/item.php index d71414d8..cd2e1670 100644 --- a/core/models/item.php +++ b/core/models/item.php @@ -153,48 +153,6 @@ class Item_Model extends ORM_MPTT { } /** - * Build a thumbnail for this item from the image provided with the - * given width and height - * - * @chainable - * @param string $filename the path to an image - * @param integer $width the desired width of the thumb - * @param integer $height the desired height of the thumb - * @return ORM - */ - public function set_thumb($filename, $width, $height) { - Image::factory($filename) - ->resize($width, $height, Image::AUTO) - ->save($this->thumb_path()); - - $dims = getimagesize($this->thumb_path()); - $this->thumb_width = $dims[0]; - $this->thumb_height = $dims[1]; - return $this; - } - - /** - * Build a resize for this item from the image provided with the - * given width and height - * - * @chainable - * @param string $filename the path to an image - * @param integer $width the desired width of the resize - * @param integer $height the desired height of the resize - * @return ORM - */ - public function set_resize($filename, $width, $height) { - Image::factory($filename) - ->resize($width, $height, Image::AUTO) - ->save($this->resize_path()); - - $dims = getimagesize($this->resize_path()); - $this->resize_width = $dims[0]; - $this->resize_height = $dims[1]; - return $this; - } - - /** * Return the relative path to this item's file. * @return string */ @@ -250,4 +208,20 @@ class Item_Model extends ORM_MPTT { } return parent::save(); } + + /** + * Return the Item_Model representing the cover for this album. + * @return Item_Model or null if there's no cover + */ + public function album_cover() { + if ($this->type != "album") { + return null; + } + + if (empty($this->album_cover_item_id)) { + return null; + } + + return model_cache::get("item", $this->album_cover_item_id); + } } diff --git a/core/models/module.php b/core/models/module.php index da9fb0a1..de4cc43d 100644 --- a/core/models/module.php +++ b/core/models/module.php @@ -18,5 +18,4 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Module_Model extends ORM { - protected $has_many = array("vars"); } diff --git a/core/models/var.php b/core/models/var.php index d5aa1849..4d7e5ffd 100644 --- a/core/models/var.php +++ b/core/models/var.php @@ -18,5 +18,4 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Var_Model extends ORM { - protected $belongs_to = array("module"); } |