Source for file dataobjectsimple.php
Documentation is available at dataobjectsimple.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
* Contains the Translation2_Container_dataobjectsimple class
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @category Internationalization
* @author Alan Knowles <alan@akbkhome.com>
* @copyright 2004-2008 Alan Knowles
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: dataobjectsimple.php,v 1.17 2008/02/02 18:05:06 quipo Exp $
* @link http://pear.php.net/package/Translation2
* require Translation2_Container class and DB_DataObjects
require_once 'Translation2/Container.php';
require_once 'DB/DataObject.php';
* Simple storage driver for fetching data from a db with DB_DataObject
* This storage driver can use all databases which are supported
* by the PEAR::DB abstraction layer to fetch data.
* // meta data etc. not supported yet...
* create table translations (
* id int(11) auto_increment not null primary key,
* alter table translations add index page (page);
* alter table translations add index lang (lang);
* alter table translations add index string_id (string_id);
* - then just run the dataobjects createtables script.
* @category Internationalization
* @author Alan Knowles <alan@akbkhome.com>
* @copyright 2004-2008 Alan Knowles
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: dataobjectsimple.php,v 1.17 2008/02/02 18:05:06 quipo Exp $
* @link http://pear.php.net/package/Translation2
* Initialize the container
* @param string $table table name
function init($table = null )
$this->_setDefaultOptions ();
// {{{ _setDefaultOptions()
* Set some default options
function _setDefaultOptions ()
$this->options['table'] = 'translations';
* Fetch the available langs if they're not cached yet.
$do = DB_DataObject ::factory ($this->options['table']);
$do->selectAdd ('distinct lang');
* Returns an array of the strings in the selected page
* @param string $pageID page/group ID
* @param string $langID language ID
function getPage($pageID = null , $langID = null )
$langID = $this->_getLangID ($langID);
if (PEAR ::isError ($langID)) {
// First get the array of string IDs
$do = DB_DataObject ::factory ($this->options['table']);
$stringIDs[$do->string_id ] = $do->translation;
// Now get the array of strings
$do = DB_DataObject ::factory ($this->options['table']);
$translations[$do->string_id ] = $do->translation;
// Construct an associative array of stringIDs and translations
foreach ($translations as $key => $value) {
$strings[$stringIDs[$key]] = $value;
* Get a single item from the container, without caching the whole page
* @param string $stringID string ID
* @param string $pageID page/group ID
* @param string $langID language ID
function getOne($stringID, $pageID = null , $langID = null )
$langID = $langID ? $langID : (isset ($this->currentLang['id']) ? $this->currentLang['id'] : '-');
$do = DB_DataObject ::factory ($this->options['table']);
$do->translation = $string;
// we dont have the base language translation..
$stringID = $do->string_id;
$do = DB_DataObject ::factory ($this->options['table']);
$do->string_id = $stringID;
$do->selectAdd ('translation');
* Get the stringID for the given string
* @param string $string string
* @param string $pageID page/group ID
// get the english version...
$do = DB_DataObject ::factory ($this->options['table']);
$do->lang = $this->currentLang['id'];
$do->translation = $string;
Documentation generated on Tue, 06 May 2008 06:00:17 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|