These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace xbanners\models\Base; |
||
4 | |||
5 | use \Exception; |
||
6 | use \PDO; |
||
7 | use Base\PropelBaseModelClass; |
||
8 | use Propel\Runtime\Propel; |
||
9 | use Propel\Runtime\ActiveQuery\Criteria; |
||
10 | use Propel\Runtime\ActiveQuery\ModelCriteria; |
||
11 | use Propel\Runtime\ActiveRecord\ActiveRecordInterface; |
||
12 | use Propel\Runtime\Collection\Collection; |
||
13 | use Propel\Runtime\Connection\ConnectionInterface; |
||
14 | use Propel\Runtime\Exception\BadMethodCallException; |
||
15 | use Propel\Runtime\Exception\LogicException; |
||
16 | use Propel\Runtime\Exception\PropelException; |
||
17 | use Propel\Runtime\Map\TableMap; |
||
18 | use Propel\Runtime\Parser\AbstractParser; |
||
19 | use xbanners\models\Banners as ChildBanners; |
||
20 | use xbanners\models\BannersI18nQuery as ChildBannersI18nQuery; |
||
21 | use xbanners\models\BannersQuery as ChildBannersQuery; |
||
22 | use xbanners\models\Map\BannersI18nTableMap; |
||
23 | |||
24 | /** |
||
25 | * Base class that represents a row from the 'banners_i18n' table. |
||
26 | * |
||
27 | * |
||
28 | * |
||
29 | * @package propel.generator.xbanners.models.Base |
||
30 | */ |
||
31 | abstract class BannersI18n extends PropelBaseModelClass implements ActiveRecordInterface |
||
32 | { |
||
33 | /** |
||
34 | * TableMap class name |
||
35 | */ |
||
36 | const TABLE_MAP = '\\xbanners\\models\\Map\\BannersI18nTableMap'; |
||
37 | |||
38 | |||
39 | /** |
||
40 | * attribute to determine if this object has previously been saved. |
||
41 | * @var boolean |
||
42 | */ |
||
43 | protected $new = true; |
||
44 | |||
45 | /** |
||
46 | * attribute to determine whether this object has been deleted. |
||
47 | * @var boolean |
||
48 | */ |
||
49 | protected $deleted = false; |
||
50 | |||
51 | /** |
||
52 | * The columns that have been modified in current object. |
||
53 | * Tracking modified columns allows us to only update modified columns. |
||
54 | * @var array |
||
55 | */ |
||
56 | protected $modifiedColumns = array(); |
||
57 | |||
58 | /** |
||
59 | * The (virtual) columns that are added at runtime |
||
60 | * The formatters can add supplementary columns based on a resultset |
||
61 | * @var array |
||
62 | */ |
||
63 | protected $virtualColumns = array(); |
||
64 | |||
65 | /** |
||
66 | * The value for the id field. |
||
67 | * |
||
68 | * @var int |
||
69 | */ |
||
70 | protected $id; |
||
71 | |||
72 | /** |
||
73 | * The value for the locale field. |
||
74 | * |
||
75 | * Note: this column has a database default value of: 'ru' |
||
76 | * @var string |
||
77 | */ |
||
78 | protected $locale; |
||
79 | |||
80 | /** |
||
81 | * The value for the name field. |
||
82 | * |
||
83 | * @var string |
||
84 | */ |
||
85 | protected $name; |
||
86 | |||
87 | /** |
||
88 | * @var ChildBanners |
||
89 | */ |
||
90 | protected $aBanners; |
||
91 | |||
92 | /** |
||
93 | * Flag to prevent endless save loop, if this object is referenced |
||
94 | * by another object which falls in this transaction. |
||
95 | * |
||
96 | * @var boolean |
||
97 | */ |
||
98 | protected $alreadyInSave = false; |
||
99 | |||
100 | /** |
||
101 | * Applies default values to this object. |
||
102 | * This method should be called from the object's constructor (or |
||
103 | * equivalent initialization method). |
||
104 | * @see __construct() |
||
105 | */ |
||
106 | public function applyDefaultValues() |
||
107 | { |
||
108 | $this->locale = 'ru'; |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Initializes internal state of xbanners\models\Base\BannersI18n object. |
||
113 | * @see applyDefaults() |
||
114 | */ |
||
115 | public function __construct() |
||
116 | { |
||
117 | $this->applyDefaultValues(); |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * Returns whether the object has been modified. |
||
122 | * |
||
123 | * @return boolean True if the object has been modified. |
||
124 | */ |
||
125 | public function isModified() |
||
126 | { |
||
127 | return !!$this->modifiedColumns; |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * Has specified column been modified? |
||
132 | * |
||
133 | * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID |
||
134 | * @return boolean True if $col has been modified. |
||
135 | */ |
||
136 | public function isColumnModified($col) |
||
137 | { |
||
138 | return $this->modifiedColumns && isset($this->modifiedColumns[$col]); |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Get the columns that have been modified in this object. |
||
143 | * @return array A unique list of the modified column names for this object. |
||
144 | */ |
||
145 | public function getModifiedColumns() |
||
146 | { |
||
147 | return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * Returns whether the object has ever been saved. This will |
||
152 | * be false, if the object was retrieved from storage or was created |
||
153 | * and then saved. |
||
154 | * |
||
155 | * @return boolean true, if the object has never been persisted. |
||
156 | */ |
||
157 | public function isNew() |
||
158 | { |
||
159 | return $this->new; |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * Setter for the isNew attribute. This method will be called |
||
164 | * by Propel-generated children and objects. |
||
165 | * |
||
166 | * @param boolean $b the state of the object. |
||
167 | */ |
||
168 | public function setNew($b) |
||
169 | { |
||
170 | $this->new = (boolean) $b; |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * Whether this object has been deleted. |
||
175 | * @return boolean The deleted state of this object. |
||
176 | */ |
||
177 | public function isDeleted() |
||
178 | { |
||
179 | return $this->deleted; |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * Specify whether this object has been deleted. |
||
184 | * @param boolean $b The deleted state of this object. |
||
185 | * @return void |
||
186 | */ |
||
187 | public function setDeleted($b) |
||
188 | { |
||
189 | $this->deleted = (boolean) $b; |
||
190 | } |
||
191 | |||
192 | /** |
||
193 | * Sets the modified state for the object to be false. |
||
194 | * @param string $col If supplied, only the specified column is reset. |
||
195 | * @return void |
||
196 | */ |
||
197 | View Code Duplication | public function resetModified($col = null) |
|
198 | { |
||
199 | if (null !== $col) { |
||
200 | if (isset($this->modifiedColumns[$col])) { |
||
201 | unset($this->modifiedColumns[$col]); |
||
202 | } |
||
203 | } else { |
||
204 | $this->modifiedColumns = array(); |
||
205 | } |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * Compares this with another <code>BannersI18n</code> instance. If |
||
210 | * <code>obj</code> is an instance of <code>BannersI18n</code>, delegates to |
||
211 | * <code>equals(BannersI18n)</code>. Otherwise, returns <code>false</code>. |
||
212 | * |
||
213 | * @param mixed $obj The object to compare to. |
||
214 | * @return boolean Whether equal to the object specified. |
||
215 | */ |
||
216 | View Code Duplication | public function equals($obj) |
|
217 | { |
||
218 | if (!$obj instanceof static) { |
||
219 | return false; |
||
220 | } |
||
221 | |||
222 | if ($this === $obj) { |
||
223 | return true; |
||
224 | } |
||
225 | |||
226 | if (null === $this->getPrimaryKey() || null === $obj->getPrimaryKey()) { |
||
227 | return false; |
||
228 | } |
||
229 | |||
230 | return $this->getPrimaryKey() === $obj->getPrimaryKey(); |
||
231 | } |
||
232 | |||
233 | /** |
||
234 | * Get the associative array of the virtual columns in this object |
||
235 | * |
||
236 | * @return array |
||
237 | */ |
||
238 | public function getVirtualColumns() |
||
239 | { |
||
240 | return $this->virtualColumns; |
||
241 | } |
||
242 | |||
243 | /** |
||
244 | * Checks the existence of a virtual column in this object |
||
245 | * |
||
246 | * @param string $name The virtual column name |
||
247 | * @return boolean |
||
248 | */ |
||
249 | public function hasVirtualColumn($name) |
||
250 | { |
||
251 | return array_key_exists($name, $this->virtualColumns); |
||
252 | } |
||
253 | |||
254 | /** |
||
255 | * Get the value of a virtual column in this object |
||
256 | * |
||
257 | * @param string $name The virtual column name |
||
258 | * @return mixed |
||
259 | * |
||
260 | * @throws PropelException |
||
261 | */ |
||
262 | View Code Duplication | public function getVirtualColumn($name) |
|
263 | { |
||
264 | if (!$this->hasVirtualColumn($name)) { |
||
265 | throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); |
||
266 | } |
||
267 | |||
268 | return $this->virtualColumns[$name]; |
||
269 | } |
||
270 | |||
271 | /** |
||
272 | * Set the value of a virtual column in this object |
||
273 | * |
||
274 | * @param string $name The virtual column name |
||
275 | * @param mixed $value The value to give to the virtual column |
||
276 | * |
||
277 | * @return $this|BannersI18n The current object, for fluid interface |
||
278 | */ |
||
279 | public function setVirtualColumn($name, $value) |
||
280 | { |
||
281 | $this->virtualColumns[$name] = $value; |
||
282 | |||
283 | return $this; |
||
284 | } |
||
285 | |||
286 | /** |
||
287 | * Logs a message using Propel::log(). |
||
288 | * |
||
289 | * @param string $msg |
||
290 | * @param int $priority One of the Propel::LOG_* logging levels |
||
291 | * @return boolean |
||
292 | */ |
||
293 | protected function log($msg, $priority = Propel::LOG_INFO) |
||
294 | { |
||
295 | return Propel::log(get_class($this) . ': ' . $msg, $priority); |
||
296 | } |
||
297 | |||
298 | /** |
||
299 | * Export the current object properties to a string, using a given parser format |
||
300 | * <code> |
||
301 | * $book = BookQuery::create()->findPk(9012); |
||
302 | * echo $book->exportTo('JSON'); |
||
303 | * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); |
||
304 | * </code> |
||
305 | * |
||
306 | * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') |
||
307 | * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. |
||
308 | * @return string The exported data |
||
309 | */ |
||
310 | View Code Duplication | public function exportTo($parser, $includeLazyLoadColumns = true) |
|
311 | { |
||
312 | if (!$parser instanceof AbstractParser) { |
||
313 | $parser = AbstractParser::getParser($parser); |
||
314 | } |
||
315 | |||
316 | return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); |
||
317 | } |
||
318 | |||
319 | /** |
||
320 | * Clean up internal collections prior to serializing |
||
321 | * Avoids recursive loops that turn into segmentation faults when serializing |
||
322 | */ |
||
323 | View Code Duplication | public function __sleep() |
|
324 | { |
||
325 | $this->clearAllReferences(); |
||
326 | |||
327 | $cls = new \ReflectionClass($this); |
||
328 | $propertyNames = []; |
||
329 | $serializableProperties = array_diff($cls->getProperties(), $cls->getProperties(\ReflectionProperty::IS_STATIC)); |
||
330 | |||
331 | foreach($serializableProperties as $property) { |
||
332 | $propertyNames[] = $property->getName(); |
||
333 | } |
||
334 | |||
335 | return $propertyNames; |
||
336 | } |
||
337 | |||
338 | /** |
||
339 | * Get the [id] column value. |
||
340 | * |
||
341 | * @return int |
||
342 | */ |
||
343 | public function getId() |
||
344 | { |
||
345 | return $this->id; |
||
346 | } |
||
347 | |||
348 | /** |
||
349 | * Get the [locale] column value. |
||
350 | * |
||
351 | * @return string |
||
352 | */ |
||
353 | public function getLocale() |
||
354 | { |
||
355 | return $this->locale; |
||
356 | } |
||
357 | |||
358 | /** |
||
359 | * Get the [name] column value. |
||
360 | * |
||
361 | * @return string |
||
362 | */ |
||
363 | public function getName() |
||
364 | { |
||
365 | return $this->name; |
||
366 | } |
||
367 | |||
368 | /** |
||
369 | * Set the value of [id] column. |
||
370 | * |
||
371 | * @param int $v new value |
||
372 | * @return $this|\xbanners\models\BannersI18n The current object (for fluent API support) |
||
373 | */ |
||
374 | View Code Duplication | public function setId($v) |
|
375 | { |
||
376 | if ($v !== null) { |
||
377 | $v = (int) $v; |
||
378 | } |
||
379 | |||
380 | if ($this->id !== $v) { |
||
381 | $this->id = $v; |
||
382 | $this->modifiedColumns[BannersI18nTableMap::COL_ID] = true; |
||
383 | } |
||
384 | |||
385 | if ($this->aBanners !== null && $this->aBanners->getId() !== $v) { |
||
386 | $this->aBanners = null; |
||
387 | } |
||
388 | |||
389 | return $this; |
||
390 | } // setId() |
||
391 | |||
392 | /** |
||
393 | * Set the value of [locale] column. |
||
394 | * |
||
395 | * @param string $v new value |
||
396 | * @return $this|\xbanners\models\BannersI18n The current object (for fluent API support) |
||
397 | */ |
||
398 | View Code Duplication | public function setLocale($v) |
|
399 | { |
||
400 | if ($v !== null) { |
||
401 | $v = (string) $v; |
||
402 | } |
||
403 | |||
404 | if ($this->locale !== $v) { |
||
405 | $this->locale = $v; |
||
406 | $this->modifiedColumns[BannersI18nTableMap::COL_LOCALE] = true; |
||
407 | } |
||
408 | |||
409 | return $this; |
||
410 | } // setLocale() |
||
411 | |||
412 | /** |
||
413 | * Set the value of [name] column. |
||
414 | * |
||
415 | * @param string $v new value |
||
416 | * @return $this|\xbanners\models\BannersI18n The current object (for fluent API support) |
||
417 | */ |
||
418 | public function setName($v) |
||
419 | { |
||
420 | if ($v !== null) { |
||
421 | $v = (string) $v; |
||
422 | } |
||
423 | |||
424 | if ($this->name !== $v) { |
||
425 | $this->name = $v; |
||
426 | $this->modifiedColumns[BannersI18nTableMap::COL_NAME] = true; |
||
427 | } |
||
428 | |||
429 | return $this; |
||
430 | } // setName() |
||
431 | |||
432 | /** |
||
433 | * Indicates whether the columns in this object are only set to default values. |
||
434 | * |
||
435 | * This method can be used in conjunction with isModified() to indicate whether an object is both |
||
436 | * modified _and_ has some values set which are non-default. |
||
437 | * |
||
438 | * @return boolean Whether the columns in this object are only been set with default values. |
||
439 | */ |
||
440 | public function hasOnlyDefaultValues() |
||
441 | { |
||
442 | if ($this->locale !== 'ru') { |
||
443 | return false; |
||
444 | } |
||
445 | |||
446 | // otherwise, everything was equal, so return TRUE |
||
447 | return true; |
||
448 | } // hasOnlyDefaultValues() |
||
449 | |||
450 | /** |
||
451 | * Hydrates (populates) the object variables with values from the database resultset. |
||
452 | * |
||
453 | * An offset (0-based "start column") is specified so that objects can be hydrated |
||
454 | * with a subset of the columns in the resultset rows. This is needed, for example, |
||
455 | * for results of JOIN queries where the resultset row includes columns from two or |
||
456 | * more tables. |
||
457 | * |
||
458 | * @param array $row The row returned by DataFetcher->fetch(). |
||
459 | * @param int $startcol 0-based offset column which indicates which restultset column to start with. |
||
460 | * @param boolean $rehydrate Whether this object is being re-hydrated from the database. |
||
461 | * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). |
||
462 | One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
463 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
464 | * |
||
465 | * @return int next starting column |
||
466 | * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. |
||
467 | */ |
||
468 | public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) |
||
469 | { |
||
470 | try { |
||
471 | |||
472 | $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : BannersI18nTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; |
||
473 | $this->id = (null !== $col) ? (int) $col : null; |
||
474 | |||
475 | $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : BannersI18nTableMap::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)]; |
||
476 | $this->locale = (null !== $col) ? (string) $col : null; |
||
477 | |||
478 | $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : BannersI18nTableMap::translateFieldName('Name', TableMap::TYPE_PHPNAME, $indexType)]; |
||
479 | $this->name = (null !== $col) ? (string) $col : null; |
||
480 | $this->resetModified(); |
||
481 | |||
482 | $this->setNew(false); |
||
483 | |||
484 | if ($rehydrate) { |
||
485 | $this->ensureConsistency(); |
||
486 | } |
||
487 | |||
488 | return $startcol + 3; // 3 = BannersI18nTableMap::NUM_HYDRATE_COLUMNS. |
||
489 | |||
490 | } catch (Exception $e) { |
||
491 | throw new PropelException(sprintf('Error populating %s object', '\\xbanners\\models\\BannersI18n'), 0, $e); |
||
492 | } |
||
493 | } |
||
494 | |||
495 | /** |
||
496 | * Checks and repairs the internal consistency of the object. |
||
497 | * |
||
498 | * This method is executed after an already-instantiated object is re-hydrated |
||
499 | * from the database. It exists to check any foreign keys to make sure that |
||
500 | * the objects related to the current object are correct based on foreign key. |
||
501 | * |
||
502 | * You can override this method in the stub class, but you should always invoke |
||
503 | * the base method from the overridden method (i.e. parent::ensureConsistency()), |
||
504 | * in case your model changes. |
||
505 | * |
||
506 | * @throws PropelException |
||
507 | */ |
||
508 | public function ensureConsistency() |
||
509 | { |
||
510 | if ($this->aBanners !== null && $this->id !== $this->aBanners->getId()) { |
||
511 | $this->aBanners = null; |
||
512 | } |
||
513 | } // ensureConsistency |
||
514 | |||
515 | /** |
||
516 | * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. |
||
517 | * |
||
518 | * This will only work if the object has been saved and has a valid primary key set. |
||
519 | * |
||
520 | * @param boolean $deep (optional) Whether to also de-associated any related objects. |
||
521 | * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. |
||
522 | * @return void |
||
523 | * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db |
||
524 | */ |
||
525 | View Code Duplication | public function reload($deep = false, ConnectionInterface $con = null) |
|
526 | { |
||
527 | if ($this->isDeleted()) { |
||
528 | throw new PropelException("Cannot reload a deleted object."); |
||
529 | } |
||
530 | |||
531 | if ($this->isNew()) { |
||
532 | throw new PropelException("Cannot reload an unsaved object."); |
||
533 | } |
||
534 | |||
535 | if ($con === null) { |
||
536 | $con = Propel::getServiceContainer()->getReadConnection(BannersI18nTableMap::DATABASE_NAME); |
||
537 | } |
||
538 | |||
539 | // We don't need to alter the object instance pool; we're just modifying this instance |
||
540 | // already in the pool. |
||
541 | |||
542 | $dataFetcher = ChildBannersI18nQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); |
||
0 ignored issues
–
show
|
|||
543 | $row = $dataFetcher->fetch(); |
||
544 | $dataFetcher->close(); |
||
545 | if (!$row) { |
||
546 | throw new PropelException('Cannot find matching row in the database to reload object values.'); |
||
547 | } |
||
548 | $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate |
||
549 | |||
550 | if ($deep) { // also de-associate any related objects? |
||
551 | |||
552 | $this->aBanners = null; |
||
553 | } // if (deep) |
||
554 | } |
||
555 | |||
556 | /** |
||
557 | * Removes this object from datastore and sets delete attribute. |
||
558 | * |
||
559 | * @param ConnectionInterface $con |
||
560 | * @return void |
||
561 | * @throws PropelException |
||
562 | * @see BannersI18n::setDeleted() |
||
563 | * @see BannersI18n::isDeleted() |
||
564 | */ |
||
565 | View Code Duplication | public function delete(ConnectionInterface $con = null) |
|
566 | { |
||
567 | if ($this->isDeleted()) { |
||
568 | throw new PropelException("This object has already been deleted."); |
||
569 | } |
||
570 | |||
571 | if ($con === null) { |
||
572 | $con = Propel::getServiceContainer()->getWriteConnection(BannersI18nTableMap::DATABASE_NAME); |
||
573 | } |
||
574 | |||
575 | $con->transaction(function () use ($con) { |
||
576 | $deleteQuery = ChildBannersI18nQuery::create() |
||
577 | ->filterByPrimaryKey($this->getPrimaryKey()); |
||
578 | $ret = $this->preDelete($con); |
||
579 | if ($ret) { |
||
580 | $deleteQuery->delete($con); |
||
581 | $this->postDelete($con); |
||
582 | $this->setDeleted(true); |
||
583 | } |
||
584 | }); |
||
585 | } |
||
586 | |||
587 | /** |
||
588 | * Persists this object to the database. |
||
589 | * |
||
590 | * If the object is new, it inserts it; otherwise an update is performed. |
||
591 | * All modified related objects will also be persisted in the doSave() |
||
592 | * method. This method wraps all precipitate database operations in a |
||
593 | * single transaction. |
||
594 | * |
||
595 | * @param ConnectionInterface $con |
||
596 | * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. |
||
597 | * @throws PropelException |
||
598 | * @see doSave() |
||
599 | */ |
||
600 | View Code Duplication | public function save(ConnectionInterface $con = null) |
|
601 | { |
||
602 | if ($this->isDeleted()) { |
||
603 | throw new PropelException("You cannot save an object that has been deleted."); |
||
604 | } |
||
605 | |||
606 | if ($con === null) { |
||
607 | $con = Propel::getServiceContainer()->getWriteConnection(BannersI18nTableMap::DATABASE_NAME); |
||
608 | } |
||
609 | |||
610 | return $con->transaction(function () use ($con) { |
||
611 | $ret = $this->preSave($con); |
||
612 | $isInsert = $this->isNew(); |
||
613 | if ($isInsert) { |
||
614 | $ret = $ret && $this->preInsert($con); |
||
615 | } else { |
||
616 | $ret = $ret && $this->preUpdate($con); |
||
617 | } |
||
618 | if ($ret) { |
||
619 | $affectedRows = $this->doSave($con); |
||
620 | if ($isInsert) { |
||
621 | $this->postInsert($con); |
||
622 | } else { |
||
623 | $this->postUpdate($con); |
||
624 | } |
||
625 | $this->postSave($con); |
||
626 | BannersI18nTableMap::addInstanceToPool($this); |
||
627 | } else { |
||
628 | $affectedRows = 0; |
||
629 | } |
||
630 | |||
631 | return $affectedRows; |
||
632 | }); |
||
633 | } |
||
634 | |||
635 | /** |
||
636 | * Performs the work of inserting or updating the row in the database. |
||
637 | * |
||
638 | * If the object is new, it inserts it; otherwise an update is performed. |
||
639 | * All related objects are also updated in this method. |
||
640 | * |
||
641 | * @param ConnectionInterface $con |
||
642 | * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. |
||
643 | * @throws PropelException |
||
644 | * @see save() |
||
645 | */ |
||
646 | View Code Duplication | protected function doSave(ConnectionInterface $con) |
|
647 | { |
||
648 | $affectedRows = 0; // initialize var to track total num of affected rows |
||
649 | if (!$this->alreadyInSave) { |
||
650 | $this->alreadyInSave = true; |
||
651 | |||
652 | // We call the save method on the following object(s) if they |
||
653 | // were passed to this object by their corresponding set |
||
654 | // method. This object relates to these object(s) by a |
||
655 | // foreign key reference. |
||
656 | |||
657 | if ($this->aBanners !== null) { |
||
658 | if ($this->aBanners->isModified() || $this->aBanners->isNew()) { |
||
659 | $affectedRows += $this->aBanners->save($con); |
||
660 | } |
||
661 | $this->setBanners($this->aBanners); |
||
662 | } |
||
663 | |||
664 | if ($this->isNew() || $this->isModified()) { |
||
665 | // persist changes |
||
666 | if ($this->isNew()) { |
||
667 | $this->doInsert($con); |
||
668 | $affectedRows += 1; |
||
669 | } else { |
||
670 | $affectedRows += $this->doUpdate($con); |
||
671 | } |
||
672 | $this->resetModified(); |
||
673 | } |
||
674 | |||
675 | $this->alreadyInSave = false; |
||
676 | |||
677 | } |
||
678 | |||
679 | return $affectedRows; |
||
680 | } // doSave() |
||
681 | |||
682 | /** |
||
683 | * Insert the row in the database. |
||
684 | * |
||
685 | * @param ConnectionInterface $con |
||
686 | * |
||
687 | * @throws PropelException |
||
688 | * @see doSave() |
||
689 | */ |
||
690 | protected function doInsert(ConnectionInterface $con) |
||
691 | { |
||
692 | $modifiedColumns = array(); |
||
693 | $index = 0; |
||
694 | |||
695 | |||
696 | // check the columns in natural order for more readable SQL queries |
||
697 | if ($this->isColumnModified(BannersI18nTableMap::COL_ID)) { |
||
698 | $modifiedColumns[':p' . $index++] = 'id'; |
||
699 | } |
||
700 | if ($this->isColumnModified(BannersI18nTableMap::COL_LOCALE)) { |
||
701 | $modifiedColumns[':p' . $index++] = 'locale'; |
||
702 | } |
||
703 | if ($this->isColumnModified(BannersI18nTableMap::COL_NAME)) { |
||
704 | $modifiedColumns[':p' . $index++] = 'name'; |
||
705 | } |
||
706 | |||
707 | $sql = sprintf( |
||
708 | 'INSERT INTO banners_i18n (%s) VALUES (%s)', |
||
709 | implode(', ', $modifiedColumns), |
||
710 | implode(', ', array_keys($modifiedColumns)) |
||
711 | ); |
||
712 | |||
713 | try { |
||
714 | $stmt = $con->prepare($sql); |
||
715 | foreach ($modifiedColumns as $identifier => $columnName) { |
||
716 | switch ($columnName) { |
||
717 | case 'id': |
||
718 | $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); |
||
719 | break; |
||
720 | case 'locale': |
||
721 | $stmt->bindValue($identifier, $this->locale, PDO::PARAM_STR); |
||
722 | break; |
||
723 | case 'name': |
||
724 | $stmt->bindValue($identifier, $this->name, PDO::PARAM_STR); |
||
725 | break; |
||
726 | } |
||
727 | } |
||
728 | $stmt->execute(); |
||
729 | } catch (Exception $e) { |
||
730 | Propel::log($e->getMessage(), Propel::LOG_ERR); |
||
731 | throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); |
||
732 | } |
||
733 | |||
734 | $this->setNew(false); |
||
735 | } |
||
736 | |||
737 | /** |
||
738 | * Update the row in the database. |
||
739 | * |
||
740 | * @param ConnectionInterface $con |
||
741 | * |
||
742 | * @return Integer Number of updated rows |
||
743 | * @see doSave() |
||
744 | */ |
||
745 | protected function doUpdate(ConnectionInterface $con) |
||
746 | { |
||
747 | $selectCriteria = $this->buildPkeyCriteria(); |
||
748 | $valuesCriteria = $this->buildCriteria(); |
||
749 | |||
750 | return $selectCriteria->doUpdate($valuesCriteria, $con); |
||
751 | } |
||
752 | |||
753 | /** |
||
754 | * Retrieves a field from the object by name passed in as a string. |
||
755 | * |
||
756 | * @param string $name name |
||
757 | * @param string $type The type of fieldname the $name is of: |
||
758 | * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
759 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
760 | * Defaults to TableMap::TYPE_PHPNAME. |
||
761 | * @return mixed Value of field. |
||
762 | */ |
||
763 | View Code Duplication | public function getByName($name, $type = TableMap::TYPE_PHPNAME) |
|
764 | { |
||
765 | $pos = BannersI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); |
||
766 | $field = $this->getByPosition($pos); |
||
767 | |||
768 | return $field; |
||
769 | } |
||
770 | |||
771 | /** |
||
772 | * Retrieves a field from the object by Position as specified in the xml schema. |
||
773 | * Zero-based. |
||
774 | * |
||
775 | * @param int $pos position in xml schema |
||
776 | * @return mixed Value of field at $pos |
||
777 | */ |
||
778 | public function getByPosition($pos) |
||
779 | { |
||
780 | switch ($pos) { |
||
781 | case 0: |
||
782 | return $this->getId(); |
||
783 | break; |
||
784 | case 1: |
||
785 | return $this->getLocale(); |
||
786 | break; |
||
787 | case 2: |
||
788 | return $this->getName(); |
||
789 | break; |
||
790 | default: |
||
791 | return null; |
||
792 | break; |
||
793 | } // switch() |
||
794 | } |
||
795 | |||
796 | /** |
||
797 | * Exports the object as an array. |
||
798 | * |
||
799 | * You can specify the key type of the array by passing one of the class |
||
800 | * type constants. |
||
801 | * |
||
802 | * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
803 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
804 | * Defaults to TableMap::TYPE_PHPNAME. |
||
805 | * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. |
||
806 | * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion |
||
807 | * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. |
||
808 | * |
||
809 | * @return array an associative array containing the field names (as keys) and field values |
||
810 | */ |
||
811 | public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) |
||
812 | { |
||
813 | |||
814 | if (isset($alreadyDumpedObjects['BannersI18n'][$this->hashCode()])) { |
||
815 | return '*RECURSION*'; |
||
816 | } |
||
817 | $alreadyDumpedObjects['BannersI18n'][$this->hashCode()] = true; |
||
818 | $keys = BannersI18nTableMap::getFieldNames($keyType); |
||
819 | $result = array( |
||
820 | $keys[0] => $this->getId(), |
||
821 | $keys[1] => $this->getLocale(), |
||
822 | $keys[2] => $this->getName(), |
||
823 | ); |
||
824 | $virtualColumns = $this->virtualColumns; |
||
825 | foreach ($virtualColumns as $key => $virtualColumn) { |
||
826 | $result[$key] = $virtualColumn; |
||
827 | } |
||
828 | |||
829 | if ($includeForeignObjects) { |
||
830 | if (null !== $this->aBanners) { |
||
831 | |||
832 | switch ($keyType) { |
||
833 | case TableMap::TYPE_CAMELNAME: |
||
834 | $key = 'banners'; |
||
835 | break; |
||
836 | case TableMap::TYPE_FIELDNAME: |
||
837 | $key = 'banners'; |
||
838 | break; |
||
839 | default: |
||
840 | $key = 'Banners'; |
||
841 | } |
||
842 | |||
843 | $result[$key] = $this->aBanners->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); |
||
844 | } |
||
845 | } |
||
846 | |||
847 | return $result; |
||
848 | } |
||
849 | |||
850 | /** |
||
851 | * Sets a field from the object by name passed in as a string. |
||
852 | * |
||
853 | * @param string $name |
||
854 | * @param mixed $value field value |
||
855 | * @param string $type The type of fieldname the $name is of: |
||
856 | * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
857 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
858 | * Defaults to TableMap::TYPE_PHPNAME. |
||
859 | * @return $this|\xbanners\models\BannersI18n |
||
860 | */ |
||
861 | public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) |
||
862 | { |
||
863 | $pos = BannersI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); |
||
864 | |||
865 | return $this->setByPosition($pos, $value); |
||
866 | } |
||
867 | |||
868 | /** |
||
869 | * Sets a field from the object by Position as specified in the xml schema. |
||
870 | * Zero-based. |
||
871 | * |
||
872 | * @param int $pos position in xml schema |
||
873 | * @param mixed $value field value |
||
874 | * @return $this|\xbanners\models\BannersI18n |
||
875 | */ |
||
876 | public function setByPosition($pos, $value) |
||
877 | { |
||
878 | switch ($pos) { |
||
879 | case 0: |
||
880 | $this->setId($value); |
||
881 | break; |
||
882 | case 1: |
||
883 | $this->setLocale($value); |
||
884 | break; |
||
885 | case 2: |
||
886 | $this->setName($value); |
||
887 | break; |
||
888 | } // switch() |
||
889 | |||
890 | return $this; |
||
891 | } |
||
892 | |||
893 | /** |
||
894 | * Populates the object using an array. |
||
895 | * |
||
896 | * This is particularly useful when populating an object from one of the |
||
897 | * request arrays (e.g. $_POST). This method goes through the column |
||
898 | * names, checking to see whether a matching key exists in populated |
||
899 | * array. If so the setByName() method is called for that column. |
||
900 | * |
||
901 | * You can specify the key type of the array by additionally passing one |
||
902 | * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
903 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
904 | * The default key type is the column's TableMap::TYPE_PHPNAME. |
||
905 | * |
||
906 | * @param array $arr An array to populate the object from. |
||
907 | * @param string $keyType The type of keys the array uses. |
||
908 | * @return void |
||
909 | */ |
||
910 | public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) |
||
911 | { |
||
912 | $keys = BannersI18nTableMap::getFieldNames($keyType); |
||
913 | |||
914 | if (array_key_exists($keys[0], $arr)) { |
||
915 | $this->setId($arr[$keys[0]]); |
||
916 | } |
||
917 | if (array_key_exists($keys[1], $arr)) { |
||
918 | $this->setLocale($arr[$keys[1]]); |
||
919 | } |
||
920 | if (array_key_exists($keys[2], $arr)) { |
||
921 | $this->setName($arr[$keys[2]]); |
||
922 | } |
||
923 | } |
||
924 | |||
925 | /** |
||
926 | * Populate the current object from a string, using a given parser format |
||
927 | * <code> |
||
928 | * $book = new Book(); |
||
929 | * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); |
||
930 | * </code> |
||
931 | * |
||
932 | * You can specify the key type of the array by additionally passing one |
||
933 | * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
934 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
935 | * The default key type is the column's TableMap::TYPE_PHPNAME. |
||
936 | * |
||
937 | * @param mixed $parser A AbstractParser instance, |
||
938 | * or a format name ('XML', 'YAML', 'JSON', 'CSV') |
||
939 | * @param string $data The source data to import from |
||
940 | * @param string $keyType The type of keys the array uses. |
||
941 | * |
||
942 | * @return $this|\xbanners\models\BannersI18n The current object, for fluid interface |
||
943 | */ |
||
944 | View Code Duplication | public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME) |
|
945 | { |
||
946 | if (!$parser instanceof AbstractParser) { |
||
947 | $parser = AbstractParser::getParser($parser); |
||
948 | } |
||
949 | |||
950 | $this->fromArray($parser->toArray($data), $keyType); |
||
951 | |||
952 | return $this; |
||
953 | } |
||
954 | |||
955 | /** |
||
956 | * Build a Criteria object containing the values of all modified columns in this object. |
||
957 | * |
||
958 | * @return Criteria The Criteria object containing all modified values. |
||
959 | */ |
||
960 | public function buildCriteria() |
||
961 | { |
||
962 | $criteria = new Criteria(BannersI18nTableMap::DATABASE_NAME); |
||
963 | |||
964 | if ($this->isColumnModified(BannersI18nTableMap::COL_ID)) { |
||
965 | $criteria->add(BannersI18nTableMap::COL_ID, $this->id); |
||
966 | } |
||
967 | if ($this->isColumnModified(BannersI18nTableMap::COL_LOCALE)) { |
||
968 | $criteria->add(BannersI18nTableMap::COL_LOCALE, $this->locale); |
||
969 | } |
||
970 | if ($this->isColumnModified(BannersI18nTableMap::COL_NAME)) { |
||
971 | $criteria->add(BannersI18nTableMap::COL_NAME, $this->name); |
||
972 | } |
||
973 | |||
974 | return $criteria; |
||
975 | } |
||
976 | |||
977 | /** |
||
978 | * Builds a Criteria object containing the primary key for this object. |
||
979 | * |
||
980 | * Unlike buildCriteria() this method includes the primary key values regardless |
||
981 | * of whether or not they have been modified. |
||
982 | * |
||
983 | * @throws LogicException if no primary key is defined |
||
984 | * |
||
985 | * @return Criteria The Criteria object containing value(s) for primary key(s). |
||
986 | */ |
||
987 | public function buildPkeyCriteria() |
||
988 | { |
||
989 | $criteria = ChildBannersI18nQuery::create(); |
||
990 | $criteria->add(BannersI18nTableMap::COL_ID, $this->id); |
||
991 | $criteria->add(BannersI18nTableMap::COL_LOCALE, $this->locale); |
||
992 | |||
993 | return $criteria; |
||
994 | } |
||
995 | |||
996 | /** |
||
997 | * If the primary key is not null, return the hashcode of the |
||
998 | * primary key. Otherwise, return the hash code of the object. |
||
999 | * |
||
1000 | * @return int Hashcode |
||
1001 | */ |
||
1002 | View Code Duplication | public function hashCode() |
|
1003 | { |
||
1004 | $validPk = null !== $this->getId() && |
||
1005 | null !== $this->getLocale(); |
||
1006 | |||
1007 | $validPrimaryKeyFKs = 1; |
||
1008 | $primaryKeyFKs = []; |
||
1009 | |||
1010 | //relation banners_i18n_fk_c926a5 to table banners |
||
1011 | if ($this->aBanners && $hash = spl_object_hash($this->aBanners)) { |
||
1012 | $primaryKeyFKs[] = $hash; |
||
1013 | } else { |
||
1014 | $validPrimaryKeyFKs = false; |
||
1015 | } |
||
1016 | |||
1017 | if ($validPk) { |
||
1018 | return crc32(json_encode($this->getPrimaryKey(), JSON_UNESCAPED_UNICODE)); |
||
1019 | } elseif ($validPrimaryKeyFKs) { |
||
1020 | return crc32(json_encode($primaryKeyFKs, JSON_UNESCAPED_UNICODE)); |
||
1021 | } |
||
1022 | |||
1023 | return spl_object_hash($this); |
||
1024 | } |
||
1025 | |||
1026 | /** |
||
1027 | * Returns the composite primary key for this object. |
||
1028 | * The array elements will be in same order as specified in XML. |
||
1029 | * @return array |
||
1030 | */ |
||
1031 | View Code Duplication | public function getPrimaryKey() |
|
1032 | { |
||
1033 | $pks = array(); |
||
1034 | $pks[0] = $this->getId(); |
||
1035 | $pks[1] = $this->getLocale(); |
||
1036 | |||
1037 | return $pks; |
||
1038 | } |
||
1039 | |||
1040 | /** |
||
1041 | * Set the [composite] primary key. |
||
1042 | * |
||
1043 | * @param array $keys The elements of the composite key (order must match the order in XML file). |
||
1044 | * @return void |
||
1045 | */ |
||
1046 | public function setPrimaryKey($keys) |
||
1047 | { |
||
1048 | $this->setId($keys[0]); |
||
1049 | $this->setLocale($keys[1]); |
||
1050 | } |
||
1051 | |||
1052 | /** |
||
1053 | * Returns true if the primary key for this object is null. |
||
1054 | * @return boolean |
||
1055 | */ |
||
1056 | public function isPrimaryKeyNull() |
||
1057 | { |
||
1058 | return (null === $this->getId()) && (null === $this->getLocale()); |
||
1059 | } |
||
1060 | |||
1061 | /** |
||
1062 | * Sets contents of passed object to values from current object. |
||
1063 | * |
||
1064 | * If desired, this method can also make copies of all associated (fkey referrers) |
||
1065 | * objects. |
||
1066 | * |
||
1067 | * @param object $copyObj An object of \xbanners\models\BannersI18n (or compatible) type. |
||
1068 | * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. |
||
1069 | * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. |
||
1070 | * @throws PropelException |
||
1071 | */ |
||
1072 | public function copyInto($copyObj, $deepCopy = false, $makeNew = true) |
||
1073 | { |
||
1074 | $copyObj->setId($this->getId()); |
||
1075 | $copyObj->setLocale($this->getLocale()); |
||
1076 | $copyObj->setName($this->getName()); |
||
1077 | if ($makeNew) { |
||
1078 | $copyObj->setNew(true); |
||
1079 | } |
||
1080 | } |
||
1081 | |||
1082 | /** |
||
1083 | * Makes a copy of this object that will be inserted as a new row in table when saved. |
||
1084 | * It creates a new object filling in the simple attributes, but skipping any primary |
||
1085 | * keys that are defined for the table. |
||
1086 | * |
||
1087 | * If desired, this method can also make copies of all associated (fkey referrers) |
||
1088 | * objects. |
||
1089 | * |
||
1090 | * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. |
||
1091 | * @return \xbanners\models\BannersI18n Clone of current object. |
||
1092 | * @throws PropelException |
||
1093 | */ |
||
1094 | View Code Duplication | public function copy($deepCopy = false) |
|
1095 | { |
||
1096 | // we use get_class(), because this might be a subclass |
||
1097 | $clazz = get_class($this); |
||
1098 | $copyObj = new $clazz(); |
||
1099 | $this->copyInto($copyObj, $deepCopy); |
||
1100 | |||
1101 | return $copyObj; |
||
1102 | } |
||
1103 | |||
1104 | /** |
||
1105 | * Declares an association between this object and a ChildBanners object. |
||
1106 | * |
||
1107 | * @param ChildBanners $v |
||
1108 | * @return $this|\xbanners\models\BannersI18n The current object (for fluent API support) |
||
1109 | * @throws PropelException |
||
1110 | */ |
||
1111 | View Code Duplication | public function setBanners(ChildBanners $v = null) |
|
1112 | { |
||
1113 | if ($v === null) { |
||
1114 | $this->setId(NULL); |
||
1115 | } else { |
||
1116 | $this->setId($v->getId()); |
||
1117 | } |
||
1118 | |||
1119 | $this->aBanners = $v; |
||
1120 | |||
1121 | // Add binding for other direction of this n:n relationship. |
||
1122 | // If this object has already been added to the ChildBanners object, it will not be re-added. |
||
1123 | if ($v !== null) { |
||
1124 | $v->addBannersI18n($this); |
||
1125 | } |
||
1126 | |||
1127 | |||
1128 | return $this; |
||
1129 | } |
||
1130 | |||
1131 | |||
1132 | /** |
||
1133 | * Get the associated ChildBanners object |
||
1134 | * |
||
1135 | * @param ConnectionInterface $con Optional Connection object. |
||
1136 | * @return ChildBanners The associated ChildBanners object. |
||
1137 | * @throws PropelException |
||
1138 | */ |
||
1139 | View Code Duplication | public function getBanners(ConnectionInterface $con = null) |
|
1140 | { |
||
1141 | if ($this->aBanners === null && ($this->id !== null)) { |
||
1142 | $this->aBanners = ChildBannersQuery::create()->findPk($this->id, $con); |
||
1143 | /* The following can be used additionally to |
||
1144 | guarantee the related object contains a reference |
||
1145 | to this object. This level of coupling may, however, be |
||
1146 | undesirable since it could result in an only partially populated collection |
||
1147 | in the referenced object. |
||
1148 | $this->aBanners->addBannersI18ns($this); |
||
1149 | */ |
||
1150 | } |
||
1151 | |||
1152 | return $this->aBanners; |
||
1153 | } |
||
1154 | |||
1155 | /** |
||
1156 | * Clears the current object, sets all attributes to their default values and removes |
||
1157 | * outgoing references as well as back-references (from other objects to this one. Results probably in a database |
||
1158 | * change of those foreign objects when you call `save` there). |
||
1159 | */ |
||
1160 | public function clear() |
||
1161 | { |
||
1162 | if (null !== $this->aBanners) { |
||
1163 | $this->aBanners->removeBannersI18n($this); |
||
1164 | } |
||
1165 | $this->id = null; |
||
1166 | $this->locale = null; |
||
1167 | $this->name = null; |
||
1168 | $this->alreadyInSave = false; |
||
1169 | $this->clearAllReferences(); |
||
1170 | $this->applyDefaultValues(); |
||
1171 | $this->resetModified(); |
||
1172 | $this->setNew(true); |
||
1173 | $this->setDeleted(false); |
||
1174 | } |
||
1175 | |||
1176 | /** |
||
1177 | * Resets all references and back-references to other model objects or collections of model objects. |
||
1178 | * |
||
1179 | * This method is used to reset all php object references (not the actual reference in the database). |
||
1180 | * Necessary for object serialisation. |
||
1181 | * |
||
1182 | * @param boolean $deep Whether to also clear the references on all referrer objects. |
||
1183 | */ |
||
1184 | public function clearAllReferences($deep = false) |
||
1185 | { |
||
1186 | if ($deep) { |
||
1187 | } // if ($deep) |
||
1188 | |||
1189 | $this->aBanners = null; |
||
1190 | } |
||
1191 | |||
1192 | /** |
||
1193 | * Return the string representation of this object |
||
1194 | * |
||
1195 | * @return string |
||
1196 | */ |
||
1197 | public function __toString() |
||
1198 | { |
||
1199 | return (string) $this->exportTo(BannersI18nTableMap::DEFAULT_STRING_FORMAT); |
||
1200 | } |
||
1201 | |||
1202 | /** |
||
1203 | * Code to be run before persisting the object |
||
1204 | * @param ConnectionInterface $con |
||
1205 | * @return boolean |
||
1206 | */ |
||
1207 | public function preSave(ConnectionInterface $con = null) |
||
1208 | { |
||
1209 | if (is_callable('parent::preSave')) { |
||
1210 | return parent::preSave($con); |
||
1211 | } |
||
1212 | return true; |
||
1213 | } |
||
1214 | |||
1215 | /** |
||
1216 | * Code to be run after persisting the object |
||
1217 | * @param ConnectionInterface $con |
||
1218 | */ |
||
1219 | public function postSave(ConnectionInterface $con = null) |
||
1220 | { |
||
1221 | if (is_callable('parent::postSave')) { |
||
1222 | parent::postSave($con); |
||
1223 | } |
||
1224 | } |
||
1225 | |||
1226 | /** |
||
1227 | * Code to be run before inserting to database |
||
1228 | * @param ConnectionInterface $con |
||
1229 | * @return boolean |
||
1230 | */ |
||
1231 | public function preInsert(ConnectionInterface $con = null) |
||
1232 | { |
||
1233 | if (is_callable('parent::preInsert')) { |
||
1234 | return parent::preInsert($con); |
||
1235 | } |
||
1236 | return true; |
||
1237 | } |
||
1238 | |||
1239 | /** |
||
1240 | * Code to be run after inserting to database |
||
1241 | * @param ConnectionInterface $con |
||
1242 | */ |
||
1243 | public function postInsert(ConnectionInterface $con = null) |
||
1244 | { |
||
1245 | if (is_callable('parent::postInsert')) { |
||
1246 | parent::postInsert($con); |
||
1247 | } |
||
1248 | } |
||
1249 | |||
1250 | /** |
||
1251 | * Code to be run before updating the object in database |
||
1252 | * @param ConnectionInterface $con |
||
1253 | * @return boolean |
||
1254 | */ |
||
1255 | public function preUpdate(ConnectionInterface $con = null) |
||
1256 | { |
||
1257 | if (is_callable('parent::preUpdate')) { |
||
1258 | return parent::preUpdate($con); |
||
1259 | } |
||
1260 | return true; |
||
1261 | } |
||
1262 | |||
1263 | /** |
||
1264 | * Code to be run after updating the object in database |
||
1265 | * @param ConnectionInterface $con |
||
1266 | */ |
||
1267 | public function postUpdate(ConnectionInterface $con = null) |
||
1268 | { |
||
1269 | if (is_callable('parent::postUpdate')) { |
||
1270 | parent::postUpdate($con); |
||
1271 | } |
||
1272 | } |
||
1273 | |||
1274 | /** |
||
1275 | * Code to be run before deleting the object in database |
||
1276 | * @param ConnectionInterface $con |
||
1277 | * @return boolean |
||
1278 | */ |
||
1279 | public function preDelete(ConnectionInterface $con = null) |
||
1280 | { |
||
1281 | if (is_callable('parent::preDelete')) { |
||
1282 | return parent::preDelete($con); |
||
1283 | } |
||
1284 | return true; |
||
1285 | } |
||
1286 | |||
1287 | /** |
||
1288 | * Code to be run after deleting the object in database |
||
1289 | * @param ConnectionInterface $con |
||
1290 | */ |
||
1291 | public function postDelete(ConnectionInterface $con = null) |
||
1292 | { |
||
1293 | if (is_callable('parent::postDelete')) { |
||
1294 | parent::postDelete($con); |
||
1295 | } |
||
1296 | } |
||
1297 | |||
1298 | |||
1299 | /** |
||
1300 | * Derived method to catches calls to undefined methods. |
||
1301 | * |
||
1302 | * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). |
||
1303 | * Allows to define default __call() behavior if you overwrite __call() |
||
1304 | * |
||
1305 | * @param string $name |
||
1306 | * @param mixed $params |
||
1307 | * |
||
1308 | * @return array|string |
||
1309 | */ |
||
1310 | View Code Duplication | public function __call($name, $params) |
|
1311 | { |
||
1312 | if (0 === strpos($name, 'get')) { |
||
1313 | $virtualColumn = substr($name, 3); |
||
1314 | if ($this->hasVirtualColumn($virtualColumn)) { |
||
1315 | return $this->getVirtualColumn($virtualColumn); |
||
1316 | } |
||
1317 | |||
1318 | $virtualColumn = lcfirst($virtualColumn); |
||
1319 | if ($this->hasVirtualColumn($virtualColumn)) { |
||
1320 | return $this->getVirtualColumn($virtualColumn); |
||
1321 | } |
||
1322 | } |
||
1323 | |||
1324 | if (0 === strpos($name, 'from')) { |
||
1325 | $format = substr($name, 4); |
||
1326 | |||
1327 | return $this->importFrom($format, reset($params)); |
||
1328 | } |
||
1329 | |||
1330 | if (0 === strpos($name, 'to')) { |
||
1331 | $format = substr($name, 2); |
||
1332 | $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; |
||
1333 | |||
1334 | return $this->exportTo($format, $includeLazyLoadColumns); |
||
1335 | } |
||
1336 | |||
1337 | throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); |
||
1338 | } |
||
1339 | |||
1340 | } |
||
1341 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: