Code Duplication    Length = 432-438 lines in 2 locations

application/modules/mod_link/models/Base/PageLinkProductQuery.php 1 location

@@ 67-504 (lines=438) @@
64
 * @method     ChildPageLinkProduct[]|\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
65
 *
66
 */
67
abstract class PageLinkProductQuery extends ModelCriteria
68
{
69
    protected $entityNotFoundExceptionClass = '\\Propel\\Runtime\\Exception\\EntityNotFoundException';
70
71
    /**
72
     * Initializes internal state of \mod_link\models\Base\PageLinkProductQuery object.
73
     *
74
     * @param     string $dbName The database name
75
     * @param     string $modelName The phpName of a model, e.g. 'Book'
76
     * @param     string $modelAlias The alias for the model in this query, e.g. 'b'
77
     */
78
    public function __construct($dbName = 'Shop', $modelName = '\\mod_link\\models\\PageLinkProduct', $modelAlias = null)
79
    {
80
        parent::__construct($dbName, $modelName, $modelAlias);
81
    }
82
83
    /**
84
     * Returns a new ChildPageLinkProductQuery object.
85
     *
86
     * @param     string $modelAlias The alias of a model in the query
87
     * @param     Criteria $criteria Optional Criteria to build the query from
88
     *
89
     * @return ChildPageLinkProductQuery
90
     */
91
    public static function create($modelAlias = null, Criteria $criteria = null)
92
    {
93
        if ($criteria instanceof ChildPageLinkProductQuery) {
94
            return $criteria;
95
        }
96
        $query = new ChildPageLinkProductQuery();
97
        if (null !== $modelAlias) {
98
            $query->setModelAlias($modelAlias);
99
        }
100
        if ($criteria instanceof Criteria) {
101
            $query->mergeWith($criteria);
102
        }
103
104
        return $query;
105
    }
106
107
    /**
108
     * Find object by primary key.
109
     * Propel uses the instance pool to skip the database if the object exists.
110
     * Go fast if the query is untouched.
111
     *
112
     * <code>
113
     * $obj = $c->findPk(array(12, 34), $con);
114
     * </code>
115
     *
116
     * @param array[$link_id, $product_id] $key Primary key to use for the query
117
     * @param ConnectionInterface $con an optional connection object
118
     *
119
     * @return ChildPageLinkProduct|array|mixed the result, formatted by the current formatter
120
     */
121
    public function findPk($key, ConnectionInterface $con = null)
122
    {
123
        if ($key === null) {
124
            return null;
125
        }
126
127
        if ($con === null) {
128
            $con = Propel::getServiceContainer()->getReadConnection(PageLinkProductTableMap::DATABASE_NAME);
129
        }
130
131
        $this->basePreSelect($con);
132
133
        if (
134
            $this->formatter || $this->modelAlias || $this->with || $this->select
135
            || $this->selectColumns || $this->asColumns || $this->selectModifiers
136
            || $this->map || $this->having || $this->joins
137
        ) {
138
            return $this->findPkComplex($key, $con);
139
        }
140
141
        if ((null !== ($obj = PageLinkProductTableMap::getInstanceFromPool(serialize([(null === $key[0] || is_scalar($key[0]) || is_callable([$key[0], '__toString']) ? (string) $key[0] : $key[0]), (null === $key[1] || is_scalar($key[1]) || is_callable([$key[1], '__toString']) ? (string) $key[1] : $key[1])]))))) {
142
            // the object is already in the instance pool
143
            return $obj;
144
        }
145
146
        return $this->findPkSimple($key, $con);
147
    }
148
149
    /**
150
     * Find object by primary key using raw SQL to go fast.
151
     * Bypass doSelect() and the object formatter by using generated code.
152
     *
153
     * @param     mixed $key Primary key to use for the query
154
     * @param     ConnectionInterface $con A connection object
155
     *
156
     * @throws \Propel\Runtime\Exception\PropelException
157
     *
158
     * @return ChildPageLinkProduct A model object, or null if the key is not found
159
     */
160
    protected function findPkSimple($key, ConnectionInterface $con)
161
    {
162
        $sql = 'SELECT link_id, product_id FROM page_link_product WHERE link_id = :p0 AND product_id = :p1';
163
        try {
164
            $stmt = $con->prepare($sql);
165
            $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT);
166
            $stmt->bindValue(':p1', $key[1], PDO::PARAM_INT);
167
            $stmt->execute();
168
        } catch (Exception $e) {
169
            Propel::log($e->getMessage(), Propel::LOG_ERR);
170
            throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e);
171
        }
172
        $obj = null;
173
        if ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
174
            /** @var ChildPageLinkProduct $obj */
175
            $obj = new ChildPageLinkProduct();
176
            $obj->hydrate($row);
177
            PageLinkProductTableMap::addInstanceToPool($obj, serialize([(null === $key[0] || is_scalar($key[0]) || is_callable([$key[0], '__toString']) ? (string) $key[0] : $key[0]), (null === $key[1] || is_scalar($key[1]) || is_callable([$key[1], '__toString']) ? (string) $key[1] : $key[1])]));
178
        }
179
        $stmt->closeCursor();
180
181
        return $obj;
182
    }
183
184
    /**
185
     * Find object by primary key.
186
     *
187
     * @param     mixed $key Primary key to use for the query
188
     * @param     ConnectionInterface $con A connection object
189
     *
190
     * @return ChildPageLinkProduct|array|mixed the result, formatted by the current formatter
191
     */
192
    protected function findPkComplex($key, ConnectionInterface $con)
193
    {
194
        // As the query uses a PK condition, no limit(1) is necessary.
195
        $criteria = $this->isKeepQuery() ? clone $this : $this;
196
        $dataFetcher = $criteria
197
            ->filterByPrimaryKey($key)
198
            ->doSelect($con);
199
200
        return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher);
201
    }
202
203
    /**
204
     * Find objects by primary key
205
     * <code>
206
     * $objs = $c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), $con);
207
     * </code>
208
     * @param     array $keys Primary keys to use for the query
209
     * @param     ConnectionInterface $con an optional connection object
210
     *
211
     * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter
212
     */
213
    public function findPks($keys, ConnectionInterface $con = null)
214
    {
215
        if (null === $con) {
216
            $con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
217
        }
218
        $this->basePreSelect($con);
219
        $criteria = $this->isKeepQuery() ? clone $this : $this;
220
        $dataFetcher = $criteria
221
            ->filterByPrimaryKeys($keys)
222
            ->doSelect($con);
223
224
        return $criteria->getFormatter()->init($criteria)->format($dataFetcher);
225
    }
226
227
    /**
228
     * Filter the query by primary key
229
     *
230
     * @param     mixed $key Primary key to use for the query
231
     *
232
     * @return $this|ChildPageLinkProductQuery The current query, for fluid interface
233
     */
234
    public function filterByPrimaryKey($key)
235
    {
236
        $this->addUsingAlias(PageLinkProductTableMap::COL_LINK_ID, $key[0], Criteria::EQUAL);
237
        $this->addUsingAlias(PageLinkProductTableMap::COL_PRODUCT_ID, $key[1], Criteria::EQUAL);
238
239
        return $this;
240
    }
241
242
    /**
243
     * Filter the query by a list of primary keys
244
     *
245
     * @param     array $keys The list of primary key to use for the query
246
     *
247
     * @return $this|ChildPageLinkProductQuery The current query, for fluid interface
248
     */
249
    public function filterByPrimaryKeys($keys)
250
    {
251
        if (empty($keys)) {
252
            return $this->add(null, '1<>1', Criteria::CUSTOM);
253
        }
254
        foreach ($keys as $key) {
255
            $cton0 = $this->getNewCriterion(PageLinkProductTableMap::COL_LINK_ID, $key[0], Criteria::EQUAL);
256
            $cton1 = $this->getNewCriterion(PageLinkProductTableMap::COL_PRODUCT_ID, $key[1], Criteria::EQUAL);
257
            $cton0->addAnd($cton1);
258
            $this->addOr($cton0);
259
        }
260
261
        return $this;
262
    }
263
264
    /**
265
     * Filter the query on the link_id column
266
     *
267
     * Example usage:
268
     * <code>
269
     * $query->filterByLinkId(1234); // WHERE link_id = 1234
270
     * $query->filterByLinkId(array(12, 34)); // WHERE link_id IN (12, 34)
271
     * $query->filterByLinkId(array('min' => 12)); // WHERE link_id > 12
272
     * </code>
273
     *
274
     * @see       filterByPageLink()
275
     *
276
     * @param     mixed $linkId The value to use as filter.
277
     *              Use scalar values for equality.
278
     *              Use array values for in_array() equivalent.
279
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
280
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
281
     *
282
     * @return $this|ChildPageLinkProductQuery The current query, for fluid interface
283
     */
284
    public function filterByLinkId($linkId = null, $comparison = null)
285
    {
286
        if (is_array($linkId)) {
287
            $useMinMax = false;
288
            if (isset($linkId['min'])) {
289
                $this->addUsingAlias(PageLinkProductTableMap::COL_LINK_ID, $linkId['min'], Criteria::GREATER_EQUAL);
290
                $useMinMax = true;
291
            }
292
            if (isset($linkId['max'])) {
293
                $this->addUsingAlias(PageLinkProductTableMap::COL_LINK_ID, $linkId['max'], Criteria::LESS_EQUAL);
294
                $useMinMax = true;
295
            }
296
            if ($useMinMax) {
297
                return $this;
298
            }
299
            if (null === $comparison) {
300
                $comparison = Criteria::IN;
301
            }
302
        }
303
304
        return $this->addUsingAlias(PageLinkProductTableMap::COL_LINK_ID, $linkId, $comparison);
305
    }
306
307
    /**
308
     * Filter the query on the product_id column
309
     *
310
     * Example usage:
311
     * <code>
312
     * $query->filterByProductId(1234); // WHERE product_id = 1234
313
     * $query->filterByProductId(array(12, 34)); // WHERE product_id IN (12, 34)
314
     * $query->filterByProductId(array('min' => 12)); // WHERE product_id > 12
315
     * </code>
316
     *
317
     * @param     mixed $productId The value to use as filter.
318
     *              Use scalar values for equality.
319
     *              Use array values for in_array() equivalent.
320
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
321
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
322
     *
323
     * @return $this|ChildPageLinkProductQuery The current query, for fluid interface
324
     */
325
    public function filterByProductId($productId = null, $comparison = null)
326
    {
327
        if (is_array($productId)) {
328
            $useMinMax = false;
329
            if (isset($productId['min'])) {
330
                $this->addUsingAlias(PageLinkProductTableMap::COL_PRODUCT_ID, $productId['min'], Criteria::GREATER_EQUAL);
331
                $useMinMax = true;
332
            }
333
            if (isset($productId['max'])) {
334
                $this->addUsingAlias(PageLinkProductTableMap::COL_PRODUCT_ID, $productId['max'], Criteria::LESS_EQUAL);
335
                $useMinMax = true;
336
            }
337
            if ($useMinMax) {
338
                return $this;
339
            }
340
            if (null === $comparison) {
341
                $comparison = Criteria::IN;
342
            }
343
        }
344
345
        return $this->addUsingAlias(PageLinkProductTableMap::COL_PRODUCT_ID, $productId, $comparison);
346
    }
347
348
    /**
349
     * Filter the query by a related \mod_link\models\PageLink object
350
     *
351
     * @param \mod_link\models\PageLink|ObjectCollection $pageLink The related object(s) to use as filter
352
     * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
353
     *
354
     * @throws \Propel\Runtime\Exception\PropelException
355
     *
356
     * @return ChildPageLinkProductQuery The current query, for fluid interface
357
     */
358
    public function filterByPageLink($pageLink, $comparison = null)
359
    {
360
        if ($pageLink instanceof \mod_link\models\PageLink) {
361
            return $this
362
                ->addUsingAlias(PageLinkProductTableMap::COL_LINK_ID, $pageLink->getId(), $comparison);
363
        } elseif ($pageLink instanceof ObjectCollection) {
364
            if (null === $comparison) {
365
                $comparison = Criteria::IN;
366
            }
367
368
            return $this
369
                ->addUsingAlias(PageLinkProductTableMap::COL_LINK_ID, $pageLink->toKeyValue('PrimaryKey', 'Id'), $comparison);
370
        } else {
371
            throw new PropelException('filterByPageLink() only accepts arguments of type \mod_link\models\PageLink or Collection');
372
        }
373
    }
374
375
    /**
376
     * Adds a JOIN clause to the query using the PageLink relation
377
     *
378
     * @param     string $relationAlias optional alias for the relation
379
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
380
     *
381
     * @return $this|ChildPageLinkProductQuery The current query, for fluid interface
382
     */
383
    public function joinPageLink($relationAlias = null, $joinType = Criteria::INNER_JOIN)
384
    {
385
        $tableMap = $this->getTableMap();
386
        $relationMap = $tableMap->getRelation('PageLink');
387
388
        // create a ModelJoin object for this join
389
        $join = new ModelJoin();
390
        $join->setJoinType($joinType);
391
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
392
        if ($previousJoin = $this->getPreviousJoin()) {
393
            $join->setPreviousJoin($previousJoin);
394
        }
395
396
        // add the ModelJoin to the current object
397
        if ($relationAlias) {
398
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
399
            $this->addJoinObject($join, $relationAlias);
400
        } else {
401
            $this->addJoinObject($join, 'PageLink');
402
        }
403
404
        return $this;
405
    }
406
407
    /**
408
     * Use the PageLink relation PageLink object
409
     *
410
     * @see useQuery()
411
     *
412
     * @param     string $relationAlias optional alias for the relation,
413
     *                                   to be used as main alias in the secondary query
414
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
415
     *
416
     * @return \mod_link\models\PageLinkQuery A secondary query class using the current class as primary query
417
     */
418
    public function usePageLinkQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
419
    {
420
        return $this
421
            ->joinPageLink($relationAlias, $joinType)
422
            ->useQuery($relationAlias ? $relationAlias : 'PageLink', '\mod_link\models\PageLinkQuery');
423
    }
424
425
    /**
426
     * Exclude object from result
427
     *
428
     * @param   ChildPageLinkProduct $pageLinkProduct Object to remove from the list of results
429
     *
430
     * @return $this|ChildPageLinkProductQuery The current query, for fluid interface
431
     */
432
    public function prune($pageLinkProduct = null)
433
    {
434
        if ($pageLinkProduct) {
435
            $this->addCond('pruneCond0', $this->getAliasedColName(PageLinkProductTableMap::COL_LINK_ID), $pageLinkProduct->getLinkId(), Criteria::NOT_EQUAL);
436
            $this->addCond('pruneCond1', $this->getAliasedColName(PageLinkProductTableMap::COL_PRODUCT_ID), $pageLinkProduct->getProductId(), Criteria::NOT_EQUAL);
437
            $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR);
438
        }
439
440
        return $this;
441
    }
442
443
    /**
444
     * Deletes all rows from the page_link_product table.
445
     *
446
     * @param ConnectionInterface $con the connection to use
447
     * @return int The number of affected rows (if supported by underlying database driver).
448
     */
449
    public function doDeleteAll(ConnectionInterface $con = null)
450
    {
451
        if (null === $con) {
452
            $con = Propel::getServiceContainer()->getWriteConnection(PageLinkProductTableMap::DATABASE_NAME);
453
        }
454
455
        // use transaction because $criteria could contain info
456
        // for more than one table or we could emulating ON DELETE CASCADE, etc.
457
        return $con->transaction(function () use ($con) {
458
            $affectedRows = 0; // initialize var to track total num of affected rows
459
            $affectedRows += parent::doDeleteAll($con);
460
            // Because this db requires some delete cascade/set null emulation, we have to
461
            // clear the cached instance *after* the emulation has happened (since
462
            // instances get re-added by the select statement contained therein).
463
            PageLinkProductTableMap::clearInstancePool();
464
            PageLinkProductTableMap::clearRelatedInstancePool();
465
466
            return $affectedRows;
467
        });
468
    }
469
470
    /**
471
     * Performs a DELETE on the database based on the current ModelCriteria
472
     *
473
     * @param ConnectionInterface $con the connection to use
474
     * @return int             The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
475
     *                         if supported by native driver or if emulated using Propel.
476
     * @throws PropelException Any exceptions caught during processing will be
477
     *                         rethrown wrapped into a PropelException.
478
     */
479
    public function delete(ConnectionInterface $con = null)
480
    {
481
        if (null === $con) {
482
            $con = Propel::getServiceContainer()->getWriteConnection(PageLinkProductTableMap::DATABASE_NAME);
483
        }
484
485
        $criteria = $this;
486
487
        // Set the correct dbName
488
        $criteria->setDbName(PageLinkProductTableMap::DATABASE_NAME);
489
490
        // use transaction because $criteria could contain info
491
        // for more than one table or we could emulating ON DELETE CASCADE, etc.
492
        return $con->transaction(function () use ($con, $criteria) {
493
            $affectedRows = 0; // initialize var to track total num of affected rows
494
495
            PageLinkProductTableMap::removeInstanceFromPool($criteria);
496
497
            $affectedRows += ModelCriteria::delete($con);
498
            PageLinkProductTableMap::clearRelatedInstancePool();
499
500
            return $affectedRows;
501
        });
502
    }
503
504
} // PageLinkProductQuery
505

application/modules/mod_link/models/Base/PageLinkProductsQuery.php 1 location

@@ 67-498 (lines=432) @@
64
 * @method     ChildPageLinkProducts[]|\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
65
 *
66
 */
67
abstract class PageLinkProductsQuery extends ModelCriteria
68
{
69
    protected $entityNotFoundExceptionClass = '\\Propel\\Runtime\\Exception\\EntityNotFoundException';
70
71
    /**
72
     * Initializes internal state of \mod_link\models\Base\PageLinkProductsQuery object.
73
     *
74
     * @param     string $dbName The database name
75
     * @param     string $modelName The phpName of a model, e.g. 'Book'
76
     * @param     string $modelAlias The alias for the model in this query, e.g. 'b'
77
     */
78
    public function __construct($dbName = 'Shop', $modelName = '\\mod_link\\models\\PageLinkProducts', $modelAlias = null)
79
    {
80
        parent::__construct($dbName, $modelName, $modelAlias);
81
    }
82
83
    /**
84
     * Returns a new ChildPageLinkProductsQuery object.
85
     *
86
     * @param     string $modelAlias The alias of a model in the query
87
     * @param     Criteria $criteria Optional Criteria to build the query from
88
     *
89
     * @return ChildPageLinkProductsQuery
90
     */
91
    public static function create($modelAlias = null, Criteria $criteria = null)
92
    {
93
        if ($criteria instanceof ChildPageLinkProductsQuery) {
94
            return $criteria;
95
        }
96
        $query = new ChildPageLinkProductsQuery();
97
        if (null !== $modelAlias) {
98
            $query->setModelAlias($modelAlias);
99
        }
100
        if ($criteria instanceof Criteria) {
101
            $query->mergeWith($criteria);
102
        }
103
104
        return $query;
105
    }
106
107
    /**
108
     * Find object by primary key.
109
     * Propel uses the instance pool to skip the database if the object exists.
110
     * Go fast if the query is untouched.
111
     *
112
     * <code>
113
     * $obj = $c->findPk(array(12, 34), $con);
114
     * </code>
115
     *
116
     * @param array[$link_id, $product_id] $key Primary key to use for the query
117
     * @param ConnectionInterface $con an optional connection object
118
     *
119
     * @return ChildPageLinkProducts|array|mixed the result, formatted by the current formatter
120
     */
121
    public function findPk($key, ConnectionInterface $con = null)
122
    {
123
        if ($key === null) {
124
            return null;
125
        }
126
        if ((null !== ($obj = PageLinkProductsTableMap::getInstanceFromPool(serialize([(null === $key[0] || is_scalar($key[0]) || is_callable([$key[0], '__toString']) ? (string) $key[0] : $key[0]), (null === $key[1] || is_scalar($key[1]) || is_callable([$key[1], '__toString']) ? (string) $key[1] : $key[1])])))) && !$this->formatter) {
127
            // the object is already in the instance pool
128
            return $obj;
129
        }
130
        if ($con === null) {
131
            $con = Propel::getServiceContainer()->getReadConnection(PageLinkProductsTableMap::DATABASE_NAME);
132
        }
133
        $this->basePreSelect($con);
134
        if ($this->formatter || $this->modelAlias || $this->with || $this->select
135
         || $this->selectColumns || $this->asColumns || $this->selectModifiers
136
         || $this->map || $this->having || $this->joins) {
137
            return $this->findPkComplex($key, $con);
138
        } else {
139
            return $this->findPkSimple($key, $con);
140
        }
141
    }
142
143
    /**
144
     * Find object by primary key using raw SQL to go fast.
145
     * Bypass doSelect() and the object formatter by using generated code.
146
     *
147
     * @param     mixed $key Primary key to use for the query
148
     * @param     ConnectionInterface $con A connection object
149
     *
150
     * @throws \Propel\Runtime\Exception\PropelException
151
     *
152
     * @return ChildPageLinkProducts A model object, or null if the key is not found
153
     */
154
    protected function findPkSimple($key, ConnectionInterface $con)
155
    {
156
        $sql = 'SELECT link_id, product_id FROM page_link_products WHERE link_id = :p0 AND product_id = :p1';
157
        try {
158
            $stmt = $con->prepare($sql);
159
            $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT);
160
            $stmt->bindValue(':p1', $key[1], PDO::PARAM_INT);
161
            $stmt->execute();
162
        } catch (Exception $e) {
163
            Propel::log($e->getMessage(), Propel::LOG_ERR);
164
            throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e);
165
        }
166
        $obj = null;
167
        if ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
168
            /** @var ChildPageLinkProducts $obj */
169
            $obj = new ChildPageLinkProducts();
170
            $obj->hydrate($row);
171
            PageLinkProductsTableMap::addInstanceToPool($obj, serialize([(null === $key[0] || is_scalar($key[0]) || is_callable([$key[0], '__toString']) ? (string) $key[0] : $key[0]), (null === $key[1] || is_scalar($key[1]) || is_callable([$key[1], '__toString']) ? (string) $key[1] : $key[1])]));
172
        }
173
        $stmt->closeCursor();
174
175
        return $obj;
176
    }
177
178
    /**
179
     * Find object by primary key.
180
     *
181
     * @param     mixed $key Primary key to use for the query
182
     * @param     ConnectionInterface $con A connection object
183
     *
184
     * @return ChildPageLinkProducts|array|mixed the result, formatted by the current formatter
185
     */
186
    protected function findPkComplex($key, ConnectionInterface $con)
187
    {
188
        // As the query uses a PK condition, no limit(1) is necessary.
189
        $criteria = $this->isKeepQuery() ? clone $this : $this;
190
        $dataFetcher = $criteria
191
            ->filterByPrimaryKey($key)
192
            ->doSelect($con);
193
194
        return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher);
195
    }
196
197
    /**
198
     * Find objects by primary key
199
     * <code>
200
     * $objs = $c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), $con);
201
     * </code>
202
     * @param     array $keys Primary keys to use for the query
203
     * @param     ConnectionInterface $con an optional connection object
204
     *
205
     * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter
206
     */
207
    public function findPks($keys, ConnectionInterface $con = null)
208
    {
209
        if (null === $con) {
210
            $con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
211
        }
212
        $this->basePreSelect($con);
213
        $criteria = $this->isKeepQuery() ? clone $this : $this;
214
        $dataFetcher = $criteria
215
            ->filterByPrimaryKeys($keys)
216
            ->doSelect($con);
217
218
        return $criteria->getFormatter()->init($criteria)->format($dataFetcher);
219
    }
220
221
    /**
222
     * Filter the query by primary key
223
     *
224
     * @param     mixed $key Primary key to use for the query
225
     *
226
     * @return $this|ChildPageLinkProductsQuery The current query, for fluid interface
227
     */
228
    public function filterByPrimaryKey($key)
229
    {
230
        $this->addUsingAlias(PageLinkProductsTableMap::COL_LINK_ID, $key[0], Criteria::EQUAL);
231
        $this->addUsingAlias(PageLinkProductsTableMap::COL_PRODUCT_ID, $key[1], Criteria::EQUAL);
232
233
        return $this;
234
    }
235
236
    /**
237
     * Filter the query by a list of primary keys
238
     *
239
     * @param     array $keys The list of primary key to use for the query
240
     *
241
     * @return $this|ChildPageLinkProductsQuery The current query, for fluid interface
242
     */
243
    public function filterByPrimaryKeys($keys)
244
    {
245
        if (empty($keys)) {
246
            return $this->add(null, '1<>1', Criteria::CUSTOM);
247
        }
248
        foreach ($keys as $key) {
249
            $cton0 = $this->getNewCriterion(PageLinkProductsTableMap::COL_LINK_ID, $key[0], Criteria::EQUAL);
250
            $cton1 = $this->getNewCriterion(PageLinkProductsTableMap::COL_PRODUCT_ID, $key[1], Criteria::EQUAL);
251
            $cton0->addAnd($cton1);
252
            $this->addOr($cton0);
253
        }
254
255
        return $this;
256
    }
257
258
    /**
259
     * Filter the query on the link_id column
260
     *
261
     * Example usage:
262
     * <code>
263
     * $query->filterByLinkId(1234); // WHERE link_id = 1234
264
     * $query->filterByLinkId(array(12, 34)); // WHERE link_id IN (12, 34)
265
     * $query->filterByLinkId(array('min' => 12)); // WHERE link_id > 12
266
     * </code>
267
     *
268
     * @see       filterByPageLink()
269
     *
270
     * @param     mixed $linkId The value to use as filter.
271
     *              Use scalar values for equality.
272
     *              Use array values for in_array() equivalent.
273
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
274
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
275
     *
276
     * @return $this|ChildPageLinkProductsQuery The current query, for fluid interface
277
     */
278
    public function filterByLinkId($linkId = null, $comparison = null)
279
    {
280
        if (is_array($linkId)) {
281
            $useMinMax = false;
282
            if (isset($linkId['min'])) {
283
                $this->addUsingAlias(PageLinkProductsTableMap::COL_LINK_ID, $linkId['min'], Criteria::GREATER_EQUAL);
284
                $useMinMax = true;
285
            }
286
            if (isset($linkId['max'])) {
287
                $this->addUsingAlias(PageLinkProductsTableMap::COL_LINK_ID, $linkId['max'], Criteria::LESS_EQUAL);
288
                $useMinMax = true;
289
            }
290
            if ($useMinMax) {
291
                return $this;
292
            }
293
            if (null === $comparison) {
294
                $comparison = Criteria::IN;
295
            }
296
        }
297
298
        return $this->addUsingAlias(PageLinkProductsTableMap::COL_LINK_ID, $linkId, $comparison);
299
    }
300
301
    /**
302
     * Filter the query on the product_id column
303
     *
304
     * Example usage:
305
     * <code>
306
     * $query->filterByProductId(1234); // WHERE product_id = 1234
307
     * $query->filterByProductId(array(12, 34)); // WHERE product_id IN (12, 34)
308
     * $query->filterByProductId(array('min' => 12)); // WHERE product_id > 12
309
     * </code>
310
     *
311
     * @param     mixed $productId The value to use as filter.
312
     *              Use scalar values for equality.
313
     *              Use array values for in_array() equivalent.
314
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
315
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
316
     *
317
     * @return $this|ChildPageLinkProductsQuery The current query, for fluid interface
318
     */
319
    public function filterByProductId($productId = null, $comparison = null)
320
    {
321
        if (is_array($productId)) {
322
            $useMinMax = false;
323
            if (isset($productId['min'])) {
324
                $this->addUsingAlias(PageLinkProductsTableMap::COL_PRODUCT_ID, $productId['min'], Criteria::GREATER_EQUAL);
325
                $useMinMax = true;
326
            }
327
            if (isset($productId['max'])) {
328
                $this->addUsingAlias(PageLinkProductsTableMap::COL_PRODUCT_ID, $productId['max'], Criteria::LESS_EQUAL);
329
                $useMinMax = true;
330
            }
331
            if ($useMinMax) {
332
                return $this;
333
            }
334
            if (null === $comparison) {
335
                $comparison = Criteria::IN;
336
            }
337
        }
338
339
        return $this->addUsingAlias(PageLinkProductsTableMap::COL_PRODUCT_ID, $productId, $comparison);
340
    }
341
342
    /**
343
     * Filter the query by a related \mod_link\models\PageLink object
344
     *
345
     * @param \mod_link\models\PageLink|ObjectCollection $pageLink The related object(s) to use as filter
346
     * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
347
     *
348
     * @throws \Propel\Runtime\Exception\PropelException
349
     *
350
     * @return ChildPageLinkProductsQuery The current query, for fluid interface
351
     */
352
    public function filterByPageLink($pageLink, $comparison = null)
353
    {
354
        if ($pageLink instanceof \mod_link\models\PageLink) {
355
            return $this
356
                ->addUsingAlias(PageLinkProductsTableMap::COL_LINK_ID, $pageLink->getId(), $comparison);
357
        } elseif ($pageLink instanceof ObjectCollection) {
358
            if (null === $comparison) {
359
                $comparison = Criteria::IN;
360
            }
361
362
            return $this
363
                ->addUsingAlias(PageLinkProductsTableMap::COL_LINK_ID, $pageLink->toKeyValue('PrimaryKey', 'Id'), $comparison);
364
        } else {
365
            throw new PropelException('filterByPageLink() only accepts arguments of type \mod_link\models\PageLink or Collection');
366
        }
367
    }
368
369
    /**
370
     * Adds a JOIN clause to the query using the PageLink relation
371
     *
372
     * @param     string $relationAlias optional alias for the relation
373
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
374
     *
375
     * @return $this|ChildPageLinkProductsQuery The current query, for fluid interface
376
     */
377
    public function joinPageLink($relationAlias = null, $joinType = Criteria::INNER_JOIN)
378
    {
379
        $tableMap = $this->getTableMap();
380
        $relationMap = $tableMap->getRelation('PageLink');
381
382
        // create a ModelJoin object for this join
383
        $join = new ModelJoin();
384
        $join->setJoinType($joinType);
385
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
386
        if ($previousJoin = $this->getPreviousJoin()) {
387
            $join->setPreviousJoin($previousJoin);
388
        }
389
390
        // add the ModelJoin to the current object
391
        if ($relationAlias) {
392
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
393
            $this->addJoinObject($join, $relationAlias);
394
        } else {
395
            $this->addJoinObject($join, 'PageLink');
396
        }
397
398
        return $this;
399
    }
400
401
    /**
402
     * Use the PageLink relation PageLink object
403
     *
404
     * @see useQuery()
405
     *
406
     * @param     string $relationAlias optional alias for the relation,
407
     *                                   to be used as main alias in the secondary query
408
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
409
     *
410
     * @return \mod_link\models\PageLinkQuery A secondary query class using the current class as primary query
411
     */
412
    public function usePageLinkQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
413
    {
414
        return $this
415
            ->joinPageLink($relationAlias, $joinType)
416
            ->useQuery($relationAlias ? $relationAlias : 'PageLink', '\mod_link\models\PageLinkQuery');
417
    }
418
419
    /**
420
     * Exclude object from result
421
     *
422
     * @param   ChildPageLinkProducts $pageLinkProducts Object to remove from the list of results
423
     *
424
     * @return $this|ChildPageLinkProductsQuery The current query, for fluid interface
425
     */
426
    public function prune($pageLinkProducts = null)
427
    {
428
        if ($pageLinkProducts) {
429
            $this->addCond('pruneCond0', $this->getAliasedColName(PageLinkProductsTableMap::COL_LINK_ID), $pageLinkProducts->getLinkId(), Criteria::NOT_EQUAL);
430
            $this->addCond('pruneCond1', $this->getAliasedColName(PageLinkProductsTableMap::COL_PRODUCT_ID), $pageLinkProducts->getProductId(), Criteria::NOT_EQUAL);
431
            $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR);
432
        }
433
434
        return $this;
435
    }
436
437
    /**
438
     * Deletes all rows from the page_link_products table.
439
     *
440
     * @param ConnectionInterface $con the connection to use
441
     * @return int The number of affected rows (if supported by underlying database driver).
442
     */
443
    public function doDeleteAll(ConnectionInterface $con = null)
444
    {
445
        if (null === $con) {
446
            $con = Propel::getServiceContainer()->getWriteConnection(PageLinkProductsTableMap::DATABASE_NAME);
447
        }
448
449
        // use transaction because $criteria could contain info
450
        // for more than one table or we could emulating ON DELETE CASCADE, etc.
451
        return $con->transaction(function () use ($con) {
452
            $affectedRows = 0; // initialize var to track total num of affected rows
453
            $affectedRows += parent::doDeleteAll($con);
454
            // Because this db requires some delete cascade/set null emulation, we have to
455
            // clear the cached instance *after* the emulation has happened (since
456
            // instances get re-added by the select statement contained therein).
457
            PageLinkProductsTableMap::clearInstancePool();
458
            PageLinkProductsTableMap::clearRelatedInstancePool();
459
460
            return $affectedRows;
461
        });
462
    }
463
464
    /**
465
     * Performs a DELETE on the database based on the current ModelCriteria
466
     *
467
     * @param ConnectionInterface $con the connection to use
468
     * @return int             The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
469
     *                         if supported by native driver or if emulated using Propel.
470
     * @throws PropelException Any exceptions caught during processing will be
471
     *                         rethrown wrapped into a PropelException.
472
     */
473
    public function delete(ConnectionInterface $con = null)
474
    {
475
        if (null === $con) {
476
            $con = Propel::getServiceContainer()->getWriteConnection(PageLinkProductsTableMap::DATABASE_NAME);
477
        }
478
479
        $criteria = $this;
480
481
        // Set the correct dbName
482
        $criteria->setDbName(PageLinkProductsTableMap::DATABASE_NAME);
483
484
        // use transaction because $criteria could contain info
485
        // for more than one table or we could emulating ON DELETE CASCADE, etc.
486
        return $con->transaction(function () use ($con, $criteria) {
487
            $affectedRows = 0; // initialize var to track total num of affected rows
488
489
            PageLinkProductsTableMap::removeInstanceFromPool($criteria);
490
491
            $affectedRows += ModelCriteria::delete($con);
492
            PageLinkProductsTableMap::clearRelatedInstancePool();
493
494
            return $affectedRows;
495
        });
496
    }
497
498
} // PageLinkProductsQuery
499