diff options
| author | Nathan Kinkade <nath@nkinka.de> | 2012-09-28 21:33:27 +0000 |
|---|---|---|
| committer | Nathan Kinkade <nath@nkinka.de> | 2012-09-28 21:33:27 +0000 |
| commit | f49fe0389c2f9d65fd66a59a66bd9afde6d779c9 (patch) | |
| tree | 5f601499411b2e3a05abc8dcddf1d8578b09f6b0 | |
| parent | 2f9824f239410088ef3436f8eaf98cfaf914210f (diff) | |
Added ability for a user to filter random image by album.
| -rw-r--r-- | helpers/randimg.php | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/helpers/randimg.php b/helpers/randimg.php index af56564..ba15f66 100644 --- a/helpers/randimg.php +++ b/helpers/randimg.php @@ -19,9 +19,33 @@ class randimg_Core { static function randimg_link() { + // Accept an "album" query parameter to allow the random image to be + // limited to a specific album name. + $album_id = null; + if ( $album_name = Input::instance()->get("album") ) { + if ( $album_item = ORM::factory("item") + ->where("name", "=", $album_name) + ->viewable() + ->find() ) + { + $album_id = $album_item->id; + } + } + $attempts=0; do { - $item = item::random_query()->where("type", "!=", "album")->find_all(1)->current(); + if ( $album_id ) { + $item = item::random_query() + ->where("type", "!=", "album") + ->where("parent_id", "=", $album_id) + ->find_all(1) + ->current(); + } else { + $item = item::random_query() + ->where("type", "!=", "album") + ->find_all(1) + ->current(); + } } while ( !$item && $attempts++ < 5 ); $randimg = new View("randimg.html"); |
