Completed
Branch master (bdef63)
by Sam
01:52
created

InstanceQuery   F

Complexity

Total Complexity 82

Size/Duplication

Total Lines 578
Duplicated Lines 49.48 %

Coupling/Cohesion

Components 2
Dependencies 25

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 82
c 1
b 0
f 1
lcom 2
cbo 25
dl 286
loc 578
rs 1.3043

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 InstanceQuery 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 InstanceQuery, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Jalle19\StatusManager\Database\Base;
4
5
use \Exception;
6
use \PDO;
7
use Jalle19\StatusManager\Database\Instance as ChildInstance;
8
use Jalle19\StatusManager\Database\InstanceQuery as ChildInstanceQuery;
9
use Jalle19\StatusManager\Database\Map\InstanceTableMap;
10
use Propel\Runtime\Propel;
11
use Propel\Runtime\ActiveQuery\Criteria;
12
use Propel\Runtime\ActiveQuery\ModelCriteria;
13
use Propel\Runtime\ActiveQuery\ModelJoin;
14
use Propel\Runtime\Collection\ObjectCollection;
15
use Propel\Runtime\Connection\ConnectionInterface;
16
use Propel\Runtime\Exception\PropelException;
17
18
/**
19
 * Base class that represents a query for the 'instance' table.
20
 *
21
 *
22
 *
23
 * @method     ChildInstanceQuery orderByName($order = Criteria::ASC) Order by the name column
24
 *
25
 * @method     ChildInstanceQuery groupByName() Group by the name column
26
 *
27
 * @method     ChildInstanceQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
28
 * @method     ChildInstanceQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
29
 * @method     ChildInstanceQuery innerJoin($relation) Adds a INNER JOIN clause to the query
30
 *
31
 * @method     ChildInstanceQuery leftJoinWith($relation) Adds a LEFT JOIN clause and with to the query
32
 * @method     ChildInstanceQuery rightJoinWith($relation) Adds a RIGHT JOIN clause and with to the query
33
 * @method     ChildInstanceQuery innerJoinWith($relation) Adds a INNER JOIN clause and with to the query
34
 *
35
 * @method     ChildInstanceQuery leftJoinUser($relationAlias = null) Adds a LEFT JOIN clause to the query using the User relation
36
 * @method     ChildInstanceQuery rightJoinUser($relationAlias = null) Adds a RIGHT JOIN clause to the query using the User relation
37
 * @method     ChildInstanceQuery innerJoinUser($relationAlias = null) Adds a INNER JOIN clause to the query using the User relation
38
 *
39
 * @method     ChildInstanceQuery joinWithUser($joinType = Criteria::INNER_JOIN) Adds a join clause and with to the query using the User relation
40
 *
41
 * @method     ChildInstanceQuery leftJoinWithUser() Adds a LEFT JOIN clause and with to the query using the User relation
42
 * @method     ChildInstanceQuery rightJoinWithUser() Adds a RIGHT JOIN clause and with to the query using the User relation
43
 * @method     ChildInstanceQuery innerJoinWithUser() Adds a INNER JOIN clause and with to the query using the User relation
44
 *
45
 * @method     ChildInstanceQuery leftJoinConnection($relationAlias = null) Adds a LEFT JOIN clause to the query using the Connection relation
46
 * @method     ChildInstanceQuery rightJoinConnection($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Connection relation
47
 * @method     ChildInstanceQuery innerJoinConnection($relationAlias = null) Adds a INNER JOIN clause to the query using the Connection relation
48
 *
49
 * @method     ChildInstanceQuery joinWithConnection($joinType = Criteria::INNER_JOIN) Adds a join clause and with to the query using the Connection relation
50
 *
51
 * @method     ChildInstanceQuery leftJoinWithConnection() Adds a LEFT JOIN clause and with to the query using the Connection relation
52
 * @method     ChildInstanceQuery rightJoinWithConnection() Adds a RIGHT JOIN clause and with to the query using the Connection relation
53
 * @method     ChildInstanceQuery innerJoinWithConnection() Adds a INNER JOIN clause and with to the query using the Connection relation
54
 *
55
 * @method     ChildInstanceQuery leftJoinChannel($relationAlias = null) Adds a LEFT JOIN clause to the query using the Channel relation
56
 * @method     ChildInstanceQuery rightJoinChannel($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Channel relation
57
 * @method     ChildInstanceQuery innerJoinChannel($relationAlias = null) Adds a INNER JOIN clause to the query using the Channel relation
58
 *
59
 * @method     ChildInstanceQuery joinWithChannel($joinType = Criteria::INNER_JOIN) Adds a join clause and with to the query using the Channel relation
60
 *
61
 * @method     ChildInstanceQuery leftJoinWithChannel() Adds a LEFT JOIN clause and with to the query using the Channel relation
62
 * @method     ChildInstanceQuery rightJoinWithChannel() Adds a RIGHT JOIN clause and with to the query using the Channel relation
63
 * @method     ChildInstanceQuery innerJoinWithChannel() Adds a INNER JOIN clause and with to the query using the Channel relation
64
 *
65
 * @method     ChildInstanceQuery leftJoinSubscription($relationAlias = null) Adds a LEFT JOIN clause to the query using the Subscription relation
66
 * @method     ChildInstanceQuery rightJoinSubscription($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Subscription relation
67
 * @method     ChildInstanceQuery innerJoinSubscription($relationAlias = null) Adds a INNER JOIN clause to the query using the Subscription relation
68
 *
69
 * @method     ChildInstanceQuery joinWithSubscription($joinType = Criteria::INNER_JOIN) Adds a join clause and with to the query using the Subscription relation
70
 *
71
 * @method     ChildInstanceQuery leftJoinWithSubscription() Adds a LEFT JOIN clause and with to the query using the Subscription relation
72
 * @method     ChildInstanceQuery rightJoinWithSubscription() Adds a RIGHT JOIN clause and with to the query using the Subscription relation
73
 * @method     ChildInstanceQuery innerJoinWithSubscription() Adds a INNER JOIN clause and with to the query using the Subscription relation
74
 *
75
 * @method     \Jalle19\StatusManager\Database\UserQuery|\Jalle19\StatusManager\Database\ConnectionQuery|\Jalle19\StatusManager\Database\ChannelQuery|\Jalle19\StatusManager\Database\SubscriptionQuery endUse() Finalizes a secondary criteria and merges it with its primary Criteria
76
 *
77
 * @method     ChildInstance findOne(ConnectionInterface $con = null) Return the first ChildInstance matching the query
78
 * @method     ChildInstance findOneOrCreate(ConnectionInterface $con = null) Return the first ChildInstance matching the query, or a new ChildInstance object populated from the query conditions when no match is found
79
 *
80
 * @method     ChildInstance findOneByName(string $name) Return the first ChildInstance filtered by the name column *
81
82
 * @method     ChildInstance requirePk($key, ConnectionInterface $con = null) Return the ChildInstance by primary key and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
83
 * @method     ChildInstance requireOne(ConnectionInterface $con = null) Return the first ChildInstance matching the query and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
84
 *
85
 * @method     ChildInstance requireOneByName(string $name) Return the first ChildInstance filtered by the name column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
86
 *
87
 * @method     ChildInstance[]|ObjectCollection find(ConnectionInterface $con = null) Return ChildInstance objects based on current ModelCriteria
88
 * @method     ChildInstance[]|ObjectCollection findByName(string $name) Return ChildInstance objects filtered by the name column
89
 * @method     ChildInstance[]|\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
90
 *
91
 */
92
abstract class InstanceQuery extends ModelCriteria
93
{
94
    protected $entityNotFoundExceptionClass = '\\Propel\\Runtime\\Exception\\EntityNotFoundException';
95
96
    /**
97
     * Initializes internal state of \Jalle19\StatusManager\Database\Base\InstanceQuery object.
98
     *
99
     * @param     string $dbName The database name
100
     * @param     string $modelName The phpName of a model, e.g. 'Book'
101
     * @param     string $modelAlias The alias for the model in this query, e.g. 'b'
102
     */
103
    public function __construct($dbName = 'tvheadend_status_manager', $modelName = '\\Jalle19\\StatusManager\\Database\\Instance', $modelAlias = null)
104
    {
105
        parent::__construct($dbName, $modelName, $modelAlias);
106
    }
107
108
    /**
109
     * Returns a new ChildInstanceQuery object.
110
     *
111
     * @param     string $modelAlias The alias of a model in the query
112
     * @param     Criteria $criteria Optional Criteria to build the query from
113
     *
114
     * @return ChildInstanceQuery
115
     */
116
    public static function create($modelAlias = null, Criteria $criteria = null)
117
    {
118
        if ($criteria instanceof ChildInstanceQuery) {
119
            return $criteria;
120
        }
121
        $query = new ChildInstanceQuery();
122
        if (null !== $modelAlias) {
123
            $query->setModelAlias($modelAlias);
124
        }
125
        if ($criteria instanceof Criteria) {
126
            $query->mergeWith($criteria);
127
        }
128
129
        return $query;
130
    }
131
132
    /**
133
     * Find object by primary key.
134
     * Propel uses the instance pool to skip the database if the object exists.
135
     * Go fast if the query is untouched.
136
     *
137
     * <code>
138
     * $obj  = $c->findPk(12, $con);
139
     * </code>
140
     *
141
     * @param mixed $key Primary key to use for the query
142
     * @param ConnectionInterface $con an optional connection object
143
     *
144
     * @return ChildInstance|array|mixed the result, formatted by the current formatter
145
     */
146
    public function findPk($key, ConnectionInterface $con = null)
147
    {
148
        if ($key === null) {
149
            return null;
150
        }
151
        if ((null !== ($obj = InstanceTableMap::getInstanceFromPool(null === $key || is_scalar($key) || is_callable([$key, '__toString']) ? (string) $key : $key))) && !$this->formatter) {
152
            // the object is already in the instance pool
153
            return $obj;
154
        }
155
        if ($con === null) {
156
            $con = Propel::getServiceContainer()->getReadConnection(InstanceTableMap::DATABASE_NAME);
157
        }
158
        $this->basePreSelect($con);
159
        if ($this->formatter || $this->modelAlias || $this->with || $this->select
160
         || $this->selectColumns || $this->asColumns || $this->selectModifiers
161
         || $this->map || $this->having || $this->joins) {
162
            return $this->findPkComplex($key, $con);
163
        } else {
164
            return $this->findPkSimple($key, $con);
165
        }
166
    }
167
168
    /**
169
     * Find object by primary key using raw SQL to go fast.
170
     * Bypass doSelect() and the object formatter by using generated code.
171
     *
172
     * @param     mixed $key Primary key to use for the query
173
     * @param     ConnectionInterface $con A connection object
174
     *
175
     * @throws \Propel\Runtime\Exception\PropelException
176
     *
177
     * @return ChildInstance A model object, or null if the key is not found
178
     */
179
    protected function findPkSimple($key, ConnectionInterface $con)
180
    {
181
        $sql = 'SELECT name FROM instance WHERE name = :p0';
182
        try {
183
            $stmt = $con->prepare($sql);
184
            $stmt->bindValue(':p0', $key, PDO::PARAM_STR);
185
            $stmt->execute();
186
        } catch (Exception $e) {
187
            Propel::log($e->getMessage(), Propel::LOG_ERR);
188
            throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e);
189
        }
190
        $obj = null;
191
        if ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
192
            /** @var ChildInstance $obj */
193
            $obj = new ChildInstance();
194
            $obj->hydrate($row);
195
            InstanceTableMap::addInstanceToPool($obj, null === $key || is_scalar($key) || is_callable([$key, '__toString']) ? (string) $key : $key);
196
        }
197
        $stmt->closeCursor();
198
199
        return $obj;
200
    }
201
202
    /**
203
     * Find object by primary key.
204
     *
205
     * @param     mixed $key Primary key to use for the query
206
     * @param     ConnectionInterface $con A connection object
207
     *
208
     * @return ChildInstance|array|mixed the result, formatted by the current formatter
209
     */
210
    protected function findPkComplex($key, ConnectionInterface $con)
211
    {
212
        // As the query uses a PK condition, no limit(1) is necessary.
213
        $criteria = $this->isKeepQuery() ? clone $this : $this;
214
        $dataFetcher = $criteria
215
            ->filterByPrimaryKey($key)
216
            ->doSelect($con);
217
218
        return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher);
219
    }
220
221
    /**
222
     * Find objects by primary key
223
     * <code>
224
     * $objs = $c->findPks(array(12, 56, 832), $con);
225
     * </code>
226
     * @param     array $keys Primary keys to use for the query
227
     * @param     ConnectionInterface $con an optional connection object
228
     *
229
     * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter
230
     */
231
    public function findPks($keys, ConnectionInterface $con = null)
232
    {
233
        if (null === $con) {
234
            $con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
235
        }
236
        $this->basePreSelect($con);
237
        $criteria = $this->isKeepQuery() ? clone $this : $this;
238
        $dataFetcher = $criteria
239
            ->filterByPrimaryKeys($keys)
240
            ->doSelect($con);
241
242
        return $criteria->getFormatter()->init($criteria)->format($dataFetcher);
243
    }
244
245
    /**
246
     * Filter the query by primary key
247
     *
248
     * @param     mixed $key Primary key to use for the query
249
     *
250
     * @return $this|ChildInstanceQuery The current query, for fluid interface
251
     */
252
    public function filterByPrimaryKey($key)
253
    {
254
255
        return $this->addUsingAlias(InstanceTableMap::COL_NAME, $key, Criteria::EQUAL);
256
    }
257
258
    /**
259
     * Filter the query by a list of primary keys
260
     *
261
     * @param     array $keys The list of primary key to use for the query
262
     *
263
     * @return $this|ChildInstanceQuery The current query, for fluid interface
264
     */
265
    public function filterByPrimaryKeys($keys)
266
    {
267
268
        return $this->addUsingAlias(InstanceTableMap::COL_NAME, $keys, Criteria::IN);
269
    }
270
271
    /**
272
     * Filter the query on the name column
273
     *
274
     * Example usage:
275
     * <code>
276
     * $query->filterByName('fooValue');   // WHERE name = 'fooValue'
277
     * $query->filterByName('%fooValue%'); // WHERE name LIKE '%fooValue%'
278
     * </code>
279
     *
280
     * @param     string $name The value to use as filter.
281
     *              Accepts wildcards (* and % trigger a LIKE)
282
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
283
     *
284
     * @return $this|ChildInstanceQuery The current query, for fluid interface
285
     */
286
    public function filterByName($name = null, $comparison = null)
287
    {
288
        if (null === $comparison) {
289
            if (is_array($name)) {
290
                $comparison = Criteria::IN;
291
            } elseif (preg_match('/[\%\*]/', $name)) {
292
                $name = str_replace('*', '%', $name);
293
                $comparison = Criteria::LIKE;
294
            }
295
        }
296
297
        return $this->addUsingAlias(InstanceTableMap::COL_NAME, $name, $comparison);
298
    }
299
300
    /**
301
     * Filter the query by a related \Jalle19\StatusManager\Database\User object
302
     *
303
     * @param \Jalle19\StatusManager\Database\User|ObjectCollection $user the related object to use as filter
304
     * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
305
     *
306
     * @return ChildInstanceQuery The current query, for fluid interface
307
     */
308
    public function filterByUser($user, $comparison = null)
309
    {
310
        if ($user instanceof \Jalle19\StatusManager\Database\User) {
311
            return $this
312
                ->addUsingAlias(InstanceTableMap::COL_NAME, $user->getInstanceName(), $comparison);
313
        } elseif ($user instanceof ObjectCollection) {
314
            return $this
315
                ->useUserQuery()
316
                ->filterByPrimaryKeys($user->getPrimaryKeys())
317
                ->endUse();
318
        } else {
319
            throw new PropelException('filterByUser() only accepts arguments of type \Jalle19\StatusManager\Database\User or Collection');
320
        }
321
    }
322
323
    /**
324
     * Adds a JOIN clause to the query using the User relation
325
     *
326
     * @param     string $relationAlias optional alias for the relation
327
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
328
     *
329
     * @return $this|ChildInstanceQuery The current query, for fluid interface
330
     */
331
    public function joinUser($relationAlias = null, $joinType = Criteria::INNER_JOIN)
332
    {
333
        $tableMap = $this->getTableMap();
334
        $relationMap = $tableMap->getRelation('User');
335
336
        // create a ModelJoin object for this join
337
        $join = new ModelJoin();
338
        $join->setJoinType($joinType);
339
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
340
        if ($previousJoin = $this->getPreviousJoin()) {
341
            $join->setPreviousJoin($previousJoin);
342
        }
343
344
        // add the ModelJoin to the current object
345
        if ($relationAlias) {
346
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
347
            $this->addJoinObject($join, $relationAlias);
348
        } else {
349
            $this->addJoinObject($join, 'User');
350
        }
351
352
        return $this;
353
    }
354
355
    /**
356
     * Use the User relation User object
357
     *
358
     * @see useQuery()
359
     *
360
     * @param     string $relationAlias optional alias for the relation,
361
     *                                   to be used as main alias in the secondary query
362
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
363
     *
364
     * @return \Jalle19\StatusManager\Database\UserQuery A secondary query class using the current class as primary query
365
     */
366
    public function useUserQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
367
    {
368
        return $this
369
            ->joinUser($relationAlias, $joinType)
370
            ->useQuery($relationAlias ? $relationAlias : 'User', '\Jalle19\StatusManager\Database\UserQuery');
371
    }
372
373
    /**
374
     * Filter the query by a related \Jalle19\StatusManager\Database\Connection object
375
     *
376
     * @param \Jalle19\StatusManager\Database\Connection|ObjectCollection $connection the related object to use as filter
377
     * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
378
     *
379
     * @return ChildInstanceQuery The current query, for fluid interface
380
     */
381
    public function filterByConnection($connection, $comparison = null)
382
    {
383
        if ($connection instanceof \Jalle19\StatusManager\Database\Connection) {
384
            return $this
385
                ->addUsingAlias(InstanceTableMap::COL_NAME, $connection->getInstanceName(), $comparison);
386
        } elseif ($connection instanceof ObjectCollection) {
387
            return $this
388
                ->useConnectionQuery()
389
                ->filterByPrimaryKeys($connection->getPrimaryKeys())
390
                ->endUse();
391
        } else {
392
            throw new PropelException('filterByConnection() only accepts arguments of type \Jalle19\StatusManager\Database\Connection or Collection');
393
        }
394
    }
395
396
    /**
397
     * Adds a JOIN clause to the query using the Connection relation
398
     *
399
     * @param     string $relationAlias optional alias for the relation
400
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
401
     *
402
     * @return $this|ChildInstanceQuery The current query, for fluid interface
403
     */
404
    public function joinConnection($relationAlias = null, $joinType = Criteria::INNER_JOIN)
405
    {
406
        $tableMap = $this->getTableMap();
407
        $relationMap = $tableMap->getRelation('Connection');
408
409
        // create a ModelJoin object for this join
410
        $join = new ModelJoin();
411
        $join->setJoinType($joinType);
412
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
413
        if ($previousJoin = $this->getPreviousJoin()) {
414
            $join->setPreviousJoin($previousJoin);
415
        }
416
417
        // add the ModelJoin to the current object
418
        if ($relationAlias) {
419
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
420
            $this->addJoinObject($join, $relationAlias);
421
        } else {
422
            $this->addJoinObject($join, 'Connection');
423
        }
424
425
        return $this;
426
    }
427
428
    /**
429
     * Use the Connection relation Connection object
430
     *
431
     * @see useQuery()
432
     *
433
     * @param     string $relationAlias optional alias for the relation,
434
     *                                   to be used as main alias in the secondary query
435
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
436
     *
437
     * @return \Jalle19\StatusManager\Database\ConnectionQuery A secondary query class using the current class as primary query
438
     */
439
    public function useConnectionQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
440
    {
441
        return $this
442
            ->joinConnection($relationAlias, $joinType)
443
            ->useQuery($relationAlias ? $relationAlias : 'Connection', '\Jalle19\StatusManager\Database\ConnectionQuery');
444
    }
445
446
    /**
447
     * Filter the query by a related \Jalle19\StatusManager\Database\Channel object
448
     *
449
     * @param \Jalle19\StatusManager\Database\Channel|ObjectCollection $channel the related object to use as filter
450
     * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
451
     *
452
     * @return ChildInstanceQuery The current query, for fluid interface
453
     */
454
    public function filterByChannel($channel, $comparison = null)
455
    {
456
        if ($channel instanceof \Jalle19\StatusManager\Database\Channel) {
457
            return $this
458
                ->addUsingAlias(InstanceTableMap::COL_NAME, $channel->getInstanceName(), $comparison);
459
        } elseif ($channel instanceof ObjectCollection) {
460
            return $this
461
                ->useChannelQuery()
462
                ->filterByPrimaryKeys($channel->getPrimaryKeys())
463
                ->endUse();
464
        } else {
465
            throw new PropelException('filterByChannel() only accepts arguments of type \Jalle19\StatusManager\Database\Channel or Collection');
466
        }
467
    }
468
469
    /**
470
     * Adds a JOIN clause to the query using the Channel relation
471
     *
472
     * @param     string $relationAlias optional alias for the relation
473
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
474
     *
475
     * @return $this|ChildInstanceQuery The current query, for fluid interface
476
     */
477
    public function joinChannel($relationAlias = null, $joinType = Criteria::INNER_JOIN)
478
    {
479
        $tableMap = $this->getTableMap();
480
        $relationMap = $tableMap->getRelation('Channel');
481
482
        // create a ModelJoin object for this join
483
        $join = new ModelJoin();
484
        $join->setJoinType($joinType);
485
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
486
        if ($previousJoin = $this->getPreviousJoin()) {
487
            $join->setPreviousJoin($previousJoin);
488
        }
489
490
        // add the ModelJoin to the current object
491
        if ($relationAlias) {
492
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
493
            $this->addJoinObject($join, $relationAlias);
494
        } else {
495
            $this->addJoinObject($join, 'Channel');
496
        }
497
498
        return $this;
499
    }
500
501
    /**
502
     * Use the Channel relation Channel object
503
     *
504
     * @see useQuery()
505
     *
506
     * @param     string $relationAlias optional alias for the relation,
507
     *                                   to be used as main alias in the secondary query
508
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
509
     *
510
     * @return \Jalle19\StatusManager\Database\ChannelQuery A secondary query class using the current class as primary query
511
     */
512
    public function useChannelQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
513
    {
514
        return $this
515
            ->joinChannel($relationAlias, $joinType)
516
            ->useQuery($relationAlias ? $relationAlias : 'Channel', '\Jalle19\StatusManager\Database\ChannelQuery');
517
    }
518
519
    /**
520
     * Filter the query by a related \Jalle19\StatusManager\Database\Subscription object
521
     *
522
     * @param \Jalle19\StatusManager\Database\Subscription|ObjectCollection $subscription the related object to use as filter
523
     * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
524
     *
525
     * @return ChildInstanceQuery The current query, for fluid interface
526
     */
527
    public function filterBySubscription($subscription, $comparison = null)
528
    {
529
        if ($subscription instanceof \Jalle19\StatusManager\Database\Subscription) {
530
            return $this
531
                ->addUsingAlias(InstanceTableMap::COL_NAME, $subscription->getInstanceName(), $comparison);
532
        } elseif ($subscription instanceof ObjectCollection) {
533
            return $this
534
                ->useSubscriptionQuery()
535
                ->filterByPrimaryKeys($subscription->getPrimaryKeys())
536
                ->endUse();
537
        } else {
538
            throw new PropelException('filterBySubscription() only accepts arguments of type \Jalle19\StatusManager\Database\Subscription or Collection');
539
        }
540
    }
541
542
    /**
543
     * Adds a JOIN clause to the query using the Subscription relation
544
     *
545
     * @param     string $relationAlias optional alias for the relation
546
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
547
     *
548
     * @return $this|ChildInstanceQuery The current query, for fluid interface
549
     */
550
    public function joinSubscription($relationAlias = null, $joinType = Criteria::INNER_JOIN)
551
    {
552
        $tableMap = $this->getTableMap();
553
        $relationMap = $tableMap->getRelation('Subscription');
554
555
        // create a ModelJoin object for this join
556
        $join = new ModelJoin();
557
        $join->setJoinType($joinType);
558
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
559
        if ($previousJoin = $this->getPreviousJoin()) {
560
            $join->setPreviousJoin($previousJoin);
561
        }
562
563
        // add the ModelJoin to the current object
564
        if ($relationAlias) {
565
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
566
            $this->addJoinObject($join, $relationAlias);
567
        } else {
568
            $this->addJoinObject($join, 'Subscription');
569
        }
570
571
        return $this;
572
    }
573
574
    /**
575
     * Use the Subscription relation Subscription object
576
     *
577
     * @see useQuery()
578
     *
579
     * @param     string $relationAlias optional alias for the relation,
580
     *                                   to be used as main alias in the secondary query
581
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
582
     *
583
     * @return \Jalle19\StatusManager\Database\SubscriptionQuery A secondary query class using the current class as primary query
584
     */
585
    public function useSubscriptionQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
586
    {
587
        return $this
588
            ->joinSubscription($relationAlias, $joinType)
589
            ->useQuery($relationAlias ? $relationAlias : 'Subscription', '\Jalle19\StatusManager\Database\SubscriptionQuery');
590
    }
591
592
    /**
593
     * Exclude object from result
594
     *
595
     * @param   ChildInstance $instance Object to remove from the list of results
596
     *
597
     * @return $this|ChildInstanceQuery The current query, for fluid interface
598
     */
599
    public function prune($instance = null)
600
    {
601
        if ($instance) {
602
            $this->addUsingAlias(InstanceTableMap::COL_NAME, $instance->getName(), Criteria::NOT_EQUAL);
603
        }
604
605
        return $this;
606
    }
607
608
    /**
609
     * Deletes all rows from the instance table.
610
     *
611
     * @param ConnectionInterface $con the connection to use
612
     * @return int The number of affected rows (if supported by underlying database driver).
613
     */
614
    public function doDeleteAll(ConnectionInterface $con = null)
615
    {
616
        if (null === $con) {
617
            $con = Propel::getServiceContainer()->getWriteConnection(InstanceTableMap::DATABASE_NAME);
618
        }
619
620
        // use transaction because $criteria could contain info
621
        // for more than one table or we could emulating ON DELETE CASCADE, etc.
622
        return $con->transaction(function () use ($con) {
623
            $affectedRows = 0; // initialize var to track total num of affected rows
624
            $affectedRows += parent::doDeleteAll($con);
625
            // Because this db requires some delete cascade/set null emulation, we have to
626
            // clear the cached instance *after* the emulation has happened (since
627
            // instances get re-added by the select statement contained therein).
628
            InstanceTableMap::clearInstancePool();
629
            InstanceTableMap::clearRelatedInstancePool();
630
631
            return $affectedRows;
632
        });
633
    }
634
635
    /**
636
     * Performs a DELETE on the database based on the current ModelCriteria
637
     *
638
     * @param ConnectionInterface $con the connection to use
639
     * @return int             The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
640
     *                         if supported by native driver or if emulated using Propel.
641
     * @throws PropelException Any exceptions caught during processing will be
642
     *                         rethrown wrapped into a PropelException.
643
     */
644
    public function delete(ConnectionInterface $con = null)
645
    {
646
        if (null === $con) {
647
            $con = Propel::getServiceContainer()->getWriteConnection(InstanceTableMap::DATABASE_NAME);
648
        }
649
650
        $criteria = $this;
651
652
        // Set the correct dbName
653
        $criteria->setDbName(InstanceTableMap::DATABASE_NAME);
654
655
        // use transaction because $criteria could contain info
656
        // for more than one table or we could emulating ON DELETE CASCADE, etc.
657
        return $con->transaction(function () use ($con, $criteria) {
658
            $affectedRows = 0; // initialize var to track total num of affected rows
659
660
            InstanceTableMap::removeInstanceFromPool($criteria);
661
662
            $affectedRows += ModelCriteria::delete($con);
663
            InstanceTableMap::clearRelatedInstancePool();
664
665
            return $affectedRows;
666
        });
667
    }
668
669
} // InstanceQuery
670