diff options
author | Bharat Mediratta <bharat@menalto.com> | 2008-12-17 22:39:33 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2008-12-17 22:39:33 +0000 |
commit | b37047ff557c88becd662bd6622bf27f7a9a78f2 (patch) | |
tree | bf1fb40207030d4f92afa3b510c9504e4769bf52 /modules/tag/models | |
parent | fe396410894f9fcf430e31216312f70db800d96e (diff) |
Add Item_Model::viewable() which we can use to restrict any query to
just items viewable by the active user. Ie:
ORM::factory("item")
->where("name", "foo")
->find_all()
Would get all items with the name "foo".
ORM::factory("item")
->viewable()
->where("name", "foo")
->find_all()
Restricts it to just the set of items that the user is allowed to see.
Diffstat (limited to 'modules/tag/models')
-rw-r--r-- | modules/tag/models/tag.php | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index de892db2..37fd92fb 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -24,14 +24,15 @@ class Tag_Model extends ORM { "name" => "required|length[4,32]"); /** - * Return all items associated with this tag. - * @param string $type the type of item (album, photo) + * Return all viewable 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 + * @param string $type the type of item (album, photo) * @return ORM_Iterator */ public function items($limit=null, $offset=0, $type=null) { $model = ORM::factory("item") + ->viewable() ->join("items_tags", "items.id", "items_tags.item_id") ->where("items_tags.tag_id", $this->id); if ($type) { @@ -39,4 +40,17 @@ class Tag_Model extends ORM { } return $model->find_all($limit, $offset); } + + /** + * Return the count of all viewable items associated with this tag. + * @param string $type the type of item (album, photo) + * @return integer + */ + public function items_count($type=null) { + return ORM::factory("item") + ->viewable() + ->join("items_tags", "items.id", "items_tags.item_id") + ->where("items_tags.tag_id", $this->id) + ->count_all(); + } }
\ No newline at end of file |