1.44 build 178


Please rate DAlbum at HotScripts.com
Please rate DAlbum at @ PHP-Resource.de
Rate DAlbum @ The PHP Resource Index
Script Rating:
Change sorting order   

From time to time it may be useful to change sorting order of images and albums without actually renaming them. With this customization it possible to assign a sorting index to any image or album, and this index will take preference over a filename.

With this customization installed, every album and image will have an extra field "SortOrder" in .albumdef.ini file. This field will also be visible in album properties. Pictures with SortOrder=0 (default) go first, followed by pictures with SortOrder=1, followed by SortOrder=2 and so on.

For example, there are three albums "One", "Two", "Three". By default DAlbum sorts them alphabetically as "One", "Three", "Two". One way of ordering them correctly would be to rename albums as "01-One", "02-Two", "03-Three", but the same result can be achieved by setting:

  • SortOrder=1 for album "Two"
  • SortOrder=2 for album "Three"

Album "One" will have SortOrder empty which means 0.

After reindexing albums will appear in correct order as "One", "Two", "Three".

A working example can be seen in samples where album "LeMassif" was assigned SortOrder=-1 and therefore is listed before other albums.

Instructions

1. Edit you custom.php and subclass CAlbum and CImage classes by adding the following code to the bottom of the file.

 class CSortImage extends CImage
{
    function &
GetCustomFieldNames()
    {
        
$f=parent::GetCustomFieldNames();
        
$f[]="SortOrder";

        return 
$f;
    }
}

class 
CSortAlbum extends CAlbum
{
    function 
cmpAlb2($a$b)
    {
        
$ai=$a->IsImage();
        
$bi=$b->IsImage();

        
// If both are images or both are albums look at "SortOrder"
        
if ( ($ai && $bi) || (!$ai && !$bi))
        {
            
$v1=(int)trim(strval($a->GetCustomField("SortOrder")));
               
$v2=(int)trim(strval($b->GetCustomField("SortOrder")));
               if (
$v1!=$v2)
                return 
$v1-$v2;
        }

        
// No sort order preference. Try names

        // If both are images - compare filenames
        
if ($ai && $bi)
            return 
strcasecmp($a->m_sBaseFilename$b->m_sBaseFilename);

        
// Albums always go before images
        
if ($ai)
            return 
1;
        if (
$bi)
            return -
1;

        
// Both are albums - compare folders
        
return strcasecmp(basename(substr($a->m_sFolder,0,-1)), basename(substr($b->m_sFolder,0,-1)));
    }

    
// Get list of custom field names
    
function &GetCustomFieldNames()
    {
        
$f=parent::GetCustomFieldNames();
        
$f[]="SortOrder";
        return 
$f;
    }

    function 
Sort()
    {
        if (!empty(
$this->m_arrContents))
            
usort($this->m_arrContents,array(get_class($this),"cmpAlb2"));
    }
}


function &
customCreateImage()
{
    return new 
CSortImage();
}

function &
customCreateAlbum()
{
    return new 
CSortAlbum();
}

2. If you already have subclassed any of these classes before, you may need to change CAlbum/CImage strings in the code above with a subclassed name and delete duplicate customCreateImage/customCreateAlbum functions. See bonus pack source code for an example.

3. Reindex. Please note that if you change SortOrder of an album, the changes will apply only after reindex