Need help modifying album tree module

michaelnyden

Joined: 2012-04-16
Posts: 27
Posted: Wed, 2012-07-25 23:41

How would I modify the album tree module to only (put in the generated list) albums starting with LetterLetterNumber (ie. TK1)
I've tried working with some kind of evaluation, ie. if() statement, etc. But it doesn't seem to work.

<?
function makelist($album,$level){
//print out the list item
?>
<li>
<a href="<?= item::root()->url() ?><?= $album->relative_url() ?>"><?=str_repeat("&nbsp;&nbsp;", $level) ?><?= html::purify($album->title) ?></a>
</li>

<?
//recurse over the children, and print their list items as well
foreach ($album->viewable()->children(null, null, array(array("type", "=", "album"))) as $child){
makelist($child,$level+1);
}
}
makelist($root,0);
?>

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Thu, 2012-07-26 03:57

I'm no regex expert as I bet this is some complex example that I can't find but should be doable with a if statement.
just wrap the if statement around the <li> so it does not display.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
michaelnyden

Joined: 2012-04-16
Posts: 27
Posted: Fri, 2012-07-27 01:47

I got it to work, finally, but now I have to figure out how to sort the ul or li elements alphabetically. Anyone know how to do this?

<ul class="treealbumnav" id="list">
<?
function makelist($album,$level){
//print out the list item
if(ctype_alpha($album->title[0]) && ctype_alpha($album->title[1]) && is_numeric(substr($album->title,2,5))){
?>
<li>
<a href="<?= item::root()->url() ?><?= $album->relative_url() ?>"><?= str_repeat("&nbsp;&nbsp;", $level) ?><?= html::purify($album->title) ?></a>
</li>

<?
}
//recurse over the children, and print their list items as well
foreach ($album->viewable()->children(null, null, array(array("type", "=", "album"))) as $child) {
makelist($child,$level+1);
}
}
makelist($root,0);
?>

</ul>

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Fri, 2012-07-27 05:34

The fourth parameter of the children function is the sort order.
see if changing:
foreach ($album->viewable()->children(null, null, array(array("type", "=", "album"))) as $child) {
to
foreach ($album->viewable()->children(null, null, array(array("type", "=", "album")), array("title", => "DESC")) as $child) {
Not tested so I might have the syntax off a bit.

Dave

_____________________________________________
Blog & G2 || floridave - Gallery Team

 
michaelnyden

Joined: 2012-04-16
Posts: 27
Posted: Fri, 2012-07-27 08:07

It doesn't work, must be the syntax...when I implement it, the album tree disappears from the sidebar completely which means it doesn't like something about the code...but I certainly appreciate the attempt!

 
michaelnyden

Joined: 2012-04-16
Posts: 27
Posted: Mon, 2012-07-30 19:56

Got it to work, just had to take a comma out:
array("title", => "DESC")) had to be array("title => "ASC")) for my uses

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Tue, 2012-07-31 01:04

Great! and thanks for posting back the solution.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
mattdm

Joined: 2005-07-22
Posts: 181
Posted: Tue, 2012-07-31 01:52

I'm not a PHP expert, but I think you're looking for something like:

if (preg_match("/^[:alpha:][:alpha:][:digit:]/", $album->title) {
 /* do your thing here */
}

This is a little cleaner to read than the strung-out version, which obviously works too. (Regular expressions are very powerful and worth taking the time to learn!)

Above, ^ means match at the start of the line, [:alpha:] is the class of all alphabetic characters in all international languages, and [:digits:] is the numbers.

PHP docs here: http://www.php.net/manual/en/book.pcre.php

 
michaelnyden

Joined: 2012-04-16
Posts: 27
Posted: Tue, 2012-09-18 21:01

Now I have another problem...it keeps the list seperate for each album it finds them in. As I said, I am a newbie...would a solution be to recurse over the entire site and save everything as an array, then alphabetize it, then spit that array out into <li>'s?

Please see attached screenshot.

Any ideas or help would be greatly appreciated!

 
undagiga

Joined: 2010-11-26
Posts: 693
Posted: Thu, 2012-09-20 00:31

I have a modified version of Album Tree that recurses over the site and stores it in an array, so that I can manipulate the list of albums before displaying them. (What I do is display a list of the first 60 or so albums, and put the rest in a drop-down selector. This means that the vertical height of the tree is not too great.) But I don't know how to alphabetise the array. I'd have thought that it wouldn't be too hard. Google?

U-G

 
michaelnyden

Joined: 2012-04-16
Posts: 27
Posted: Thu, 2012-09-20 00:37

well I know you can just run a natsort or sort on it and php will sort it for you. can you share this modified album tree?

Thanks,
Michael

 
undagiga

Joined: 2010-11-26
Posts: 693
Posted: Thu, 2012-09-20 08:38

My version attached. No warranties of any kind. It will show just a drop-down selector on resize pages. On thumb pages it will show a list of the first 60 or so albums, and a drop-down for the rest. The number in the list is less on the root page and more on other thumb pages. It's a bit specialised, and so I'm not proposing to put this on the wiki, also because I think it's based on an older version of Album Tree.

U-G

 
michaelnyden

Joined: 2012-04-16
Posts: 27
Posted: Thu, 2012-09-20 16:02

That's fine, I just appreciate that you shared it so I can see the code that you used to put it all into an array and manipulate the output.

 
undagiga

Joined: 2010-11-26
Posts: 693
Posted: Thu, 2012-09-20 22:55

It occurred to me that my version might be of wider interest, since it solves a particular problem if you want to use a list of albums rather than a drop-down selector, and you have a lot of albums. But it would need some work and a clean up, since my PHP is *very* rudimentary, and I'd probably need to add an admin page so that you could specify the mix and list length. I'd only think about it if there was enough interest.