Route::doInsert()   F
last analyzed

Complexity

Conditions 15
Paths 385

Size

Total Lines 69

Duplication

Lines 0
Ratio 0 %

Importance

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

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...
1179
     */
1180
    public function buildPkeyCriteria()
1181
    {
1182
        $criteria = ChildRouteQuery::create();
1183
        $criteria->add(RouteTableMap::COL_ID, $this->id);
1184
1185
        return $criteria;
1186
    }
1187
1188
    /**
1189
     * If the primary key is not null, return the hashcode of the
1190
     * primary key. Otherwise, return the hash code of the object.
1191
     *
1192
     * @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...
1193
     */
1194 View Code Duplication
    public function hashCode()
1195
    {
1196
        $validPk = null !== $this->getId();
1197
1198
        $validPrimaryKeyFKs = 0;
1199
        $primaryKeyFKs = [];
1200
1201
        if ($validPk) {
1202
            return crc32(json_encode($this->getPrimaryKey(), JSON_UNESCAPED_UNICODE));
1203
        } elseif ($validPrimaryKeyFKs) {
1204
            return crc32(json_encode($primaryKeyFKs, JSON_UNESCAPED_UNICODE));
1205
        }
1206
1207
        return spl_object_hash($this);
1208
    }
1209
1210
    /**
1211
     * Returns the primary key for this object (row).
1212
     * @return int
1213
     */
1214
    public function getPrimaryKey()
1215
    {
1216
        return $this->getId();
1217
    }
1218
1219
    /**
1220
     * Generic method to set the primary key (id column).
1221
     *
1222
     * @param       int $key Primary key.
1223
     * @return void
1224
     */
1225
    public function setPrimaryKey($key)
1226
    {
1227
        $this->setId($key);
1228
    }
1229
1230
    /**
1231
     * Returns true if the primary key for this object is null.
1232
     * @return boolean
1233
     */
1234
    public function isPrimaryKeyNull()
1235
    {
1236
        return null === $this->getId();
1237
    }
1238
1239
    /**
1240
     * Sets contents of passed object to values from current object.
1241
     *
1242
     * If desired, this method can also make copies of all associated (fkey referrers)
1243
     * objects.
1244
     *
1245
     * @param      object $copyObj An object of \core\models\Route (or compatible) type.
1246
     * @param      boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1247
     * @param      boolean $makeNew Whether to reset autoincrement PKs and make the object new.
1248
     * @throws PropelException
1249
     */
1250
    public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
1251
    {
1252
        $copyObj->setEntityId($this->getEntityId());
1253
        $copyObj->setType($this->getType());
1254
        $copyObj->setParentUrl($this->getParentUrl());
1255
        $copyObj->setUrl($this->getUrl());
1256
1257
        if ($deepCopy) {
1258
            // important: temporarily setNew(false) because this affects the behavior of
1259
            // the getter/setter methods for fkey referrer objects.
1260
            $copyObj->setNew(false);
1261
1262
            foreach ($this->getSCategories() as $relObj) {
1263
                if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
1264
                    $copyObj->addSCategory($relObj->copy($deepCopy));
1265
                }
1266
            }
1267
1268
            foreach ($this->getSProductss() as $relObj) {
1269
                if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
1270
                    $copyObj->addSProducts($relObj->copy($deepCopy));
1271
                }
1272
            }
1273
1274
        } // if ($deepCopy)
1275
1276
        if ($makeNew) {
1277
            $copyObj->setNew(true);
1278
            $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
1279
        }
1280
    }
1281
1282
    /**
1283
     * Makes a copy of this object that will be inserted as a new row in table when saved.
1284
     * It creates a new object filling in the simple attributes, but skipping any primary
1285
     * keys that are defined for the table.
1286
     *
1287
     * If desired, this method can also make copies of all associated (fkey referrers)
1288
     * objects.
1289
     *
1290
     * @param  boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1291
     * @return \core\models\Route Clone of current object.
1292
     * @throws PropelException
1293
     */
1294 View Code Duplication
    public function copy($deepCopy = false)
1295
    {
1296
        // we use get_class(), because this might be a subclass
1297
        $clazz = get_class($this);
1298
        $copyObj = new $clazz();
1299
        $this->copyInto($copyObj, $deepCopy);
1300
1301
        return $copyObj;
1302
    }
1303
1304
1305
    /**
1306
     * Initializes a collection based on the name of a relation.
1307
     * Avoids crafting an 'init[$relationName]s' method name
1308
     * that wouldn't work when StandardEnglishPluralizer is used.
1309
     *
1310
     * @param      string $relationName The name of the relation to initialize
1311
     * @return void
1312
     */
1313
    public function initRelation($relationName)
1314
    {
1315
        if ('SCategory' == $relationName) {
1316
            return $this->initSCategories();
1317
        }
1318
        if ('SProducts' == $relationName) {
1319
            return $this->initSProductss();
1320
        }
1321
    }
1322
1323
    /**
1324
     * Clears out the collSCategories collection
1325
     *
1326
     * This does not modify the database; however, it will remove any associated objects, causing
1327
     * them to be refetched by subsequent calls to accessor method.
1328
     *
1329
     * @return void
1330
     * @see        addSCategories()
1331
     */
1332
    public function clearSCategories()
1333
    {
1334
        $this->collSCategories = null; // important to set this to NULL since that means it is uninitialized
1335
    }
1336
1337
    /**
1338
     * Reset is the collSCategories collection loaded partially.
1339
     */
1340
    public function resetPartialSCategories($v = true)
1341
    {
1342
        $this->collSCategoriesPartial = $v;
1343
    }
1344
1345
    /**
1346
     * Initializes the collSCategories collection.
1347
     *
1348
     * By default this just sets the collSCategories collection to an empty array (like clearcollSCategories());
1349
     * however, you may wish to override this method in your stub class to provide setting appropriate
1350
     * to your application -- for example, setting the initial array to the values stored in database.
1351
     *
1352
     * @param      boolean $overrideExisting If set to true, the method call initializes
1353
     *                                        the collection even if it is not empty
1354
     *
1355
     * @return void
1356
     */
1357 View Code Duplication
    public function initSCategories($overrideExisting = true)
1358
    {
1359
        if (null !== $this->collSCategories && !$overrideExisting) {
1360
            return;
1361
        }
1362
1363
        $collectionClassName = SCategoryTableMap::getTableMap()->getCollectionClassName();
1364
1365
        $this->collSCategories = new $collectionClassName;
1366
        $this->collSCategories->setModel('\SCategory');
1367
    }
1368
1369
    /**
1370
     * Gets an array of SCategory objects which contain a foreign key that references this object.
1371
     *
1372
     * If the $criteria is not null, it is used to always fetch the results from the database.
1373
     * Otherwise the results are fetched from the database the first time, then cached.
1374
     * Next time the same method is called without $criteria, the cached collection is returned.
1375
     * If this ChildRoute is new, it will return
1376
     * an empty collection or the current collection; the criteria is ignored on a new object.
1377
     *
1378
     * @param      Criteria $criteria optional Criteria object to narrow the query
1379
     * @param      ConnectionInterface $con optional connection object
1380
     * @return ObjectCollection|SCategory[] List of SCategory objects
1381
     * @throws PropelException
1382
     */
1383 View Code Duplication
    public function getSCategories(Criteria $criteria = null, ConnectionInterface $con = null)
1384
    {
1385
        $partial = $this->collSCategoriesPartial && !$this->isNew();
1386
        if (null === $this->collSCategories || null !== $criteria  || $partial) {
1387
            if ($this->isNew() && null === $this->collSCategories) {
1388
                // return empty collection
1389
                $this->initSCategories();
1390
            } else {
1391
                $collSCategories = SCategoryQuery::create(null, $criteria)
1392
                    ->filterByRoute($this)
1393
                    ->find($con);
1394
1395
                if (null !== $criteria) {
1396
                    if (false !== $this->collSCategoriesPartial && count($collSCategories)) {
1397
                        $this->initSCategories(false);
1398
1399
                        foreach ($collSCategories as $obj) {
1400
                            if (false == $this->collSCategories->contains($obj)) {
1401
                                $this->collSCategories->append($obj);
1402
                            }
1403
                        }
1404
1405
                        $this->collSCategoriesPartial = true;
1406
                    }
1407
1408
                    return $collSCategories;
1409
                }
1410
1411
                if ($partial && $this->collSCategories) {
1412
                    foreach ($this->collSCategories as $obj) {
1413
                        if ($obj->isNew()) {
1414
                            $collSCategories[] = $obj;
1415
                        }
1416
                    }
1417
                }
1418
1419
                $this->collSCategories = $collSCategories;
1420
                $this->collSCategoriesPartial = false;
1421
            }
1422
        }
1423
1424
        return $this->collSCategories;
1425
    }
1426
1427
    /**
1428
     * Sets a collection of SCategory objects related by a one-to-many relationship
1429
     * to the current object.
1430
     * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
1431
     * and new objects from the given Propel collection.
1432
     *
1433
     * @param      Collection $sCategories A Propel collection.
1434
     * @param      ConnectionInterface $con Optional connection object
1435
     * @return $this|ChildRoute The current object (for fluent API support)
1436
     */
1437 View Code Duplication
    public function setSCategories(Collection $sCategories, ConnectionInterface $con = null)
1438
    {
1439
        /** @var SCategory[] $sCategoriesToDelete */
1440
        $sCategoriesToDelete = $this->getSCategories(new Criteria(), $con)->diff($sCategories);
1441
1442
1443
        $this->sCategoriesScheduledForDeletion = $sCategoriesToDelete;
1444
1445
        foreach ($sCategoriesToDelete as $sCategoryRemoved) {
1446
            $sCategoryRemoved->setRoute(null);
1447
        }
1448
1449
        $this->collSCategories = null;
1450
        foreach ($sCategories as $sCategory) {
1451
            $this->addSCategory($sCategory);
1452
        }
1453
1454
        $this->collSCategories = $sCategories;
0 ignored issues
show
Documentation Bug introduced by
It seems like $sCategories of type object<Propel\Runtime\Collection\Collection> is incompatible with the declared type object<Propel\Runtime\Co...eger,object<SCategory>> of property $collSCategories.

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...
1455
        $this->collSCategoriesPartial = false;
1456
1457
        return $this;
1458
    }
1459
1460
    /**
1461
     * Returns the number of related BaseSCategory objects.
1462
     *
1463
     * @param      Criteria $criteria
1464
     * @param      boolean $distinct
1465
     * @param      ConnectionInterface $con
1466
     * @return int             Count of related BaseSCategory objects.
1467
     * @throws PropelException
1468
     */
1469 View Code Duplication
    public function countSCategories(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
1470
    {
1471
        $partial = $this->collSCategoriesPartial && !$this->isNew();
1472
        if (null === $this->collSCategories || null !== $criteria || $partial) {
1473
            if ($this->isNew() && null === $this->collSCategories) {
1474
                return 0;
1475
            }
1476
1477
            if ($partial && !$criteria) {
1478
                return count($this->getSCategories());
1479
            }
1480
1481
            $query = SCategoryQuery::create(null, $criteria);
1482
            if ($distinct) {
1483
                $query->distinct();
1484
            }
1485
1486
            return $query
1487
                ->filterByRoute($this)
1488
                ->count($con);
1489
        }
1490
1491
        return count($this->collSCategories);
1492
    }
1493
1494
    /**
1495
     * Method called to associate a SCategory object to this object
1496
     * through the SCategory foreign key attribute.
1497
     *
1498
     * @param  SCategory $l SCategory
1499
     * @return $this|\core\models\Route The current object (for fluent API support)
1500
     */
1501
    public function addSCategory(SCategory $l)
1502
    {
1503
        if ($this->collSCategories === null) {
1504
            $this->initSCategories();
1505
            $this->collSCategoriesPartial = true;
1506
        }
1507
1508
        if (!$this->collSCategories->contains($l)) {
1509
            $this->doAddSCategory($l);
1510
1511
            if ($this->sCategoriesScheduledForDeletion and $this->sCategoriesScheduledForDeletion->contains($l)) {
1512
                $this->sCategoriesScheduledForDeletion->remove($this->sCategoriesScheduledForDeletion->search($l));
1513
            }
1514
        }
1515
1516
        return $this;
1517
    }
1518
1519
    /**
1520
     * @param SCategory $sCategory The SCategory object to add.
1521
     */
1522
    protected function doAddSCategory(SCategory $sCategory)
1523
    {
1524
        $this->collSCategories[]= $sCategory;
1525
        $sCategory->setRoute($this);
1526
    }
1527
1528
    /**
1529
     * @param  SCategory $sCategory The SCategory object to remove.
1530
     * @return $this|ChildRoute The current object (for fluent API support)
1531
     */
1532 View Code Duplication
    public function removeSCategory(SCategory $sCategory)
1533
    {
1534
        if ($this->getSCategories()->contains($sCategory)) {
1535
            $pos = $this->collSCategories->search($sCategory);
1536
            $this->collSCategories->remove($pos);
1537
            if (null === $this->sCategoriesScheduledForDeletion) {
1538
                $this->sCategoriesScheduledForDeletion = clone $this->collSCategories;
1539
                $this->sCategoriesScheduledForDeletion->clear();
1540
            }
1541
            $this->sCategoriesScheduledForDeletion[]= $sCategory;
1542
            $sCategory->setRoute(null);
1543
        }
1544
1545
        return $this;
1546
    }
1547
1548
1549
    /**
1550
     * If this collection has already been initialized with
1551
     * an identical criteria, it returns the collection.
1552
     * Otherwise if this Route is new, it will return
1553
     * an empty collection; or if this Route has previously
1554
     * been saved, it will retrieve related SCategories from storage.
1555
     *
1556
     * This method is protected by default in order to keep the public
1557
     * api reasonable.  You can provide public methods for those you
1558
     * actually need in Route.
1559
     *
1560
     * @param      Criteria $criteria optional Criteria object to narrow the query
1561
     * @param      ConnectionInterface $con optional connection object
1562
     * @param      string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN)
1563
     * @return ObjectCollection|SCategory[] List of SCategory objects
1564
     */
1565 View Code Duplication
    public function getSCategoriesJoinSCategory(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN)
1566
    {
1567
        $query = SCategoryQuery::create(null, $criteria);
1568
        $query->joinWith('SCategory', $joinBehavior);
1569
1570
        return $this->getSCategories($query, $con);
1571
    }
1572
1573
    /**
1574
     * Clears out the collSProductss collection
1575
     *
1576
     * This does not modify the database; however, it will remove any associated objects, causing
1577
     * them to be refetched by subsequent calls to accessor method.
1578
     *
1579
     * @return void
1580
     * @see        addSProductss()
1581
     */
1582
    public function clearSProductss()
1583
    {
1584
        $this->collSProductss = null; // important to set this to NULL since that means it is uninitialized
1585
    }
1586
1587
    /**
1588
     * Reset is the collSProductss collection loaded partially.
1589
     */
1590
    public function resetPartialSProductss($v = true)
1591
    {
1592
        $this->collSProductssPartial = $v;
1593
    }
1594
1595
    /**
1596
     * Initializes the collSProductss collection.
1597
     *
1598
     * By default this just sets the collSProductss collection to an empty array (like clearcollSProductss());
1599
     * however, you may wish to override this method in your stub class to provide setting appropriate
1600
     * to your application -- for example, setting the initial array to the values stored in database.
1601
     *
1602
     * @param      boolean $overrideExisting If set to true, the method call initializes
1603
     *                                        the collection even if it is not empty
1604
     *
1605
     * @return void
1606
     */
1607 View Code Duplication
    public function initSProductss($overrideExisting = true)
1608
    {
1609
        if (null !== $this->collSProductss && !$overrideExisting) {
1610
            return;
1611
        }
1612
1613
        $collectionClassName = SProductsTableMap::getTableMap()->getCollectionClassName();
1614
1615
        $this->collSProductss = new $collectionClassName;
1616
        $this->collSProductss->setModel('\SProducts');
1617
    }
1618
1619
    /**
1620
     * Gets an array of SProducts objects which contain a foreign key that references this object.
1621
     *
1622
     * If the $criteria is not null, it is used to always fetch the results from the database.
1623
     * Otherwise the results are fetched from the database the first time, then cached.
1624
     * Next time the same method is called without $criteria, the cached collection is returned.
1625
     * If this ChildRoute is new, it will return
1626
     * an empty collection or the current collection; the criteria is ignored on a new object.
1627
     *
1628
     * @param      Criteria $criteria optional Criteria object to narrow the query
1629
     * @param      ConnectionInterface $con optional connection object
1630
     * @return ObjectCollection|SProducts[] List of SProducts objects
1631
     * @throws PropelException
1632
     */
1633 View Code Duplication
    public function getSProductss(Criteria $criteria = null, ConnectionInterface $con = null)
1634
    {
1635
        $partial = $this->collSProductssPartial && !$this->isNew();
1636
        if (null === $this->collSProductss || null !== $criteria  || $partial) {
1637
            if ($this->isNew() && null === $this->collSProductss) {
1638
                // return empty collection
1639
                $this->initSProductss();
1640
            } else {
1641
                $collSProductss = SProductsQuery::create(null, $criteria)
1642
                    ->filterByRoute($this)
1643
                    ->find($con);
1644
1645
                if (null !== $criteria) {
1646
                    if (false !== $this->collSProductssPartial && count($collSProductss)) {
1647
                        $this->initSProductss(false);
1648
1649
                        foreach ($collSProductss as $obj) {
1650
                            if (false == $this->collSProductss->contains($obj)) {
1651
                                $this->collSProductss->append($obj);
1652
                            }
1653
                        }
1654
1655
                        $this->collSProductssPartial = true;
1656
                    }
1657
1658
                    return $collSProductss;
1659
                }
1660
1661
                if ($partial && $this->collSProductss) {
1662
                    foreach ($this->collSProductss as $obj) {
1663
                        if ($obj->isNew()) {
1664
                            $collSProductss[] = $obj;
1665
                        }
1666
                    }
1667
                }
1668
1669
                $this->collSProductss = $collSProductss;
1670
                $this->collSProductssPartial = false;
1671
            }
1672
        }
1673
1674
        return $this->collSProductss;
1675
    }
1676
1677
    /**
1678
     * Sets a collection of SProducts objects related by a one-to-many relationship
1679
     * to the current object.
1680
     * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
1681
     * and new objects from the given Propel collection.
1682
     *
1683
     * @param      Collection $sProductss A Propel collection.
1684
     * @param      ConnectionInterface $con Optional connection object
1685
     * @return $this|ChildRoute The current object (for fluent API support)
1686
     */
1687 View Code Duplication
    public function setSProductss(Collection $sProductss, ConnectionInterface $con = null)
1688
    {
1689
        /** @var SProducts[] $sProductssToDelete */
1690
        $sProductssToDelete = $this->getSProductss(new Criteria(), $con)->diff($sProductss);
1691
1692
1693
        $this->sProductssScheduledForDeletion = $sProductssToDelete;
1694
1695
        foreach ($sProductssToDelete as $sProductsRemoved) {
1696
            $sProductsRemoved->setRoute(null);
1697
        }
1698
1699
        $this->collSProductss = null;
1700
        foreach ($sProductss as $sProducts) {
1701
            $this->addSProducts($sProducts);
1702
        }
1703
1704
        $this->collSProductss = $sProductss;
0 ignored issues
show
Documentation Bug introduced by
It seems like $sProductss of type object<Propel\Runtime\Collection\Collection> is incompatible with the declared type object<Propel\Runtime\Co...eger,object<SProducts>> of property $collSProductss.

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...
1705
        $this->collSProductssPartial = false;
1706
1707
        return $this;
1708
    }
1709
1710
    /**
1711
     * Returns the number of related BaseSProducts objects.
1712
     *
1713
     * @param      Criteria $criteria
1714
     * @param      boolean $distinct
1715
     * @param      ConnectionInterface $con
1716
     * @return int             Count of related BaseSProducts objects.
1717
     * @throws PropelException
1718
     */
1719 View Code Duplication
    public function countSProductss(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
1720
    {
1721
        $partial = $this->collSProductssPartial && !$this->isNew();
1722
        if (null === $this->collSProductss || null !== $criteria || $partial) {
1723
            if ($this->isNew() && null === $this->collSProductss) {
1724
                return 0;
1725
            }
1726
1727
            if ($partial && !$criteria) {
1728
                return count($this->getSProductss());
1729
            }
1730
1731
            $query = SProductsQuery::create(null, $criteria);
1732
            if ($distinct) {
1733
                $query->distinct();
1734
            }
1735
1736
            return $query
1737
                ->filterByRoute($this)
1738
                ->count($con);
1739
        }
1740
1741
        return count($this->collSProductss);
1742
    }
1743
1744
    /**
1745
     * Method called to associate a SProducts object to this object
1746
     * through the SProducts foreign key attribute.
1747
     *
1748
     * @param  SProducts $l SProducts
1749
     * @return $this|\core\models\Route The current object (for fluent API support)
1750
     */
1751
    public function addSProducts(SProducts $l)
1752
    {
1753
        if ($this->collSProductss === null) {
1754
            $this->initSProductss();
1755
            $this->collSProductssPartial = true;
1756
        }
1757
1758
        if (!$this->collSProductss->contains($l)) {
1759
            $this->doAddSProducts($l);
1760
1761
            if ($this->sProductssScheduledForDeletion and $this->sProductssScheduledForDeletion->contains($l)) {
1762
                $this->sProductssScheduledForDeletion->remove($this->sProductssScheduledForDeletion->search($l));
1763
            }
1764
        }
1765
1766
        return $this;
1767
    }
1768
1769
    /**
1770
     * @param SProducts $sProducts The SProducts object to add.
1771
     */
1772
    protected function doAddSProducts(SProducts $sProducts)
1773
    {
1774
        $this->collSProductss[]= $sProducts;
1775
        $sProducts->setRoute($this);
1776
    }
1777
1778
    /**
1779
     * @param  SProducts $sProducts The SProducts object to remove.
1780
     * @return $this|ChildRoute The current object (for fluent API support)
1781
     */
1782 View Code Duplication
    public function removeSProducts(SProducts $sProducts)
1783
    {
1784
        if ($this->getSProductss()->contains($sProducts)) {
1785
            $pos = $this->collSProductss->search($sProducts);
1786
            $this->collSProductss->remove($pos);
1787
            if (null === $this->sProductssScheduledForDeletion) {
1788
                $this->sProductssScheduledForDeletion = clone $this->collSProductss;
1789
                $this->sProductssScheduledForDeletion->clear();
1790
            }
1791
            $this->sProductssScheduledForDeletion[]= $sProducts;
1792
            $sProducts->setRoute(null);
1793
        }
1794
1795
        return $this;
1796
    }
1797
1798
1799
    /**
1800
     * If this collection has already been initialized with
1801
     * an identical criteria, it returns the collection.
1802
     * Otherwise if this Route is new, it will return
1803
     * an empty collection; or if this Route has previously
1804
     * been saved, it will retrieve related SProductss from storage.
1805
     *
1806
     * This method is protected by default in order to keep the public
1807
     * api reasonable.  You can provide public methods for those you
1808
     * actually need in Route.
1809
     *
1810
     * @param      Criteria $criteria optional Criteria object to narrow the query
1811
     * @param      ConnectionInterface $con optional connection object
1812
     * @param      string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN)
1813
     * @return ObjectCollection|SProducts[] List of SProducts objects
1814
     */
1815 View Code Duplication
    public function getSProductssJoinBrand(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN)
1816
    {
1817
        $query = SProductsQuery::create(null, $criteria);
1818
        $query->joinWith('Brand', $joinBehavior);
1819
1820
        return $this->getSProductss($query, $con);
1821
    }
1822
1823
1824
    /**
1825
     * If this collection has already been initialized with
1826
     * an identical criteria, it returns the collection.
1827
     * Otherwise if this Route is new, it will return
1828
     * an empty collection; or if this Route has previously
1829
     * been saved, it will retrieve related SProductss from storage.
1830
     *
1831
     * This method is protected by default in order to keep the public
1832
     * api reasonable.  You can provide public methods for those you
1833
     * actually need in Route.
1834
     *
1835
     * @param      Criteria $criteria optional Criteria object to narrow the query
1836
     * @param      ConnectionInterface $con optional connection object
1837
     * @param      string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN)
1838
     * @return ObjectCollection|SProducts[] List of SProducts objects
1839
     */
1840 View Code Duplication
    public function getSProductssJoinMainCategory(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN)
1841
    {
1842
        $query = SProductsQuery::create(null, $criteria);
1843
        $query->joinWith('MainCategory', $joinBehavior);
1844
1845
        return $this->getSProductss($query, $con);
1846
    }
1847
1848
    /**
1849
     * Clears the current object, sets all attributes to their default values and removes
1850
     * outgoing references as well as back-references (from other objects to this one. Results probably in a database
1851
     * change of those foreign objects when you call `save` there).
1852
     */
1853 View Code Duplication
    public function clear()
1854
    {
1855
        $this->id = null;
1856
        $this->entity_id = null;
1857
        $this->type = null;
1858
        $this->parent_url = null;
1859
        $this->url = null;
1860
        $this->alreadyInSave = false;
1861
        $this->clearAllReferences();
1862
        $this->applyDefaultValues();
1863
        $this->resetModified();
1864
        $this->setNew(true);
1865
        $this->setDeleted(false);
1866
    }
1867
1868
    /**
1869
     * Resets all references and back-references to other model objects or collections of model objects.
1870
     *
1871
     * This method is used to reset all php object references (not the actual reference in the database).
1872
     * Necessary for object serialisation.
1873
     *
1874
     * @param      boolean $deep Whether to also clear the references on all referrer objects.
1875
     */
1876
    public function clearAllReferences($deep = false)
1877
    {
1878
        if ($deep) {
1879
            if ($this->collSCategories) {
1880
                foreach ($this->collSCategories as $o) {
1881
                    $o->clearAllReferences($deep);
1882
                }
1883
            }
1884
            if ($this->collSProductss) {
1885
                foreach ($this->collSProductss as $o) {
1886
                    $o->clearAllReferences($deep);
1887
                }
1888
            }
1889
        } // if ($deep)
1890
1891
        $this->collSCategories = null;
1892
        $this->collSProductss = null;
1893
    }
1894
1895
    /**
1896
     * Return the string representation of this object
1897
     *
1898
     * @return string
1899
     */
1900
    public function __toString()
1901
    {
1902
        return (string) $this->exportTo(RouteTableMap::DEFAULT_STRING_FORMAT);
1903
    }
1904
1905
    /**
1906
     * Code to be run before persisting the object
1907
     * @param  ConnectionInterface $con
1908
     * @return boolean
1909
     */
1910
    public function preSave(ConnectionInterface $con = null)
1911
    {
1912
        if (is_callable('parent::preSave')) {
1913
            return parent::preSave($con);
1914
        }
1915
        return true;
1916
    }
1917
1918
    /**
1919
     * Code to be run after persisting the object
1920
     * @param ConnectionInterface $con
1921
     */
1922
    public function postSave(ConnectionInterface $con = null)
1923
    {
1924
        if (is_callable('parent::postSave')) {
1925
            parent::postSave($con);
1926
        }
1927
    }
1928
1929
    /**
1930
     * Code to be run before inserting to database
1931
     * @param  ConnectionInterface $con
1932
     * @return boolean
1933
     */
1934
    public function preInsert(ConnectionInterface $con = null)
1935
    {
1936
        if (is_callable('parent::preInsert')) {
1937
            return parent::preInsert($con);
1938
        }
1939
        return true;
1940
    }
1941
1942
    /**
1943
     * Code to be run after inserting to database
1944
     * @param ConnectionInterface $con
1945
     */
1946
    public function postInsert(ConnectionInterface $con = null)
1947
    {
1948
        if (is_callable('parent::postInsert')) {
1949
            parent::postInsert($con);
1950
        }
1951
    }
1952
1953
    /**
1954
     * Code to be run before updating the object in database
1955
     * @param  ConnectionInterface $con
1956
     * @return boolean
1957
     */
1958
    public function preUpdate(ConnectionInterface $con = null)
1959
    {
1960
        if (is_callable('parent::preUpdate')) {
1961
            return parent::preUpdate($con);
1962
        }
1963
        return true;
1964
    }
1965
1966
    /**
1967
     * Code to be run after updating the object in database
1968
     * @param ConnectionInterface $con
1969
     */
1970
    public function postUpdate(ConnectionInterface $con = null)
1971
    {
1972
        if (is_callable('parent::postUpdate')) {
1973
            parent::postUpdate($con);
1974
        }
1975
    }
1976
1977
    /**
1978
     * Code to be run before deleting the object in database
1979
     * @param  ConnectionInterface $con
1980
     * @return boolean
1981
     */
1982
    public function preDelete(ConnectionInterface $con = null)
1983
    {
1984
        if (is_callable('parent::preDelete')) {
1985
            return parent::preDelete($con);
1986
        }
1987
        return true;
1988
    }
1989
1990
    /**
1991
     * Code to be run after deleting the object in database
1992
     * @param ConnectionInterface $con
1993
     */
1994
    public function postDelete(ConnectionInterface $con = null)
1995
    {
1996
        if (is_callable('parent::postDelete')) {
1997
            parent::postDelete($con);
1998
        }
1999
    }
2000
2001
2002
    /**
2003
     * Derived method to catches calls to undefined methods.
2004
     *
2005
     * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.).
2006
     * Allows to define default __call() behavior if you overwrite __call()
2007
     *
2008
     * @param string $name
2009
     * @param mixed  $params
2010
     *
2011
     * @return array|string
2012
     */
2013 View Code Duplication
    public function __call($name, $params)
2014
    {
2015
        if (0 === strpos($name, 'get')) {
2016
            $virtualColumn = substr($name, 3);
2017
            if ($this->hasVirtualColumn($virtualColumn)) {
2018
                return $this->getVirtualColumn($virtualColumn);
2019
            }
2020
2021
            $virtualColumn = lcfirst($virtualColumn);
2022
            if ($this->hasVirtualColumn($virtualColumn)) {
2023
                return $this->getVirtualColumn($virtualColumn);
2024
            }
2025
        }
2026
2027
        if (0 === strpos($name, 'from')) {
2028
            $format = substr($name, 4);
2029
2030
            return $this->importFrom($format, reset($params));
2031
        }
2032
2033
        if (0 === strpos($name, 'to')) {
2034
            $format = substr($name, 2);
2035
            $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true;
2036
2037
            return $this->exportTo($format, $includeLazyLoadColumns);
2038
        }
2039
2040
        throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name));
2041
    }
2042
2043
}
2044