BannersQuery   F
last analyzed

Complexity

Total Complexity 93

Size/Duplication

Total Lines 707
Duplicated Lines 47.81 %

Coupling/Cohesion

Components 2
Dependencies 19

Importance

Changes 0
Metric Value
dl 338
loc 707
rs 1.893
c 0
b 0
f 0
wmc 93
lcom 2
cbo 19

27 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 15 15 4
C findPk() 27 27 17
B findPkSimple() 22 22 6
A findPkComplex() 10 10 2
A findPks() 13 13 3
A filterByPrimaryKey() 0 5 1
A filterByPrimaryKeys() 0 5 1
B filterById() 22 22 6
A filterByPlace() 10 10 3
B filterByWidth() 22 22 6
B filterByHeight() 22 22 6
A filterByEffects() 10 10 3
A filterByPageType() 10 10 3
A filterByBannerImage() 14 14 3
A joinBannerImage() 23 23 4
A useBannerImageQuery() 0 6 2
A filterByBannersI18n() 14 14 3
A joinBannersI18n() 23 23 4
A useBannersI18nQuery() 0 6 2
A prune() 0 8 2
A doDeleteAll() 21 21 2
A delete() 28 28 2
A doOnDeleteCascade() 15 25 2
A joinI18n() 8 8 2
A joinWithI18n() 9 9 1
A useI18nQuery() 0 6 2

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like BannersQuery often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use BannersQuery, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace xbanners\models\Base;
4
5
use \Exception;
6
use \PDO;
7
use Propel\Runtime\Propel;
8
use Propel\Runtime\ActiveQuery\Criteria;
9
use Propel\Runtime\ActiveQuery\ModelCriteria;
10
use Propel\Runtime\ActiveQuery\ModelJoin;
11
use Propel\Runtime\Collection\ObjectCollection;
12
use Propel\Runtime\Connection\ConnectionInterface;
13
use Propel\Runtime\Exception\PropelException;
14
use xbanners\models\Banners as ChildBanners;
15
use xbanners\models\BannersI18nQuery as ChildBannersI18nQuery;
16
use xbanners\models\BannersQuery as ChildBannersQuery;
17
use xbanners\models\Map\BannerImageTableMap;
18
use xbanners\models\Map\BannersI18nTableMap;
19
use xbanners\models\Map\BannersTableMap;
20
21
/**
22
 * Base class that represents a query for the 'banners' table.
23
 *
24
 *
25
 *
26
 * @method     ChildBannersQuery orderById($order = Criteria::ASC) Order by the id column
27
 * @method     ChildBannersQuery orderByPlace($order = Criteria::ASC) Order by the place column
28
 * @method     ChildBannersQuery orderByWidth($order = Criteria::ASC) Order by the width column
29
 * @method     ChildBannersQuery orderByHeight($order = Criteria::ASC) Order by the height column
30
 * @method     ChildBannersQuery orderByEffects($order = Criteria::ASC) Order by the effects column
31
 * @method     ChildBannersQuery orderByPageType($order = Criteria::ASC) Order by the page_type column
32
 *
33
 * @method     ChildBannersQuery groupById() Group by the id column
34
 * @method     ChildBannersQuery groupByPlace() Group by the place column
35
 * @method     ChildBannersQuery groupByWidth() Group by the width column
36
 * @method     ChildBannersQuery groupByHeight() Group by the height column
37
 * @method     ChildBannersQuery groupByEffects() Group by the effects column
38
 * @method     ChildBannersQuery groupByPageType() Group by the page_type column
39
 *
40
 * @method     ChildBannersQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
41
 * @method     ChildBannersQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
42
 * @method     ChildBannersQuery innerJoin($relation) Adds a INNER JOIN clause to the query
43
 *
44
 * @method     ChildBannersQuery leftJoinWith($relation) Adds a LEFT JOIN clause and with to the query
45
 * @method     ChildBannersQuery rightJoinWith($relation) Adds a RIGHT JOIN clause and with to the query
46
 * @method     ChildBannersQuery innerJoinWith($relation) Adds a INNER JOIN clause and with to the query
47
 *
48
 * @method     ChildBannersQuery leftJoinBannerImage($relationAlias = null) Adds a LEFT JOIN clause to the query using the BannerImage relation
49
 * @method     ChildBannersQuery rightJoinBannerImage($relationAlias = null) Adds a RIGHT JOIN clause to the query using the BannerImage relation
50
 * @method     ChildBannersQuery innerJoinBannerImage($relationAlias = null) Adds a INNER JOIN clause to the query using the BannerImage relation
51
 *
52
 * @method     ChildBannersQuery joinWithBannerImage($joinType = Criteria::INNER_JOIN) Adds a join clause and with to the query using the BannerImage relation
53
 *
54
 * @method     ChildBannersQuery leftJoinWithBannerImage() Adds a LEFT JOIN clause and with to the query using the BannerImage relation
55
 * @method     ChildBannersQuery rightJoinWithBannerImage() Adds a RIGHT JOIN clause and with to the query using the BannerImage relation
56
 * @method     ChildBannersQuery innerJoinWithBannerImage() Adds a INNER JOIN clause and with to the query using the BannerImage relation
57
 *
58
 * @method     ChildBannersQuery leftJoinBannersI18n($relationAlias = null) Adds a LEFT JOIN clause to the query using the BannersI18n relation
59
 * @method     ChildBannersQuery rightJoinBannersI18n($relationAlias = null) Adds a RIGHT JOIN clause to the query using the BannersI18n relation
60
 * @method     ChildBannersQuery innerJoinBannersI18n($relationAlias = null) Adds a INNER JOIN clause to the query using the BannersI18n relation
61
 *
62
 * @method     ChildBannersQuery joinWithBannersI18n($joinType = Criteria::INNER_JOIN) Adds a join clause and with to the query using the BannersI18n relation
63
 *
64
 * @method     ChildBannersQuery leftJoinWithBannersI18n() Adds a LEFT JOIN clause and with to the query using the BannersI18n relation
65
 * @method     ChildBannersQuery rightJoinWithBannersI18n() Adds a RIGHT JOIN clause and with to the query using the BannersI18n relation
66
 * @method     ChildBannersQuery innerJoinWithBannersI18n() Adds a INNER JOIN clause and with to the query using the BannersI18n relation
67
 *
68
 * @method     \xbanners\models\BannerImageQuery|\xbanners\models\BannersI18nQuery endUse() Finalizes a secondary criteria and merges it with its primary Criteria
69
 *
70
 * @method     ChildBanners findOne(ConnectionInterface $con = null) Return the first ChildBanners matching the query
71
 * @method     ChildBanners findOneOrCreate(ConnectionInterface $con = null) Return the first ChildBanners matching the query, or a new ChildBanners object populated from the query conditions when no match is found
72
 *
73
 * @method     ChildBanners findOneById(int $id) Return the first ChildBanners filtered by the id column
74
 * @method     ChildBanners findOneByPlace(string $place) Return the first ChildBanners filtered by the place column
75
 * @method     ChildBanners findOneByWidth(int $width) Return the first ChildBanners filtered by the width column
76
 * @method     ChildBanners findOneByHeight(int $height) Return the first ChildBanners filtered by the height column
77
 * @method     ChildBanners findOneByEffects(string $effects) Return the first ChildBanners filtered by the effects column
78
 * @method     ChildBanners findOneByPageType(string $page_type) Return the first ChildBanners filtered by the page_type column *
79
80
 * @method     ChildBanners requirePk($key, ConnectionInterface $con = null) Return the ChildBanners by primary key and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
81
 * @method     ChildBanners requireOne(ConnectionInterface $con = null) Return the first ChildBanners matching the query and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
82
 *
83
 * @method     ChildBanners requireOneById(int $id) Return the first ChildBanners filtered by the id column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
84
 * @method     ChildBanners requireOneByPlace(string $place) Return the first ChildBanners filtered by the place column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
85
 * @method     ChildBanners requireOneByWidth(int $width) Return the first ChildBanners filtered by the width column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
86
 * @method     ChildBanners requireOneByHeight(int $height) Return the first ChildBanners filtered by the height column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
87
 * @method     ChildBanners requireOneByEffects(string $effects) Return the first ChildBanners filtered by the effects column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
88
 * @method     ChildBanners requireOneByPageType(string $page_type) Return the first ChildBanners filtered by the page_type column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
89
 *
90
 * @method     ChildBanners[]|ObjectCollection find(ConnectionInterface $con = null) Return ChildBanners objects based on current ModelCriteria
91
 * @method     ChildBanners[]|ObjectCollection findById(int $id) Return ChildBanners objects filtered by the id column
92
 * @method     ChildBanners[]|ObjectCollection findByPlace(string $place) Return ChildBanners objects filtered by the place column
93
 * @method     ChildBanners[]|ObjectCollection findByWidth(int $width) Return ChildBanners objects filtered by the width column
94
 * @method     ChildBanners[]|ObjectCollection findByHeight(int $height) Return ChildBanners objects filtered by the height column
95
 * @method     ChildBanners[]|ObjectCollection findByEffects(string $effects) Return ChildBanners objects filtered by the effects column
96
 * @method     ChildBanners[]|ObjectCollection findByPageType(string $page_type) Return ChildBanners objects filtered by the page_type column
97
 * @method     ChildBanners[]|\Propel\Runtime\Util\PropelModelPager paginate($page = 1, $maxPerPage = 10, ConnectionInterface $con = null) Issue a SELECT query based on the current ModelCriteria and uses a page and a maximum number of results per page to compute an offset and a limit
98
 *
99
 */
100
abstract class BannersQuery extends ModelCriteria
101
{
102
    protected $entityNotFoundExceptionClass = '\\Propel\\Runtime\\Exception\\EntityNotFoundException';
103
104
    /**
105
     * Initializes internal state of \xbanners\models\Base\BannersQuery object.
106
     *
107
     * @param     string $dbName The database name
108
     * @param     string $modelName The phpName of a model, e.g. 'Book'
109
     * @param     string $modelAlias The alias for the model in this query, e.g. 'b'
110
     */
111
    public function __construct($dbName = 'Shop', $modelName = '\\xbanners\\models\\Banners', $modelAlias = null)
112
    {
113
        parent::__construct($dbName, $modelName, $modelAlias);
114
    }
115
116
    /**
117
     * Returns a new ChildBannersQuery object.
118
     *
119
     * @param     string $modelAlias The alias of a model in the query
120
     * @param     Criteria $criteria Optional Criteria to build the query from
121
     *
122
     * @return ChildBannersQuery
123
     */
124 View Code Duplication
    public static function create($modelAlias = null, Criteria $criteria = null)
125
    {
126
        if ($criteria instanceof ChildBannersQuery) {
127
            return $criteria;
128
        }
129
        $query = new ChildBannersQuery();
130
        if (null !== $modelAlias) {
131
            $query->setModelAlias($modelAlias);
132
        }
133
        if ($criteria instanceof Criteria) {
134
            $query->mergeWith($criteria);
135
        }
136
137
        return $query;
138
    }
139
140
    /**
141
     * Find object by primary key.
142
     * Propel uses the instance pool to skip the database if the object exists.
143
     * Go fast if the query is untouched.
144
     *
145
     * <code>
146
     * $obj  = $c->findPk(12, $con);
147
     * </code>
148
     *
149
     * @param mixed $key Primary key to use for the query
150
     * @param ConnectionInterface $con an optional connection object
151
     *
152
     * @return ChildBanners|array|mixed the result, formatted by the current formatter
153
     */
154 View Code Duplication
    public function findPk($key, ConnectionInterface $con = null)
155
    {
156
        if ($key === null) {
157
            return null;
158
        }
159
160
        if ($con === null) {
161
            $con = Propel::getServiceContainer()->getReadConnection(BannersTableMap::DATABASE_NAME);
162
        }
163
164
        $this->basePreSelect($con);
165
166
        if (
167
            $this->formatter || $this->modelAlias || $this->with || $this->select
168
            || $this->selectColumns || $this->asColumns || $this->selectModifiers
169
            || $this->map || $this->having || $this->joins
170
        ) {
171
            return $this->findPkComplex($key, $con);
172
        }
173
174
        if ((null !== ($obj = BannersTableMap::getInstanceFromPool(null === $key || is_scalar($key) || is_callable([$key, '__toString']) ? (string) $key : $key)))) {
175
            // the object is already in the instance pool
176
            return $obj;
177
        }
178
179
        return $this->findPkSimple($key, $con);
180
    }
181
182
    /**
183
     * Find object by primary key using raw SQL to go fast.
184
     * Bypass doSelect() and the object formatter by using generated code.
185
     *
186
     * @param     mixed $key Primary key to use for the query
187
     * @param     ConnectionInterface $con A connection object
188
     *
189
     * @throws \Propel\Runtime\Exception\PropelException
190
     *
191
     * @return ChildBanners A model object, or null if the key is not found
0 ignored issues
show
Documentation introduced by
Should the return type not be ChildBanners|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...
192
     */
193 View Code Duplication
    protected function findPkSimple($key, ConnectionInterface $con)
194
    {
195
        $sql = 'SELECT id, place, width, height, effects, page_type FROM banners WHERE id = :p0';
196
        try {
197
            $stmt = $con->prepare($sql);
198
            $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
199
            $stmt->execute();
200
        } catch (Exception $e) {
201
            Propel::log($e->getMessage(), Propel::LOG_ERR);
202
            throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e);
203
        }
204
        $obj = null;
205
        if ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
206
            /** @var ChildBanners $obj */
207
            $obj = new ChildBanners();
208
            $obj->hydrate($row);
209
            BannersTableMap::addInstanceToPool($obj, null === $key || is_scalar($key) || is_callable([$key, '__toString']) ? (string) $key : $key);
210
        }
211
        $stmt->closeCursor();
212
213
        return $obj;
214
    }
215
216
    /**
217
     * Find object by primary key.
218
     *
219
     * @param     mixed $key Primary key to use for the query
220
     * @param     ConnectionInterface $con A connection object
221
     *
222
     * @return ChildBanners|array|mixed the result, formatted by the current formatter
223
     */
224 View Code Duplication
    protected function findPkComplex($key, ConnectionInterface $con)
225
    {
226
        // As the query uses a PK condition, no limit(1) is necessary.
227
        $criteria = $this->isKeepQuery() ? clone $this : $this;
228
        $dataFetcher = $criteria
229
            ->filterByPrimaryKey($key)
230
            ->doSelect($con);
231
232
        return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher);
233
    }
234
235
    /**
236
     * Find objects by primary key
237
     * <code>
238
     * $objs = $c->findPks(array(12, 56, 832), $con);
239
     * </code>
240
     * @param     array $keys Primary keys to use for the query
241
     * @param     ConnectionInterface $con an optional connection object
242
     *
243
     * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter
244
     */
245 View Code Duplication
    public function findPks($keys, ConnectionInterface $con = null)
246
    {
247
        if (null === $con) {
248
            $con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
249
        }
250
        $this->basePreSelect($con);
251
        $criteria = $this->isKeepQuery() ? clone $this : $this;
252
        $dataFetcher = $criteria
253
            ->filterByPrimaryKeys($keys)
254
            ->doSelect($con);
255
256
        return $criteria->getFormatter()->init($criteria)->format($dataFetcher);
257
    }
258
259
    /**
260
     * Filter the query by primary key
261
     *
262
     * @param     mixed $key Primary key to use for the query
263
     *
264
     * @return $this|ChildBannersQuery The current query, for fluid interface
265
     */
266
    public function filterByPrimaryKey($key)
267
    {
268
269
        return $this->addUsingAlias(BannersTableMap::COL_ID, $key, Criteria::EQUAL);
270
    }
271
272
    /**
273
     * Filter the query by a list of primary keys
274
     *
275
     * @param     array $keys The list of primary key to use for the query
276
     *
277
     * @return $this|ChildBannersQuery The current query, for fluid interface
278
     */
279
    public function filterByPrimaryKeys($keys)
280
    {
281
282
        return $this->addUsingAlias(BannersTableMap::COL_ID, $keys, Criteria::IN);
283
    }
284
285
    /**
286
     * Filter the query on the id column
287
     *
288
     * Example usage:
289
     * <code>
290
     * $query->filterById(1234); // WHERE id = 1234
291
     * $query->filterById(array(12, 34)); // WHERE id IN (12, 34)
292
     * $query->filterById(array('min' => 12)); // WHERE id > 12
293
     * </code>
294
     *
295
     * @param     mixed $id The value to use as filter.
296
     *              Use scalar values for equality.
297
     *              Use array values for in_array() equivalent.
298
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
299
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
300
     *
301
     * @return $this|ChildBannersQuery The current query, for fluid interface
302
     */
303 View Code Duplication
    public function filterById($id = null, $comparison = null)
304
    {
305
        if (is_array($id)) {
306
            $useMinMax = false;
307
            if (isset($id['min'])) {
308
                $this->addUsingAlias(BannersTableMap::COL_ID, $id['min'], Criteria::GREATER_EQUAL);
309
                $useMinMax = true;
310
            }
311
            if (isset($id['max'])) {
312
                $this->addUsingAlias(BannersTableMap::COL_ID, $id['max'], Criteria::LESS_EQUAL);
313
                $useMinMax = true;
314
            }
315
            if ($useMinMax) {
316
                return $this;
317
            }
318
            if (null === $comparison) {
319
                $comparison = Criteria::IN;
320
            }
321
        }
322
323
        return $this->addUsingAlias(BannersTableMap::COL_ID, $id, $comparison);
324
    }
325
326
    /**
327
     * Filter the query on the place column
328
     *
329
     * Example usage:
330
     * <code>
331
     * $query->filterByPlace('fooValue');   // WHERE place = 'fooValue'
332
     * $query->filterByPlace('%fooValue%', Criteria::LIKE); // WHERE place LIKE '%fooValue%'
333
     * </code>
334
     *
335
     * @param     string $place The value to use as filter.
336
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
337
     *
338
     * @return $this|ChildBannersQuery The current query, for fluid interface
339
     */
340 View Code Duplication
    public function filterByPlace($place = null, $comparison = null)
341
    {
342
        if (null === $comparison) {
343
            if (is_array($place)) {
344
                $comparison = Criteria::IN;
345
            }
346
        }
347
348
        return $this->addUsingAlias(BannersTableMap::COL_PLACE, $place, $comparison);
349
    }
350
351
    /**
352
     * Filter the query on the width column
353
     *
354
     * Example usage:
355
     * <code>
356
     * $query->filterByWidth(1234); // WHERE width = 1234
357
     * $query->filterByWidth(array(12, 34)); // WHERE width IN (12, 34)
358
     * $query->filterByWidth(array('min' => 12)); // WHERE width > 12
359
     * </code>
360
     *
361
     * @param     mixed $width The value to use as filter.
362
     *              Use scalar values for equality.
363
     *              Use array values for in_array() equivalent.
364
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
365
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
366
     *
367
     * @return $this|ChildBannersQuery The current query, for fluid interface
368
     */
369 View Code Duplication
    public function filterByWidth($width = null, $comparison = null)
370
    {
371
        if (is_array($width)) {
372
            $useMinMax = false;
373
            if (isset($width['min'])) {
374
                $this->addUsingAlias(BannersTableMap::COL_WIDTH, $width['min'], Criteria::GREATER_EQUAL);
375
                $useMinMax = true;
376
            }
377
            if (isset($width['max'])) {
378
                $this->addUsingAlias(BannersTableMap::COL_WIDTH, $width['max'], Criteria::LESS_EQUAL);
379
                $useMinMax = true;
380
            }
381
            if ($useMinMax) {
382
                return $this;
383
            }
384
            if (null === $comparison) {
385
                $comparison = Criteria::IN;
386
            }
387
        }
388
389
        return $this->addUsingAlias(BannersTableMap::COL_WIDTH, $width, $comparison);
390
    }
391
392
    /**
393
     * Filter the query on the height column
394
     *
395
     * Example usage:
396
     * <code>
397
     * $query->filterByHeight(1234); // WHERE height = 1234
398
     * $query->filterByHeight(array(12, 34)); // WHERE height IN (12, 34)
399
     * $query->filterByHeight(array('min' => 12)); // WHERE height > 12
400
     * </code>
401
     *
402
     * @param     mixed $height The value to use as filter.
403
     *              Use scalar values for equality.
404
     *              Use array values for in_array() equivalent.
405
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
406
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
407
     *
408
     * @return $this|ChildBannersQuery The current query, for fluid interface
409
     */
410 View Code Duplication
    public function filterByHeight($height = null, $comparison = null)
411
    {
412
        if (is_array($height)) {
413
            $useMinMax = false;
414
            if (isset($height['min'])) {
415
                $this->addUsingAlias(BannersTableMap::COL_HEIGHT, $height['min'], Criteria::GREATER_EQUAL);
416
                $useMinMax = true;
417
            }
418
            if (isset($height['max'])) {
419
                $this->addUsingAlias(BannersTableMap::COL_HEIGHT, $height['max'], Criteria::LESS_EQUAL);
420
                $useMinMax = true;
421
            }
422
            if ($useMinMax) {
423
                return $this;
424
            }
425
            if (null === $comparison) {
426
                $comparison = Criteria::IN;
427
            }
428
        }
429
430
        return $this->addUsingAlias(BannersTableMap::COL_HEIGHT, $height, $comparison);
431
    }
432
433
    /**
434
     * Filter the query on the effects column
435
     *
436
     * Example usage:
437
     * <code>
438
     * $query->filterByEffects('fooValue');   // WHERE effects = 'fooValue'
439
     * $query->filterByEffects('%fooValue%', Criteria::LIKE); // WHERE effects LIKE '%fooValue%'
440
     * </code>
441
     *
442
     * @param     string $effects The value to use as filter.
443
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
444
     *
445
     * @return $this|ChildBannersQuery The current query, for fluid interface
446
     */
447 View Code Duplication
    public function filterByEffects($effects = null, $comparison = null)
448
    {
449
        if (null === $comparison) {
450
            if (is_array($effects)) {
451
                $comparison = Criteria::IN;
452
            }
453
        }
454
455
        return $this->addUsingAlias(BannersTableMap::COL_EFFECTS, $effects, $comparison);
456
    }
457
458
    /**
459
     * Filter the query on the page_type column
460
     *
461
     * Example usage:
462
     * <code>
463
     * $query->filterByPageType('fooValue');   // WHERE page_type = 'fooValue'
464
     * $query->filterByPageType('%fooValue%', Criteria::LIKE); // WHERE page_type LIKE '%fooValue%'
465
     * </code>
466
     *
467
     * @param     string $pageType The value to use as filter.
468
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
469
     *
470
     * @return $this|ChildBannersQuery The current query, for fluid interface
471
     */
472 View Code Duplication
    public function filterByPageType($pageType = null, $comparison = null)
473
    {
474
        if (null === $comparison) {
475
            if (is_array($pageType)) {
476
                $comparison = Criteria::IN;
477
            }
478
        }
479
480
        return $this->addUsingAlias(BannersTableMap::COL_PAGE_TYPE, $pageType, $comparison);
481
    }
482
483
    /**
484
     * Filter the query by a related \xbanners\models\BannerImage object
485
     *
486
     * @param \xbanners\models\BannerImage|ObjectCollection $bannerImage the related object to use as filter
487
     * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
488
     *
489
     * @return ChildBannersQuery The current query, for fluid interface
490
     */
491 View Code Duplication
    public function filterByBannerImage($bannerImage, $comparison = null)
492
    {
493
        if ($bannerImage instanceof \xbanners\models\BannerImage) {
494
            return $this
495
                ->addUsingAlias(BannersTableMap::COL_ID, $bannerImage->getBannerId(), $comparison);
496
        } elseif ($bannerImage instanceof ObjectCollection) {
497
            return $this
498
                ->useBannerImageQuery()
499
                ->filterByPrimaryKeys($bannerImage->getPrimaryKeys())
500
                ->endUse();
501
        } else {
502
            throw new PropelException('filterByBannerImage() only accepts arguments of type \xbanners\models\BannerImage or Collection');
503
        }
504
    }
505
506
    /**
507
     * Adds a JOIN clause to the query using the BannerImage relation
508
     *
509
     * @param     string $relationAlias optional alias for the relation
510
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
511
     *
512
     * @return $this|ChildBannersQuery The current query, for fluid interface
513
     */
514 View Code Duplication
    public function joinBannerImage($relationAlias = null, $joinType = Criteria::INNER_JOIN)
515
    {
516
        $tableMap = $this->getTableMap();
517
        $relationMap = $tableMap->getRelation('BannerImage');
518
519
        // create a ModelJoin object for this join
520
        $join = new ModelJoin();
521
        $join->setJoinType($joinType);
522
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
523
        if ($previousJoin = $this->getPreviousJoin()) {
524
            $join->setPreviousJoin($previousJoin);
0 ignored issues
show
Compatibility introduced by
$previousJoin of type object<Propel\Runtime\ActiveQuery\Join> is not a sub-type of object<Propel\Runtime\ActiveQuery\ModelJoin>. It seems like you assume a child class of the class Propel\Runtime\ActiveQuery\Join 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...
525
        }
526
527
        // add the ModelJoin to the current object
528
        if ($relationAlias) {
529
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
530
            $this->addJoinObject($join, $relationAlias);
531
        } else {
532
            $this->addJoinObject($join, 'BannerImage');
533
        }
534
535
        return $this;
536
    }
537
538
    /**
539
     * Use the BannerImage relation BannerImage object
540
     *
541
     * @see useQuery()
542
     *
543
     * @param     string $relationAlias optional alias for the relation,
544
     *                                   to be used as main alias in the secondary query
545
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
546
     *
547
     * @return \xbanners\models\BannerImageQuery A secondary query class using the current class as primary query
548
     */
549
    public function useBannerImageQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
550
    {
551
        return $this
552
            ->joinBannerImage($relationAlias, $joinType)
553
            ->useQuery($relationAlias ? $relationAlias : 'BannerImage', '\xbanners\models\BannerImageQuery');
554
    }
555
556
    /**
557
     * Filter the query by a related \xbanners\models\BannersI18n object
558
     *
559
     * @param \xbanners\models\BannersI18n|ObjectCollection $bannersI18n the related object to use as filter
560
     * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
561
     *
562
     * @return ChildBannersQuery The current query, for fluid interface
563
     */
564 View Code Duplication
    public function filterByBannersI18n($bannersI18n, $comparison = null)
565
    {
566
        if ($bannersI18n instanceof \xbanners\models\BannersI18n) {
567
            return $this
568
                ->addUsingAlias(BannersTableMap::COL_ID, $bannersI18n->getId(), $comparison);
569
        } elseif ($bannersI18n instanceof ObjectCollection) {
570
            return $this
571
                ->useBannersI18nQuery()
572
                ->filterByPrimaryKeys($bannersI18n->getPrimaryKeys())
573
                ->endUse();
574
        } else {
575
            throw new PropelException('filterByBannersI18n() only accepts arguments of type \xbanners\models\BannersI18n or Collection');
576
        }
577
    }
578
579
    /**
580
     * Adds a JOIN clause to the query using the BannersI18n relation
581
     *
582
     * @param     string $relationAlias optional alias for the relation
583
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
584
     *
585
     * @return $this|ChildBannersQuery The current query, for fluid interface
586
     */
587 View Code Duplication
    public function joinBannersI18n($relationAlias = null, $joinType = 'LEFT JOIN')
588
    {
589
        $tableMap = $this->getTableMap();
590
        $relationMap = $tableMap->getRelation('BannersI18n');
591
592
        // create a ModelJoin object for this join
593
        $join = new ModelJoin();
594
        $join->setJoinType($joinType);
595
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
596
        if ($previousJoin = $this->getPreviousJoin()) {
597
            $join->setPreviousJoin($previousJoin);
0 ignored issues
show
Compatibility introduced by
$previousJoin of type object<Propel\Runtime\ActiveQuery\Join> is not a sub-type of object<Propel\Runtime\ActiveQuery\ModelJoin>. It seems like you assume a child class of the class Propel\Runtime\ActiveQuery\Join 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...
598
        }
599
600
        // add the ModelJoin to the current object
601
        if ($relationAlias) {
602
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
603
            $this->addJoinObject($join, $relationAlias);
604
        } else {
605
            $this->addJoinObject($join, 'BannersI18n');
606
        }
607
608
        return $this;
609
    }
610
611
    /**
612
     * Use the BannersI18n relation BannersI18n object
613
     *
614
     * @see useQuery()
615
     *
616
     * @param     string $relationAlias optional alias for the relation,
617
     *                                   to be used as main alias in the secondary query
618
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
619
     *
620
     * @return \xbanners\models\BannersI18nQuery A secondary query class using the current class as primary query
621
     */
622
    public function useBannersI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN')
623
    {
624
        return $this
625
            ->joinBannersI18n($relationAlias, $joinType)
626
            ->useQuery($relationAlias ? $relationAlias : 'BannersI18n', '\xbanners\models\BannersI18nQuery');
627
    }
628
629
    /**
630
     * Exclude object from result
631
     *
632
     * @param   ChildBanners $banners Object to remove from the list of results
633
     *
634
     * @return $this|ChildBannersQuery The current query, for fluid interface
635
     */
636
    public function prune($banners = null)
637
    {
638
        if ($banners) {
639
            $this->addUsingAlias(BannersTableMap::COL_ID, $banners->getId(), Criteria::NOT_EQUAL);
640
        }
641
642
        return $this;
643
    }
644
645
    /**
646
     * Deletes all rows from the banners table.
647
     *
648
     * @param ConnectionInterface $con the connection to use
649
     * @return int The number of affected rows (if supported by underlying database driver).
650
     */
651 View Code Duplication
    public function doDeleteAll(ConnectionInterface $con = null)
652
    {
653
        if (null === $con) {
654
            $con = Propel::getServiceContainer()->getWriteConnection(BannersTableMap::DATABASE_NAME);
655
        }
656
657
        // use transaction because $criteria could contain info
658
        // for more than one table or we could emulating ON DELETE CASCADE, etc.
659
        return $con->transaction(function () use ($con) {
660
            $affectedRows = 0; // initialize var to track total num of affected rows
661
            $affectedRows += $this->doOnDeleteCascade($con);
662
            $affectedRows += parent::doDeleteAll($con);
663
            // Because this db requires some delete cascade/set null emulation, we have to
664
            // clear the cached instance *after* the emulation has happened (since
665
            // instances get re-added by the select statement contained therein).
666
            BannersTableMap::clearInstancePool();
667
            BannersTableMap::clearRelatedInstancePool();
668
669
            return $affectedRows;
670
        });
671
    }
672
673
    /**
674
     * Performs a DELETE on the database based on the current ModelCriteria
675
     *
676
     * @param ConnectionInterface $con the connection to use
677
     * @return int             The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
678
     *                         if supported by native driver or if emulated using Propel.
679
     * @throws PropelException Any exceptions caught during processing will be
680
     *                         rethrown wrapped into a PropelException.
681
     */
682 View Code Duplication
    public function delete(ConnectionInterface $con = null)
683
    {
684
        if (null === $con) {
685
            $con = Propel::getServiceContainer()->getWriteConnection(BannersTableMap::DATABASE_NAME);
686
        }
687
688
        $criteria = $this;
689
690
        // Set the correct dbName
691
        $criteria->setDbName(BannersTableMap::DATABASE_NAME);
692
693
        // use transaction because $criteria could contain info
694
        // for more than one table or we could emulating ON DELETE CASCADE, etc.
695
        return $con->transaction(function () use ($con, $criteria) {
696
            $affectedRows = 0; // initialize var to track total num of affected rows
697
698
            // cloning the Criteria in case it's modified by doSelect() or doSelectStmt()
699
            $c = clone $criteria;
700
            $affectedRows += $c->doOnDeleteCascade($con);
701
702
            BannersTableMap::removeInstanceFromPool($criteria);
703
704
            $affectedRows += ModelCriteria::delete($con);
705
            BannersTableMap::clearRelatedInstancePool();
706
707
            return $affectedRows;
708
        });
709
    }
710
711
    /**
712
     * This is a method for emulating ON DELETE CASCADE for DBs that don't support this
713
     * feature (like MySQL or SQLite).
714
     *
715
     * This method is not very speedy because it must perform a query first to get
716
     * the implicated records and then perform the deletes by calling those Query classes.
717
     *
718
     * This method should be used within a transaction if possible.
719
     *
720
     * @param ConnectionInterface $con
721
     * @return int The number of affected rows (if supported by underlying database driver).
722
     */
723
    protected function doOnDeleteCascade(ConnectionInterface $con)
724
    {
725
        // initialize var to track total num of affected rows
726
        $affectedRows = 0;
727
728
        // first find the objects that are implicated by the $this
729
        $objects = ChildBannersQuery::create(null, $this)->find($con);
730 View Code Duplication
        foreach ($objects as $obj) {
731
732
733
            // delete related BannerImage objects
734
            $query = new \xbanners\models\BannerImageQuery;
735
736
            $query->add(BannerImageTableMap::COL_BANNER_ID, $obj->getId());
737
            $affectedRows += $query->delete($con);
738
739
            // delete related BannersI18n objects
740
            $query = new \xbanners\models\BannersI18nQuery;
741
742
            $query->add(BannersI18nTableMap::COL_ID, $obj->getId());
743
            $affectedRows += $query->delete($con);
744
        }
745
746
        return $affectedRows;
747
    }
748
749
    // i18n behavior
750
751
    /**
752
     * Adds a JOIN clause to the query using the i18n relation
753
     *
754
     * @param     string $locale Locale to use for the join condition, e.g. 'fr_FR'
755
     * @param     string $relationAlias optional alias for the relation
756
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join.
757
     *
758
     * @return    ChildBannersQuery The current query, for fluid interface
759
     */
760 View Code Duplication
    public function joinI18n($locale = 'ru', $relationAlias = null, $joinType = Criteria::LEFT_JOIN)
761
    {
762
        $relationName = $relationAlias ? $relationAlias : 'BannersI18n';
763
764
        return $this
765
            ->joinBannersI18n($relationAlias, $joinType)
766
            ->addJoinCondition($relationName, $relationName . '.Locale = ?', $locale);
767
    }
768
769
    /**
770
     * Adds a JOIN clause to the query and hydrates the related I18n object.
771
     * Shortcut for $c->joinI18n($locale)->with()
772
     *
773
     * @param     string $locale Locale to use for the join condition, e.g. 'fr_FR'
774
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join.
775
     *
776
     * @return    $this|ChildBannersQuery The current query, for fluid interface
777
     */
778 View Code Duplication
    public function joinWithI18n($locale = 'ru', $joinType = Criteria::LEFT_JOIN)
779
    {
780
        $this
781
            ->joinI18n($locale, null, $joinType)
782
            ->with('BannersI18n');
783
        $this->with['BannersI18n']->setIsWithOneToMany(false);
784
785
        return $this;
786
    }
787
788
    /**
789
     * Use the I18n relation query object
790
     *
791
     * @see       useQuery()
792
     *
793
     * @param     string $locale Locale to use for the join condition, e.g. 'fr_FR'
794
     * @param     string $relationAlias optional alias for the relation
795
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join.
796
     *
797
     * @return    ChildBannersI18nQuery A secondary query class using the current class as primary query
798
     */
799
    public function useI18nQuery($locale = 'ru', $relationAlias = null, $joinType = Criteria::LEFT_JOIN)
800
    {
801
        return $this
802
            ->joinI18n($locale, $relationAlias, $joinType)
803
            ->useQuery($relationAlias ? $relationAlias : 'BannersI18n', '\xbanners\models\BannersI18nQuery');
804
    }
805
806
} // BannersQuery
807