Translation2
[ class tree: Translation2 ] [ index: Translation2 ] [ all elements ]

Source for file mdb.php

Documentation is available at mdb.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3.  
  4. /**
  5.  * Contains the Translation2_Admin_Container_mdb class
  6.  *
  7.  * PHP versions 4 and 5
  8.  *
  9.  * LICENSE: Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in the
  15.  *    documentation and/or other materials provided with the distribution.
  16.  * 3. The name of the author may not be used to endorse or promote products
  17.  *    derived from this software without specific prior written permission.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
  20.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22.  * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
  23.  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  28.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29.  *
  30.  * @category  Internationalization
  31.  * @package   Translation2
  32.  * @author    Lorenzo Alberton <l.alberton@quipo.it>
  33.  * @author    Ian Eure <ieure@php.net>
  34.  * @copyright 2004-2007 Lorenzo Alberton, Ian Eure
  35.  * @license   http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
  36.  * @version   CVS: $Id: mdb.php,v 1.38 2008/05/03 09:17:59 quipo Exp $
  37.  * @link      http://pear.php.net/package/Translation2
  38.  */
  39.  
  40. /**
  41.  * require Translation2_Container_mdb class
  42.  */
  43. require_once 'Translation2/Container/mdb.php';
  44.  
  45. /**
  46.  * Storage driver for storing/fetching data to/from a database
  47.  *
  48.  * This storage driver can use all databases which are supported
  49.  * by the PEAR::MDB abstraction layer to store and fetch data.
  50.  *
  51.  * @category  Internationalization
  52.  * @package   Translation2
  53.  * @author    Lorenzo Alberton <l.alberton@quipo.it>
  54.  * @author    Ian Eure <ieure@php.net>
  55.  * @copyright 2004-2007 Lorenzo Alberton, Ian Eure
  56.  * @license   http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
  57.  * @link      http://pear.php.net/package/Translation2
  58.  */
  59. {
  60.     // {{{ addLang()
  61.  
  62.     /**
  63.      * Creates a new table to store the strings in this language.
  64.      * If the table is shared with other langs, it is ALTERed to
  65.      * hold strings in this lang too.
  66.      *
  67.      * @param array $langData language data
  68.      * @param array $options  options
  69.      *
  70.      * @return true|PEAR_Error
  71.      */
  72.     function addLang($langData$options = array())
  73.     {
  74.         $tables $this->db->listTables();
  75.         if (PEAR::isError($tables)) {
  76.             return $tables;
  77.         }
  78.  
  79.         $lang_col $this->_getLangCol($langData['lang_id']);
  80.  
  81.         if (in_array($langData['table_name']$tables)) {
  82.             //table exists
  83.             $query sprintf('ALTER TABLE %s ADD %s%s TEXT',
  84.                 $this->db->quoteIdentifier($langData['table_name']),
  85.                 $this->db->phptype == 'mssql' '' 'COLUMN ',
  86.                 $this->db->quoteIdentifier($lang_col)
  87.             );
  88.             ++$this->_queries;
  89.             return $this->db->query($query);
  90.         }
  91.  
  92.         //table does not exist
  93.         $queries = array();
  94.         $queries[sprintf('CREATE TABLE %s ( '
  95.                              .'%s VARCHAR(%d) default NULL, '
  96.                              .'%s TEXT NOT NULL, '
  97.                              .'%s TEXT )',
  98.             $this->db->quoteIdentifier($langData['table_name']),
  99.             $this->db->quoteIdentifier($this->options['string_page_id_col']),
  100.             (int)$this->options['string_page_id_col_length'],
  101.             $this->db->quoteIdentifier($this->options['string_id_col']),
  102.             $this->db->quoteIdentifier($lang_col)
  103.         );
  104.         $mysqlClause ($this->db->phptype == 'mysql''(255)' '';
  105.  
  106.         $index_name sprintf('%s_%s_%s_index',
  107.             $langData['table_name'],
  108.             $this->options['string_page_id_col'],
  109.             $this->options['string_id_col']
  110.         );
  111.         $queries[]  sprintf('CREATE UNIQUE INDEX %s ON %s (%s, %s%s)',
  112.              $this->db->quoteIdentifier($index_name),
  113.              $this->db->quoteIdentifier($langData['table_name']),
  114.              $this->db->quoteIdentifier($this->options['string_page_id_col']),
  115.              $this->db->quoteIdentifier($this->options['string_id_col']),
  116.              $mysqlClause
  117.         );
  118.  
  119.         $index_name sprintf('%s_%s_index',
  120.             $langData['table_name'],
  121.             $this->options['string_page_id_col']
  122.         );
  123.         $queries[]  sprintf('CREATE INDEX %s ON %s (%s)',
  124.              $this->db->quoteIdentifier($index_name),
  125.              $this->db->quoteIdentifier($langData['table_name']),
  126.              $this->db->quoteIdentifier($this->options['string_page_id_col'])
  127.         );
  128.  
  129.         $index_name sprintf('%s_%s_index',
  130.             $langData['table_name'],
  131.             $this->options['string_id_col']
  132.         );
  133.         $queries[]  sprintf('CREATE INDEX %s ON %s (%s%s)',
  134.              $this->db->quoteIdentifier($index_name),
  135.              $this->db->quoteIdentifier($langData['table_name']),
  136.              $this->db->quoteIdentifier($this->options['string_id_col']),
  137.              $mysqlClause
  138.         );
  139.  
  140.         foreach ($queries as $query{
  141.             ++$this->_queries;
  142.             $res $this->db->query($query);
  143.             if (PEAR::isError($res)) {
  144.                 return $res;
  145.             }
  146.         }
  147.         return true;
  148.     }
  149.  
  150.     // }}}
  151.     // {{{ addLangToList()
  152.  
  153.     /**
  154.      * Creates a new entry in the langsAvail table.
  155.      * If the table doesn't exist yet, it is created.
  156.      *
  157.      * @param array $langData array('lang_id'    => 'en',
  158.      *                               'table_name' => 'i18n',
  159.      *                               'name'       => 'english',
  160.      *                               'meta'       => 'some meta info',
  161.      *                               'error_text' => 'not available',
  162.      *                               'encoding'   => 'iso-8859-1');
  163.      *
  164.      * @return true|PEAR_Error
  165.      */
  166.     function addLangToList($langData)
  167.     {
  168.         $tables $this->db->listTables();
  169.         if (PEAR::isError($tables)) {
  170.             return $tables;
  171.         }
  172.  
  173.         if (!in_array($this->options['langs_avail_table']$tables)) {
  174.             $queries   = array();
  175.             $queries[sprintf('CREATE TABLE %s ('
  176.                                 .'%s VARCHAR(16), '
  177.                                 .'%s VARCHAR(200), '
  178.                                 .'%s TEXT, '
  179.                                 .'%s VARCHAR(250), '
  180.                                 .'%s VARCHAR(16) )',
  181.                 $this->db->quoteIdentifier($this->options['langs_avail_table']),
  182.                 $this->db->quoteIdentifier($this->options['lang_id_col']),
  183.                 $this->db->quoteIdentifier($this->options['lang_name_col']),
  184.                 $this->db->quoteIdentifier($this->options['lang_meta_col']),
  185.                 $this->db->quoteIdentifier($this->options['lang_errmsg_col']),
  186.                 $this->db->quoteIdentifier($this->options['lang_encoding_col'])
  187.             );
  188.             $queries[sprintf('CREATE UNIQUE INDEX %s_%s_index ON %s (%s)',
  189.                 $this->options['langs_avail_table'],
  190.                 $this->options['lang_id_col'],
  191.                 $this->db->quoteIdentifier($this->options['langs_avail_table']),
  192.                 $this->db->quoteIdentifier($this->options['lang_id_col'])
  193.             );
  194.  
  195.             foreach ($queries as $query{
  196.                 ++$this->_queries;
  197.                 $res $this->db->query($query);
  198.                 if (PEAR::isError($res)) {
  199.                     return $res;
  200.                 }
  201.             }
  202.         }
  203.  
  204.         $query sprintf('INSERT INTO %s (%s, %s, %s, %s, %s) VALUES (%s, %s, %s, %s, %s)',
  205.             $this->db->quoteIdentifier($this->options['langs_avail_table']),
  206.             $this->db->quoteIdentifier($this->options['lang_id_col']),
  207.             $this->db->quoteIdentifier($this->options['lang_name_col']),
  208.             $this->db->quoteIdentifier($this->options['lang_meta_col']),
  209.             $this->db->quoteIdentifier($this->options['lang_errmsg_col']),
  210.             $this->db->quoteIdentifier($this->options['lang_encoding_col']),
  211.             $this->db->getTextValue($langData['lang_id']),
  212.             $this->db->getTextValue($langData['name']),
  213.             $this->db->getTextValue($langData['meta']),
  214.             $this->db->getTextValue($langData['error_text']),
  215.             $this->db->getTextValue($langData['encoding'])
  216.         );
  217.  
  218.         ++$this->_queries;
  219.         $success $this->db->query($query);
  220.         $this->options['strings_tables'][$langData['lang_id']] $langData['table_name'];
  221.         return $success;
  222.     }
  223.  
  224.     // }}}
  225.     // {{{ removeLang()
  226.  
  227.     /**
  228.      * Remove the lang from the langsAvail table and drop the strings table.
  229.      * If the strings table holds other langs and $force==false, then
  230.      * only the lang column is dropped. If $force==true the whole
  231.      * table is dropped without any check
  232.      *
  233.      * @param string  $langID language ID
  234.      * @param boolean $force  if true, drop the whole table without further checks
  235.      *
  236.      * @return true|PEAR_Error
  237.      */
  238.     function removeLang($langID$force)
  239.     {
  240.         //remove from langsAvail
  241.         $query sprintf('DELETE FROM %s WHERE %s = %s',
  242.             $this->db->quoteIdentifier($this->options['langs_avail_table']),
  243.             $this->db->quoteIdentifier($this->options['lang_id_col']),
  244.             $this->db->getTextValue($langID)
  245.         );
  246.         ++$this->_queries;
  247.         $res $this->db->query($query);
  248.         if (PEAR::isError($res)) {
  249.             return $res;
  250.         }
  251.  
  252.         $lang_table $this->_getLangTable($langID);
  253.         if ($force{
  254.             //remove the whole table
  255.             ++$this->_queries;
  256.             return $this->db->query('DROP TABLE ' $this->db->quoteIdentifier($lang_table));
  257.         }
  258.  
  259.         //drop only the column for this lang
  260.         $query sprintf('ALTER TABLE %s DROP COLUMN %s',
  261.             $this->db->quoteIdentifier($lang_table),
  262.             $this->db->quoteIdentifier($this->_getLangCol($langID))
  263.         );
  264.         ++$this->_queries;
  265.         return $this->db->query($query);
  266.     }
  267.  
  268.     // }}}
  269.     // {{{ updateLang()
  270.  
  271.     /**
  272.      * Update the lang info in the langsAvail table
  273.      *
  274.      * @param array $langData array of language data
  275.      *
  276.      * @return true|PEAR_Error
  277.      */
  278.     function updateLang($langData)
  279.     {
  280.         $allFields = array(
  281.             //'lang_id'    => 'lang_id_col',
  282.             'name'       => 'lang_name_col',
  283.             'meta'       => 'lang_meta_col',
  284.             'error_text' => 'lang_errmsg_col',
  285.             'encoding'   => 'lang_encoding_col',
  286.         );
  287.         $updateFields array_keys($langData);
  288.         $langSet      = array();
  289.         foreach ($allFields as $field => $col{
  290.             if (in_array($field$updateFields)) {
  291.                 $langSet[$this->db->quoteIdentifier($this->options[$col]' = ' .
  292.                              $this->db->getTextValue($langData[$field]);
  293.             }
  294.         }
  295.         $query sprintf('UPDATE %s SET %s WHERE %s=%s',
  296.             $this->db->quoteIdentifier($this->options['langs_avail_table']),
  297.             implode(', '$langSet),
  298.             $this->db->quoteIdentifier($this->options['lang_id_col']),
  299.             $this->db->getTextValue($langData['lang_id'])
  300.         );
  301.  
  302.         ++$this->_queries;
  303.         $success $this->db->query($query);
  304.         $this->fetchLangs();  //update memory cache
  305.         return $success;
  306.     }
  307.  
  308.     // }}}
  309.     // {{{ add()
  310.  
  311.     /**
  312.      * Add a new entry in the strings table.
  313.      *
  314.      * @param string $stringID    string ID
  315.      * @param string $pageID      page/group ID
  316.      * @param array  $stringArray Associative array with string translations.
  317.      *                Sample format:  array('en' => 'sample', 'it' => 'esempio')
  318.      *
  319.      * @return true|PEAR_Error
  320.      */
  321.     function add($stringID$pageID$stringArray)
  322.     {
  323.         $langs array_intersect(
  324.             array_keys($stringArray),
  325.             $this->getLangs('ids')
  326.         );
  327.  
  328.         if (!count($langs)) {
  329.             //return error: no valid lang provided
  330.             return true;
  331.         }
  332.  
  333.         // Langs may be in different tables - we need to split up queries along
  334.         // table lines, so we can keep DB traffic to a minimum.
  335.  
  336.         $unquoted_stringID $stringID;
  337.         $unquoted_pageID   $pageID;
  338.         $stringID          $this->db->getTextValue($stringID);
  339.         $pageID            is_null($pageID'NULL' $this->db->getTextValue($pageID);
  340.         // Loop over the tables we need to insert into.
  341.         foreach ($this->_tableLangs($langsas $table => $tableLangs{
  342.             $exists $this->_recordExists($unquoted_stringID$unquoted_pageID$table);
  343.             if (PEAR::isError($exists)) {
  344.                 return $exists;
  345.             }
  346.             $func  $exists '_getUpdateQuery' '_getInsertQuery';
  347.             $query $this->$func($table$tableLangs$stringID$pageID$stringArray);
  348.  
  349.             ++$this->_queries;
  350.             $res $this->db->query($query);
  351.             if (PEAR::isError($res)) {
  352.                 return $res;
  353.             }
  354.         }
  355.  
  356.         return true;
  357.     }
  358.  
  359.     // }}}
  360.     // {{{ update()
  361.  
  362.     /**
  363.      * Update an existing entry in the strings table.
  364.      *
  365.      * @param string $stringID    string ID
  366.      * @param string $pageID      page/group ID
  367.      * @param array  $stringArray Associative array with string translations.
  368.      *                Sample format:  array('en' => 'sample', 'it' => 'esempio')
  369.      *
  370.      * @return true|PEAR_Error
  371.      */
  372.     function update($stringID$pageID$stringArray)
  373.     {
  374.         return $this->add($stringID$pageID$stringArray);
  375.     }
  376.  
  377.     // }}}
  378.     // {{{ _getInsertQuery()
  379.  
  380.     /**
  381.      * Build a SQL query to INSERT a record
  382.      *
  383.      * @param string $table        table name
  384.      * @param array  &$tableLangs  tables containing the languages
  385.      * @param string $stringID     string ID
  386.      * @param string $pageID       page/group ID
  387.      * @param array  &$stringArray array of strings
  388.      *
  389.      * @return string INSERT query
  390.      * @access private
  391.      */
  392.     function _getInsertQuery($table&$tableLangs$stringID$pageID&$stringArray)
  393.     {
  394.         $tableCols $this->_getLangCols($tableLangs);
  395.         $langData  = array();
  396.         foreach ($tableLangs as $lang{
  397.             $langData[$lang$this->db->getTextValue($stringArray[$lang]);
  398.         }
  399.         foreach (array_keys($tableColsas $k{
  400.             $tableCols[$k$this->db->quoteIdentifier($tableCols[$k]);
  401.         }
  402.  
  403.         return sprintf('INSERT INTO %s (%s, %s, %s) VALUES (%s, %s, %s)',
  404.             $this->db->quoteIdentifier($table),
  405.             $this->db->quoteIdentifier($this->options['string_id_col']),
  406.             $this->db->quoteIdentifier($this->options['string_page_id_col']),
  407.             implode(', '$tableCols),
  408.             $stringID,
  409.             $pageID,
  410.             implode(', '$langData)
  411.         );
  412.     }
  413.  
  414.     // }}}
  415.     // {{{ _getUpdateQuery()
  416.  
  417.     /**
  418.      * Build a SQL query to UPDATE a record
  419.      *
  420.      * @param string $table        table name
  421.      * @param array  &$tableLangs  tables containing the languages
  422.      * @param string $stringID     string ID
  423.      * @param string $pageID       page/group ID
  424.      * @param array  &$stringArray array of strings
  425.      *
  426.      * @return string UPDATE query
  427.      * @access private
  428.      */
  429.     function _getUpdateQuery($table&$tableLangs$stringID$pageID&$stringArray)
  430.     {
  431.         $tableCols $this->_getLangCols($tableLangs);
  432.         $langSet   = array();
  433.         foreach ($tableLangs as $lang{
  434.             $langSet[$this->db->quoteIdentifier($tableCols[$lang]' = ' .
  435.                          $this->db->getTextValue($stringArray[$lang]);
  436.         }
  437.  
  438.         return sprintf('UPDATE %s SET %s WHERE %s = %s AND %s = %s',
  439.             $this->db->quoteIdentifier($table),
  440.             implode(', '$langSet),
  441.             $this->db->quoteIdentifier($this->options['string_id_col']),
  442.             $stringID,
  443.             $this->db->quoteIdentifier($this->options['string_page_id_col']),
  444.             $pageID
  445.         );
  446.     }
  447.  
  448.     // }}}
  449.     // {{{ remove()
  450.  
  451.     /**
  452.      * Remove an entry from the strings table.
  453.      *
  454.      * @param string $stringID string ID
  455.      * @param string $pageID   page/group ID
  456.      *
  457.      * @return boolean|PEAR_Error
  458.      */
  459.     function remove($stringID$pageID)
  460.     {
  461.         $tables array_unique($this->_getLangTables());
  462.  
  463.         $stringID $this->db->getTextValue($stringID);
  464.         // get the tables and skip the non existent ones
  465.         $dbTables $this->db->listTables();
  466.         foreach ($tables as $table{
  467.             if (!in_array($table$dbTables)) {
  468.                 continue;
  469.             }
  470.             $query sprintf('DELETE FROM %s WHERE %s = %s AND %s',
  471.                 $this->db->quoteIdentifier($table),
  472.                 $this->db->quoteIdentifier($this->options['string_id_col']),
  473.                 $stringID,
  474.                 $this->db->quoteIdentifier($this->options['string_page_id_col'])
  475.             );
  476.             if (is_null($pageID)) {
  477.                 $query .= ' IS NULL';
  478.             else {
  479.                 $query .= ' = ' $this->db->getTextValue($pageID);
  480.             }
  481.  
  482.             ++$this->_queries;
  483.             $res $this->db->query($query);
  484.             if (PEAR::isError($res)) {
  485.                 return $res;
  486.             }
  487.         }
  488.  
  489.         return true;
  490.     }
  491.  
  492.     // }}}
  493.     // {{{ removePage
  494.  
  495.     /**
  496.      * Remove all the strings in the given page/group
  497.      *
  498.      * @param string $pageID page/group ID
  499.      *
  500.      * @return mixed true on success, PEAR_Error on failure
  501.      */
  502.     function removePage($pageID = null)
  503.     {
  504.         $tables array_unique($this->_getLangTables());
  505.  
  506.         // get the tables and skip the non existent ones
  507.         $dbTables $this->db->listTables();
  508.         foreach ($tables as $table{
  509.             if (!in_array($table$dbTables)) {
  510.                 continue;
  511.             }
  512.             $query sprintf('DELETE FROM %s WHERE %s',
  513.                  $this->db->quoteIdentifier($tabletrue),
  514.                  $this->db->quoteIdentifier($this->options['string_page_id_col']true)
  515.             );
  516.             if (is_null($pageID)) {
  517.                 $query .= ' IS NULL';
  518.             else {
  519.                 $query .= ' = ' $this->db->getTextValue($pageID);
  520.             }
  521.  
  522.             ++$this->_queries;
  523.             $res $this->db->query($query);
  524.             if (PEAR::isError($res)) {
  525.                 return $res;
  526.             }
  527.         }
  528.  
  529.         return true;
  530.     }
  531.  
  532.     // }}}
  533.     // {{{ getPageNames()
  534.  
  535.     /**
  536.      * Get a list of all the pageIDs in any table.
  537.      *
  538.      * @return array 
  539.      */
  540.     function getPageNames()
  541.     {
  542.         $pages = array();
  543.         foreach ($this->_getLangTables(as $table{
  544.             $query sprintf('SELECT DISTINCT %s FROM %s',
  545.                  $this->db->quoteIdentifier($this->options['string_page_id_col']),
  546.                  $this->db->quoteIdentifier($table)
  547.             );
  548.             ++$this->_queries;
  549.             $res $this->db->getCol($query);
  550.             if (PEAR::isError($res)) {
  551.                 return $res;
  552.             }
  553.             $pages array_merge($pages$res);
  554.         }
  555.         return array_unique($pages);
  556.     }
  557.  
  558.     // }}}
  559.     // {{{ _tableLangs()
  560.  
  561.     /**
  562.      * Get table -> language mapping
  563.      *
  564.      * The key of the array is the table that a language is stored in;
  565.      * the value is an /array/ of languages stored in that table.
  566.      *
  567.      * @param array $langs Languages to get mapping for
  568.      *
  569.      * @return array  Table -> language mapping
  570.      * @access private
  571.      * @see    Translation2_Container_MDB::_getLangTable()
  572.      */
  573.     function &_tableLangs($langs)
  574.     {
  575.         $tables = array();
  576.         foreach ($langs as $lang{
  577.             $table $this->_getLangTable($lang);
  578.             $tables[$table][$lang;
  579.         }
  580.         return $tables;
  581.     }
  582.  
  583.     // }}}
  584.     // {{{ _getLangTables()
  585.  
  586.     /**
  587.      * Get tables for languages
  588.      *
  589.      * This is like _getLangTable(), but it returns an array of the tables for
  590.      * multiple languages.
  591.      *
  592.      * @param array $langs Languages to get tables for
  593.      *
  594.      * @return array 
  595.      * @access private
  596.      */
  597.     function &_getLangTables($langs = null)
  598.     {
  599.         $tables = array();
  600.         $langs  !is_array($langs$this->getLangs('ids'$langs;
  601.         foreach ($langs as $lang{
  602.             $tables[$this->_getLangTable($lang);
  603.         }
  604.         $tables array_unique($tables);
  605.         return $tables;
  606.     }
  607.  
  608.     // }}}
  609.     // {{{ _getLangCols()
  610.  
  611.     /**
  612.      * Get table columns strings are stored in
  613.      *
  614.      * This is like _getLangCol(), except it returns an array which contains
  615.      * the mapping for multiple languages.
  616.      *
  617.      * @param array $langs Languages to get mapping for
  618.      *
  619.      * @return array  Language -> column mapping
  620.      * @access private
  621.      * @see    Translation2_Container_MDB::_getLangCol()
  622.      */
  623.     function &_getLangCols($langs)
  624.     {
  625.         $cols = array();
  626.         foreach ($langs as $lang{
  627.             $cols[$lang$this->_getLangCol($lang);
  628.         }
  629.         return $cols;
  630.     }
  631.  
  632.     // }}}
  633.     // {{{ _recordExists()
  634.  
  635.     /**
  636.      * Check if there's already a record in the table with the
  637.      * given (pageID, stringID) pair.
  638.      *
  639.      * @param string $stringID string ID
  640.      * @param string $pageID   page/group ID
  641.      * @param string $table    table name
  642.      *
  643.      * @return boolean 
  644.      * @access private
  645.      */
  646.     function _recordExists($stringID$pageID$table)
  647.     {
  648.         $stringID $this->db->getTextValue($stringID);
  649.         $pageID   is_null($pageID' IS NULL' ' = ' $this->db->getTextValue($pageID);
  650.         $query    sprintf('SELECT COUNT(*) FROM %s WHERE %s=%s AND %s%s',
  651.             $this->db->quoteIdentifier($table),
  652.             $this->db->quoteIdentifier($this->options['string_id_col']),
  653.             $stringID,
  654.             $this->db->quoteIdentifier($this->options['string_page_id_col']),
  655.             $pageID
  656.         );
  657.         ++$this->_queries;
  658.         $res $this->db->getOne($query);
  659.         if (PEAR::isError($res)) {
  660.             return $res;
  661.         }
  662.         return ($res > 0);
  663.     }
  664.  
  665.     // }}}
  666.     // {{{ _filterStringsByTable()
  667.  
  668.     /**
  669.      * Get only the strings for the langs in the given table
  670.      *
  671.      * @param array  $stringArray Associative array with string translations.
  672.      *                Sample format: array('en' => 'sample', 'it' => 'esempio')
  673.      * @param string $table       table name
  674.      *
  675.      * @return array strings
  676.      * @access private
  677.      */
  678.     function &_filterStringsByTable($stringArray$table)
  679.     {
  680.         $strings = array();
  681.         foreach ($stringArray as $lang => $string{
  682.             if ($table == $this->_getLangTable($lang)) {
  683.                 $strings[$lang$string;
  684.             }
  685.         }
  686.         return $strings;
  687.     }
  688.  
  689.     // }}}
  690.     // {{{ _getLangsInTable()
  691.  
  692.     /**
  693.      * Get the languages sharing the given table
  694.      *
  695.      * @param string $table table name
  696.      *
  697.      * @return array 
  698.      */
  699.     function &_getLangsInTable($table)
  700.     {
  701.         $this->fetchLangs()// force cache refresh
  702.         $langsInTable = array();
  703.         foreach (array_keys($this->langsas $lang{
  704.             if ($table == $this->_getLangTable($lang)) {
  705.                 $langsInTable[$lang;
  706.             }
  707.         }
  708.         return $langsInTable;
  709.     }
  710.  
  711.     // }}}
  712. }
  713. ?>

Documentation generated on Fri, 14 Nov 2008 11:30:27 -0500 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.