Coverage for Doctrine_I18n

Back to coverage report

1 <?php
2 /*
3  *  $Id$
4  *
5  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16  *
17  * This software consists of voluntary contributions made by many individuals
18  * and is licensed under the LGPL. For more information, see
19  * <http://www.phpdoctrine.org>.
20  */
21 Doctrine::autoload('Doctrine_Record_Generator');
22 /**
23  * Doctrine_I18n
24  *
25  * @package     Doctrine
26  * @subpackage  I18n
27  * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
28  * @link        www.phpdoctrine.org
29  * @since       1.0
30  * @version     $Revision$
31  * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
32  */
33 class Doctrine_I18n extends Doctrine_Record_Generator
34 {
35     protected $_options = array(
36                             'className'     => '%CLASS%Translation',
37                             'fields'        => array(),
38                             'generateFiles' => false,
39                             'table'         => false,
40                             'pluginTable'   => false,
41                             'children'      => array(),
42                             );
43
44     /**
45      * __construct
46      *
47      * @param string $options 
48      * @return void
49      */
50     public function __construct($options)
51     {
52         $this->_options = array_merge($this->_options, $options);
53     }
54
55     public function buildRelation()
56     {
57        $this->buildForeignRelation('Translation');
58         $this->buildLocalRelation();
59     }
60
61     /**
62      * buildDefinition
63      *
64      * @param object $Doctrine_Table
65      * @return void
66      */
67     public function setTableDefinition()
68     {
69        if (empty($this->_options['fields'])) {
70            throw new Doctrine_I18n_Exception('Fields not set.');
71        }
72
73         $options = array('className' => $this->_options['className']);
74
75         $cols = $this->_options['table']->getColumns();
76
77         foreach ($cols as $column => $definition) {
78             if (in_array($column, $this->_options['fields'])) {
79                 $columns[$column] = $definition;
80                 $this->_options['table']->removeColumn($column);
81             }
82         }
83
84         $this->hasColumns($columns);
85
86         $this->hasColumn('lang', 'string', 2, array('fixed'   => true,
87                                                     'primary' => true));
88                                                     
89         $this->bindQueryParts(array('indexBy' => 'lang'));
90     }
91 }