4a7bb50006b5554d642b092a4bd5e6fa4f366dd3
[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      * index defines primary key
24      *
25      * @var boolean
26      */
27     public $primary;
28
29     /**
30      * index defines unique key
31      *
32      * @var boolean
33      */
34     public $unique;
35
36     /**
37      * index defines any key, except (foreign, unique or primary)
38      *
39      * @var boolean
40      */
41     public $mul;
42     
43     /**
44      * index defines foreign key
45      *
46      * @var boolean
47      */
48     public $foreign;
49     
50     /**
51      * name of referenced table of foreign key
52      *
53      * @var string
54      */
55     public $referencetable;
56     
57     /**
58      * name of referenced table field/column of foreign key
59      *
60      * @var string
61      */
62     public $referencefield;
63     
64     /**
65      * defines behaviour of foreign key
66      *
67      * @var boolean
68      */
69     public $referenceOnDelete;
70     
71     /**
72      * defines behaviour of foreign key
73      *
74      * @var boolean
75      */
76     public $referenceOnUpdate;
77     
78     /**
79      * lenght of index 
80      * 
81      * @var integer
82      */
83     public $length = NULL;
84     
85     abstract protected function _setIndex($_declaration);
86
87     public function setForeignKey($_foreign)
88     {
89         $this->foreign = 'true';
90     }
91
92 //    
93 //    /**
94 //     * set index from declaration 
95 //    * @param stdClass $_declaration
96 //     * NOT IMPLEMENTED YET
97 //     */  
98 //    public function addIndex($_definition)
99 //    {
100 //        foreach ($this->declaration['index'] as $index) {
101 //            if ($index->field['name'] == $_definition['COLUMN_NAME']) {
102 //                if ($_definition['CONSTRAINT_NAME'] == 'PRIMARY') {
103 //                    $index->setName($_definition['COLUMN_NAME']);
104 //                } else {
105 //                    $index->setName($_definition['CONSTRAINT_NAME']);
106 //                }
107 //            }
108 //        }
109 //    }
110 //    
111 //    /**
112 //     * set index from declaration 
113 //    * @param stdClass $_declaration
114 //     * NOT IMPLEMENTED YET
115 //     */     
116 //    public function setIndex($_definition)
117 //    {
118 //        foreach ($this->declaration['index'] as $index) {
119 //            if ($index->field['name'] == $_definition['COLUMN_NAME']) {
120 //                if ($_definition['CONSTRAINT_NAME'] == 'PRIMARY') {
121 //                    $index->setName($_definition['COLUMN_NAME']);
122 //                } else {
123 //                    $index->setName($_definition['CONSTRAINT_NAME']);
124 //                }
125 //            }
126 //        }
127 //    }
128 //    
129 //    /**
130 //     * set index from declaration 
131 //    * @param stdClass $_declaration
132 //     * NOT IMPLEMENTED YET
133 //     */  
134 //    public function setForeign($_definition)
135 //    {
136 //        foreach ($this->declaration['index'] as $index) {
137 //            //// auto shutup by cweiss: echo "<h1>"  . substr($_definition['CONSTRAINT_NAME'], strlen(SQL_TABLE_PREFIX)) . "/" .$index->field->name.  "</h1>";
138 //            
139 //            //if ($index->field->name == substr($_definition['CONSTRAINT_NAME'], strlen(SQL_TABLE_PREFIX)))
140 //            //{
141 //                $index->setForeignKey($_definition);
142 //            //}
143 //        }
144 //    }
145     
146 }