DigiKam to PHP Photo Album - model

Data Model

The data model is set of PHP classes that let me easily abstract the elements of my galleries.

Album Image

In almost every case, when I get an Album, I also need an Image that represents the thumbnail for the album. When I get an Image, I need the Album in which the image is contained. The need for a class that held an Album and an Image was something that developed late in my work. It is a super simple class, it just has an Album and an Image.

Get the code here: AlbumImage.php

Album

The album is the primary method for structuring images. The album class has a number of properties which basically map to colums in the table. A few methods were added to normalize the album names and to ensure that the URLs that I generated were consistent across my pages.

Get the code here: Album.php

Image

The image is the second most fundamental element in the galleries. Like the album, the image class largly maps to the columns in the database table that I had built.

Get the code here: Image.php

DataModel

The DataModel is a layer of abstraction that I put in to make the classes a bit cleaner. It uses the DatabaseConnection class to do the work - I think of this as the business logic for how my model works.

Get the code here: DataModel.php

DatabaseConnection

The DatabaseConnection class handles the task of talking to the database. If you switch from MySql to something else, theoretically, this is the only class you'd need to touch. The logic for determining when to show "private" images/galleris is also contained in this class; I elected to use a cookie setting to know when to allow private images to be included.

Get the code here: DatabaseConnection.php

Tag

The Tag class is another relatively simple class. It contains an id, the display name and a count of photos with that tag (which changes based on the context in which the tag is queried).

Get the code here: Tag.php