Retrieve albums separately from other items

RwD
RwD's picture

Joined: 2005-01-09
Posts: 383
Posted: Thu, 2005-09-15 20:45

I am showing albums separately from the other items in my yet to be finished theme. But suddenly I remembered there is a page maximum on how many items that are displayed (columns * rows = nr of items displayed). And even though I first show all albums and then completely separately show items in a differen section on the page. But the total number of items displayed is never more then the 9 items that come from the (default) 3 colums * 3 rows set.

Trying to look at the code I was wondering how I could then first retrieve all albums disregarding any maximum set and afterwards retrieve all items. So I could for example have 5 albums and 9 non-album-items (if 3*3 set). (So from galleries pov I retrieved 14 items). But the piece of code that returns the items doesn't allow me to do what I want or doesn't want to do it very efectively:

/**
 * Load commonly used data into theme template
 * Always loaded:
 *   item        item data
 *   children    array of child item data
 * Available keys to include in $dataToLoad parameter:
 *   owner = item owner data
 *      ^if childIds non-empty also fill ownerMap with array of ownerId => owner data
 *   viewCount = number of views for item
 *      ^if childIds non-empty also set viewCount on each child item
 *   childCount = number of children for item
 *      ^if childIds non-empty also set childCount on each child item that canContainChildren
 *   descendentCount = number of descendents for item
 *      ^if childIds non-empty also set descendentCount on each child that canContainChildren
 *   parents = array of ancestor data; also set parent key (direct parent data)
 *   systemLinks = array of array('text'=>.., 'params'=>.., 'moduleId'=>..)
 *   itemLinks = array of id => array('text'=>.., 'params'=>.., 'moduleId'=>..)
 *      ^if childIds non-empty also set itemLinks on each child item
 *   childItemLinksDetailed = boolean.  true if you want detailed item links for children.
 *                            you always get detailed item links for the current item
 *   itemSummaries = set itemSummaries (array of moduleId => html) on each child item
 *   thumbnails = if childIds non-empty then set thumbnail on each child item
 *   pageNavigator = calculate urls for first/back/next/last links for album page navigation
 *   itemNavigator = calculate urls for first/back/next/last links for photo navigation
 *   navThumbnails = load the thumbnails for itemNavigator items
 *   jumpRange = calculate page urls for inter-album navigation (eg, "page: 1, 2 .. 7, 8")
 *       Include 'pageWindowSize'=># in $params to override default of 6
 *   imageViews = loads entity data for resizes and source images, suitable for display
 *                when viewing a single image:
 *                'imageViews' => derivatives,
 *                'sourceImage' => data item,
 *                   ^ contains 'viewInline' boolean, specifying if it can be displayed inline
 *                   ^ contains 'itemTypeName' string, the type of item
 *                   ^ contains 'isSource' member
 *                'imageViewsIndex' => index to the resize currently displayed
 *                'sourceImageViewIndex' => index to the source currently displayed
 *                'fullSizeDimensions' => a string with dimensions of the orig. (eg, "640x480")
 *   permissions array of item permissions, respecting the guest mode flag.
 *               Periods in permissions have been converted to underscores
 *               to make them more Smarty friendly, so if you want to check
 *               a permission in smarty you'd do:
 *                   {if isset($theme.permissions.core_addDataItem)}
 *
 * @param object GalleryItem the item to display
 * @param array theme parameters
 * @param array (string data key, ..) data to load into template
 * @param array (optional) ids of child items to display
 * @return object GalleryStatus a status code
 * @access public
 * @static
 */
function loadCommonTemplateData(&$template, $item, $params, $dataToLoad,
				    $childIds=array())

In these comments it nowhere states I can retrieve only albums or only items in a certain way almost forcing me to simply retrieve EVERYTHING.

I do not think gallery is actually very well capable of doing what I want or is that my imagination :P

In any case; can someone give me a few hints here?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-09-15 21:19

so what exactly do you want? yes you want only albums. but where, for what?

 
RwD
RwD's picture

Joined: 2005-01-09
Posts: 383
Posted: Thu, 2005-09-15 21:32

I want to get:
- All subalbums (direct children, no sub-subalbums)
- Items paged per 9 (where 9 is the setting made in the admin part)

For the items it doesn't matter how many albums where retrieved, the maximum total item count should reflect the columns*rows setting

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-09-15 22:41

$theme.children (in tpl files) / $theme['children'] (in theme.inc) contains all direct children of the album.
if you want a list of only subalbums, you could do

in theme.inc in showAlbumPage():

$theme['subalbums'] = array();
foreach ($theme['children'] as $child) {
    if (isset($child['canContainChildren'] && $child['canContainChildren']) {
        $theme['subalbums'][] = $child;
    }
}
}

then you have this list available in your templates.

alternatively, you could do the same loop in the template file, just with smarty instead of with php.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-09-15 22:44

9 items per page?
are you creating your own theme?
you can either define how many cols / rows and GalleryTheme will return cols*rows children or you can define the pagesize.
see matrix theme vs. hybdrid. i guess hybrid uses not cols / rows but pagesize.

 
RwD
RwD's picture

Joined: 2005-01-09
Posts: 383
Posted: Fri, 2005-09-16 05:03

$theme['children'] Only contains the children of the current page, so if you have 12 subitems of which nr 11 & 12 are albums then they are not in $theme['children'] when you are on page one.

I will take a look at the differene between hybrid and matrix.

Also I just figured out that I am already retrieving a sub-subalbum list exactly like the classic theme is doing. So I do have the code available about how to get subalbums of an item. I think I will be able to adapt it to get both albums and items! The code will be available with the theme, but I might post it here as well...

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-09-16 08:38

i see. yes makes sense to use the classic theme.inc code.

 
RwD
RwD's picture

Joined: 2005-01-09
Posts: 383
Posted: Fri, 2005-09-16 08:41

btw, it is not hybrid but siriux that defines a nr-of-items rather then columns*rows

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-09-16 09:53

lol, sorry for the misinformation. thanks.

 
RwD
RwD's picture

Joined: 2005-01-09
Posts: 383
Posted: Fri, 2005-09-16 17:26

Might anybody be interested in this; I found the functions that will get dataitems and albumitems seperately.

fetchChildAlbumItemIds
fetchChildDataItemIds

Ok, they only get the ids, but from there it is a tiny step to all the info :)
The only stupid thing is that I will have to include the paging code from the gallery core and that I cannot stop the gallery code from getting child ids before the showAlbumPage code gets to work. (That means extra queries for data I will discard)

Can any of the last two problems be helped without coding the paging thing again and doing the extra queries for getting the item ids I will throw away anyway as soon as showAlbumPage is called???

 
RwD
RwD's picture

Joined: 2005-01-09
Posts: 383
Posted: Sun, 2005-09-18 13:38

I've finally done it. Was a little bit more frustrating to build then I expected. For future reference; the loadCommonTemplateData function doesn't add any children if the $theme['children'] array already is set. (That was the part that made me do two days* of puzzling to figure out why copying and modifying the code didn't produce the expected result). You will figure out what I mean if you try modifying something in the themes yourself if you don't know it know.

edit:
*two quarter days actually :P

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Sun, 2005-09-18 13:53

yep, documention would certainly have saved you a few hours :(

 
RwD
RwD's picture

Joined: 2005-01-09
Posts: 383
Posted: Sun, 2005-09-18 17:29

haha, if I'd not have assumed a lot of things instead of actually checking them it would have saved me some time as well ;)