~desarrollokumbia/kumbia/ActiveRecord

« back to all changes in this revision

Viewing changes to db_pool/metadata.php

  • Committer: Emilio Silveira
  • Date: 2010-01-10 04:49:16 UTC
  • Revision ID: emilio.rst@gmail.com-20100110044916-qvymkocllio8mv43
Aun con la metadata

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
 
require_once CORE_PATH . 'libs/ActiveRecord/db_pool/column.php';
3
 
class Rows implements ArrayAccess
 
2
/**
 
3
 * KumbiaPHP web & app Framework
 
4
 *
 
5
 * LICENSE
 
6
 *
 
7
 * This source file is subject to the new BSD license that is bundled
 
8
 * with this package in the file LICENSE.txt.
 
9
 * It is also available through the world-wide-web at this URL:
 
10
 * http://wiki.kumbiaphp.com/Licencia
 
11
 * If you did not receive a copy of the license and are unable to
 
12
 * obtain it through the world-wide-web, please send an email
 
13
 * to license@kumbiaphp.com so we can send you a copy immediately.
 
14
 *
 
15
 * Metadata de modelo
 
16
 * 
 
17
 * @category   Kumbia
 
18
 * @package    DbPool 
 
19
 * @copyright  Copyright (c) 2005-2010 Kumbia Team (http://www.kumbiaphp.com)
 
20
 * @license    http://wiki.kumbiaphp.com/Licencia     New BSD License
 
21
 */
 
22
 
 
23
// @see Attribute 
 
24
require_once CORE_PATH . 'libs/ActiveRecord/db_pool/attribute.php';
 
25
 
 
26
class Metadata
4
27
{
5
 
    private $_columns = array();
6
 
    /**
7
 
     * Primary Key's
 
28
    /**
 
29
     * Atributos de modelo
 
30
     *
 
31
     * @var array
 
32
     **/
 
33
    private $_attributes = array();
 
34
    
 
35
    /**
 
36
     * Clave primaria
 
37
     *
 
38
     * @var string
8
39
     */
9
40
    private $_PK = NULL;
 
41
    
10
42
    /**
11
 
     * Foreing Key's
 
43
     * Claves foraneas
 
44
     *
 
45
     * @var array
12
46
     */
13
47
    private $_FK = NULL;
14
 
    /**
15
 
     * Relaciones
16
 
     */
17
 
    private $_relations = array();
18
 
    public function column ($col = NULL)
19
 
    {
20
 
        if (! isset($this->_columns[$col])) {
21
 
            $this->_columns[$col] = new Column();
22
 
        }
23
 
        return $this->_columns[$col];
24
 
    }
25
 
    /**
26
 
     * Obtiene las Columnas
27
 
     */
28
 
    public function getColumns()
29
 
    {
30
 
        return $this->_columns;
31
 
    }
32
 
    /**
33
 
     * setea una relacion (asociaciones)
34
 
     */
35
 
    public function setRelation($column=NULL, $relation=NULL)
36
 
    {
37
 
        $this->_relations[$column] = $relation;
38
 
    }
39
 
    /**
40
 
     * Obtiene las Relaciones de la columna
41
 
     */
42
 
    public function getRelations($column=NULL)
43
 
    {
44
 
        if($column && array_key_exists($column, $this->_relations)){
45
 
            return $this->_relations[$column];
46
 
        }
47
 
        return $this->_relations;
48
 
    }
 
48
 
 
49
    /**
 
50
     * Obtiene la metadata de un atributo
 
51
     *
 
52
     * @param string $attribute nombre de atributo
 
53
     * @return Attribute
 
54
     **/
 
55
    public function attribute ($attribute = NULL)
 
56
    {
 
57
        if (! isset($this->_attributes[$attribute])) {
 
58
            $this->_attributes[$attribute] = new Attribute();
 
59
        }
 
60
        return $this->_attributes[$attribute];
 
61
    }
 
62
    /**
 
63
     * Obtiene los atributos
 
64
     *
 
65
     * @return array
 
66
     */
 
67
    public function getAttributes()
 
68
    {
 
69
        return $this->_attributes;
 
70
    }
 
71
    
 
72
    /**
 
73
     * Asigna la clave primaria
 
74
     *
 
75
     * @param string $pk
 
76
     **/
49
77
    public function setPK($pk=NULL)
50
78
    {
51
79
        $this->_PK = $pk;
52
80
    }
 
81
    
 
82
    /**
 
83
     * Obtiene la clave primaria
 
84
     *
 
85
     * @return string
 
86
     **/
53
87
    public function getPK()
54
88
    {
55
89
        return $this->_PK;
56
90
    }
 
91
    
 
92
    /**
 
93
     * Asigna las claves foraneas
 
94
     *
 
95
     * @param array $fk
 
96
     **/
57
97
    public function setFK($fk=NULL)
58
98
    {
59
99
        $this->_FK = $fk;
60
100
    }
 
101
    
 
102
    /**
 
103
     * Obtiene las claves foraneas
 
104
     *
 
105
     * @return array | NULL
 
106
     **/
61
107
    public function getFK()
62
108
    {
63
109
        return $this->_FK;
64
110
    }
65
 
    
66
 
    //Implementacion de ArrayAccess
67
 
    public function offsetExists ($offset)
68
 
    {
69
 
        return isset($this->_columns[$offset]);
70
 
    }
71
 
    public function offsetSet ($offset, $value)
72
 
    {
73
 
        //self::$_columns[$offset] = $value;
74
 
    }
75
 
    public function offsetGet ($offset)
76
 
    {
77
 
        //return self::$_columns[$offset];
78
 
    }
79
 
    public function offsetUnset ($offset)
80
 
    {
81
 
        unset($this->_columns[$offset]);
82
 
    }
83
111
}
 
 
b'\\ No newline at end of file'