I18n.php 3.06 KB
Newer Older
zYne's avatar
zYne committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<?php
/*
 *  $Id$
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "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 COPYRIGHT
 * OWNER 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.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the LGPL. For more information, see
19
 * <http://www.phpdoctrine.org>.
zYne's avatar
zYne committed
20
 */
21

zYne's avatar
zYne committed
22 23 24 25
/**
 * Doctrine_I18n
 *
 * @package     Doctrine
26
 * @subpackage  I18n
zYne's avatar
zYne committed
27 28 29 30 31 32
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
 * @link        www.phpdoctrine.com
 * @since       1.0
 * @version     $Revision$
 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
 */
zYne's avatar
zYne committed
33
class Doctrine_I18n extends Doctrine_Record_Generator
zYne's avatar
zYne committed
34 35 36 37 38 39
{
    protected $_options = array(
                            'className'     => '%CLASS%Translation',
                            'fields'        => array(),
                            'generateFiles' => false,
                            'table'         => false,
zYne's avatar
zYne committed
40
                            'pluginTable'   => false,
zYne's avatar
zYne committed
41
                            'children'      => array(),
zYne's avatar
zYne committed
42 43
                            );

44 45 46 47 48 49
    /**
     * __construct
     *
     * @param string $options 
     * @return void
     */
zYne's avatar
zYne committed
50 51 52 53 54
    public function __construct($options)
    {
        $this->_options = array_merge($this->_options, $options);
    }

55 56 57 58 59 60
    public function buildRelation()
    {
    	$this->buildForeignRelation('Translation');
        $this->buildLocalRelation();
    }

61 62 63
    /**
     * buildDefinition
     *
64
     * @param object $Doctrine_Table
65 66
     * @return void
     */
67
    public function setTableDefinition()
zYne's avatar
zYne committed
68
    {
69 70 71
      	if (empty($this->_options['fields'])) {
      	    throw new Doctrine_I18n_Exception('Fields not set.');
      	}
zYne's avatar
zYne committed
72 73

        $options = array('className' => $this->_options['className']);
zYne's avatar
zYne committed
74

75
        $cols = $this->_options['table']->getColumns();
zYne's avatar
zYne committed
76 77 78 79

        foreach ($cols as $column => $definition) {
            if (in_array($column, $this->_options['fields'])) {
                $columns[$column] = $definition;
80
                $this->_options['table']->removeColumn($column);
zYne's avatar
zYne committed
81 82
            }
        }
83

84
        $this->hasColumns($columns);
zYne's avatar
zYne committed
85

86 87 88 89
        $this->hasColumn('lang', 'string', 2, array('fixed'   => true,
                                                    'primary' => true));
                                                    
        $this->bindQueryParts(array('indexBy' => 'lang'));
zYne's avatar
zYne committed
90
    }
zYne's avatar
zYne committed
91
}