Table.php 3.23 KB
Newer Older
lsmith's avatar
lsmith committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
<?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
 * <http://www.phpdoctrine.com>.
 */
Doctrine::autoload('Doctrine_Schema_Object');
/**
 * class Doctrine_Schema_Table
 * Holds information on a database table
25
 *
lsmith's avatar
lsmith committed
26
 * @package     Doctrine
27
 * @subpackage  Schema
lsmith's avatar
lsmith committed
28 29 30 31 32
 * @link        www.phpdoctrine.com
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
 * @since       1.0
 * @version     $Revision$
 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
33
 * @author      Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com>
lsmith's avatar
lsmith committed
34
 */
lsmith's avatar
lsmith committed
35 36
class Doctrine_Schema_Table extends Doctrine_Schema_Object implements Countable, IteratorAggregate
{
lsmith's avatar
lsmith committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50

    protected $definition = array('name'        => '',
                                  'check'       => '',
                                  'charset'     => '',
                                  'description' => '');
    /**
     * Relations this table has with others. An array of Doctrine_Schema_Relation
     */
    private $relations = array();
    /**
     *
     * @return bool
     * @access public
     */
lsmith's avatar
lsmith committed
51 52
    public function isValid( )
    {
lsmith's avatar
lsmith committed
53 54 55 56 57 58 59

    }
    /**
     * returns an array of Doctrine_Schema_Column objects
     *
     * @return array
     */
lsmith's avatar
lsmith committed
60 61
    public function getColumns()
    {
lsmith's avatar
lsmith committed
62 63 64 65 66
        return $this->children;
    }
    /**
     * @return Doctrine_Schema_Column|false
     */
lsmith's avatar
lsmith committed
67 68
    public function getColumn($name)
    {
lsmith's avatar
lsmith committed
69 70 71 72 73 74 75 76 77 78 79
        if ( ! isset($this->children[$name])) {
            return false;
        }
        return $this->children[$name];
    }
    /**
     *
     * @param Doctrine_Schema_Column column
     * @return Doctrine_Schema_Table
     * @access public
     */
lsmith's avatar
lsmith committed
80 81
    public function addColumn(Doctrine_Schema_Column $column)
    {
lsmith's avatar
lsmith committed
82 83 84 85 86 87 88 89 90 91 92 93
        $name = $column->get('name');
        $this->children[$name] = $column;

        return $this;
    }

    /**
     * Adds a relation between a local column and a 2nd table / column
     *
     * @param Doctrine_Schema_Relation Relation
     *
    */
94
    public function setRelation(Doctrine_Schema_Relation $relation) {
lsmith's avatar
lsmith committed
95 96 97 98 99 100 101
         $this->relations[] = $relation;
    }
    /**
     * Return all the relations this table has with others
     *
     * @return array Array of Doctrine_Schema_Relation
    */
102
    public function getRelations() {
lsmith's avatar
lsmith committed
103 104 105 106
        return $this->relations;
    }

}