From ab20406ef21c1011c2a4b189e8340dc7ee87a813 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sun, 23 Nov 2008 18:00:44 +0000 Subject: Tag module database definitions --- core/models/item.php | 7 +++++++ modules/tag/helpers/tag_installer.php | 17 +++++++++++++++++ modules/tag/models/tag.php | 25 +++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 modules/tag/models/tag.php diff --git a/core/models/item.php b/core/models/item.php index 4481a3a9..ba759c2b 100644 --- a/core/models/item.php +++ b/core/models/item.php @@ -21,6 +21,13 @@ class Item_Model extends ORM_MPTT { protected $children = 'items'; protected $has_one = array("owner" => "user"); + function __construct($id=null) { + parent::__construct($id); + if (!in_array("tags", $this->has_and_belongs_to_many) && module::is_installed("tag")) { + $this->has_and_belongs_to_many[] = "tags"; + } + } + /** * Is this item an album? * @return true if it's an album diff --git a/modules/tag/helpers/tag_installer.php b/modules/tag/helpers/tag_installer.php index 03823ff3..7c10be97 100644 --- a/modules/tag/helpers/tag_installer.php +++ b/modules/tag/helpers/tag_installer.php @@ -20,14 +20,31 @@ class tag_installer { public static function install() { Kohana::log("debug", "tag_installer::install"); + $db = Database::instance(); $version = module::get_version("tags"); Kohana::log("debug", "tag: $version"); if ($version == 0) { + $db->query("CREATE TABLE IF NOT EXISTS `tags` ( + `id` int(9) NOT NULL auto_increment, + `tag_text` varchar(255) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY(`display_name`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + + $db->query("CREATE TABLE IF NOT EXISTS `items_tags` ( + `item_id` int(9) NOT NULL, + `tag_id` int(9) NOT NULL, + PRIMARY KEY (`item_id`, `tag_id`), + UNIQUE KEY(`tag_id`, `item_id`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); module::set_version("tag", 1); } } public static function uninstall() { + $db = Database::instance(); + $db->query("DROP TABLE IF EXISTS `tags`;"); + $db->query("DROP TABLE IF EXISTS `items_tags`;"); module::delete("tag"); } } diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php new file mode 100644 index 00000000..0bf85843 --- /dev/null +++ b/modules/tag/models/tag.php @@ -0,0 +1,25 @@ + "required|length[4,32]"); +} \ No newline at end of file -- cgit v1.2.3