diff options
Diffstat (limited to 'modules/tag/models')
| -rw-r--r-- | modules/tag/models/tag.php | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index c038f6d1..53ccc856 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -1,7 +1,7 @@ <?php defined("SYSPATH") or die("No direct script access."); /** * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2010 Bharat Mediratta + * Copyright (C) 2000-2011 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 @@ -20,6 +20,15 @@ class Tag_Model_Core extends ORM { protected $has_and_belongs_to_many = array("items"); + public function __construct($id=null) { + parent::__construct($id); + + if (!$this->loaded()) { + // Set reasonable defaults + $this->count = 0; + } + } + /** * Return all viewable items associated with this tag. * @param integer $limit number of rows to limit result to @@ -69,10 +78,13 @@ class Tag_Model_Core extends ORM { $related_item_ids[$row->item_id] = 1; } - if (isset($this->changed_relations["items"])) { - $changed = array_merge( - array_diff($this->changed_relations["items"], $this->object_relations["items"]), - array_diff($this->object_relations["items"], $this->changed_relations["items"])); + if (isset($this->object_relations["items"])) { + $added = array_diff($this->changed_relations["items"], $this->object_relations["items"]); + $removed = array_diff($this->object_relations["items"], $this->changed_relations["items"]); + if (isset($this->changed_relations["items"])) { + $changed = array_merge($added, $removed); + } + $this->count = count($this->object_relations["items"]) + count($added) - count($removed); } $result = parent::save(); |
