\Jonah_Driver_Sql

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.

Summary

Methods
Properties
Constants
__construct()
deleteChannel()
getChannels()
getChannel()
getStories()
saveStory()
getStory()
getStoryLink()
getChecksum()
getIntervalLabel()
renderChannel()
getStoryIdsByChannel()
listTagInfo()
getIdBySlug()
saveChannel()
getChannelId()
getStoryCount()
getLatestStoryId()
deleteStory()
No public properties found
No constants found
_escapeStories()
_escapeStoryDescriptions()
getStoryAsMessage()
_getChannels()
_getChannel()
_timestampChannel()
_readStory()
_deleteChannel()
_saveStory()
_convertFromBackend()
_getStoryIdsByChannel()
_getStories()
_getIdBySlug()
_getStory()
_addPermalink()
_connect()
$_params
$_db
$_connected
N/A
No private methods found
No private properties found
N/A

Properties

$_params

$_params : array

Hash containing connection parameters.

Type

array

$_db

$_db : \Horde_Db_Adapter_Base

Handle for the current database connection.

Type

\Horde_Db_Adapter_Base

$_connected

$_connected : boolean

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

Type

boolean

Methods

__construct()

__construct(array  $params = array()) 

Constructs a new Driver storage object.

Parameters

array $params

A hash containing connection parameters.

deleteChannel()

deleteChannel(array  $info) 

Remove a channel from storage.

Parameters

array $info

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

getChannels()

getChannels() : array

Get a list of stored channels.

Throws

\Jonah_Exception

Returns

array —

An array of channel hashes.

getChannel()

getChannel(integer  $channel_id) : array

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

Parameters

integer $channel_id

The channel id to fetch.

Throws

\InvalidArgumentException

Returns

array —

The channel details as an array

getStories()

getStories(integer  $criteria, integer  $order = \Jonah::ORDER_PUBLISHED) : array

Returns the most recent or all stories from a channel.

Parameters

integer $criteria

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

integer $order

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

Throws

\InvalidArgumentException

Returns

array —

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

saveStory()

saveStory(array  $info) 

Save the provided story to storage.

Parameters

array $info

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

getStory()

getStory(integer  $story_id, boolean  $read = false) : array

Retrieve the requested story from storage.

Parameters

integer $story_id

The story id to obtain.

boolean $read

Increment the read counter?

Returns

array —

The story information array

getStoryLink()

getStoryLink(array  $channel, array  $story) : \Horde_Url

Returns the official link to a story.

Parameters

array $channel

A channel hash.

array $story

A story hash.

Returns

\Horde_Url —

The story link.

getChecksum()

getChecksum(  $story) 

Parameters

$story

getIntervalLabel()

getIntervalLabel(  $seconds = null) 

Parameters

$seconds

renderChannel()

renderChannel(integer  $channel_id, string  $tpl, integer  $max = 10, integer  $from, integer  $order = \Jonah::ORDER_PUBLISHED) : string

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

Parameters

integer $channel_id

The news channel to get stories from.

string $tpl

The name of the template to use.

integer $max

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

integer $from

The number of the story to start with.

integer $order

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

Returns

string —

The rendered story listing.

getStoryIdsByChannel()

getStoryIdsByChannel(integer  $channel_id) : array

Return a list of story_ids contained in the specified channel.

Parameters

integer $channel_id

The channel_id

Returns

array —

An array of story_ids.

listTagInfo()

listTagInfo(  $channel_id = null) 

Parameters

$channel_id

getIdBySlug()

getIdBySlug(  $channel) 

Parameters

$channel

saveChannel()

saveChannel(array  $info) : integer

Saves a channel to the backend.

Parameters

array $info

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.

Throws

\Jonah_Exception

Returns

integer —

The channel ID.

getChannelId()

getChannelId(string  $channel) : integer

Look up a channel ID by its name

Parameters

string $channel

Returns

integer —

Channel ID

getStoryCount()

getStoryCount(integer  $channel_id) : integer

Returns the total number of stories in the specified channel.

Parameters

integer $channel_id

The Channel Id

Returns

integer —

The count

getLatestStoryId()

getLatestStoryId(integer  $channel_id) : integer

Gets the latest released story from a given internal channel

Parameters

integer $channel_id

The channel id.

Throws

\Jonah_Exception
\Horde_Exception_NotFound

Returns

integer —

The story id.

deleteStory()

deleteStory(  $channel_id,   $story_id) 

Parameters

$channel_id
$story_id

_escapeStories()

_escapeStories(  $value,   $key) 

Parameters

$value
$key

_escapeStoryDescriptions()

_escapeStoryDescriptions(  $value,   $key) 

Parameters

$value
$key

getStoryAsMessage()

getStoryAsMessage(array  $story) : \MIME_Part

Returns the provided story as a MIME part.

Parameters

array $story

A data array representing a story.

Returns

\MIME_Part —

The MIME message part containing the story parts.

_getChannels()

_getChannels() : array

Get a list of stored channels.

Throws

\Jonah_Exception

Returns

array —

An array of channel hashes.

_getChannel()

_getChannel(  $channel_id) : array

Retrieve a single channel definition from storage.

Parameters

$channel_id

Throws

\Jonah_Exception
\Horde_Exception_NotFound

Returns

array —

The channel definition array.

_timestampChannel()

_timestampChannel(integer  $channel_id, integer  $timestamp) : boolean

Update the channel's timestamp

Parameters

integer $channel_id

The channel id.

integer $timestamp

The new timestamp.

Throws

\Jonah_Exception

Returns

boolean

_readStory()

_readStory(integer  $story_id) 

Increment the story's read count.

Parameters

integer $story_id

The story_id to increment.

Throws

\Jonah_Exception

_deleteChannel()

_deleteChannel(integer  $channel_id) : \boolean.

Remove a channel from storage.

Parameters

integer $channel_id

The channel to remove.

Throws

\Jonah_Exception

Returns

\boolean.

_saveStory()

_saveStory(  $info) 

Save a story to storage.

Parameters

$info

Throws

\Jonah_Exception

_convertFromBackend()

_convertFromBackend(array  $story) : array

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

Parameters

array $story

A story hash.

Returns

array —

The converted hash.

_getStoryIdsByChannel()

_getStoryIdsByChannel(  $channel_id) 

Parameters

$channel_id

_getStories()

_getStories(array  $criteria,   $order = \Jonah::ORDER_PUBLISHED) : array

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

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

Parameters

array $criteria
$order

Returns

array

_getIdBySlug()

_getIdBySlug(string  $slug) : integer

Obtain a channel id from a slug

Parameters

string $slug

The slug to search for.

Returns

integer —

The channel id.

_getStory()

_getStory(integer  $story_id, boolean  $read = false) : \The

Retrieve a story from storage.

Parameters

integer $story_id

They story id.

boolean $read

Increment the read counter?

Throws

\Horde_Exception_NotFound
\Jonah_Exception

Returns

\The —

story array.

_addPermalink()

_addPermalink(array  $story) 

Adds a missing permalink to a story.

Parameters

array $story

A story hash.

Throws

\Jonah_Exception

_connect()

_connect() : boolean

Attempts to open a persistent connection to the SQL server.

Throws

\Jonah_Exception

Returns

boolean —

True on success.