diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-01-23 08:11:33 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-01-23 08:11:33 +0000 |
commit | 94e356fc31d00acb67b5f62d3e0577bbcefe4cf4 (patch) | |
tree | 40511bbaa53e83a49c6cc9e4acb45e68fb8c6ace | |
parent | cd6629ad23ba9468002d063483e9c49b59e200aa (diff) |
Take advantage of the new support for parentheses added in r19879 and
fix a bug in viewable() that was AND'ing all view permissions together
(which meant that you had to have *all* permissions to view an item,
instead of just one).
Also, add a "max" param to the thumb_tag() so that we can specify a
max dimension for the thumbnail. This will be used in the upcoming
"move item" feature.
-rw-r--r-- | core/models/item.php | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/core/models/item.php b/core/models/item.php index 9444f7ac..5654b36f 100644 --- a/core/models/item.php +++ b/core/models/item.php @@ -39,11 +39,32 @@ class Item_Model extends ORM_MPTT { $this->view_restrictions = array(); } else { foreach (user::group_ids() as $id) { - $this->view_restrictions["view_$id"] = access::ALLOW; + // Separate the first restriction from the rest to make it easier for us to formulate + // our where clause below + if (empty($this->view_restrictions)) { + $this->view_restrictions[0] = "view_$id"; + } else { + $this->view_restrictions[1]["view_$id"] = access::ALLOW; + } } } } - $this->where($this->view_restrictions); + switch (count($this->view_restrictions)) { + case 0: + break; + + case 1: + $this->where($this->view_restrictions); + break; + + default: + $this->open_paren(); + $this->where($this->view_restrictions[0], access::ALLOW); + $this->orwhere($this->view_restrictions[1]); + $this->close_paren(); + break; + } + return $this; } @@ -259,11 +280,22 @@ class Item_Model extends ORM_MPTT { * @param array $extra_attrs Extra attributes to add to the img tag * @return string */ - public function thumb_tag($extra_attrs) { + public function thumb_tag($extra_attrs, $max=null) { + $width = $this->thumb_width; + $height = $this->thumb_height; + if (isset($max)) { + if ($width > $height) { + $height = (int)($max * ($height / $width)); + $width = $max; + } else { + $width = (int)($max * ($width / $height)); + $height = $max; + } + } return html::image(array("src" => $this->thumb_url(), "alt" => $this->title, - "width" => $this->thumb_width, - "height" => $this->thumb_height), + "width" => $width, + "height" => $height), $extra_attrs); } |