set explicit lenght for index
[tine20] / tine20 / Setup / Backend / Schema / Index / Abstract.php
1 <?php
2 /**
3  * Tine 2.0 - http://www.tine20.org
4  * 
5  * @package     Setup
6  * @license     http://www.gnu.org/licenses/agpl.html
7  * @copyright   Copyright (c) 2008 Metaways Infosystems GmbH (http://www.metaways.de)
8  * @author      Matthias Greiling <m.greiling@metaways.de>
9  */
10
11
12 abstract class Setup_Backend_Schema_Index_Abstract extends Setup_Backend_Schema_Abstract
13 {
14     
15     /**
16      * the name of the field(s)/column(s) in its own table 
17      *
18      * @var array
19      */
20     public $field = array();
21     
22     /**
23      * length for fields
24      * 
25      * @var array
26      */
27     public $fieldLength = array();
28
29     /**
30      * index defines primary key
31      *
32      * @var boolean
33      */
34     public $primary;
35
36     /**
37      * index defines unique key
38      *
39      * @var boolean
40      */
41     public $unique;
42
43     /**
44      * index defines any key, except (foreign, unique or primary)
45      *
46      * @var boolean
47      */
48     public $mul;
49     
50     /**
51      * index defines foreign key
52      *
53      * @var boolean
54      */
55     public $foreign;
56     
57     /**
58      * name of referenced table of foreign key
59      *
60      * @var string
61      */
62     public $referencetable;
63     
64     /**
65      * name of referenced table field/column of foreign key
66      *
67      * @var string
68      */
69     public $referencefield;
70     
71     /**
72      * defines behaviour of foreign key
73      *
74      * @var boolean
75      */
76     public $referenceOnDelete;
77     
78     /**
79      * defines behaviour of foreign key
80      *
81      * @var boolean
82      */
83     public $referenceOnUpdate;
84     
85     /**
86      * lenght of index 
87      * 
88      * @var integer
89      */
90     public $length = NULL;
91     
92     abstract protected function _setIndex($_declaration);
93
94     public function setForeignKey($_foreign)
95     {
96         $this->foreign = 'true';
97     }
98
99 //    
100 //    /**
101 //     * set index from declaration 
102 //    * @param stdClass $_declaration
103 //     * NOT IMPLEMENTED YET
104 //     */  
105 //    public function addIndex($_definition)
106 //    {
107 //        foreach ($this->declaration['index'] as $index) {
108 //            if ($index->field['name'] == $_definition['COLUMN_NAME']) {
109 //                if ($_definition['CONSTRAINT_NAME'] == 'PRIMARY') {
110 //                    $index->setName($_definition['COLUMN_NAME']);
111 //                } else {
112 //                    $index->setName($_definition['CONSTRAINT_NAME']);
113 //                }
114 //            }
115 //        }
116 //    }
117 //    
118 //    /**
119 //     * set index from declaration 
120 //    * @param stdClass $_declaration
121 //     * NOT IMPLEMENTED YET
122 //     */     
123 //    public function setIndex($_definition)
124 //    {
125 //        foreach ($this->declaration['index'] as $index) {
126 //            if ($index->field['name'] == $_definition['COLUMN_NAME']) {
127 //                if ($_definition['CONSTRAINT_NAME'] == 'PRIMARY') {
128 //                    $index->setName($_definition['COLUMN_NAME']);
129 //                } else {
130 //                    $index->setName($_definition['CONSTRAINT_NAME']);
131 //                }
132 //            }
133 //        }
134 //    }
135 //    
136 //    /**
137 //     * set index from declaration 
138 //    * @param stdClass $_declaration
139 //     * NOT IMPLEMENTED YET
140 //     */  
141 //    public function setForeign($_definition)
142 //    {
143 //        foreach ($this->declaration['index'] as $index) {
144 //            //// auto shutup by cweiss: echo "<h1>"  . substr($_definition['CONSTRAINT_NAME'], strlen(SQL_TABLE_PREFIX)) . "/" .$index->field->name.  "</h1>";
145 //            
146 //            //if ($index->field->name == substr($_definition['CONSTRAINT_NAME'], strlen(SQL_TABLE_PREFIX)))
147 //            //{
148 //                $index->setForeignKey($_definition);
149 //            //}
150 //        }
151 //    }
152     
153 }