\Klutz_Driver_Sql

Klutz Driver implementation for comics as files with SUM info stored in SQL database.

Required parameters:

'directory'  The main directory the comics are stored in

Summary

Methods
Properties
Constants
factory()
listDates()
imageSize()
imageExists()
storeImage()
retrieveImage()
Klutz_Driver_sql()
loadSums()
rebuildSums()
addSum()
removeSum()
isUnique()
removeImage()
removeDate()
$basedir
$subdir
$_db
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$basedir

$basedir : string

The base directory we store comics in.

Type

string

$subdir

$subdir : string

The format for the various subdirectories.

WARNING: DO NOT CHANGE THIS!

Type

string

$_db

$_db : 

The MDB2 database object

Type

Methods

factory()

factory(string  $driver = null, array  $params = null) : object

Gets a concrete Klutz_Driver instance.

Parameters

string $driver

The type of concrete Klutz_Driver subclass to return. The code for the driver is dynamically included.

array $params

A hash containing any additional configuration or connection parameters a subclass might need

Returns

object —

Klutz_Driver The newly created concrete instance, or false on error.

listDates()

listDates(\timestamp  $date = null, \timestamp  $oldest = null, \timestamp  $newest = null) : mixed

Get a list of the dates for which we have comics between $oldest and $newest. Only returns dates we have at least one comic for.

Parameters

\timestamp $date

The reference date (default today)

\timestamp $oldest

The earliest possible date to return (default first of the month)

\timestamp $newest

The latest possible date to return (default last date of the month)

Returns

mixed —

An array of dates in $subdir format between $oldest and $newest that we have comics for | PEAR_Error

imageSize()

imageSize(string  $index, \timestamp  $date = null) : string

Get the image dimensions for the requested image.

The image is not stored locally so this function returns an empty string. Performance hit is too expensive to make this worth it.

Parameters

string $index

The index of the comic to check

\timestamp $date

The date of the comic to check (default today)

Returns

string —

Attributes for an tag giving height and width

imageExists()

imageExists(string  $index, \timestamp  $date = null) : boolean

Find out if we already have a local copy of this image.

Even though we never actually store a local copy, pretend.

Parameters

string $index

The index of the comic to check

\timestamp $date

The date of the comic to check (default today)

Returns

boolean —

False in this driver

storeImage()

storeImage(string  $index, string  $image,   $date = null) : boolean

Store an image for later retrieval.

Even though we never actually store a local copy, pretend.

Parameters

string $index

The index of the comic to retrieve

string $image

Raw (binary) image data to store

$date

Returns

boolean —

True on success, false otherwise

retrieveImage()

retrieveImage(string  $index, \timestamp  $date = null) : mixed

Retrieve an image from storage. Make sure the image exists first with imageExists().

Parameters

string $index

The index of the comic to retrieve

\timestamp $date

The date for which we want $comic

Returns

mixed —

If the image exists locally, return a Klutz_Image object. If it doesn't, return a string with the URL pointing to the comic.

Klutz_Driver_sql()

Klutz_Driver_sql(array  $params = array()) 

Constructs a new SQL storage object.

Parameters

array $params

A hash containing connection parameters.

loadSums()

loadSums() 

We do nothing in this function for the SQL driver since we grab the info on demand from the database. We keep the function here, however to honor our 'interface' since we call this function from various places in the client code.

rebuildSums()

rebuildSums() : void

Rebuild the table of unique identifiers.

addSum()

addSum(string  $index, \timestamp  $date, string  $data) : boolean|\PEAR_Error

Add a unique identifier for a given image.

Parameters

string $index

The index for the comic

\timestamp $date

The date of the comic

string $data

The md5 of the raw (binary) image data

Returns

boolean|\PEAR_Error —

True on success, PEAR_Error on failure.

removeSum()

removeSum(string  $index = null, \timestamp  $date = null) : integer|\PEAR_Error

Remove the unique identifier for the given comic and/or date. If both are passed, removes the uid for that comic and date. If only a comic is passed, removes all uids for that comic. If only a date is passed removes uids for all comics on that date. If neither is passed, all uids are wiped out.

Parameters

string $index

Index for the comic to delete. If left out all comics will be assumed.

\timestamp $date

Date to remove. If left out, assumes all dates.

Returns

integer|\PEAR_Error —

number of affected Comics on success, PEAR_Error on failure.

isUnique()

isUnique(\Klutz_Image  $image) : boolean

Determine if the image passed is a unique image (one we don't already have).

This allows for $days = random, etc., but keeps us from getting the same comic day after day.

Parameters

\Klutz_Image $image

Raw (binary) image data.

Returns

boolean —

True if unique, false otherwise.

removeImage()

removeImage(string  $index, \timestamp  $date = null) : boolean

Remove an image from the storage system (including its unique ID).

Parameters

string $index

The index of the comic to remove

\timestamp $date

The date of the comic to remove (default today)

Returns

boolean —

True on success, else false

removeDate()

removeDate(\timestamp  $date = null) : boolean

Remove all images from the storage system (including unique IDs) for a given date.

Parameters

\timestamp $date

The date to remove comics for (default today)

Returns

boolean —

True on success, else false