Rev 56 | Rev 61 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 56 | Rev 58 | ||
---|---|---|---|
Line 20... | Line 20... | ||
20 | * @var string
|
20 | * @var string
|
21 | */
|
21 | */
|
22 | protected static $_name = ''; |
22 | protected static $_name = ''; |
23 | 23 | ||
24 | /**
|
24 | /**
|
- | 25 | * Columns definition
|
|
- | 26 | * @var array
|
|
- | 27 | * @see Table::create()
|
|
- | 28 | */
|
|
- | 29 | protected static $_columns; |
|
- | 30 | ||
- | 31 | /**
|
|
- | 32 | * Indexes definition
|
|
- | 33 | * @var array
|
|
- | 34 | * @see Table::create()
|
|
- | 35 | */
|
|
- | 36 | protected static $_indexes; |
|
- | 37 | ||
- | 38 | /**
|
|
- | 39 | * Constraints definition
|
|
- | 40 | * @var array
|
|
- | 41 | * @see Table::create()
|
|
- | 42 | */
|
|
- | 43 | protected static $_constraints; |
|
- | 44 | ||
- | 45 | /**
|
|
25 | * Database of the table
|
46 | * Database of the table
|
26 | * @var Database|string
|
47 | * @var Database|string
|
- | 48 | * @see Table::create()
|
|
27 | */
|
49 | */
|
28 | protected static $_database; |
50 | protected static $_database; |
29 | 51 | ||
30 | /**
|
52 | /**
|
31 | * Name of the primary key column of the table
|
53 | * Name of the primary key column of the table
|
Line 163... | Line 185... | ||
163 | $class = \get_class($this); |
185 | $class = \get_class($this); |
164 | return $class::$_id; |
186 | return $class::$_id; |
165 | }
|
187 | }
|
166 | 188 | ||
167 | /**
|
189 | /**
|
- | 190 | * Returns the <var>options</var> array for {@link Database::createTable}
|
|
- | 191 | *
|
|
- | 192 | * Should be called and overridden by inheriting classes.
|
|
- | 193 | *
|
|
- | 194 | * @return array
|
|
- | 195 | */
|
|
- | 196 | protected function _createOptions () |
|
- | 197 | {
|
|
- | 198 | $options = array(); |
|
- | 199 | ||
- | 200 | foreach (array('indexes', 'constraints') as $option) |
|
- | 201 | {
|
|
- | 202 | if ($class::${"_$option"}) |
|
- | 203 | {
|
|
- | 204 | $options[$option] = $class::${"_$option"}; |
|
- | 205 | }
|
|
- | 206 | }
|
|
- | 207 | ||
- | 208 | return $options; |
|
- | 209 | }
|
|
- | 210 | ||
- | 211 | /**
|
|
- | 212 | * Creates the table for this model
|
|
- | 213 | *
|
|
- | 214 | * @return bool
|
|
- | 215 | */
|
|
- | 216 | public function create () |
|
- | 217 | {
|
|
- | 218 | $class = \get_class($this); |
|
- | 219 | return $this->database->createTable( |
|
- | 220 | $class::$_name, $class::$_columns, $this->_createOptions()); |
|
- | 221 | }
|
|
- | 222 | ||
- | 223 | /**
|
|
168 | * Initiates a transaction
|
224 | * Initiates a transaction
|
169 | *
|
225 | *
|
170 | * @return bool
|
226 | * @return bool
|
171 | * @see Database::beginTransaction()
|
227 | * @see Database::beginTransaction()
|
172 | */
|
228 | */
|