Documentation

Jonah_Driver_Sql extends Jonah_Driver
in package

Jonah storage implementation for PHP's PEAR database abstraction layer.

The table structure can be created by the scripts/db/jonah_news.sql script. The needed tables are jonah_channels and jonah_stories.

Copyright 2002-2017 Horde LLC (http://www.horde.org/)

See the enclosed file LICENSE for license information (BSD). If you did not did not receive this file, see http://cvs.horde.org/co.php/jonah/LICENSE.

Tags
author

Marko Djukic marko@oblo.com

author

Chuck Hagenbuch chuck@horde.org

author

Jan Schneider jan@horde.org

author

Ben Klang ben@alkaloid.net

author

Michael J. Rubinsky mrubinsk@horde.org

Table of Contents

$_connected  : bool
Boolean indicating whether or not we're connected to the SQL server.
$_db  : Horde_Db_Adapter_Base
Handle for the current database connection.
$_params  : array<string|int, mixed>
Hash containing connection parameters.
__construct()  : mixed
Constructs a new Driver storage object.
deleteChannel()  : mixed
Remove a channel from storage.
deleteStory()  : mixed
getChannel()  : array<string|int, mixed>
Fetches the requested channel, while actually passing on the request to the backend _getChannel() function to do the real work.
getChannelId()  : int
Look up a channel ID by its name
getChannels()  : array<string|int, mixed>
Get a list of stored channels.
getChecksum()  : mixed
getIdBySlug()  : mixed
getIntervalLabel()  : mixed
getLatestStoryId()  : int
Gets the latest released story from a given internal channel
getStories()  : array<string|int, mixed>
Returns the most recent or all stories from a channel.
getStory()  : array<string|int, mixed>
Retrieve the requested story from storage.
getStoryCount()  : int
Returns the total number of stories in the specified channel.
getStoryIdsByChannel()  : array<string|int, mixed>
Return a list of story_ids contained in the specified channel.
getStoryLink()  : Horde_Url
Returns the official link to a story.
listTagInfo()  : mixed
renderChannel()  : string
Returns the stories of a channel rendered with the specified template.
saveChannel()  : int
Saves a channel to the backend.
saveStory()  : mixed
Save the provided story to storage.
_addPermalink()  : mixed
Adds a missing permalink to a story.
_connect()  : bool
Attempts to open a persistent connection to the SQL server.
_convertFromBackend()  : array<string|int, mixed>
Converts the text fields of a story from the backend charset to the output charset.
_deleteChannel()  : mixed
Remove a channel from storage.
_escapeStories()  : mixed
_escapeStoryDescriptions()  : mixed
_getChannel()  : array<string|int, mixed>
Retrieve a single channel definition from storage.
_getChannels()  : array<string|int, mixed>
Get a list of stored channels.
_getIdBySlug()  : int
Obtain a channel id from a slug
_getStories()  : array<string|int, mixed>
Returns a list of stories from the storage backend filtered by arbitrary criteria.
_getStory()  : The
Retrieve a story from storage.
_getStoryIdsByChannel()  : mixed
_readStory()  : mixed
Increment the story's read count.
_saveStory()  : mixed
Save a story to storage.
_timestampChannel()  : bool
Update the channel's timestamp
getStoryAsMessage()  : MIME_Part
Returns the provided story as a MIME part.

Properties

$_connected

Boolean indicating whether or not we're connected to the SQL server.

protected bool $_connected = alse

$_db

Handle for the current database connection.

protected Horde_Db_Adapter_Base $_db

$_params

Hash containing connection parameters.

protected array<string|int, mixed> $_params = array()

Methods

__construct()

Constructs a new Driver storage object.

public __construct([mixed $params = array() ]) : mixed
Parameters
$params : mixed = array()

A hash containing connection parameters.

Return values
mixed

deleteChannel()

Remove a channel from storage.

public deleteChannel(array<string|int, mixed> $info) : mixed
Parameters
$info : array<string|int, mixed>

A channel info array. (@TODO: Look at passing just the id?)

Return values
mixed

deleteStory()

public deleteStory(mixed $channel_id, mixed $story_id) : mixed
Parameters
$channel_id : mixed
$story_id : mixed
Return values
mixed

getChannel()

Fetches the requested channel, while actually passing on the request to the backend _getChannel() function to do the real work.

public getChannel(int $channel_id) : array<string|int, mixed>
Parameters
$channel_id : int

The channel id to fetch.

Tags
throws
InvalidArgumentException
Return values
array<string|int, mixed>

The channel details as an array

getChannelId()

Look up a channel ID by its name

public getChannelId(string $channel) : int
Parameters
$channel : string
Return values
int

Channel ID

getChannels()

Get a list of stored channels.

public getChannels() : array<string|int, mixed>
Tags
throws
Jonah_Exception
Return values
array<string|int, mixed>

An array of channel hashes.

getChecksum()

public getChecksum(mixed $story) : mixed
Parameters
$story : mixed
Return values
mixed

getIdBySlug()

public getIdBySlug(mixed $channel) : mixed
Parameters
$channel : mixed
Return values
mixed

getIntervalLabel()

public getIntervalLabel([mixed $seconds = null ]) : mixed
Parameters
$seconds : mixed = null
Return values
mixed

getLatestStoryId()

Gets the latest released story from a given internal channel

public getLatestStoryId(int $channel_id) : int
Parameters
$channel_id : int

The channel id.

Tags
throws
Jonah_Exception
throws
Horde_Exception_NotFound
Return values
int

The story id.

getStories()

Returns the most recent or all stories from a channel.

public getStories(int $criteria[, int $order = Jonah::ORDER_PUBLISHED ]) : array<string|int, mixed>
Parameters
$criteria : int

An associative array of attributes on which the resulting stories should be filtered. Examples: 'channel' => (string) Channel slug 'channel_id' => (integer) Channel ID (Either an id or slug is required) 'author' => (string) Story author 'updated-min' => (Horde_Date) Only return stories updated on or after this date 'updated-max' => (Horde_Date) Only return stories updatedon or before this date 'published-min' => (Horde_Date) Only return stories published on or after this date 'published-max' => (Horde_Date) Only return stories published on or before date 'tags' => (array) Tag names that must match to be included 'keywords' => (array) Strings which must match to be included 'published' => (boolean) Whether to return only published stories: Possible values: null return both 'published' returns publised 'unpublished' returns unpublished 'startnumber' => (integer) Story number to start at 'limit' => (integer) Max number of stories

$order : int = Jonah::ORDER_PUBLISHED

How to order the results. A Jonah::ORDER_* constant.

Tags
throws
InvalidArgumentException
Return values
array<string|int, mixed>

The specified number (or less, if there are fewer) of stories from the given channel.

getStory()

Retrieve the requested story from storage.

public getStory(int $story_id[, bool $read = false ]) : array<string|int, mixed>
Parameters
$story_id : int

The story id to obtain.

$read : bool = false

Increment the read counter?

Return values
array<string|int, mixed>

The story information array

getStoryCount()

Returns the total number of stories in the specified channel.

public getStoryCount(int $channel_id) : int
Parameters
$channel_id : int

The Channel Id

Return values
int

The count

getStoryIdsByChannel()

Return a list of story_ids contained in the specified channel.

public getStoryIdsByChannel(int $channel_id) : array<string|int, mixed>
Parameters
$channel_id : int

The channel_id

Return values
array<string|int, mixed>

An array of story_ids.

Returns the official link to a story.

public getStoryLink(array<string|int, mixed> $channel, array<string|int, mixed> $story) : Horde_Url
Parameters
$channel : array<string|int, mixed>

A channel hash.

$story : array<string|int, mixed>

A story hash.

Return values
Horde_Url

The story link.

listTagInfo()

public listTagInfo([mixed $channel_id = null ]) : mixed
Parameters
$channel_id : mixed = null
Return values
mixed

renderChannel()

Returns the stories of a channel rendered with the specified template.

public renderChannel(int $channel_id, string $tpl[, int $max = 10 ], int $from[, int $order = Jonah::ORDER_PUBLISHED ]) : string
Parameters
$channel_id : int

The news channel to get stories from.

$tpl : string

The name of the template to use.

$max : int = 10

The maximum number of stories to get. If null, all stories will be returned.

$from : int

The number of the story to start with.

$order : int = Jonah::ORDER_PUBLISHED

How to sort the results for internal channels Possible values are the Jonah::ORDER_* constants.

Tags
TODO:

This doesn't belong in a storage driver class. Move it to a view or possible a static method in Jonah::?

Return values
string

The rendered story listing.

saveChannel()

Saves a channel to the backend.

public saveChannel(array<string|int, mixed> &$info) : int
Parameters
$info : array<string|int, mixed>

The channel to add. Must contain a combination of the following entries:

'channel_id'       If empty a new channel is being added, otherwise one
                   is being edited.
'channel_slug'     The channel slug.
'channel_name'     The headline.
'channel_desc'     A description of this channel.
'channel_interval' If external then interval at which to refresh.
'channel_link'     The link to the source.
'channel_url'      The url from where to fetch the story list.
'channel_image'    A channel image.
Tags
throws
Jonah_Exception
Return values
int

The channel ID.

saveStory()

Save the provided story to storage.

public saveStory(array<string|int, mixed> &$info) : mixed
Parameters
$info : array<string|int, mixed>

The story information array. Passed by reference so we can add/change the id when saved.

Return values
mixed

Adds a missing permalink to a story.

protected _addPermalink(array<string|int, mixed> &$story) : mixed
Parameters
$story : array<string|int, mixed>

A story hash.

Tags
throws
Jonah_Exception
Return values
mixed

_connect()

Attempts to open a persistent connection to the SQL server.

protected _connect() : bool
Tags
TODO:

This class needs to be refactored to use Horde_Db

throws
Jonah_Exception
Return values
bool

True on success.

_convertFromBackend()

Converts the text fields of a story from the backend charset to the output charset.

protected _convertFromBackend(array<string|int, mixed> $story) : array<string|int, mixed>
Parameters
$story : array<string|int, mixed>

A story hash.

Return values
array<string|int, mixed>

The converted hash.

_deleteChannel()

Remove a channel from storage.

protected _deleteChannel(int $channel_id) : mixed
Parameters
$channel_id : int

The channel to remove.

Tags
throws
Jonah_Exception
Return values
mixed

_escapeStories()

protected _escapeStories(mixed &$value, mixed $key) : mixed
Parameters
$value : mixed
$key : mixed
Tags
TODO:

Move to a view class or static Jonah:: method?

Return values
mixed

_escapeStoryDescriptions()

protected _escapeStoryDescriptions(mixed &$value, mixed $key) : mixed
Parameters
$value : mixed
$key : mixed
Tags
TODO:

Move to a view class or static Jonah:: method?

Return values
mixed

_getChannel()

Retrieve a single channel definition from storage.

protected _getChannel(mixed $channel_id) : array<string|int, mixed>
Parameters
$channel_id : mixed
Tags
throws
Jonah_Exception
throws
Horde_Exception_NotFound
Return values
array<string|int, mixed>

The channel definition array.

_getChannels()

Get a list of stored channels.

protected _getChannels() : array<string|int, mixed>
Tags
throws
Jonah_Exception
Return values
array<string|int, mixed>

An array of channel hashes.

_getIdBySlug()

Obtain a channel id from a slug

protected _getIdBySlug(string $slug) : int
Parameters
$slug : string

The slug to search for.

Return values
int

The channel id.

_getStories()

Returns a list of stories from the storage backend filtered by arbitrary criteria.

protected _getStories(array<string|int, mixed> $criteria[, mixed $order = Jonah::ORDER_PUBLISHED ]) : array<string|int, mixed>

NOTE: $criteria['channel_id'] MUST be set for this method to work.

Parameters
$criteria : array<string|int, mixed>
$order : mixed = Jonah::ORDER_PUBLISHED
Tags
see

Jonah_Driver#getStories

Return values
array<string|int, mixed>

_getStory()

Retrieve a story from storage.

protected _getStory(int $story_id[, bool $read = false ]) : The
Parameters
$story_id : int

They story id.

$read : bool = false

Increment the read counter?

Tags
throws
Horde_Exception_NotFound
throws
Jonah_Exception
Return values
The

story array.

_getStoryIdsByChannel()

protected _getStoryIdsByChannel(mixed $channel_id) : mixed
Parameters
$channel_id : mixed
Return values
mixed

_readStory()

Increment the story's read count.

protected _readStory(int $story_id) : mixed
Parameters
$story_id : int

The story_id to increment.

Tags
throws
Jonah_Exception
Return values
mixed

_saveStory()

Save a story to storage.

protected _saveStory(array<string|int, mixed> &$info) : mixed
Parameters
$info : array<string|int, mixed>

The story info array.

Tags
throws
Jonah_Exception
Return values
mixed

_timestampChannel()

Update the channel's timestamp

protected _timestampChannel(int $channel_id, int $timestamp) : bool
Parameters
$channel_id : int

The channel id.

$timestamp : int

The new timestamp.

Tags
throws
Jonah_Exception
Return values
bool

getStoryAsMessage()

Returns the provided story as a MIME part.

protected getStoryAsMessage(array<string|int, mixed> $story) : MIME_Part
Parameters
$story : array<string|int, mixed>

A data array representing a story.

Tags
TODO:

Refactor to use new Horde MIME library

Return values
MIME_Part

The MIME message part containing the story parts.

Search results