From b613daa27ba76ca695121cff7f527330ce9b56f0 Mon Sep 17 00:00:00 2001 From: rWatcher Date: Wed, 9 Nov 2011 17:58:43 -0500 Subject: [PATCH] Make $children behave more like Gallery's $children variable. Fixes issue with Custom Fields module. --- .../tag_albums/controllers/tag_albums.php | 17 ++++--- .../libraries/Tag_Albums_Children.php | 48 +++++++++++++++++++ .../tag_albums/controllers/tag_albums.php | 17 ++++--- .../libraries/Tag_Albums_Children.php | 48 +++++++++++++++++++ 4 files changed, 116 insertions(+), 14 deletions(-) create mode 100644 3.0/modules/tag_albums/libraries/Tag_Albums_Children.php create mode 100644 3.1/modules/tag_albums/libraries/Tag_Albums_Children.php diff --git a/3.0/modules/tag_albums/controllers/tag_albums.php b/3.0/modules/tag_albums/controllers/tag_albums.php index b351d2f6..c234a1c5 100644 --- a/3.0/modules/tag_albums/controllers/tag_albums.php +++ b/3.0/modules/tag_albums/controllers/tag_albums.php @@ -102,7 +102,7 @@ class tag_albums_Controller extends Controller { // Figure out which items to display on this page and store their details in $children. $tag_children = $this->_get_records($tag_ids, $page_size, $offset, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, true); - $children = Array(); + $children_array = Array(); foreach ($tag_children as $one_child) { $child_tag = new Tag_Albums_Item($one_child->title, url::site("tag_albums/show/" . $one_child->id . "/0/" . $id . "/" . urlencode($one_child->name)), $one_child->type, $one_child->id); $child_tag->id = $one_child->id; @@ -111,8 +111,9 @@ class tag_albums_Controller extends Controller { if ($one_child->has_thumb()) { $child_tag->set_thumb($one_child->thumb_url(), $one_child->thumb_width, $one_child->thumb_height); } - $children[] = $child_tag; + $children_array[] = $child_tag; } + $children = new Tag_Albums_Children($children_array); // Set up the previous and next page buttons. if ($page > 1) { @@ -318,7 +319,7 @@ class tag_albums_Controller extends Controller { // Generate an arry of "fake" items, one for each tag on the page. // Grab thumbnails from the most recently uploaded item for each tag, if available. - $children = Array(); + $children_array = Array(); foreach ($display_tags as $one_tag) { $tag_item = ORM::factory("item") ->viewable() @@ -332,8 +333,9 @@ class tag_albums_Controller extends Controller { $child_tag->set_thumb($tag_item[0]->thumb_url(), $tag_item[0]->thumb_width, $tag_item[0]->thumb_height); } } - $children[] = $child_tag; + $children_array[] = $child_tag; } + $children = new Tag_Albums_Children($children_array); // Set up breadcrumbs. $tag_album_breadcrumbs = Array(); @@ -441,7 +443,7 @@ class tag_albums_Controller extends Controller { $tag_children = $this->_get_records(Array($id), $page_size, $offset, "items." . $sort_page_field, $sort_page_direction, "OR", true); // Create an array of "fake" items to display on the page. - $children = Array(); + $children_array = Array(); foreach ($tag_children as $one_child) { $child_tag = new Tag_Albums_Item($one_child->title, url::site("tag_albums/show/" . $one_child->id . "/" . $id . "/" . $album_id . "/" . urlencode($one_child->name)), $one_child->type, $one_child->id); $child_tag->id = $one_child->id; @@ -450,9 +452,10 @@ class tag_albums_Controller extends Controller { if ($one_child->has_thumb()) { $child_tag->set_thumb($one_child->thumb_url(), $one_child->thumb_width, $one_child->thumb_height); } - $children[] = $child_tag; + $children_array[] = $child_tag; } - + $children = new Tag_Albums_Children($children_array); + // Set up the previous and next page buttons. if ($page > 1) { $previous_page = $page - 1; diff --git a/3.0/modules/tag_albums/libraries/Tag_Albums_Children.php b/3.0/modules/tag_albums/libraries/Tag_Albums_Children.php new file mode 100644 index 00000000..c6ea859d --- /dev/null +++ b/3.0/modules/tag_albums/libraries/Tag_Albums_Children.php @@ -0,0 +1,48 @@ +position = 0; + $this->array = $children; + } + + function rewind() { + $this->position = 0; + } + + function current() { + return $this->array[$this->position]; + } + + function key() { + return $this->position; + } + + function next() { + ++$this->position; + } + + function valid() { + return isset($this->array[$this->position]); + } +} diff --git a/3.1/modules/tag_albums/controllers/tag_albums.php b/3.1/modules/tag_albums/controllers/tag_albums.php index b351d2f6..c234a1c5 100644 --- a/3.1/modules/tag_albums/controllers/tag_albums.php +++ b/3.1/modules/tag_albums/controllers/tag_albums.php @@ -102,7 +102,7 @@ class tag_albums_Controller extends Controller { // Figure out which items to display on this page and store their details in $children. $tag_children = $this->_get_records($tag_ids, $page_size, $offset, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, true); - $children = Array(); + $children_array = Array(); foreach ($tag_children as $one_child) { $child_tag = new Tag_Albums_Item($one_child->title, url::site("tag_albums/show/" . $one_child->id . "/0/" . $id . "/" . urlencode($one_child->name)), $one_child->type, $one_child->id); $child_tag->id = $one_child->id; @@ -111,8 +111,9 @@ class tag_albums_Controller extends Controller { if ($one_child->has_thumb()) { $child_tag->set_thumb($one_child->thumb_url(), $one_child->thumb_width, $one_child->thumb_height); } - $children[] = $child_tag; + $children_array[] = $child_tag; } + $children = new Tag_Albums_Children($children_array); // Set up the previous and next page buttons. if ($page > 1) { @@ -318,7 +319,7 @@ class tag_albums_Controller extends Controller { // Generate an arry of "fake" items, one for each tag on the page. // Grab thumbnails from the most recently uploaded item for each tag, if available. - $children = Array(); + $children_array = Array(); foreach ($display_tags as $one_tag) { $tag_item = ORM::factory("item") ->viewable() @@ -332,8 +333,9 @@ class tag_albums_Controller extends Controller { $child_tag->set_thumb($tag_item[0]->thumb_url(), $tag_item[0]->thumb_width, $tag_item[0]->thumb_height); } } - $children[] = $child_tag; + $children_array[] = $child_tag; } + $children = new Tag_Albums_Children($children_array); // Set up breadcrumbs. $tag_album_breadcrumbs = Array(); @@ -441,7 +443,7 @@ class tag_albums_Controller extends Controller { $tag_children = $this->_get_records(Array($id), $page_size, $offset, "items." . $sort_page_field, $sort_page_direction, "OR", true); // Create an array of "fake" items to display on the page. - $children = Array(); + $children_array = Array(); foreach ($tag_children as $one_child) { $child_tag = new Tag_Albums_Item($one_child->title, url::site("tag_albums/show/" . $one_child->id . "/" . $id . "/" . $album_id . "/" . urlencode($one_child->name)), $one_child->type, $one_child->id); $child_tag->id = $one_child->id; @@ -450,9 +452,10 @@ class tag_albums_Controller extends Controller { if ($one_child->has_thumb()) { $child_tag->set_thumb($one_child->thumb_url(), $one_child->thumb_width, $one_child->thumb_height); } - $children[] = $child_tag; + $children_array[] = $child_tag; } - + $children = new Tag_Albums_Children($children_array); + // Set up the previous and next page buttons. if ($page > 1) { $previous_page = $page - 1; diff --git a/3.1/modules/tag_albums/libraries/Tag_Albums_Children.php b/3.1/modules/tag_albums/libraries/Tag_Albums_Children.php new file mode 100644 index 00000000..c6ea859d --- /dev/null +++ b/3.1/modules/tag_albums/libraries/Tag_Albums_Children.php @@ -0,0 +1,48 @@ +position = 0; + $this->array = $children; + } + + function rewind() { + $this->position = 0; + } + + function current() { + return $this->array[$this->position]; + } + + function key() { + return $this->position; + } + + function next() { + ++$this->position; + } + + function valid() { + return isset($this->array[$this->position]); + } +}