Reference Manuals

Album

Album — An album object that can contain one or more Photo objects.

Album is part of the Gallery package.

Synopsis

class Album implements Iterator (internal interface) {
        private        array               $attrs
        private        bool                $attrs_dirty
        public         Gallery             $gallery
        private        array               $photos
        private        array               $photo_ids
        private        array               $photo_slice
        private        int                 $photo_slice_length
        private        int                 $photo_slice_offset

        private        Album               __construct               ( Gallery &$gallery,
                                                                       array $album );
        public         mixed               add_photo                 ( string $file );
        public         mixed               current                   ( void );
        public         void                delete_all_photos         ( void );
        public         void                delete_photo              ( int $photo_id );
        public         mixed               from_id                   ( Gallery &$gallery,
                                                                       int $album_id );
        public         mixed               from_title                ( Gallery &$gallery,
                                                                       string $album_title );
        private        mixed               get_attr_name             ( string $attr_name );
        public         mixed               key                       ( void );
        public         int                 length                    ( void );
        private        void                move                      ( int $offset );
        public         void                move_down                 ( void );
        public         void                move_up                   ( void );
        public         mixed               next                      ( void );
        public         mixed               photo                     ( int $photo_id );
        public         void                rewind                    ( void );
        public         void                save                      ( mixed $recursive );
        public         void                slice                     ( int $offset,
                                                                       int $length );
        private        void                slice_update              ( void );
        public         bool                valid                     ( void );
        public         mixed               __get                     (  $attr_name );
        public         bool                __isset                   (  $attr_name );
        public         void                __set                     (  $attr_name,
                                                                        $attr_value );
        public         void                __unset                   (  $attr_name );
}

Object Hierarchy

Album

Implemented Interfaces

Album implements Iterator (internal interface)

Description

An album object that can contain one or more Photo objects.

The album metadata is stored in an SQL database. The minimal definition for the albums table is:

 CREATE TABLE albums (
   album_id INTEGER PRIMARY KEY AUTOINCREMENT,
   album_title VARCHAR(256),
   album_rank INTEGER,
   album_created INTEGER,
   album_updated INTEGER
 )
These columns are available as attributes of the Album object, without the album_ prefix. Any extra columns in the database table are also exposed as attributes of the Album object through their column names. If the column names start with the album_ prefix then they will have this prefix stripped.Like the Gallery base object, the Album object is iterable. For example, when you have an albums table with album_description as an extra column, you can do this:
 $gallery = new Gallery(...);

 foreach ($gallery as &$album) {
     printf('%s - %s', $album->title, $album->description);

     foreach ($album as &$photo)
         echo $photo->title;
 }

Attribute Details

$attrs

private        array          $attrs

This holds the album's metadata attributes

Default value: empty string


$attrs_dirty

private        bool           $attrs_dirty

TRUE if the attributes have been changed

Default value: empty string


$gallery

public         Gallery        $gallery

A reference to the parent Gallery object

Default value: empty string


$photos

private        array          $photos

An array containing all loaded Photo objects

Default value: empty string


$photo_ids

private        array          $photo_ids

An array containing all the IDs for the album's photos

Default value: empty string


$photo_slice

private        array          $photo_slice

An array containing all photo IDs in the current slice

Default value: empty string


$photo_slice_length

private        int            $photo_slice_length

Length of the photo slice. Zero means to the end of the array

Default value: empty string


$photo_slice_offset

private        int            $photo_slice_offset

Offset of the photo slice

Default value: empty string

Method Details

__construct()

private        Album          __construct               ( Gallery &$gallery,
                                                          array $album );

Create a new Album object.

The constructor is private since you should use the from_id() or from_title factory methods.

&$gallery
A reference to the parent Gallery object
$album
An array containing the album's metadata attributes

add_photo()

public         mixed          add_photo                 ( string $file );

Add the image $file as a new photo to this album.

The image file is compied to the gallery and the full size and thumbnail images will be generated by applying the transformation stacks. If everything was succesfull it will return the Photo object for the new photo, otherwise it returns NULL.

$file

current()

public         mixed          current                   ( void );

Part of the Iterator interfaceSee the PHP manual on object iteration: http://www.php.net/manual/en/language.oop5.iterations.php


delete_all_photos()

public         void           delete_all_photos         ( void );

Delete all photos in the album


delete_photo()

public         void           delete_photo              ( int $photo_id );

Delete a photo from the album

This also removes the actual image files.

$photo_id
The ID of the photo to remove

from_id()

public         mixed          from_id                   ( Gallery &$gallery,
                                                          int $album_id );

Static factory method to create an Album object for the album with the given ID

The result should be assigned by reference. Example:

$album =& Album::from_id($gallery, $album_id);

&$gallery
A reference to the parent Gallery object
$album_id
The album ID

from_title()

public         mixed          from_title                ( Gallery &$gallery,
                                                          string $album_title );

Static factory method to create an Album object for the album with the given title

The result should be assigned by reference. Example:

$album =& Album::from_title($gallery, $album_title);

&$gallery
A reference to the parent Gallery object
$album_title
The album title

get_attr_name()

private        mixed          get_attr_name             ( string $attr_name );

Check the attribute name and prefix it with "album_" if need be.

Returns FALSE if the attribute does not exist.

$attr_name
The attribute name

key()

public         mixed          key                       ( void );

Part of the Iterator interfaceSee the PHP manual on object iteration: http://www.php.net/manual/en/language.oop5.iterations.php


length()

public         int            length                    ( void );

Return the number of photos in the album


move()

private        void           move                      ( int $offset );

Switch the Album's rank with the Album on $offset positions away

$offset
The offset of the Album to swap rank with

move_down()

public         void           move_down                 ( void );

Move this Album down in the rank order.


move_up()

public         void           move_up                   ( void );

Move this Album up in the rank order.


next()

public         mixed          next                      ( void );

Part of the Iterator interfaceSee the PHP manual on object iteration: http://www.php.net/manual/en/language.oop5.iterations.php


photo()

public         mixed          photo                     ( int $photo_id );

Get the Photo object for the given photo ID

$photo_id
The photo's ID

rewind()

public         void           rewind                    ( void );

Part of the Iterator interface

See the PHP manual on object iteration: http://www.php.net/manual/en/language.oop5.iterations.php


save()

public         void           save                      ( mixed $recursive );

Save the Album and all photos to the database

Set $recursive to FALSE if you only want to save the Album metadata and not the photos it contains

$recursive

slice()

public         void           slice                     ( int $offset,
                                                          int $length );

Set the slice of photos that the Iterator interface will iterate over.

$offset
If offset is non-negative, the slice will start at that offset in the photo list. If offset is negative, the slice will start that far from the end of the photo list.
$length
length If length is given and is positive, then the slice will have that many elements in it. If length is given and is negative then the slice will stop that many elements from the end of the array. If it is omitted, then the slice will have everything from offset up until the end of the photo list.

slice_update()

private        void           slice_update              ( void );

Update the slice of photos that the interface will iterate over, based on $photo_slice_offset and $photo_slice_length.


valid()

public         bool           valid                     ( void );

Part of the Iterator interfaceSee the PHP manual on object iteration: http://www.php.net/manual/en/language.oop5.iterations.php


__get()

public         mixed          __get                     (  $attr_name );

Magic method for using the Album's metadata attributes.Because Albums are stored in the database, you cannot add or remove attributes.See the PHP manual on overloading: http://nl.php.net/manual/en/language.oop5.overloading.php

$attr_name

__isset()

public         bool           __isset                   (  $attr_name );

Magic method for using the Album's metadata attributes.Because Albums are stored in the database, you cannot add or remove attributes.See the PHP manual on overloading: http://nl.php.net/manual/en/language.oop5.overloading.php

$attr_name

__set()

public         void           __set                     (  $attr_name,
                                                           $attr_value );

Magic method for using the Album's metadata attributes.Because Albums are stored in the database, you cannot add or remove attributes.See the PHP manual on overloading: http://nl.php.net/manual/en/language.oop5.overloading.php

$attr_name
$attr_value

__unset()

public         void           __unset                   (  $attr_name );

Magic method for using the Album's metadata attributes.Because Albums are stored in the database, you cannot add or remove attributes.See the PHP manual on overloading: http://nl.php.net/manual/en/language.oop5.overloading.php

$attr_name