BannerImage::doInsert()   F
last analyzed

Complexity

Conditions 25
Paths 17409

Size

Total Lines 99

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 25
nc 17409
nop 1
dl 0
loc 99
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Collection\ObjectCollection;
14
use Propel\Runtime\Connection\ConnectionInterface;
15
use Propel\Runtime\Exception\BadMethodCallException;
16
use Propel\Runtime\Exception\LogicException;
17
use Propel\Runtime\Exception\PropelException;
18
use Propel\Runtime\Map\TableMap;
19
use Propel\Runtime\Parser\AbstractParser;
20
use xbanners\models\BannerImage as ChildBannerImage;
21
use xbanners\models\BannerImageI18n as ChildBannerImageI18n;
22
use xbanners\models\BannerImageI18nQuery as ChildBannerImageI18nQuery;
23
use xbanners\models\BannerImageQuery as ChildBannerImageQuery;
24
use xbanners\models\Banners as ChildBanners;
25
use xbanners\models\BannersQuery as ChildBannersQuery;
26
use xbanners\models\Map\BannerImageI18nTableMap;
27
use xbanners\models\Map\BannerImageTableMap;
28
29
/**
30
 * Base class that represents a row from the 'banner_image' table.
31
 *
32
 *
33
 *
34
 * @package    propel.generator.xbanners.models.Base
35
 */
36
abstract class BannerImage extends PropelBaseModelClass implements ActiveRecordInterface
37
{
38
    /**
39
     * TableMap class name
40
     */
41
    const TABLE_MAP = '\\xbanners\\models\\Map\\BannerImageTableMap';
42
43
44
    /**
45
     * attribute to determine if this object has previously been saved.
46
     * @var boolean
47
     */
48
    protected $new = true;
49
50
    /**
51
     * attribute to determine whether this object has been deleted.
52
     * @var boolean
53
     */
54
    protected $deleted = false;
55
56
    /**
57
     * The columns that have been modified in current object.
58
     * Tracking modified columns allows us to only update modified columns.
59
     * @var array
60
     */
61
    protected $modifiedColumns = array();
62
63
    /**
64
     * The (virtual) columns that are added at runtime
65
     * The formatters can add supplementary columns based on a resultset
66
     * @var array
67
     */
68
    protected $virtualColumns = array();
69
70
    /**
71
     * The value for the id field.
72
     *
73
     * @var        int
74
     */
75
    protected $id;
76
77
    /**
78
     * The value for the banner_id field.
79
     *
80
     * @var        int
81
     */
82
    protected $banner_id;
83
84
    /**
85
     * The value for the target field.
86
     *
87
     * @var        int
88
     */
89
    protected $target;
90
91
    /**
92
     * The value for the url field.
93
     *
94
     * @var        string
95
     */
96
    protected $url;
97
98
    /**
99
     * The value for the allowed_page field.
100
     *
101
     * @var        int
102
     */
103
    protected $allowed_page;
104
105
    /**
106
     * The value for the position field.
107
     *
108
     * @var        int
109
     */
110
    protected $position;
111
112
    /**
113
     * The value for the active_from field.
114
     *
115
     * @var        int
116
     */
117
    protected $active_from;
118
119
    /**
120
     * The value for the active_to field.
121
     *
122
     * @var        int
123
     */
124
    protected $active_to;
125
126
    /**
127
     * The value for the active field.
128
     *
129
     * @var        int
130
     */
131
    protected $active;
132
133
    /**
134
     * The value for the permanent field.
135
     *
136
     * @var        int
137
     */
138
    protected $permanent;
139
140
    /**
141
     * @var        ChildBanners
142
     */
143
    protected $aBanners;
144
145
    /**
146
     * @var        ObjectCollection|ChildBannerImageI18n[] Collection to store aggregation of ChildBannerImageI18n objects.
147
     */
148
    protected $collBannerImageI18ns;
149
    protected $collBannerImageI18nsPartial;
150
151
    /**
152
     * Flag to prevent endless save loop, if this object is referenced
153
     * by another object which falls in this transaction.
154
     *
155
     * @var boolean
156
     */
157
    protected $alreadyInSave = false;
158
159
    // i18n behavior
160
161
    /**
162
     * Current locale
163
     * @var        string
164
     */
165
    protected $currentLocale = 'ru';
166
167
    /**
168
     * Current translation objects
169
     * @var        array[ChildBannerImageI18n]
170
     */
171
    protected $currentTranslations;
172
173
    /**
174
     * An array of objects scheduled for deletion.
175
     * @var ObjectCollection|ChildBannerImageI18n[]
176
     */
177
    protected $bannerImageI18nsScheduledForDeletion = null;
178
179
    /**
180
     * Initializes internal state of xbanners\models\Base\BannerImage object.
181
     */
182
    public function __construct()
183
    {
184
    }
185
186
    /**
187
     * Returns whether the object has been modified.
188
     *
189
     * @return boolean True if the object has been modified.
190
     */
191
    public function isModified()
192
    {
193
        return !!$this->modifiedColumns;
194
    }
195
196
    /**
197
     * Has specified column been modified?
198
     *
199
     * @param  string  $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID
200
     * @return boolean True if $col has been modified.
201
     */
202
    public function isColumnModified($col)
203
    {
204
        return $this->modifiedColumns && isset($this->modifiedColumns[$col]);
205
    }
206
207
    /**
208
     * Get the columns that have been modified in this object.
209
     * @return array A unique list of the modified column names for this object.
210
     */
211
    public function getModifiedColumns()
212
    {
213
        return $this->modifiedColumns ? array_keys($this->modifiedColumns) : [];
214
    }
215
216
    /**
217
     * Returns whether the object has ever been saved.  This will
218
     * be false, if the object was retrieved from storage or was created
219
     * and then saved.
220
     *
221
     * @return boolean true, if the object has never been persisted.
222
     */
223
    public function isNew()
224
    {
225
        return $this->new;
226
    }
227
228
    /**
229
     * Setter for the isNew attribute.  This method will be called
230
     * by Propel-generated children and objects.
231
     *
232
     * @param boolean $b the state of the object.
233
     */
234
    public function setNew($b)
235
    {
236
        $this->new = (boolean) $b;
237
    }
238
239
    /**
240
     * Whether this object has been deleted.
241
     * @return boolean The deleted state of this object.
242
     */
243
    public function isDeleted()
244
    {
245
        return $this->deleted;
246
    }
247
248
    /**
249
     * Specify whether this object has been deleted.
250
     * @param  boolean $b The deleted state of this object.
251
     * @return void
252
     */
253
    public function setDeleted($b)
254
    {
255
        $this->deleted = (boolean) $b;
256
    }
257
258
    /**
259
     * Sets the modified state for the object to be false.
260
     * @param  string $col If supplied, only the specified column is reset.
261
     * @return void
262
     */
263 View Code Duplication
    public function resetModified($col = null)
264
    {
265
        if (null !== $col) {
266
            if (isset($this->modifiedColumns[$col])) {
267
                unset($this->modifiedColumns[$col]);
268
            }
269
        } else {
270
            $this->modifiedColumns = array();
271
        }
272
    }
273
274
    /**
275
     * Compares this with another <code>BannerImage</code> instance.  If
276
     * <code>obj</code> is an instance of <code>BannerImage</code>, delegates to
277
     * <code>equals(BannerImage)</code>.  Otherwise, returns <code>false</code>.
278
     *
279
     * @param  mixed   $obj The object to compare to.
280
     * @return boolean Whether equal to the object specified.
281
     */
282 View Code Duplication
    public function equals($obj)
283
    {
284
        if (!$obj instanceof static) {
285
            return false;
286
        }
287
288
        if ($this === $obj) {
289
            return true;
290
        }
291
292
        if (null === $this->getPrimaryKey() || null === $obj->getPrimaryKey()) {
293
            return false;
294
        }
295
296
        return $this->getPrimaryKey() === $obj->getPrimaryKey();
297
    }
298
299
    /**
300
     * Get the associative array of the virtual columns in this object
301
     *
302
     * @return array
303
     */
304
    public function getVirtualColumns()
305
    {
306
        return $this->virtualColumns;
307
    }
308
309
    /**
310
     * Checks the existence of a virtual column in this object
311
     *
312
     * @param  string  $name The virtual column name
313
     * @return boolean
314
     */
315
    public function hasVirtualColumn($name)
316
    {
317
        return array_key_exists($name, $this->virtualColumns);
318
    }
319
320
    /**
321
     * Get the value of a virtual column in this object
322
     *
323
     * @param  string $name The virtual column name
324
     * @return mixed
325
     *
326
     * @throws PropelException
327
     */
328 View Code Duplication
    public function getVirtualColumn($name)
329
    {
330
        if (!$this->hasVirtualColumn($name)) {
331
            throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name));
332
        }
333
334
        return $this->virtualColumns[$name];
335
    }
336
337
    /**
338
     * Set the value of a virtual column in this object
339
     *
340
     * @param string $name  The virtual column name
341
     * @param mixed  $value The value to give to the virtual column
342
     *
343
     * @return $this|BannerImage The current object, for fluid interface
344
     */
345
    public function setVirtualColumn($name, $value)
346
    {
347
        $this->virtualColumns[$name] = $value;
348
349
        return $this;
350
    }
351
352
    /**
353
     * Logs a message using Propel::log().
354
     *
355
     * @param  string  $msg
356
     * @param  int     $priority One of the Propel::LOG_* logging levels
357
     * @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...
358
     */
359
    protected function log($msg, $priority = Propel::LOG_INFO)
360
    {
361
        return Propel::log(get_class($this) . ': ' . $msg, $priority);
362
    }
363
364
    /**
365
     * Export the current object properties to a string, using a given parser format
366
     * <code>
367
     * $book = BookQuery::create()->findPk(9012);
368
     * echo $book->exportTo('JSON');
369
     *  => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}');
370
     * </code>
371
     *
372
     * @param  mixed   $parser                 A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV')
373
     * @param  boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE.
374
     * @return string  The exported data
375
     */
376 View Code Duplication
    public function exportTo($parser, $includeLazyLoadColumns = true)
377
    {
378
        if (!$parser instanceof AbstractParser) {
379
            $parser = AbstractParser::getParser($parser);
380
        }
381
382
        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\BannerImage::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...
383
    }
384
385
    /**
386
     * Clean up internal collections prior to serializing
387
     * Avoids recursive loops that turn into segmentation faults when serializing
388
     */
389 View Code Duplication
    public function __sleep()
390
    {
391
        $this->clearAllReferences();
392
393
        $cls = new \ReflectionClass($this);
394
        $propertyNames = [];
395
        $serializableProperties = array_diff($cls->getProperties(), $cls->getProperties(\ReflectionProperty::IS_STATIC));
396
397
        foreach($serializableProperties as $property) {
398
            $propertyNames[] = $property->getName();
399
        }
400
401
        return $propertyNames;
402
    }
403
404
    /**
405
     * Get the [id] column value.
406
     *
407
     * @return int
408
     */
409
    public function getId()
410
    {
411
        return $this->id;
412
    }
413
414
    /**
415
     * Get the [banner_id] column value.
416
     *
417
     * @return int
418
     */
419
    public function getBannerId()
420
    {
421
        return $this->banner_id;
422
    }
423
424
    /**
425
     * Get the [target] column value.
426
     *
427
     * @return int
428
     */
429
    public function getTarget()
430
    {
431
        return $this->target;
432
    }
433
434
    /**
435
     * Get the [url] column value.
436
     *
437
     * @return string
438
     */
439
    public function getUrl()
440
    {
441
        return $this->url;
442
    }
443
444
    /**
445
     * Get the [allowed_page] column value.
446
     *
447
     * @return int
448
     */
449
    public function getAllowedPage()
450
    {
451
        return $this->allowed_page;
452
    }
453
454
    /**
455
     * Get the [position] column value.
456
     *
457
     * @return int
458
     */
459
    public function getPosition()
460
    {
461
        return $this->position;
462
    }
463
464
    /**
465
     * Get the [active_from] column value.
466
     *
467
     * @return int
468
     */
469
    public function getActiveFrom()
470
    {
471
        return $this->active_from;
472
    }
473
474
    /**
475
     * Get the [active_to] column value.
476
     *
477
     * @return int
478
     */
479
    public function getActiveTo()
480
    {
481
        return $this->active_to;
482
    }
483
484
    /**
485
     * Get the [active] column value.
486
     *
487
     * @return int
488
     */
489
    public function getActive()
490
    {
491
        return $this->active;
492
    }
493
494
    /**
495
     * Get the [permanent] column value.
496
     *
497
     * @return int
498
     */
499
    public function getPermanent()
500
    {
501
        return $this->permanent;
502
    }
503
504
    /**
505
     * Set the value of [id] column.
506
     *
507
     * @param int $v new value
508
     * @return $this|\xbanners\models\BannerImage The current object (for fluent API support)
509
     */
510 View Code Duplication
    public function setId($v)
511
    {
512
        if ($v !== null) {
513
            $v = (int) $v;
514
        }
515
516
        if ($this->id !== $v) {
517
            $this->id = $v;
518
            $this->modifiedColumns[BannerImageTableMap::COL_ID] = true;
519
        }
520
521
        return $this;
522
    } // setId()
523
524
    /**
525
     * Set the value of [banner_id] column.
526
     *
527
     * @param int $v new value
528
     * @return $this|\xbanners\models\BannerImage The current object (for fluent API support)
529
     */
530 View Code Duplication
    public function setBannerId($v)
531
    {
532
        if ($v !== null) {
533
            $v = (int) $v;
534
        }
535
536
        if ($this->banner_id !== $v) {
537
            $this->banner_id = $v;
538
            $this->modifiedColumns[BannerImageTableMap::COL_BANNER_ID] = true;
539
        }
540
541
        if ($this->aBanners !== null && $this->aBanners->getId() !== $v) {
542
            $this->aBanners = null;
543
        }
544
545
        return $this;
546
    } // setBannerId()
547
548
    /**
549
     * Set the value of [target] column.
550
     *
551
     * @param int $v new value
552
     * @return $this|\xbanners\models\BannerImage The current object (for fluent API support)
553
     */
554 View Code Duplication
    public function setTarget($v)
555
    {
556
        if ($v !== null) {
557
            $v = (int) $v;
558
        }
559
560
        if ($this->target !== $v) {
561
            $this->target = $v;
562
            $this->modifiedColumns[BannerImageTableMap::COL_TARGET] = true;
563
        }
564
565
        return $this;
566
    } // setTarget()
567
568
    /**
569
     * Set the value of [url] column.
570
     *
571
     * @param string $v new value
572
     * @return $this|\xbanners\models\BannerImage The current object (for fluent API support)
573
     */
574 View Code Duplication
    public function setUrl($v)
575
    {
576
        if ($v !== null) {
577
            $v = (string) $v;
578
        }
579
580
        if ($this->url !== $v) {
581
            $this->url = $v;
582
            $this->modifiedColumns[BannerImageTableMap::COL_URL] = true;
583
        }
584
585
        return $this;
586
    } // setUrl()
587
588
    /**
589
     * Set the value of [allowed_page] column.
590
     *
591
     * @param int $v new value
592
     * @return $this|\xbanners\models\BannerImage The current object (for fluent API support)
593
     */
594 View Code Duplication
    public function setAllowedPage($v)
595
    {
596
        if ($v !== null) {
597
            $v = (int) $v;
598
        }
599
600
        if ($this->allowed_page !== $v) {
601
            $this->allowed_page = $v;
602
            $this->modifiedColumns[BannerImageTableMap::COL_ALLOWED_PAGE] = true;
603
        }
604
605
        return $this;
606
    } // setAllowedPage()
607
608
    /**
609
     * Set the value of [position] column.
610
     *
611
     * @param int $v new value
612
     * @return $this|\xbanners\models\BannerImage The current object (for fluent API support)
613
     */
614 View Code Duplication
    public function setPosition($v)
615
    {
616
        if ($v !== null) {
617
            $v = (int) $v;
618
        }
619
620
        if ($this->position !== $v) {
621
            $this->position = $v;
622
            $this->modifiedColumns[BannerImageTableMap::COL_POSITION] = true;
623
        }
624
625
        return $this;
626
    } // setPosition()
627
628
    /**
629
     * Set the value of [active_from] column.
630
     *
631
     * @param int $v new value
632
     * @return $this|\xbanners\models\BannerImage The current object (for fluent API support)
633
     */
634 View Code Duplication
    public function setActiveFrom($v)
635
    {
636
        if ($v !== null) {
637
            $v = (int) $v;
638
        }
639
640
        if ($this->active_from !== $v) {
641
            $this->active_from = $v;
642
            $this->modifiedColumns[BannerImageTableMap::COL_ACTIVE_FROM] = true;
643
        }
644
645
        return $this;
646
    } // setActiveFrom()
647
648
    /**
649
     * Set the value of [active_to] column.
650
     *
651
     * @param int $v new value
652
     * @return $this|\xbanners\models\BannerImage The current object (for fluent API support)
653
     */
654 View Code Duplication
    public function setActiveTo($v)
655
    {
656
        if ($v !== null) {
657
            $v = (int) $v;
658
        }
659
660
        if ($this->active_to !== $v) {
661
            $this->active_to = $v;
662
            $this->modifiedColumns[BannerImageTableMap::COL_ACTIVE_TO] = true;
663
        }
664
665
        return $this;
666
    } // setActiveTo()
667
668
    /**
669
     * Set the value of [active] column.
670
     *
671
     * @param int $v new value
672
     * @return $this|\xbanners\models\BannerImage The current object (for fluent API support)
673
     */
674 View Code Duplication
    public function setActive($v)
675
    {
676
        if ($v !== null) {
677
            $v = (int) $v;
678
        }
679
680
        if ($this->active !== $v) {
681
            $this->active = $v;
682
            $this->modifiedColumns[BannerImageTableMap::COL_ACTIVE] = true;
683
        }
684
685
        return $this;
686
    } // setActive()
687
688
    /**
689
     * Set the value of [permanent] column.
690
     *
691
     * @param int $v new value
692
     * @return $this|\xbanners\models\BannerImage The current object (for fluent API support)
693
     */
694 View Code Duplication
    public function setPermanent($v)
695
    {
696
        if ($v !== null) {
697
            $v = (int) $v;
698
        }
699
700
        if ($this->permanent !== $v) {
701
            $this->permanent = $v;
702
            $this->modifiedColumns[BannerImageTableMap::COL_PERMANENT] = true;
703
        }
704
705
        return $this;
706
    } // setPermanent()
707
708
    /**
709
     * Indicates whether the columns in this object are only set to default values.
710
     *
711
     * This method can be used in conjunction with isModified() to indicate whether an object is both
712
     * modified _and_ has some values set which are non-default.
713
     *
714
     * @return boolean Whether the columns in this object are only been set with default values.
715
     */
716
    public function hasOnlyDefaultValues()
717
    {
718
        // otherwise, everything was equal, so return TRUE
719
        return true;
720
    } // hasOnlyDefaultValues()
721
722
    /**
723
     * Hydrates (populates) the object variables with values from the database resultset.
724
     *
725
     * An offset (0-based "start column") is specified so that objects can be hydrated
726
     * with a subset of the columns in the resultset rows.  This is needed, for example,
727
     * for results of JOIN queries where the resultset row includes columns from two or
728
     * more tables.
729
     *
730
     * @param array   $row       The row returned by DataFetcher->fetch().
731
     * @param int     $startcol  0-based offset column which indicates which restultset column to start with.
732
     * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
733
     * @param string  $indexType The index type of $row. Mostly DataFetcher->getIndexType().
734
                                  One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
735
     *                            TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
736
     *
737
     * @return int             next starting column
738
     * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
739
     */
740
    public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM)
741
    {
742
        try {
743
744
            $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : BannerImageTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)];
745
            $this->id = (null !== $col) ? (int) $col : null;
746
747
            $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : BannerImageTableMap::translateFieldName('BannerId', TableMap::TYPE_PHPNAME, $indexType)];
748
            $this->banner_id = (null !== $col) ? (int) $col : null;
749
750
            $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : BannerImageTableMap::translateFieldName('Target', TableMap::TYPE_PHPNAME, $indexType)];
751
            $this->target = (null !== $col) ? (int) $col : null;
752
753
            $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : BannerImageTableMap::translateFieldName('Url', TableMap::TYPE_PHPNAME, $indexType)];
754
            $this->url = (null !== $col) ? (string) $col : null;
755
756
            $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : BannerImageTableMap::translateFieldName('AllowedPage', TableMap::TYPE_PHPNAME, $indexType)];
757
            $this->allowed_page = (null !== $col) ? (int) $col : null;
758
759
            $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : BannerImageTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)];
760
            $this->position = (null !== $col) ? (int) $col : null;
761
762
            $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : BannerImageTableMap::translateFieldName('ActiveFrom', TableMap::TYPE_PHPNAME, $indexType)];
763
            $this->active_from = (null !== $col) ? (int) $col : null;
764
765
            $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : BannerImageTableMap::translateFieldName('ActiveTo', TableMap::TYPE_PHPNAME, $indexType)];
766
            $this->active_to = (null !== $col) ? (int) $col : null;
767
768
            $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : BannerImageTableMap::translateFieldName('Active', TableMap::TYPE_PHPNAME, $indexType)];
769
            $this->active = (null !== $col) ? (int) $col : null;
770
771
            $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : BannerImageTableMap::translateFieldName('Permanent', TableMap::TYPE_PHPNAME, $indexType)];
772
            $this->permanent = (null !== $col) ? (int) $col : null;
773
            $this->resetModified();
774
775
            $this->setNew(false);
776
777
            if ($rehydrate) {
778
                $this->ensureConsistency();
779
            }
780
781
            return $startcol + 10; // 10 = BannerImageTableMap::NUM_HYDRATE_COLUMNS.
782
783
        } catch (Exception $e) {
784
            throw new PropelException(sprintf('Error populating %s object', '\\xbanners\\models\\BannerImage'), 0, $e);
785
        }
786
    }
787
788
    /**
789
     * Checks and repairs the internal consistency of the object.
790
     *
791
     * This method is executed after an already-instantiated object is re-hydrated
792
     * from the database.  It exists to check any foreign keys to make sure that
793
     * the objects related to the current object are correct based on foreign key.
794
     *
795
     * You can override this method in the stub class, but you should always invoke
796
     * the base method from the overridden method (i.e. parent::ensureConsistency()),
797
     * in case your model changes.
798
     *
799
     * @throws PropelException
800
     */
801
    public function ensureConsistency()
802
    {
803
        if ($this->aBanners !== null && $this->banner_id !== $this->aBanners->getId()) {
804
            $this->aBanners = null;
805
        }
806
    } // ensureConsistency
807
808
    /**
809
     * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
810
     *
811
     * This will only work if the object has been saved and has a valid primary key set.
812
     *
813
     * @param      boolean $deep (optional) Whether to also de-associated any related objects.
814
     * @param      ConnectionInterface $con (optional) The ConnectionInterface connection to use.
815
     * @return void
816
     * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
817
     */
818 View Code Duplication
    public function reload($deep = false, ConnectionInterface $con = null)
819
    {
820
        if ($this->isDeleted()) {
821
            throw new PropelException("Cannot reload a deleted object.");
822
        }
823
824
        if ($this->isNew()) {
825
            throw new PropelException("Cannot reload an unsaved object.");
826
        }
827
828
        if ($con === null) {
829
            $con = Propel::getServiceContainer()->getReadConnection(BannerImageTableMap::DATABASE_NAME);
830
        }
831
832
        // We don't need to alter the object instance pool; we're just modifying this instance
833
        // already in the pool.
834
835
        $dataFetcher = ChildBannerImageQuery::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...
836
        $row = $dataFetcher->fetch();
837
        $dataFetcher->close();
838
        if (!$row) {
839
            throw new PropelException('Cannot find matching row in the database to reload object values.');
840
        }
841
        $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate
842
843
        if ($deep) {  // also de-associate any related objects?
844
845
            $this->aBanners = null;
846
            $this->collBannerImageI18ns = null;
847
848
        } // if (deep)
849
    }
850
851
    /**
852
     * Removes this object from datastore and sets delete attribute.
853
     *
854
     * @param      ConnectionInterface $con
855
     * @return void
856
     * @throws PropelException
857
     * @see BannerImage::setDeleted()
858
     * @see BannerImage::isDeleted()
859
     */
860 View Code Duplication
    public function delete(ConnectionInterface $con = null)
861
    {
862
        if ($this->isDeleted()) {
863
            throw new PropelException("This object has already been deleted.");
864
        }
865
866
        if ($con === null) {
867
            $con = Propel::getServiceContainer()->getWriteConnection(BannerImageTableMap::DATABASE_NAME);
868
        }
869
870
        $con->transaction(function () use ($con) {
871
            $deleteQuery = ChildBannerImageQuery::create()
872
                ->filterByPrimaryKey($this->getPrimaryKey());
873
            $ret = $this->preDelete($con);
874
            if ($ret) {
875
                $deleteQuery->delete($con);
876
                $this->postDelete($con);
877
                $this->setDeleted(true);
878
            }
879
        });
880
    }
881
882
    /**
883
     * Persists this object to the database.
884
     *
885
     * If the object is new, it inserts it; otherwise an update is performed.
886
     * All modified related objects will also be persisted in the doSave()
887
     * method.  This method wraps all precipitate database operations in a
888
     * single transaction.
889
     *
890
     * @param      ConnectionInterface $con
891
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
892
     * @throws PropelException
893
     * @see doSave()
894
     */
895 View Code Duplication
    public function save(ConnectionInterface $con = null)
896
    {
897
        if ($this->isDeleted()) {
898
            throw new PropelException("You cannot save an object that has been deleted.");
899
        }
900
901
        if ($this->alreadyInSave) {
902
            return 0;
903
        }
904
905
        if ($con === null) {
906
            $con = Propel::getServiceContainer()->getWriteConnection(BannerImageTableMap::DATABASE_NAME);
907
        }
908
909
        return $con->transaction(function () use ($con) {
910
            $ret = $this->preSave($con);
911
            $isInsert = $this->isNew();
912
            if ($isInsert) {
913
                $ret = $ret && $this->preInsert($con);
914
            } else {
915
                $ret = $ret && $this->preUpdate($con);
916
            }
917
            if ($ret) {
918
                $affectedRows = $this->doSave($con);
919
                if ($isInsert) {
920
                    $this->postInsert($con);
921
                } else {
922
                    $this->postUpdate($con);
923
                }
924
                $this->postSave($con);
925
                BannerImageTableMap::addInstanceToPool($this);
926
            } else {
927
                $affectedRows = 0;
928
            }
929
930
            return $affectedRows;
931
        });
932
    }
933
934
    /**
935
     * Performs the work of inserting or updating the row in the database.
936
     *
937
     * If the object is new, it inserts it; otherwise an update is performed.
938
     * All related objects are also updated in this method.
939
     *
940
     * @param      ConnectionInterface $con
941
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
942
     * @throws PropelException
943
     * @see save()
944
     */
945
    protected function doSave(ConnectionInterface $con)
946
    {
947
        $affectedRows = 0; // initialize var to track total num of affected rows
948
        if (!$this->alreadyInSave) {
949
            $this->alreadyInSave = true;
950
951
            // We call the save method on the following object(s) if they
952
            // were passed to this object by their corresponding set
953
            // method.  This object relates to these object(s) by a
954
            // foreign key reference.
955
956
            if ($this->aBanners !== null) {
957
                if ($this->aBanners->isModified() || $this->aBanners->isNew()) {
958
                    $affectedRows += $this->aBanners->save($con);
959
                }
960
                $this->setBanners($this->aBanners);
961
            }
962
963
            if ($this->isNew() || $this->isModified()) {
964
                // persist changes
965
                if ($this->isNew()) {
966
                    $this->doInsert($con);
967
                    $affectedRows += 1;
968
                } else {
969
                    $affectedRows += $this->doUpdate($con);
970
                }
971
                $this->resetModified();
972
            }
973
974
            if ($this->bannerImageI18nsScheduledForDeletion !== null) {
975
                if (!$this->bannerImageI18nsScheduledForDeletion->isEmpty()) {
976
                    \xbanners\models\BannerImageI18nQuery::create()
977
                        ->filterByPrimaryKeys($this->bannerImageI18nsScheduledForDeletion->getPrimaryKeys(false))
978
                        ->delete($con);
979
                    $this->bannerImageI18nsScheduledForDeletion = null;
980
                }
981
            }
982
983
            if ($this->collBannerImageI18ns !== null) {
984
                foreach ($this->collBannerImageI18ns as $referrerFK) {
985
                    if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
986
                        $affectedRows += $referrerFK->save($con);
987
                    }
988
                }
989
            }
990
991
            $this->alreadyInSave = false;
992
993
        }
994
995
        return $affectedRows;
996
    } // doSave()
997
998
    /**
999
     * Insert the row in the database.
1000
     *
1001
     * @param      ConnectionInterface $con
1002
     *
1003
     * @throws PropelException
1004
     * @see doSave()
1005
     */
1006
    protected function doInsert(ConnectionInterface $con)
1007
    {
1008
        $modifiedColumns = array();
1009
        $index = 0;
1010
1011
        $this->modifiedColumns[BannerImageTableMap::COL_ID] = true;
1012
        if (null !== $this->id) {
1013
            throw new PropelException('Cannot insert a value for auto-increment primary key (' . BannerImageTableMap::COL_ID . ')');
1014
        }
1015
1016
         // check the columns in natural order for more readable SQL queries
1017
        if ($this->isColumnModified(BannerImageTableMap::COL_ID)) {
1018
            $modifiedColumns[':p' . $index++]  = 'id';
1019
        }
1020
        if ($this->isColumnModified(BannerImageTableMap::COL_BANNER_ID)) {
1021
            $modifiedColumns[':p' . $index++]  = 'banner_id';
1022
        }
1023
        if ($this->isColumnModified(BannerImageTableMap::COL_TARGET)) {
1024
            $modifiedColumns[':p' . $index++]  = 'target';
1025
        }
1026
        if ($this->isColumnModified(BannerImageTableMap::COL_URL)) {
1027
            $modifiedColumns[':p' . $index++]  = 'url';
1028
        }
1029
        if ($this->isColumnModified(BannerImageTableMap::COL_ALLOWED_PAGE)) {
1030
            $modifiedColumns[':p' . $index++]  = 'allowed_page';
1031
        }
1032
        if ($this->isColumnModified(BannerImageTableMap::COL_POSITION)) {
1033
            $modifiedColumns[':p' . $index++]  = 'position';
1034
        }
1035
        if ($this->isColumnModified(BannerImageTableMap::COL_ACTIVE_FROM)) {
1036
            $modifiedColumns[':p' . $index++]  = 'active_from';
1037
        }
1038
        if ($this->isColumnModified(BannerImageTableMap::COL_ACTIVE_TO)) {
1039
            $modifiedColumns[':p' . $index++]  = 'active_to';
1040
        }
1041
        if ($this->isColumnModified(BannerImageTableMap::COL_ACTIVE)) {
1042
            $modifiedColumns[':p' . $index++]  = 'active';
1043
        }
1044
        if ($this->isColumnModified(BannerImageTableMap::COL_PERMANENT)) {
1045
            $modifiedColumns[':p' . $index++]  = 'permanent';
1046
        }
1047
1048
        $sql = sprintf(
1049
            'INSERT INTO banner_image (%s) VALUES (%s)',
1050
            implode(', ', $modifiedColumns),
1051
            implode(', ', array_keys($modifiedColumns))
1052
        );
1053
1054
        try {
1055
            $stmt = $con->prepare($sql);
1056
            foreach ($modifiedColumns as $identifier => $columnName) {
1057
                switch ($columnName) {
1058
                    case 'id':
1059
                        $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
1060
                        break;
1061
                    case 'banner_id':
1062
                        $stmt->bindValue($identifier, $this->banner_id, PDO::PARAM_INT);
1063
                        break;
1064
                    case 'target':
1065
                        $stmt->bindValue($identifier, $this->target, PDO::PARAM_INT);
1066
                        break;
1067
                    case 'url':
1068
                        $stmt->bindValue($identifier, $this->url, PDO::PARAM_STR);
1069
                        break;
1070
                    case 'allowed_page':
1071
                        $stmt->bindValue($identifier, $this->allowed_page, PDO::PARAM_INT);
1072
                        break;
1073
                    case 'position':
1074
                        $stmt->bindValue($identifier, $this->position, PDO::PARAM_INT);
1075
                        break;
1076
                    case 'active_from':
1077
                        $stmt->bindValue($identifier, $this->active_from, PDO::PARAM_INT);
1078
                        break;
1079
                    case 'active_to':
1080
                        $stmt->bindValue($identifier, $this->active_to, PDO::PARAM_INT);
1081
                        break;
1082
                    case 'active':
1083
                        $stmt->bindValue($identifier, $this->active, PDO::PARAM_INT);
1084
                        break;
1085
                    case 'permanent':
1086
                        $stmt->bindValue($identifier, $this->permanent, PDO::PARAM_INT);
1087
                        break;
1088
                }
1089
            }
1090
            $stmt->execute();
1091
        } catch (Exception $e) {
1092
            Propel::log($e->getMessage(), Propel::LOG_ERR);
1093
            throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e);
1094
        }
1095
1096
        try {
1097
            $pk = $con->lastInsertId();
1098
        } catch (Exception $e) {
1099
            throw new PropelException('Unable to get autoincrement id.', 0, $e);
1100
        }
1101
        $this->setId($pk);
1102
1103
        $this->setNew(false);
1104
    }
1105
1106
    /**
1107
     * Update the row in the database.
1108
     *
1109
     * @param      ConnectionInterface $con
1110
     *
1111
     * @return Integer Number of updated rows
1112
     * @see doSave()
1113
     */
1114
    protected function doUpdate(ConnectionInterface $con)
1115
    {
1116
        $selectCriteria = $this->buildPkeyCriteria();
1117
        $valuesCriteria = $this->buildCriteria();
1118
1119
        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...
1120
    }
1121
1122
    /**
1123
     * Retrieves a field from the object by name passed in as a string.
1124
     *
1125
     * @param      string $name name
1126
     * @param      string $type The type of fieldname the $name is of:
1127
     *                     one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
1128
     *                     TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1129
     *                     Defaults to TableMap::TYPE_PHPNAME.
1130
     * @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...
1131
     */
1132 View Code Duplication
    public function getByName($name, $type = TableMap::TYPE_PHPNAME)
1133
    {
1134
        $pos = BannerImageTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM);
1135
        $field = $this->getByPosition($pos);
1136
1137
        return $field;
1138
    }
1139
1140
    /**
1141
     * Retrieves a field from the object by Position as specified in the xml schema.
1142
     * Zero-based.
1143
     *
1144
     * @param      int $pos position in xml schema
1145
     * @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...
1146
     */
1147
    public function getByPosition($pos)
1148
    {
1149
        switch ($pos) {
1150
            case 0:
1151
                return $this->getId();
1152
                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...
1153
            case 1:
1154
                return $this->getBannerId();
1155
                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...
1156
            case 2:
1157
                return $this->getTarget();
1158
                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...
1159
            case 3:
1160
                return $this->getUrl();
1161
                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...
1162
            case 4:
1163
                return $this->getAllowedPage();
1164
                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...
1165
            case 5:
1166
                return $this->getPosition();
1167
                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...
1168
            case 6:
1169
                return $this->getActiveFrom();
1170
                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...
1171
            case 7:
1172
                return $this->getActiveTo();
1173
                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...
1174
            case 8:
1175
                return $this->getActive();
1176
                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...
1177
            case 9:
1178
                return $this->getPermanent();
1179
                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...
1180
            default:
1181
                return null;
1182
                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...
1183
        } // switch()
1184
    }
1185
1186
    /**
1187
     * Exports the object as an array.
1188
     *
1189
     * You can specify the key type of the array by passing one of the class
1190
     * type constants.
1191
     *
1192
     * @param     string  $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
1193
     *                    TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1194
     *                    Defaults to TableMap::TYPE_PHPNAME.
1195
     * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
1196
     * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
1197
     * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
1198
     *
1199
     * @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?

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...
1200
     */
1201
    public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
1202
    {
1203
1204
        if (isset($alreadyDumpedObjects['BannerImage'][$this->hashCode()])) {
1205
            return '*RECURSION*';
1206
        }
1207
        $alreadyDumpedObjects['BannerImage'][$this->hashCode()] = true;
1208
        $keys = BannerImageTableMap::getFieldNames($keyType);
1209
        $result = array(
1210
            $keys[0] => $this->getId(),
1211
            $keys[1] => $this->getBannerId(),
1212
            $keys[2] => $this->getTarget(),
1213
            $keys[3] => $this->getUrl(),
1214
            $keys[4] => $this->getAllowedPage(),
1215
            $keys[5] => $this->getPosition(),
1216
            $keys[6] => $this->getActiveFrom(),
1217
            $keys[7] => $this->getActiveTo(),
1218
            $keys[8] => $this->getActive(),
1219
            $keys[9] => $this->getPermanent(),
1220
        );
1221
        $virtualColumns = $this->virtualColumns;
1222
        foreach ($virtualColumns as $key => $virtualColumn) {
1223
            $result[$key] = $virtualColumn;
1224
        }
1225
1226
        if ($includeForeignObjects) {
1227 View Code Duplication
            if (null !== $this->aBanners) {
1228
1229
                switch ($keyType) {
1230
                    case TableMap::TYPE_CAMELNAME:
1231
                        $key = 'banners';
1232
                        break;
1233
                    case TableMap::TYPE_FIELDNAME:
1234
                        $key = 'banners';
1235
                        break;
1236
                    default:
1237
                        $key = 'Banners';
1238
                }
1239
1240
                $result[$key] = $this->aBanners->toArray($keyType, $includeLazyLoadColumns,  $alreadyDumpedObjects, true);
1241
            }
1242
            if (null !== $this->collBannerImageI18ns) {
1243
1244
                switch ($keyType) {
1245
                    case TableMap::TYPE_CAMELNAME:
1246
                        $key = 'bannerImageI18ns';
1247
                        break;
1248
                    case TableMap::TYPE_FIELDNAME:
1249
                        $key = 'banner_image_i18ns';
1250
                        break;
1251
                    default:
1252
                        $key = 'BannerImageI18ns';
1253
                }
1254
1255
                $result[$key] = $this->collBannerImageI18ns->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
1256
            }
1257
        }
1258
1259
        return $result;
1260
    }
1261
1262
    /**
1263
     * Sets a field from the object by name passed in as a string.
1264
     *
1265
     * @param  string $name
1266
     * @param  mixed  $value field value
1267
     * @param  string $type The type of fieldname the $name is of:
1268
     *                one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
1269
     *                TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1270
     *                Defaults to TableMap::TYPE_PHPNAME.
1271
     * @return $this|\xbanners\models\BannerImage
1272
     */
1273
    public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME)
1274
    {
1275
        $pos = BannerImageTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM);
1276
1277
        return $this->setByPosition($pos, $value);
1278
    }
1279
1280
    /**
1281
     * Sets a field from the object by Position as specified in the xml schema.
1282
     * Zero-based.
1283
     *
1284
     * @param  int $pos position in xml schema
1285
     * @param  mixed $value field value
1286
     * @return $this|\xbanners\models\BannerImage
1287
     */
1288
    public function setByPosition($pos, $value)
1289
    {
1290
        switch ($pos) {
1291
            case 0:
1292
                $this->setId($value);
1293
                break;
1294
            case 1:
1295
                $this->setBannerId($value);
1296
                break;
1297
            case 2:
1298
                $this->setTarget($value);
1299
                break;
1300
            case 3:
1301
                $this->setUrl($value);
1302
                break;
1303
            case 4:
1304
                $this->setAllowedPage($value);
1305
                break;
1306
            case 5:
1307
                $this->setPosition($value);
1308
                break;
1309
            case 6:
1310
                $this->setActiveFrom($value);
1311
                break;
1312
            case 7:
1313
                $this->setActiveTo($value);
1314
                break;
1315
            case 8:
1316
                $this->setActive($value);
1317
                break;
1318
            case 9:
1319
                $this->setPermanent($value);
1320
                break;
1321
        } // switch()
1322
1323
        return $this;
1324
    }
1325
1326
    /**
1327
     * Populates the object using an array.
1328
     *
1329
     * This is particularly useful when populating an object from one of the
1330
     * request arrays (e.g. $_POST).  This method goes through the column
1331
     * names, checking to see whether a matching key exists in populated
1332
     * array. If so the setByName() method is called for that column.
1333
     *
1334
     * You can specify the key type of the array by additionally passing one
1335
     * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
1336
     * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1337
     * The default key type is the column's TableMap::TYPE_PHPNAME.
1338
     *
1339
     * @param      array  $arr     An array to populate the object from.
1340
     * @param      string $keyType The type of keys the array uses.
1341
     * @return void
1342
     */
1343
    public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME)
1344
    {
1345
        $keys = BannerImageTableMap::getFieldNames($keyType);
1346
1347
        if (array_key_exists($keys[0], $arr)) {
1348
            $this->setId($arr[$keys[0]]);
1349
        }
1350
        if (array_key_exists($keys[1], $arr)) {
1351
            $this->setBannerId($arr[$keys[1]]);
1352
        }
1353
        if (array_key_exists($keys[2], $arr)) {
1354
            $this->setTarget($arr[$keys[2]]);
1355
        }
1356
        if (array_key_exists($keys[3], $arr)) {
1357
            $this->setUrl($arr[$keys[3]]);
1358
        }
1359
        if (array_key_exists($keys[4], $arr)) {
1360
            $this->setAllowedPage($arr[$keys[4]]);
1361
        }
1362
        if (array_key_exists($keys[5], $arr)) {
1363
            $this->setPosition($arr[$keys[5]]);
1364
        }
1365
        if (array_key_exists($keys[6], $arr)) {
1366
            $this->setActiveFrom($arr[$keys[6]]);
1367
        }
1368
        if (array_key_exists($keys[7], $arr)) {
1369
            $this->setActiveTo($arr[$keys[7]]);
1370
        }
1371
        if (array_key_exists($keys[8], $arr)) {
1372
            $this->setActive($arr[$keys[8]]);
1373
        }
1374
        if (array_key_exists($keys[9], $arr)) {
1375
            $this->setPermanent($arr[$keys[9]]);
1376
        }
1377
    }
1378
1379
     /**
1380
     * Populate the current object from a string, using a given parser format
1381
     * <code>
1382
     * $book = new Book();
1383
     * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}');
1384
     * </code>
1385
     *
1386
     * You can specify the key type of the array by additionally passing one
1387
     * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
1388
     * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1389
     * The default key type is the column's TableMap::TYPE_PHPNAME.
1390
     *
1391
     * @param mixed $parser A AbstractParser instance,
1392
     *                       or a format name ('XML', 'YAML', 'JSON', 'CSV')
1393
     * @param string $data The source data to import from
1394
     * @param string $keyType The type of keys the array uses.
1395
     *
1396
     * @return $this|\xbanners\models\BannerImage The current object, for fluid interface
1397
     */
1398 View Code Duplication
    public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME)
1399
    {
1400
        if (!$parser instanceof AbstractParser) {
1401
            $parser = AbstractParser::getParser($parser);
1402
        }
1403
1404
        $this->fromArray($parser->toArray($data), $keyType);
1405
1406
        return $this;
1407
    }
1408
1409
    /**
1410
     * Build a Criteria object containing the values of all modified columns in this object.
1411
     *
1412
     * @return Criteria The Criteria object containing all modified values.
1413
     */
1414
    public function buildCriteria()
1415
    {
1416
        $criteria = new Criteria(BannerImageTableMap::DATABASE_NAME);
1417
1418
        if ($this->isColumnModified(BannerImageTableMap::COL_ID)) {
1419
            $criteria->add(BannerImageTableMap::COL_ID, $this->id);
1420
        }
1421
        if ($this->isColumnModified(BannerImageTableMap::COL_BANNER_ID)) {
1422
            $criteria->add(BannerImageTableMap::COL_BANNER_ID, $this->banner_id);
1423
        }
1424
        if ($this->isColumnModified(BannerImageTableMap::COL_TARGET)) {
1425
            $criteria->add(BannerImageTableMap::COL_TARGET, $this->target);
1426
        }
1427
        if ($this->isColumnModified(BannerImageTableMap::COL_URL)) {
1428
            $criteria->add(BannerImageTableMap::COL_URL, $this->url);
1429
        }
1430
        if ($this->isColumnModified(BannerImageTableMap::COL_ALLOWED_PAGE)) {
1431
            $criteria->add(BannerImageTableMap::COL_ALLOWED_PAGE, $this->allowed_page);
1432
        }
1433
        if ($this->isColumnModified(BannerImageTableMap::COL_POSITION)) {
1434
            $criteria->add(BannerImageTableMap::COL_POSITION, $this->position);
1435
        }
1436
        if ($this->isColumnModified(BannerImageTableMap::COL_ACTIVE_FROM)) {
1437
            $criteria->add(BannerImageTableMap::COL_ACTIVE_FROM, $this->active_from);
1438
        }
1439
        if ($this->isColumnModified(BannerImageTableMap::COL_ACTIVE_TO)) {
1440
            $criteria->add(BannerImageTableMap::COL_ACTIVE_TO, $this->active_to);
1441
        }
1442
        if ($this->isColumnModified(BannerImageTableMap::COL_ACTIVE)) {
1443
            $criteria->add(BannerImageTableMap::COL_ACTIVE, $this->active);
1444
        }
1445
        if ($this->isColumnModified(BannerImageTableMap::COL_PERMANENT)) {
1446
            $criteria->add(BannerImageTableMap::COL_PERMANENT, $this->permanent);
1447
        }
1448
1449
        return $criteria;
1450
    }
1451
1452
    /**
1453
     * Builds a Criteria object containing the primary key for this object.
1454
     *
1455
     * Unlike buildCriteria() this method includes the primary key values regardless
1456
     * of whether or not they have been modified.
1457
     *
1458
     * @throws LogicException if no primary key is defined
1459
     *
1460
     * @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 ChildBannerImageQuery.

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...
1461
     */
1462
    public function buildPkeyCriteria()
1463
    {
1464
        $criteria = ChildBannerImageQuery::create();
1465
        $criteria->add(BannerImageTableMap::COL_ID, $this->id);
1466
1467
        return $criteria;
1468
    }
1469
1470
    /**
1471
     * If the primary key is not null, return the hashcode of the
1472
     * primary key. Otherwise, return the hash code of the object.
1473
     *
1474
     * @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...
1475
     */
1476 View Code Duplication
    public function hashCode()
1477
    {
1478
        $validPk = null !== $this->getId();
1479
1480
        $validPrimaryKeyFKs = 0;
1481
        $primaryKeyFKs = [];
1482
1483
        if ($validPk) {
1484
            return crc32(json_encode($this->getPrimaryKey(), JSON_UNESCAPED_UNICODE));
1485
        } elseif ($validPrimaryKeyFKs) {
1486
            return crc32(json_encode($primaryKeyFKs, JSON_UNESCAPED_UNICODE));
1487
        }
1488
1489
        return spl_object_hash($this);
1490
    }
1491
1492
    /**
1493
     * Returns the primary key for this object (row).
1494
     * @return int
1495
     */
1496
    public function getPrimaryKey()
1497
    {
1498
        return $this->getId();
1499
    }
1500
1501
    /**
1502
     * Generic method to set the primary key (id column).
1503
     *
1504
     * @param       int $key Primary key.
1505
     * @return void
1506
     */
1507
    public function setPrimaryKey($key)
1508
    {
1509
        $this->setId($key);
1510
    }
1511
1512
    /**
1513
     * Returns true if the primary key for this object is null.
1514
     * @return boolean
1515
     */
1516
    public function isPrimaryKeyNull()
1517
    {
1518
        return null === $this->getId();
1519
    }
1520
1521
    /**
1522
     * Sets contents of passed object to values from current object.
1523
     *
1524
     * If desired, this method can also make copies of all associated (fkey referrers)
1525
     * objects.
1526
     *
1527
     * @param      object $copyObj An object of \xbanners\models\BannerImage (or compatible) type.
1528
     * @param      boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1529
     * @param      boolean $makeNew Whether to reset autoincrement PKs and make the object new.
1530
     * @throws PropelException
1531
     */
1532
    public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
1533
    {
1534
        $copyObj->setBannerId($this->getBannerId());
1535
        $copyObj->setTarget($this->getTarget());
1536
        $copyObj->setUrl($this->getUrl());
1537
        $copyObj->setAllowedPage($this->getAllowedPage());
1538
        $copyObj->setPosition($this->getPosition());
1539
        $copyObj->setActiveFrom($this->getActiveFrom());
1540
        $copyObj->setActiveTo($this->getActiveTo());
1541
        $copyObj->setActive($this->getActive());
1542
        $copyObj->setPermanent($this->getPermanent());
1543
1544
        if ($deepCopy) {
1545
            // important: temporarily setNew(false) because this affects the behavior of
1546
            // the getter/setter methods for fkey referrer objects.
1547
            $copyObj->setNew(false);
1548
1549
            foreach ($this->getBannerImageI18ns() as $relObj) {
1550
                if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
1551
                    $copyObj->addBannerImageI18n($relObj->copy($deepCopy));
1552
                }
1553
            }
1554
1555
        } // if ($deepCopy)
1556
1557
        if ($makeNew) {
1558
            $copyObj->setNew(true);
1559
            $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
1560
        }
1561
    }
1562
1563
    /**
1564
     * Makes a copy of this object that will be inserted as a new row in table when saved.
1565
     * It creates a new object filling in the simple attributes, but skipping any primary
1566
     * keys that are defined for the table.
1567
     *
1568
     * If desired, this method can also make copies of all associated (fkey referrers)
1569
     * objects.
1570
     *
1571
     * @param  boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1572
     * @return \xbanners\models\BannerImage Clone of current object.
1573
     * @throws PropelException
1574
     */
1575 View Code Duplication
    public function copy($deepCopy = false)
1576
    {
1577
        // we use get_class(), because this might be a subclass
1578
        $clazz = get_class($this);
1579
        $copyObj = new $clazz();
1580
        $this->copyInto($copyObj, $deepCopy);
1581
1582
        return $copyObj;
1583
    }
1584
1585
    /**
1586
     * Declares an association between this object and a ChildBanners object.
1587
     *
1588
     * @param  ChildBanners $v
1589
     * @return $this|\xbanners\models\BannerImage The current object (for fluent API support)
1590
     * @throws PropelException
1591
     */
1592
    public function setBanners(ChildBanners $v = null)
1593
    {
1594
        if ($v === null) {
1595
            $this->setBannerId(NULL);
1596
        } else {
1597
            $this->setBannerId($v->getId());
1598
        }
1599
1600
        $this->aBanners = $v;
1601
1602
        // Add binding for other direction of this n:n relationship.
1603
        // If this object has already been added to the ChildBanners object, it will not be re-added.
1604
        if ($v !== null) {
1605
            $v->addBannerImage($this);
0 ignored issues
show
Compatibility introduced by
$this of type object<xbanners\models\Base\BannerImage> is not a sub-type of object<xbanners\models\BannerImage>. It seems like you assume a child class of the class xbanners\models\Base\BannerImage 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...
1606
        }
1607
1608
1609
        return $this;
1610
    }
1611
1612
1613
    /**
1614
     * Get the associated ChildBanners object
1615
     *
1616
     * @param  ConnectionInterface $con Optional Connection object.
1617
     * @return ChildBanners The associated ChildBanners object.
1618
     * @throws PropelException
1619
     */
1620 View Code Duplication
    public function getBanners(ConnectionInterface $con = null)
1621
    {
1622
        if ($this->aBanners === null && ($this->banner_id !== null)) {
1623
            $this->aBanners = ChildBannersQuery::create()->findPk($this->banner_id, $con);
1624
            /* The following can be used additionally to
1625
                guarantee the related object contains a reference
1626
                to this object.  This level of coupling may, however, be
1627
                undesirable since it could result in an only partially populated collection
1628
                in the referenced object.
1629
                $this->aBanners->addBannerImages($this);
1630
             */
1631
        }
1632
1633
        return $this->aBanners;
1634
    }
1635
1636
1637
    /**
1638
     * Initializes a collection based on the name of a relation.
1639
     * Avoids crafting an 'init[$relationName]s' method name
1640
     * that wouldn't work when StandardEnglishPluralizer is used.
1641
     *
1642
     * @param      string $relationName The name of the relation to initialize
1643
     * @return void
1644
     */
1645
    public function initRelation($relationName)
1646
    {
1647
        if ('BannerImageI18n' == $relationName) {
1648
            return $this->initBannerImageI18ns();
1649
        }
1650
    }
1651
1652
    /**
1653
     * Clears out the collBannerImageI18ns collection
1654
     *
1655
     * This does not modify the database; however, it will remove any associated objects, causing
1656
     * them to be refetched by subsequent calls to accessor method.
1657
     *
1658
     * @return void
1659
     * @see        addBannerImageI18ns()
1660
     */
1661
    public function clearBannerImageI18ns()
1662
    {
1663
        $this->collBannerImageI18ns = null; // important to set this to NULL since that means it is uninitialized
1664
    }
1665
1666
    /**
1667
     * Reset is the collBannerImageI18ns collection loaded partially.
1668
     */
1669
    public function resetPartialBannerImageI18ns($v = true)
1670
    {
1671
        $this->collBannerImageI18nsPartial = $v;
1672
    }
1673
1674
    /**
1675
     * Initializes the collBannerImageI18ns collection.
1676
     *
1677
     * By default this just sets the collBannerImageI18ns collection to an empty array (like clearcollBannerImageI18ns());
1678
     * however, you may wish to override this method in your stub class to provide setting appropriate
1679
     * to your application -- for example, setting the initial array to the values stored in database.
1680
     *
1681
     * @param      boolean $overrideExisting If set to true, the method call initializes
1682
     *                                        the collection even if it is not empty
1683
     *
1684
     * @return void
1685
     */
1686 View Code Duplication
    public function initBannerImageI18ns($overrideExisting = true)
1687
    {
1688
        if (null !== $this->collBannerImageI18ns && !$overrideExisting) {
1689
            return;
1690
        }
1691
1692
        $collectionClassName = BannerImageI18nTableMap::getTableMap()->getCollectionClassName();
1693
1694
        $this->collBannerImageI18ns = new $collectionClassName;
1695
        $this->collBannerImageI18ns->setModel('\xbanners\models\BannerImageI18n');
1696
    }
1697
1698
    /**
1699
     * Gets an array of ChildBannerImageI18n objects which contain a foreign key that references this object.
1700
     *
1701
     * If the $criteria is not null, it is used to always fetch the results from the database.
1702
     * Otherwise the results are fetched from the database the first time, then cached.
1703
     * Next time the same method is called without $criteria, the cached collection is returned.
1704
     * If this ChildBannerImage is new, it will return
1705
     * an empty collection or the current collection; the criteria is ignored on a new object.
1706
     *
1707
     * @param      Criteria $criteria optional Criteria object to narrow the query
1708
     * @param      ConnectionInterface $con optional connection object
1709
     * @return ObjectCollection|ChildBannerImageI18n[] List of ChildBannerImageI18n objects
1710
     * @throws PropelException
1711
     */
1712 View Code Duplication
    public function getBannerImageI18ns(Criteria $criteria = null, ConnectionInterface $con = null)
1713
    {
1714
        $partial = $this->collBannerImageI18nsPartial && !$this->isNew();
1715
        if (null === $this->collBannerImageI18ns || null !== $criteria  || $partial) {
1716
            if ($this->isNew() && null === $this->collBannerImageI18ns) {
1717
                // return empty collection
1718
                $this->initBannerImageI18ns();
1719
            } else {
1720
                $collBannerImageI18ns = ChildBannerImageI18nQuery::create(null, $criteria)
1721
                    ->filterByBannerImage($this)
0 ignored issues
show
Documentation introduced by
$this is of type this<xbanners\models\Base\BannerImage>, but the function expects a object<xbanners\models\B...ction\ObjectCollection>.

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...
1722
                    ->find($con);
0 ignored issues
show
Bug introduced by
It seems like $con defined by parameter $con on line 1712 can be null; however, xbanners\models\Base\BannerImageI18nQuery::find() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
1723
1724
                if (null !== $criteria) {
1725
                    if (false !== $this->collBannerImageI18nsPartial && count($collBannerImageI18ns)) {
1726
                        $this->initBannerImageI18ns(false);
1727
1728
                        foreach ($collBannerImageI18ns as $obj) {
1729
                            if (false == $this->collBannerImageI18ns->contains($obj)) {
1730
                                $this->collBannerImageI18ns->append($obj);
1731
                            }
1732
                        }
1733
1734
                        $this->collBannerImageI18nsPartial = true;
1735
                    }
1736
1737
                    return $collBannerImageI18ns;
1738
                }
1739
1740
                if ($partial && $this->collBannerImageI18ns) {
1741
                    foreach ($this->collBannerImageI18ns as $obj) {
1742
                        if ($obj->isNew()) {
1743
                            $collBannerImageI18ns[] = $obj;
1744
                        }
1745
                    }
1746
                }
1747
1748
                $this->collBannerImageI18ns = $collBannerImageI18ns;
1749
                $this->collBannerImageI18nsPartial = false;
1750
            }
1751
        }
1752
1753
        return $this->collBannerImageI18ns;
1754
    }
1755
1756
    /**
1757
     * Sets a collection of ChildBannerImageI18n objects related by a one-to-many relationship
1758
     * to the current object.
1759
     * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
1760
     * and new objects from the given Propel collection.
1761
     *
1762
     * @param      Collection $bannerImageI18ns A Propel collection.
1763
     * @param      ConnectionInterface $con Optional connection object
1764
     * @return $this|ChildBannerImage The current object (for fluent API support)
1765
     */
1766
    public function setBannerImageI18ns(Collection $bannerImageI18ns, ConnectionInterface $con = null)
1767
    {
1768
        /** @var ChildBannerImageI18n[] $bannerImageI18nsToDelete */
1769
        $bannerImageI18nsToDelete = $this->getBannerImageI18ns(new Criteria(), $con)->diff($bannerImageI18ns);
1770
1771
1772
        //since at least one column in the foreign key is at the same time a PK
1773
        //we can not just set a PK to NULL in the lines below. We have to store
1774
        //a backup of all values, so we are able to manipulate these items based on the onDelete value later.
1775
        $this->bannerImageI18nsScheduledForDeletion = clone $bannerImageI18nsToDelete;
1776
1777
        foreach ($bannerImageI18nsToDelete as $bannerImageI18nRemoved) {
1778
            $bannerImageI18nRemoved->setBannerImage(null);
1779
        }
1780
1781
        $this->collBannerImageI18ns = null;
1782
        foreach ($bannerImageI18ns as $bannerImageI18n) {
1783
            $this->addBannerImageI18n($bannerImageI18n);
1784
        }
1785
1786
        $this->collBannerImageI18ns = $bannerImageI18ns;
0 ignored issues
show
Documentation Bug introduced by
It seems like $bannerImageI18ns of type object<Propel\Runtime\Collection\Collection> is incompatible with the declared type object<Propel\Runtime\Co...odels\BannerImageI18n>> of property $collBannerImageI18ns.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
1787
        $this->collBannerImageI18nsPartial = false;
1788
1789
        return $this;
1790
    }
1791
1792
    /**
1793
     * Returns the number of related BannerImageI18n objects.
1794
     *
1795
     * @param      Criteria $criteria
1796
     * @param      boolean $distinct
1797
     * @param      ConnectionInterface $con
1798
     * @return int             Count of related BannerImageI18n objects.
1799
     * @throws PropelException
1800
     */
1801 View Code Duplication
    public function countBannerImageI18ns(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
1802
    {
1803
        $partial = $this->collBannerImageI18nsPartial && !$this->isNew();
1804
        if (null === $this->collBannerImageI18ns || null !== $criteria || $partial) {
1805
            if ($this->isNew() && null === $this->collBannerImageI18ns) {
1806
                return 0;
1807
            }
1808
1809
            if ($partial && !$criteria) {
1810
                return count($this->getBannerImageI18ns());
1811
            }
1812
1813
            $query = ChildBannerImageI18nQuery::create(null, $criteria);
1814
            if ($distinct) {
1815
                $query->distinct();
1816
            }
1817
1818
            return $query
1819
                ->filterByBannerImage($this)
0 ignored issues
show
Documentation introduced by
$this is of type this<xbanners\models\Base\BannerImage>, but the function expects a object<xbanners\models\B...ction\ObjectCollection>.

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...
1820
                ->count($con);
1821
        }
1822
1823
        return count($this->collBannerImageI18ns);
1824
    }
1825
1826
    /**
1827
     * Method called to associate a ChildBannerImageI18n object to this object
1828
     * through the ChildBannerImageI18n foreign key attribute.
1829
     *
1830
     * @param  ChildBannerImageI18n $l ChildBannerImageI18n
1831
     * @return $this|\xbanners\models\BannerImage The current object (for fluent API support)
1832
     */
1833 View Code Duplication
    public function addBannerImageI18n(ChildBannerImageI18n $l)
1834
    {
1835
        if ($l && $locale = $l->getLocale()) {
1836
            $this->setLocale($locale);
1837
            $this->currentTranslations[$locale] = $l;
1838
        }
1839
        if ($this->collBannerImageI18ns === null) {
1840
            $this->initBannerImageI18ns();
1841
            $this->collBannerImageI18nsPartial = true;
1842
        }
1843
1844
        if (!$this->collBannerImageI18ns->contains($l)) {
1845
            $this->doAddBannerImageI18n($l);
1846
1847
            if ($this->bannerImageI18nsScheduledForDeletion and $this->bannerImageI18nsScheduledForDeletion->contains($l)) {
1848
                $this->bannerImageI18nsScheduledForDeletion->remove($this->bannerImageI18nsScheduledForDeletion->search($l));
1849
            }
1850
        }
1851
1852
        return $this;
1853
    }
1854
1855
    /**
1856
     * @param ChildBannerImageI18n $bannerImageI18n The ChildBannerImageI18n object to add.
1857
     */
1858
    protected function doAddBannerImageI18n(ChildBannerImageI18n $bannerImageI18n)
1859
    {
1860
        $this->collBannerImageI18ns[]= $bannerImageI18n;
1861
        $bannerImageI18n->setBannerImage($this);
0 ignored issues
show
Documentation introduced by
$this is of type this<xbanners\models\Base\BannerImage>, but the function expects a null|object<xbanners\models\BannerImage>.

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...
1862
    }
1863
1864
    /**
1865
     * @param  ChildBannerImageI18n $bannerImageI18n The ChildBannerImageI18n object to remove.
1866
     * @return $this|ChildBannerImage The current object (for fluent API support)
1867
     */
1868
    public function removeBannerImageI18n(ChildBannerImageI18n $bannerImageI18n)
1869
    {
1870
        if ($this->getBannerImageI18ns()->contains($bannerImageI18n)) {
1871
            $pos = $this->collBannerImageI18ns->search($bannerImageI18n);
1872
            $this->collBannerImageI18ns->remove($pos);
1873
            if (null === $this->bannerImageI18nsScheduledForDeletion) {
1874
                $this->bannerImageI18nsScheduledForDeletion = clone $this->collBannerImageI18ns;
1875
                $this->bannerImageI18nsScheduledForDeletion->clear();
1876
            }
1877
            $this->bannerImageI18nsScheduledForDeletion[]= clone $bannerImageI18n;
1878
            $bannerImageI18n->setBannerImage(null);
1879
        }
1880
1881
        return $this;
1882
    }
1883
1884
    /**
1885
     * Clears the current object, sets all attributes to their default values and removes
1886
     * outgoing references as well as back-references (from other objects to this one. Results probably in a database
1887
     * change of those foreign objects when you call `save` there).
1888
     */
1889
    public function clear()
1890
    {
1891
        if (null !== $this->aBanners) {
1892
            $this->aBanners->removeBannerImage($this);
0 ignored issues
show
Compatibility introduced by
$this of type object<xbanners\models\Base\BannerImage> is not a sub-type of object<xbanners\models\BannerImage>. It seems like you assume a child class of the class xbanners\models\Base\BannerImage 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...
1893
        }
1894
        $this->id = null;
1895
        $this->banner_id = null;
1896
        $this->target = null;
1897
        $this->url = null;
1898
        $this->allowed_page = null;
1899
        $this->position = null;
1900
        $this->active_from = null;
1901
        $this->active_to = null;
1902
        $this->active = null;
1903
        $this->permanent = null;
1904
        $this->alreadyInSave = false;
1905
        $this->clearAllReferences();
1906
        $this->resetModified();
1907
        $this->setNew(true);
1908
        $this->setDeleted(false);
1909
    }
1910
1911
    /**
1912
     * Resets all references and back-references to other model objects or collections of model objects.
1913
     *
1914
     * This method is used to reset all php object references (not the actual reference in the database).
1915
     * Necessary for object serialisation.
1916
     *
1917
     * @param      boolean $deep Whether to also clear the references on all referrer objects.
1918
     */
1919
    public function clearAllReferences($deep = false)
1920
    {
1921
        if ($deep) {
1922
            if ($this->collBannerImageI18ns) {
1923
                foreach ($this->collBannerImageI18ns as $o) {
1924
                    $o->clearAllReferences($deep);
1925
                }
1926
            }
1927
        } // if ($deep)
1928
1929
        // i18n behavior
1930
        $this->currentLocale = 'ru';
1931
        $this->currentTranslations = null;
1932
1933
        $this->collBannerImageI18ns = null;
1934
        $this->aBanners = null;
1935
    }
1936
1937
    /**
1938
     * Return the string representation of this object
1939
     *
1940
     * @return string
1941
     */
1942
    public function __toString()
1943
    {
1944
        return (string) $this->exportTo(BannerImageTableMap::DEFAULT_STRING_FORMAT);
1945
    }
1946
1947
    // i18n behavior
1948
1949
    /**
1950
     * Sets the locale for translations
1951
     *
1952
     * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
1953
     *
1954
     * @return    $this|ChildBannerImage The current object (for fluent API support)
1955
     */
1956
    public function setLocale($locale = 'ru')
1957
    {
1958
        $this->currentLocale = $locale;
1959
1960
        return $this;
1961
    }
1962
1963
    /**
1964
     * Gets the locale for translations
1965
     *
1966
     * @return    string $locale Locale to use for the translation, e.g. 'fr_FR'
1967
     */
1968
    public function getLocale()
1969
    {
1970
        return $this->currentLocale;
1971
    }
1972
1973
    /**
1974
     * Returns the current translation for a given locale
1975
     *
1976
     * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
1977
     * @param     ConnectionInterface $con an optional connection object
1978
     *
1979
     * @return ChildBannerImageI18n */
1980 View Code Duplication
    public function getTranslation($locale = 'ru', ConnectionInterface $con = null)
1981
    {
1982
        if (!isset($this->currentTranslations[$locale])) {
1983
            if (null !== $this->collBannerImageI18ns) {
1984
                foreach ($this->collBannerImageI18ns as $translation) {
1985
                    if ($translation->getLocale() == $locale) {
1986
                        $this->currentTranslations[$locale] = $translation;
1987
1988
                        return $translation;
1989
                    }
1990
                }
1991
            }
1992
            if ($this->isNew()) {
1993
                $translation = new ChildBannerImageI18n();
1994
                $translation->setLocale($locale);
1995
            } else {
1996
                $translation = ChildBannerImageI18nQuery::create()
1997
                    ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
1998
                    ->findOneOrCreate($con);
0 ignored issues
show
Bug introduced by
It seems like $con defined by parameter $con on line 1980 can be null; however, xbanners\models\Base\Ban...uery::findOneOrCreate() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
1999
                $this->currentTranslations[$locale] = $translation;
2000
            }
2001
            $this->addBannerImageI18n($translation);
2002
        }
2003
2004
        return $this->currentTranslations[$locale];
2005
    }
2006
2007
    /**
2008
     * Remove the translation for a given locale
2009
     *
2010
     * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
2011
     * @param     ConnectionInterface $con an optional connection object
2012
     *
2013
     * @return    $this|ChildBannerImage The current object (for fluent API support)
2014
     */
2015 View Code Duplication
    public function removeTranslation($locale = 'ru', ConnectionInterface $con = null)
2016
    {
2017
        if (!$this->isNew()) {
2018
            ChildBannerImageI18nQuery::create()
2019
                ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
2020
                ->delete($con);
2021
        }
2022
        if (isset($this->currentTranslations[$locale])) {
2023
            unset($this->currentTranslations[$locale]);
2024
        }
2025
        foreach ($this->collBannerImageI18ns as $key => $translation) {
2026
            if ($translation->getLocale() == $locale) {
2027
                unset($this->collBannerImageI18ns[$key]);
2028
                break;
2029
            }
2030
        }
2031
2032
        return $this;
2033
    }
2034
2035
    /**
2036
     * Returns the current translation
2037
     *
2038
     * @param     ConnectionInterface $con an optional connection object
2039
     *
2040
     * @return ChildBannerImageI18n */
2041
    public function getCurrentTranslation(ConnectionInterface $con = null)
2042
    {
2043
        return $this->getTranslation($this->getLocale(), $con);
2044
    }
2045
2046
2047
        /**
2048
         * Get the [src] column value.
2049
         *
2050
         * @return string
2051
         */
2052
        public function getSrc()
2053
        {
2054
        return $this->getCurrentTranslation()->getSrc();
2055
    }
2056
2057
2058
        /**
2059
         * Set the value of [src] column.
2060
         *
2061
         * @param string $v new value
2062
         * @return $this|\xbanners\models\BannerImageI18n The current object (for fluent API support)
2063
         */
2064
        public function setSrc($v)
2065
        {    $this->getCurrentTranslation()->setSrc($v);
2066
2067
        return $this;
2068
    }
2069
2070
2071
        /**
2072
         * Get the [name] column value.
2073
         *
2074
         * @return string
2075
         */
2076
        public function getName()
2077
        {
2078
        return $this->getCurrentTranslation()->getName();
2079
    }
2080
2081
2082
        /**
2083
         * Set the value of [name] column.
2084
         *
2085
         * @param string $v new value
2086
         * @return $this|\xbanners\models\BannerImageI18n The current object (for fluent API support)
2087
         */
2088
        public function setName($v)
2089
        {    $this->getCurrentTranslation()->setName($v);
2090
2091
        return $this;
2092
    }
2093
2094
2095
        /**
2096
         * Get the [clicks] column value.
2097
         *
2098
         * @return int
2099
         */
2100
        public function getClicks()
2101
        {
2102
        return $this->getCurrentTranslation()->getClicks();
2103
    }
2104
2105
2106
        /**
2107
         * Set the value of [clicks] column.
2108
         *
2109
         * @param int $v new value
2110
         * @return $this|\xbanners\models\BannerImageI18n The current object (for fluent API support)
2111
         */
2112
        public function setClicks($v)
2113
        {    $this->getCurrentTranslation()->setClicks($v);
2114
2115
        return $this;
2116
    }
2117
2118
2119
        /**
2120
         * Get the [description] column value.
2121
         *
2122
         * @return string
2123
         */
2124
        public function getDescription()
2125
        {
2126
        return $this->getCurrentTranslation()->getDescription();
2127
    }
2128
2129
2130
        /**
2131
         * Set the value of [description] column.
2132
         *
2133
         * @param string $v new value
2134
         * @return $this|\xbanners\models\BannerImageI18n The current object (for fluent API support)
2135
         */
2136
        public function setDescription($v)
2137
        {    $this->getCurrentTranslation()->setDescription($v);
2138
2139
        return $this;
2140
    }
2141
2142
    /**
2143
     * Code to be run before persisting the object
2144
     * @param  ConnectionInterface $con
2145
     * @return boolean
2146
     */
2147
    public function preSave(ConnectionInterface $con = null)
2148
    {
2149
        if (is_callable('parent::preSave')) {
2150
            return parent::preSave($con);
2151
        }
2152
        return true;
2153
    }
2154
2155
    /**
2156
     * Code to be run after persisting the object
2157
     * @param ConnectionInterface $con
2158
     */
2159
    public function postSave(ConnectionInterface $con = null)
2160
    {
2161
        if (is_callable('parent::postSave')) {
2162
            parent::postSave($con);
2163
        }
2164
    }
2165
2166
    /**
2167
     * Code to be run before inserting to database
2168
     * @param  ConnectionInterface $con
2169
     * @return boolean
2170
     */
2171
    public function preInsert(ConnectionInterface $con = null)
2172
    {
2173
        if (is_callable('parent::preInsert')) {
2174
            return parent::preInsert($con);
2175
        }
2176
        return true;
2177
    }
2178
2179
    /**
2180
     * Code to be run after inserting to database
2181
     * @param ConnectionInterface $con
2182
     */
2183
    public function postInsert(ConnectionInterface $con = null)
2184
    {
2185
        if (is_callable('parent::postInsert')) {
2186
            parent::postInsert($con);
2187
        }
2188
    }
2189
2190
    /**
2191
     * Code to be run before updating the object in database
2192
     * @param  ConnectionInterface $con
2193
     * @return boolean
2194
     */
2195
    public function preUpdate(ConnectionInterface $con = null)
2196
    {
2197
        if (is_callable('parent::preUpdate')) {
2198
            return parent::preUpdate($con);
2199
        }
2200
        return true;
2201
    }
2202
2203
    /**
2204
     * Code to be run after updating the object in database
2205
     * @param ConnectionInterface $con
2206
     */
2207
    public function postUpdate(ConnectionInterface $con = null)
2208
    {
2209
        if (is_callable('parent::postUpdate')) {
2210
            parent::postUpdate($con);
2211
        }
2212
    }
2213
2214
    /**
2215
     * Code to be run before deleting the object in database
2216
     * @param  ConnectionInterface $con
2217
     * @return boolean
2218
     */
2219
    public function preDelete(ConnectionInterface $con = null)
2220
    {
2221
        if (is_callable('parent::preDelete')) {
2222
            return parent::preDelete($con);
2223
        }
2224
        return true;
2225
    }
2226
2227
    /**
2228
     * Code to be run after deleting the object in database
2229
     * @param ConnectionInterface $con
2230
     */
2231
    public function postDelete(ConnectionInterface $con = null)
2232
    {
2233
        if (is_callable('parent::postDelete')) {
2234
            parent::postDelete($con);
2235
        }
2236
    }
2237
2238
2239
    /**
2240
     * Derived method to catches calls to undefined methods.
2241
     *
2242
     * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.).
2243
     * Allows to define default __call() behavior if you overwrite __call()
2244
     *
2245
     * @param string $name
2246
     * @param mixed  $params
2247
     *
2248
     * @return array|string
2249
     */
2250 View Code Duplication
    public function __call($name, $params)
2251
    {
2252
        if (0 === strpos($name, 'get')) {
2253
            $virtualColumn = substr($name, 3);
2254
            if ($this->hasVirtualColumn($virtualColumn)) {
2255
                return $this->getVirtualColumn($virtualColumn);
2256
            }
2257
2258
            $virtualColumn = lcfirst($virtualColumn);
2259
            if ($this->hasVirtualColumn($virtualColumn)) {
2260
                return $this->getVirtualColumn($virtualColumn);
2261
            }
2262
        }
2263
2264
        if (0 === strpos($name, 'from')) {
2265
            $format = substr($name, 4);
2266
2267
            return $this->importFrom($format, reset($params));
2268
        }
2269
2270
        if (0 === strpos($name, 'to')) {
2271
            $format = substr($name, 2);
2272
            $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true;
2273
2274
            return $this->exportTo($format, $includeLazyLoadColumns);
2275
        }
2276
2277
        throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name));
2278
    }
2279
2280
}
2281