Completed
Push — development ( cfd391...deed4d )
by Andrij
12:03
created

BannersI18n::save()   D

Complexity

Conditions 9
Paths 4

Size

Total Lines 38
Code Lines 25

Duplication

Lines 38
Ratio 100 %

Importance

Changes 0
Metric Value
cc 9
eloc 25
nc 4
nop 1
dl 38
loc 38
rs 4.909
c 0
b 0
f 0
1
<?php
2
3
namespace xbanners\models\Base;
4
5
use \Exception;
6
use \PDO;
7
use CMSFactory\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;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before member var; 2 found
Loading history...
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
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
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
0 ignored issues
show
introduced by
If there is no return value for a function, there must not be a @return tag.
Loading history...
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
0 ignored issues
show
introduced by
If there is no return value for a function, there must not be a @return tag.
Loading history...
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.
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 3 found
Loading history...
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
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
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
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
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
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
276
     *
277
     * @return $this|BannersI18n The current object, for fluid interface
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
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
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
290
     * @param  int     $priority One of the Propel::LOG_* logging levels
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 5 found
Loading history...
291
     * @return boolean
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
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')
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 3 found
Loading history...
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));
0 ignored issues
show
Bug introduced by
It seems like $this->toArray(\Propel\R...Columns, array(), true) targeting xbanners\models\Base\BannersI18n::toArray() can also be of type string; however, Propel\Runtime\Parser\AbstractParser::fromArray() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
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) {
0 ignored issues
show
introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
Coding Style introduced by
Expected 1 space after FOREACH keyword; 0 found
Loading history...
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)
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
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)
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
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)
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
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') {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return !($this->locale !== 'ru');.
Loading history...
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().
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 3 found
Loading history...
459
     * @param int     $startcol  0-based offset column which indicates which restultset column to start with.
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 5 found
Loading history...
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().
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
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.
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
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
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
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
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
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
0 ignored issues
show
introduced by
If there is no return value for a function, there must not be a @return tag.
Loading history...
523
     * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
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
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Propel\Runtime\ActiveQuery\BaseModelCriteria as the method find() does only exist in the following sub-classes of Propel\Runtime\ActiveQuery\BaseModelCriteria: Propel\Runtime\ActiveQuery\ModelCriteria, core\models\Base\RouteQuery, core\models\RouteQuery, xbanners\models\BannerImageI18nQuery, xbanners\models\BannerImageQuery, xbanners\models\BannersI18nQuery, xbanners\models\BannersQuery, xbanners\models\Base\BannerImageI18nQuery, xbanners\models\Base\BannerImageQuery, xbanners\models\Base\BannersI18nQuery, xbanners\models\Base\BannersQuery. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

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

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
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?
0 ignored issues
show
introduced by
There should be no white space after an opening "{"
Loading history...
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
0 ignored issues
show
introduced by
If there is no return value for a function, there must not be a @return tag.
Loading history...
561
     * @throws PropelException
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
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
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
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 ($this->alreadyInSave) {
607
            return 0;
608
        }
609
610
        if ($con === null) {
611
            $con = Propel::getServiceContainer()->getWriteConnection(BannersI18nTableMap::DATABASE_NAME);
612
        }
613
614
        return $con->transaction(function () use ($con) {
615
            $ret = $this->preSave($con);
616
            $isInsert = $this->isNew();
617
            if ($isInsert) {
618
                $ret = $ret && $this->preInsert($con);
619
            } else {
620
                $ret = $ret && $this->preUpdate($con);
621
            }
622
            if ($ret) {
623
                $affectedRows = $this->doSave($con);
624
                if ($isInsert) {
625
                    $this->postInsert($con);
626
                } else {
627
                    $this->postUpdate($con);
628
                }
629
                $this->postSave($con);
630
                BannersI18nTableMap::addInstanceToPool($this);
0 ignored issues
show
Compatibility introduced by
$this of type object<xbanners\models\Base\BannersI18n> is not a sub-type of object<xbanners\models\BannersI18n>. It seems like you assume a child class of the class xbanners\models\Base\BannersI18n to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
631
            } else {
632
                $affectedRows = 0;
633
            }
634
635
            return $affectedRows;
636
        });
637
    }
638
639
    /**
640
     * Performs the work of inserting or updating the row in the database.
641
     *
642
     * If the object is new, it inserts it; otherwise an update is performed.
643
     * All related objects are also updated in this method.
644
     *
645
     * @param      ConnectionInterface $con
646
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
647
     * @throws PropelException
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
648
     * @see save()
649
     */
650 View Code Duplication
    protected function doSave(ConnectionInterface $con)
651
    {
652
        $affectedRows = 0; // initialize var to track total num of affected rows
653
        if (!$this->alreadyInSave) {
654
            $this->alreadyInSave = true;
655
656
            // We call the save method on the following object(s) if they
657
            // were passed to this object by their corresponding set
658
            // method.  This object relates to these object(s) by a
659
            // foreign key reference.
660
661
            if ($this->aBanners !== null) {
662
                if ($this->aBanners->isModified() || $this->aBanners->isNew()) {
663
                    $affectedRows += $this->aBanners->save($con);
664
                }
665
                $this->setBanners($this->aBanners);
666
            }
667
668
            if ($this->isNew() || $this->isModified()) {
669
                // persist changes
670
                if ($this->isNew()) {
671
                    $this->doInsert($con);
672
                    $affectedRows += 1;
673
                } else {
674
                    $affectedRows += $this->doUpdate($con);
675
                }
676
                $this->resetModified();
677
            }
678
679
            $this->alreadyInSave = false;
680
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
681
        }
682
683
        return $affectedRows;
684
    } // doSave()
685
686
    /**
687
     * Insert the row in the database.
688
     *
689
     * @param      ConnectionInterface $con
690
     *
691
     * @throws PropelException
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
692
     * @see doSave()
693
     */
694
    protected function doInsert(ConnectionInterface $con)
695
    {
696
        $modifiedColumns = array();
697
        $index = 0;
698
699
700
         // check the columns in natural order for more readable SQL queries
701
        if ($this->isColumnModified(BannersI18nTableMap::COL_ID)) {
702
            $modifiedColumns[':p' . $index++]  = 'id';
703
        }
704
        if ($this->isColumnModified(BannersI18nTableMap::COL_LOCALE)) {
705
            $modifiedColumns[':p' . $index++]  = 'locale';
706
        }
707
        if ($this->isColumnModified(BannersI18nTableMap::COL_NAME)) {
708
            $modifiedColumns[':p' . $index++]  = 'name';
709
        }
710
711
        $sql = sprintf(
712
            'INSERT INTO banners_i18n (%s) VALUES (%s)',
713
            implode(', ', $modifiedColumns),
714
            implode(', ', array_keys($modifiedColumns))
715
        );
716
717
        try {
718
            $stmt = $con->prepare($sql);
719
            foreach ($modifiedColumns as $identifier => $columnName) {
720
                switch ($columnName) {
721
                    case 'id':
722
                        $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
723
                        break;
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
724
                    case 'locale':
725
                        $stmt->bindValue($identifier, $this->locale, PDO::PARAM_STR);
726
                        break;
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
727
                    case 'name':
728
                        $stmt->bindValue($identifier, $this->name, PDO::PARAM_STR);
729
                        break;
730
                }
731
            }
732
            $stmt->execute();
733
        } catch (Exception $e) {
734
            Propel::log($e->getMessage(), Propel::LOG_ERR);
735
            throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e);
736
        }
737
738
        $this->setNew(false);
739
    }
740
741
    /**
742
     * Update the row in the database.
743
     *
744
     * @param      ConnectionInterface $con
745
     *
746
     * @return Integer Number of updated rows
747
     * @see doSave()
748
     */
749
    protected function doUpdate(ConnectionInterface $con)
750
    {
751
        $selectCriteria = $this->buildPkeyCriteria();
752
        $valuesCriteria = $this->buildCriteria();
753
754
        return $selectCriteria->doUpdate($valuesCriteria, $con);
0 ignored issues
show
Documentation introduced by
$valuesCriteria is of type object<Propel\Runtime\ActiveQuery\Criteria>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
755
    }
756
757
    /**
758
     * Retrieves a field from the object by name passed in as a string.
759
     *
760
     * @param      string $name name
761
     * @param      string $type The type of fieldname the $name is of:
762
     *                     one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
763
     *                     TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
764
     *                     Defaults to TableMap::TYPE_PHPNAME.
765
     * @return mixed Value of field.
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use integer|null|string.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
766
     */
767 View Code Duplication
    public function getByName($name, $type = TableMap::TYPE_PHPNAME)
768
    {
769
        $pos = BannersI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM);
770
        $field = $this->getByPosition($pos);
771
772
        return $field;
773
    }
774
775
    /**
776
     * Retrieves a field from the object by Position as specified in the xml schema.
777
     * Zero-based.
778
     *
779
     * @param      int $pos position in xml schema
780
     * @return mixed Value of field at $pos
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use integer|null|string.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
781
     */
782
    public function getByPosition($pos)
783
    {
784
        switch ($pos) {
785
            case 0:
786
                return $this->getId();
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
787
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
788
            case 1:
789
                return $this->getLocale();
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
790
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
791
            case 2:
792
                return $this->getName();
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
793
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
794
            default:
795
                return null;
796
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
797
        } // switch()
798
    }
799
800
    /**
801
     * Exports the object as an array.
802
     *
803
     * You can specify the key type of the array by passing one of the class
804
     * type constants.
805
     *
806
     * @param     string  $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
807
     *                    TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
808
     *                    Defaults to TableMap::TYPE_PHPNAME.
809
     * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
810
     * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
811
     * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
812
     *
813
     * @return array an associative array containing the field names (as keys) and field values
0 ignored issues
show
Documentation introduced by
Should the return type not be string|array<*,integer|string|array>?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
814
     */
815
    public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
816
    {
817
818
        if (isset($alreadyDumpedObjects['BannersI18n'][$this->hashCode()])) {
819
            return '*RECURSION*';
820
        }
821
        $alreadyDumpedObjects['BannersI18n'][$this->hashCode()] = true;
822
        $keys = BannersI18nTableMap::getFieldNames($keyType);
823
        $result = array(
824
            $keys[0] => $this->getId(),
825
            $keys[1] => $this->getLocale(),
826
            $keys[2] => $this->getName(),
827
        );
828
        $virtualColumns = $this->virtualColumns;
829
        foreach ($virtualColumns as $key => $virtualColumn) {
830
            $result[$key] = $virtualColumn;
831
        }
832
833
        if ($includeForeignObjects) {
834
            if (null !== $this->aBanners) {
835
836
                switch ($keyType) {
837
                    case TableMap::TYPE_CAMELNAME:
838
                        $key = 'banners';
839
                        break;
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
840
                    case TableMap::TYPE_FIELDNAME:
841
                        $key = 'banners';
842
                        break;
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
843
                    default:
844
                        $key = 'Banners';
845
                }
846
847
                $result[$key] = $this->aBanners->toArray($keyType, $includeLazyLoadColumns,  $alreadyDumpedObjects, true);
0 ignored issues
show
Coding Style introduced by
Expected 1 space instead of 2 after comma in function call.
Loading history...
introduced by
Expected one space after the comma, 2 found
Loading history...
848
            }
849
        }
850
851
        return $result;
852
    }
853
854
    /**
855
     * Sets a field from the object by name passed in as a string.
856
     *
857
     * @param  string $name
858
     * @param  mixed  $value field value
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
859
     * @param  string $type The type of fieldname the $name is of:
860
     *                one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
861
     *                TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
862
     *                Defaults to TableMap::TYPE_PHPNAME.
863
     * @return $this|\xbanners\models\BannersI18n
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
864
     */
865
    public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME)
866
    {
867
        $pos = BannersI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM);
868
869
        return $this->setByPosition($pos, $value);
870
    }
871
872
    /**
873
     * Sets a field from the object by Position as specified in the xml schema.
874
     * Zero-based.
875
     *
876
     * @param  int $pos position in xml schema
877
     * @param  mixed $value field value
878
     * @return $this|\xbanners\models\BannersI18n
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
879
     */
880
    public function setByPosition($pos, $value)
881
    {
882
        switch ($pos) {
883
            case 0:
884
                $this->setId($value);
885
                break;
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
886
            case 1:
887
                $this->setLocale($value);
888
                break;
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
889
            case 2:
890
                $this->setName($value);
891
                break;
892
        } // switch()
893
894
        return $this;
895
    }
896
897
    /**
898
     * Populates the object using an array.
899
     *
900
     * This is particularly useful when populating an object from one of the
901
     * request arrays (e.g. $_POST).  This method goes through the column
902
     * names, checking to see whether a matching key exists in populated
903
     * array. If so the setByName() method is called for that column.
904
     *
905
     * You can specify the key type of the array by additionally passing one
906
     * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
907
     * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
908
     * The default key type is the column's TableMap::TYPE_PHPNAME.
909
     *
910
     * @param      array  $arr     An array to populate the object from.
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
911
     * @param      string $keyType The type of keys the array uses.
912
     * @return void
0 ignored issues
show
introduced by
If there is no return value for a function, there must not be a @return tag.
Loading history...
913
     */
914
    public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME)
915
    {
916
        $keys = BannersI18nTableMap::getFieldNames($keyType);
917
918
        if (array_key_exists($keys[0], $arr)) {
919
            $this->setId($arr[$keys[0]]);
920
        }
921
        if (array_key_exists($keys[1], $arr)) {
922
            $this->setLocale($arr[$keys[1]]);
923
        }
924
        if (array_key_exists($keys[2], $arr)) {
925
            $this->setName($arr[$keys[2]]);
926
        }
927
    }
928
929
     /**
930
     * Populate the current object from a string, using a given parser format
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
931
     * <code>
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
932
     * $book = new Book();
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
933
     * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}');
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
934
     * </code>
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
935
     *
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
936
     * You can specify the key type of the array by additionally passing one
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
937
     * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
938
     * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
939
     * The default key type is the column's TableMap::TYPE_PHPNAME.
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
940
     *
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
941
     * @param mixed $parser A AbstractParser instance,
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
942
     *                       or a format name ('XML', 'YAML', 'JSON', 'CSV')
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
introduced by
Parameter comment must end with a full stop
Loading history...
943
     * @param string $data The source data to import from
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
944
     * @param string $keyType The type of keys the array uses.
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
945
     *
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
946
     * @return $this|\xbanners\models\BannersI18n The current object, for fluid interface
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
introduced by
@return data type must not contain "$"
Loading history...
947
     */
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
948 View Code Duplication
    public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME)
949
    {
950
        if (!$parser instanceof AbstractParser) {
951
            $parser = AbstractParser::getParser($parser);
952
        }
953
954
        $this->fromArray($parser->toArray($data), $keyType);
955
956
        return $this;
957
    }
958
959
    /**
960
     * Build a Criteria object containing the values of all modified columns in this object.
961
     *
962
     * @return Criteria The Criteria object containing all modified values.
963
     */
964
    public function buildCriteria()
965
    {
966
        $criteria = new Criteria(BannersI18nTableMap::DATABASE_NAME);
967
968
        if ($this->isColumnModified(BannersI18nTableMap::COL_ID)) {
969
            $criteria->add(BannersI18nTableMap::COL_ID, $this->id);
970
        }
971
        if ($this->isColumnModified(BannersI18nTableMap::COL_LOCALE)) {
972
            $criteria->add(BannersI18nTableMap::COL_LOCALE, $this->locale);
973
        }
974
        if ($this->isColumnModified(BannersI18nTableMap::COL_NAME)) {
975
            $criteria->add(BannersI18nTableMap::COL_NAME, $this->name);
976
        }
977
978
        return $criteria;
979
    }
980
981
    /**
982
     * Builds a Criteria object containing the primary key for this object.
983
     *
984
     * Unlike buildCriteria() this method includes the primary key values regardless
985
     * of whether or not they have been modified.
986
     *
987
     * @throws LogicException if no primary key is defined
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
988
     *
989
     * @return Criteria The Criteria object containing value(s) for primary key(s).
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use ChildBannersI18nQuery.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
990
     */
991
    public function buildPkeyCriteria()
992
    {
993
        $criteria = ChildBannersI18nQuery::create();
994
        $criteria->add(BannersI18nTableMap::COL_ID, $this->id);
995
        $criteria->add(BannersI18nTableMap::COL_LOCALE, $this->locale);
996
997
        return $criteria;
998
    }
999
1000
    /**
1001
     * If the primary key is not null, return the hashcode of the
1002
     * primary key. Otherwise, return the hash code of the object.
1003
     *
1004
     * @return int Hashcode
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
1005
     */
1006 View Code Duplication
    public function hashCode()
1007
    {
1008
        $validPk = null !== $this->getId() &&
1009
            null !== $this->getLocale();
1010
1011
        $validPrimaryKeyFKs = 1;
1012
        $primaryKeyFKs = [];
1013
1014
        //relation banners_i18n_fk_c926a5 to table banners
1015
        if ($this->aBanners && $hash = spl_object_hash($this->aBanners)) {
1016
            $primaryKeyFKs[] = $hash;
1017
        } else {
1018
            $validPrimaryKeyFKs = false;
1019
        }
1020
1021
        if ($validPk) {
1022
            return crc32(json_encode($this->getPrimaryKey(), JSON_UNESCAPED_UNICODE));
1023
        } elseif ($validPrimaryKeyFKs) {
1024
            return crc32(json_encode($primaryKeyFKs, JSON_UNESCAPED_UNICODE));
1025
        }
1026
1027
        return spl_object_hash($this);
1028
    }
1029
1030
    /**
1031
     * Returns the composite primary key for this object.
1032
     * The array elements will be in same order as specified in XML.
1033
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<integer|string>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
1034
     */
1035 View Code Duplication
    public function getPrimaryKey()
1036
    {
1037
        $pks = array();
1038
        $pks[0] = $this->getId();
1039
        $pks[1] = $this->getLocale();
1040
1041
        return $pks;
1042
    }
1043
1044
    /**
1045
     * Set the [composite] primary key.
1046
     *
1047
     * @param      array $keys The elements of the composite key (order must match the order in XML file).
1048
     * @return void
0 ignored issues
show
introduced by
If there is no return value for a function, there must not be a @return tag.
Loading history...
1049
     */
1050
    public function setPrimaryKey($keys)
1051
    {
1052
        $this->setId($keys[0]);
1053
        $this->setLocale($keys[1]);
1054
    }
1055
1056
    /**
1057
     * Returns true if the primary key for this object is null.
1058
     * @return boolean
1059
     */
1060
    public function isPrimaryKeyNull()
1061
    {
1062
        return (null === $this->getId()) && (null === $this->getLocale());
1063
    }
1064
1065
    /**
1066
     * Sets contents of passed object to values from current object.
1067
     *
1068
     * If desired, this method can also make copies of all associated (fkey referrers)
1069
     * objects.
1070
     *
1071
     * @param      object $copyObj An object of \xbanners\models\BannersI18n (or compatible) type.
1072
     * @param      boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1073
     * @param      boolean $makeNew Whether to reset autoincrement PKs and make the object new.
1074
     * @throws PropelException
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
1075
     */
1076
    public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
0 ignored issues
show
Unused Code introduced by
The parameter $deepCopy is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1077
    {
1078
        $copyObj->setId($this->getId());
1079
        $copyObj->setLocale($this->getLocale());
1080
        $copyObj->setName($this->getName());
1081
        if ($makeNew) {
1082
            $copyObj->setNew(true);
1083
        }
1084
    }
1085
1086
    /**
1087
     * Makes a copy of this object that will be inserted as a new row in table when saved.
1088
     * It creates a new object filling in the simple attributes, but skipping any primary
1089
     * keys that are defined for the table.
1090
     *
1091
     * If desired, this method can also make copies of all associated (fkey referrers)
1092
     * objects.
1093
     *
1094
     * @param  boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1095
     * @return \xbanners\models\BannersI18n Clone of current object.
1096
     * @throws PropelException
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
1097
     */
1098 View Code Duplication
    public function copy($deepCopy = false)
1099
    {
1100
        // we use get_class(), because this might be a subclass
1101
        $clazz = get_class($this);
1102
        $copyObj = new $clazz();
1103
        $this->copyInto($copyObj, $deepCopy);
1104
1105
        return $copyObj;
1106
    }
1107
1108
    /**
1109
     * Declares an association between this object and a ChildBanners object.
1110
     *
1111
     * @param  ChildBanners $v
1112
     * @return $this|\xbanners\models\BannersI18n The current object (for fluent API support)
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
1113
     * @throws PropelException
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
1114
     */
1115 View Code Duplication
    public function setBanners(ChildBanners $v = null)
1116
    {
1117
        if ($v === null) {
1118
            $this->setId(NULL);
1119
        } else {
1120
            $this->setId($v->getId());
1121
        }
1122
1123
        $this->aBanners = $v;
1124
1125
        // Add binding for other direction of this n:n relationship.
1126
        // If this object has already been added to the ChildBanners object, it will not be re-added.
1127
        if ($v !== null) {
1128
            $v->addBannersI18n($this);
0 ignored issues
show
Compatibility introduced by
$this of type object<xbanners\models\Base\BannersI18n> is not a sub-type of object<xbanners\models\BannersI18n>. It seems like you assume a child class of the class xbanners\models\Base\BannersI18n to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
1129
        }
1130
1131
1132
        return $this;
1133
    }
1134
1135
1136
    /**
1137
     * Get the associated ChildBanners object
1138
     *
1139
     * @param  ConnectionInterface $con Optional Connection object.
1140
     * @return ChildBanners The associated ChildBanners object.
1141
     * @throws PropelException
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
1142
     */
1143 View Code Duplication
    public function getBanners(ConnectionInterface $con = null)
1144
    {
1145
        if ($this->aBanners === null && ($this->id !== null)) {
1146
            $this->aBanners = ChildBannersQuery::create()->findPk($this->id, $con);
1147
            /* The following can be used additionally to
1148
                guarantee the related object contains a reference
1149
                to this object.  This level of coupling may, however, be
1150
                undesirable since it could result in an only partially populated collection
1151
                in the referenced object.
1152
                $this->aBanners->addBannersI18ns($this);
1153
             */
1154
        }
1155
1156
        return $this->aBanners;
1157
    }
1158
1159
    /**
1160
     * Clears the current object, sets all attributes to their default values and removes
1161
     * outgoing references as well as back-references (from other objects to this one. Results probably in a database
1162
     * change of those foreign objects when you call `save` there).
1163
     */
1164
    public function clear()
1165
    {
1166
        if (null !== $this->aBanners) {
1167
            $this->aBanners->removeBannersI18n($this);
0 ignored issues
show
Compatibility introduced by
$this of type object<xbanners\models\Base\BannersI18n> is not a sub-type of object<xbanners\models\BannersI18n>. It seems like you assume a child class of the class xbanners\models\Base\BannersI18n to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
1168
        }
1169
        $this->id = null;
1170
        $this->locale = null;
1171
        $this->name = null;
1172
        $this->alreadyInSave = false;
1173
        $this->clearAllReferences();
1174
        $this->applyDefaultValues();
1175
        $this->resetModified();
1176
        $this->setNew(true);
1177
        $this->setDeleted(false);
1178
    }
1179
1180
    /**
1181
     * Resets all references and back-references to other model objects or collections of model objects.
1182
     *
1183
     * This method is used to reset all php object references (not the actual reference in the database).
1184
     * Necessary for object serialisation.
1185
     *
1186
     * @param      boolean $deep Whether to also clear the references on all referrer objects.
1187
     */
1188
    public function clearAllReferences($deep = false)
1189
    {
1190
        if ($deep) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
1191
        } // if ($deep)
1192
1193
        $this->aBanners = null;
1194
    }
1195
1196
    /**
1197
     * Return the string representation of this object
1198
     *
1199
     * @return string
1200
     */
1201
    public function __toString()
1202
    {
1203
        return (string) $this->exportTo(BannersI18nTableMap::DEFAULT_STRING_FORMAT);
1204
    }
1205
1206
    /**
1207
     * Code to be run before persisting the object
1208
     * @param  ConnectionInterface $con
1209
     * @return boolean
1210
     */
1211
    public function preSave(ConnectionInterface $con = null)
1212
    {
1213
        if (is_callable('parent::preSave')) {
1214
            return parent::preSave($con);
1215
        }
1216
        return true;
1217
    }
1218
1219
    /**
1220
     * Code to be run after persisting the object
1221
     * @param ConnectionInterface $con
1222
     */
1223
    public function postSave(ConnectionInterface $con = null)
1224
    {
1225
        if (is_callable('parent::postSave')) {
1226
            parent::postSave($con);
1227
        }
1228
    }
1229
1230
    /**
1231
     * Code to be run before inserting to database
1232
     * @param  ConnectionInterface $con
1233
     * @return boolean
1234
     */
1235
    public function preInsert(ConnectionInterface $con = null)
1236
    {
1237
        if (is_callable('parent::preInsert')) {
1238
            return parent::preInsert($con);
1239
        }
1240
        return true;
1241
    }
1242
1243
    /**
1244
     * Code to be run after inserting to database
1245
     * @param ConnectionInterface $con
1246
     */
1247
    public function postInsert(ConnectionInterface $con = null)
1248
    {
1249
        if (is_callable('parent::postInsert')) {
1250
            parent::postInsert($con);
1251
        }
1252
    }
1253
1254
    /**
1255
     * Code to be run before updating the object in database
1256
     * @param  ConnectionInterface $con
1257
     * @return boolean
1258
     */
1259
    public function preUpdate(ConnectionInterface $con = null)
1260
    {
1261
        if (is_callable('parent::preUpdate')) {
1262
            return parent::preUpdate($con);
1263
        }
1264
        return true;
1265
    }
1266
1267
    /**
1268
     * Code to be run after updating the object in database
1269
     * @param ConnectionInterface $con
1270
     */
1271
    public function postUpdate(ConnectionInterface $con = null)
1272
    {
1273
        if (is_callable('parent::postUpdate')) {
1274
            parent::postUpdate($con);
1275
        }
1276
    }
1277
1278
    /**
1279
     * Code to be run before deleting the object in database
1280
     * @param  ConnectionInterface $con
1281
     * @return boolean
1282
     */
1283
    public function preDelete(ConnectionInterface $con = null)
1284
    {
1285
        if (is_callable('parent::preDelete')) {
1286
            return parent::preDelete($con);
1287
        }
1288
        return true;
1289
    }
1290
1291
    /**
1292
     * Code to be run after deleting the object in database
1293
     * @param ConnectionInterface $con
1294
     */
1295
    public function postDelete(ConnectionInterface $con = null)
1296
    {
1297
        if (is_callable('parent::postDelete')) {
1298
            parent::postDelete($con);
1299
        }
1300
    }
1301
1302
1303
    /**
1304
     * Derived method to catches calls to undefined methods.
1305
     *
1306
     * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.).
1307
     * Allows to define default __call() behavior if you overwrite __call()
1308
     *
1309
     * @param string $name
1310
     * @param mixed  $params
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
1311
     *
1312
     * @return array|string
1313
     */
1314 View Code Duplication
    public function __call($name, $params)
1315
    {
1316
        if (0 === strpos($name, 'get')) {
1317
            $virtualColumn = substr($name, 3);
1318
            if ($this->hasVirtualColumn($virtualColumn)) {
1319
                return $this->getVirtualColumn($virtualColumn);
1320
            }
1321
1322
            $virtualColumn = lcfirst($virtualColumn);
1323
            if ($this->hasVirtualColumn($virtualColumn)) {
1324
                return $this->getVirtualColumn($virtualColumn);
1325
            }
1326
        }
1327
1328
        if (0 === strpos($name, 'from')) {
1329
            $format = substr($name, 4);
1330
1331
            return $this->importFrom($format, reset($params));
1332
        }
1333
1334
        if (0 === strpos($name, 'to')) {
1335
            $format = substr($name, 2);
1336
            $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true;
1337
1338
            return $this->exportTo($format, $includeLazyLoadColumns);
1339
        }
1340
1341
        throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name));
1342
    }
1343
1344
}
1345