diff options
author | Bharat Mediratta <bharat@menalto.com> | 2008-11-26 21:50:45 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2008-11-26 21:50:45 +0000 |
commit | 974f9f778891bbefeb083b2d97b3dae206c96452 (patch) | |
tree | 721c3c78bddb09c26ec306ae13e4093667961a97 /modules/tag/models | |
parent | 4e8937ccefc95272442a9cd5ccb71aab01f113a1 (diff) |
Add a new "tag" page type.
Create the concept of "page types" which let us specify the kind of
page that we're rendering in high level terms. Currently there are
three page types: album, photo and tag.
The tag page type uses slightly different variables. It has a $tag
but no $item. Adjust all sidebar_block() functions to avoid printing
stuff that's dependent on the item if there is no item.
Simplify the tag code to stop trying to fake an item.
Update the theme slightly to use $item and $tag where appropriate
(notably, for making the <title> element).
Diffstat (limited to 'modules/tag/models')
-rw-r--r-- | modules/tag/models/tag.php | 61 |
1 files changed, 8 insertions, 53 deletions
diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index c0e94f29..59dd8d54 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -20,64 +20,19 @@ class Tag_Model extends ORM { protected $has_and_belongs_to_many = array("items"); - protected $_children = array(); - var $rules = array( "name" => "required|length[4,32]"); /** - * Emulate the album method charactistics so that the tag looks like an album to the framework. - */ - public function __call($function, $args) { - if ($function == "children") { - return $this->_get_tag_children($args[0], $args[1]); - } else if ($function == "children_count") { - return $this->count; - } else if ($function == "parents") { - // Need to return as an ORM_Iterator as opposed to just the model. - return ORM::factory("item") - ->where("id", 1) - ->find_all(); - } else { - return parent::__call($function, $args); - } - } - - /** - * Emulate the album property charactistics so that the tag looks like an album to the framework. - */ - public function __get($property) { - if ($property == "title" || $property == "title_edit" || $property == "name_edit") { - return $this->name; - } else if ($property == "description_edit") { - return "There are {$this->count} items tagged."; - } else if ($property == "owner") { - return null; - } else { - return parent::__get($property); - } - } - - /** - * Get the item children. This code was borrowed from the ORM::__get($column) method and modified - * to allow for the specification of the limit and offset. - * @param int $limit - * @param int $offset + * Return all items associated with this tag. + * @param integer $limit number of rows to limit result to + * @param integer $offset offset in result to start returning rows from * @return ORM_Iterator */ - private function _get_tag_children($limit, $offset) { - // Load the child model - $model = ORM::factory(inflector::singular("items")); - - // Load JOIN info - $join_table = $model->join_table($this->table_name); - $join_col1 = $model->foreign_key(NULL, $join_table); - $join_col2 = $model->foreign_key(TRUE); - - // one<>alias:many relationship - return $model - ->join($join_table, $join_col1, $join_col2) - ->where($this->foreign_key(NULL, $join_table), $this->object[$this->primary_key]) + public function items($limit=null, $offset=0) { + return ORM::factory("item") + ->join("items_tags", "items.id", "items_tags.item_id") + ->where("items_tags.tag_id", $this->id) ->find_all($limit, $offset); - } + } }
\ No newline at end of file |