Code Duplication    Length = 25-26 lines in 4 locations

class/bookshop_books.php 4 locations

@@ 167-192 (lines=26) @@
164
	 * @param integer $category Identifiant de la catégorie (évenutellement)
165
     * @return array   Tableau de livres (sous la forme d'objets)
166
     */
167
    public function getMostViewedBooks($start = 0, $limit = 0, $category = 0)
168
    {
169
        $tbl_datas = array();
170
        $criteria  = new CriteriaCompo();
171
        $criteria->add(new Criteria('book_online', 1, '='));
172
		if(bookshop_getmoduleoption('show_unpublished') == 0) {	// Ne pas afficher les livres qui ne sont pas publiés
173
            $criteria->add(new Criteria('book_submitted', time(), '<='));
174
        }
175
        if (bookshop_getmoduleoption('nostock_display') == 0) {    // Se limiter aux seuls livres encore en stock
176
            $criteria->add(new Criteria('book_stock', 0, '>'));
177
        }
178
        if (is_array($category)) {
179
            $criteria->add(new Criteria('book_cid', '(' . implode(',', $category) . ')', 'IN'));
180
        } elseif ($category != 0) {
181
            $criteria->add(new Criteria('book_cid', (int)$category, '='));
182
        }
183
		// On se limite aux livres qui ont été vraiment vus !
184
        $criteria->add(new Criteria('book_hits', 0, '>'));
185
        $criteria->setLimit($limit);
186
        $criteria->setStart($start);
187
        $criteria->setSort('book_hits');
188
        $criteria->setOrder('DESC');
189
        $tbl_datas =& $this->getObjects($criteria, true);
190
191
        return $tbl_datas;
192
    }
193
194
    /**
195
	 * Renvoie la liste des x livres les mieux notés par les visiteurs
@@ 235-259 (lines=25) @@
232
	 * @param integer $category Identifiant de la catégorie (évenutellement)
233
     * @return array   Tableau de livres (sous la forme d'objets)
234
     */
235
    public function getRecentRecommendedBooks($start = 0, $limit = 0, $category = 0)
236
    {
237
        $tbl_datas = array();
238
        $criteria  = new CriteriaCompo();
239
        $criteria->add(new Criteria('book_online', 1, '='));
240
        $criteria->add(new Criteria('book_recommended', '0000-00-00', '<>'));
241
		if(bookshop_getmoduleoption('show_unpublished') == 0) {	// Ne pas afficher les livres qui ne sont pas publiés
242
            $criteria->add(new Criteria('book_submitted', time(), '<='));
243
        }
244
        if (bookshop_getmoduleoption('nostock_display') == 0) {    // Se limiter aux seuls livres encore en stock
245
            $criteria->add(new Criteria('book_stock', 0, '>'));
246
        }
247
        if (is_array($category)) {
248
            $criteria->add(new Criteria('book_cid', '(' . implode(',', $category) . ')', 'IN'));
249
        } elseif ($category != 0) {
250
            $criteria->add(new Criteria('book_cid', (int)$category, '='));
251
        }
252
        $criteria->setLimit($limit);
253
        $criteria->setStart($start);
254
        $criteria->setSort('book_recommended');
255
        $criteria->setOrder('DESC');
256
        $tbl_datas =& $this->getObjects($criteria, true);
257
258
        return $tbl_datas;
259
    }
260
261
    /**
262
	 * Renvoie le nombre total de livres recommandés
@@ 323-347 (lines=25) @@
320
     *
321
     * @return array
322
     */
323
    public function getBooksForNewsletter($startingDate, $endingDate, $category = 0, $start = 0, $limit = 0)
324
    {
325
        $tblDatas = array();
326
        $criteria = new CriteriaCompo();
327
        $criteria->add(new Criteria('book_online', 1, '='));
328
        $criteria->add(new Criteria('book_submitted', $startingDate, '>='));
329
        $criteria->add(new Criteria('book_submitted', $endingDate, '<='));
330
		if(bookshop_getmoduleoption('show_unpublished') == 0) {	// Ne pas afficher les livres qui ne sont pas publiés
331
            $criteria->add(new Criteria('book_submitted', time(), '<='));
332
        }
333
        if (bookshop_getmoduleoption('nostock_display') == 0) {    // Se limiter aux seuls livres encore en stock
334
            $criteria->add(new Criteria('book_stock', 0, '>'));
335
        }
336
        if (is_array($category)) {
337
            $criteria->add(new Criteria('book_cid', '(' . implode(',', $category) . ')', 'IN'));
338
        } elseif ($category > 0) {
339
            $criteria->add(new Criteria('book_cid', (int)$category, '='));
340
        }
341
        $criteria->setLimit($limit);
342
        $criteria->setStart($start);
343
        $criteria->setSort('book_title');
344
        $tblDatas =& $this->getObjects($criteria, true);
345
346
        return $tblDatas;
347
    }
348
349
    /**
350
	 * Renvoie le nombre total de livres publiés dans la base en tenant compte des préférences du module
@@ 505-529 (lines=25) @@
502
	 * @param integer $category Identifiant de la catégorie (évenutellement)
503
     * @return array   Tableau de livres (sous la forme d'objets)
504
     */
505
    public function getPromotionalBooks($start = 0, $limit = 0, $category = 0)
506
    {
507
        $tbl_datas = array();
508
        $criteria  = new CriteriaCompo();
509
        $criteria->add(new Criteria('book_online', 1, '='));
510
		if(bookshop_getmoduleoption('show_unpublished') == 0) {	// Ne pas afficher les livres qui ne sont pas publiés
511
            $criteria->add(new Criteria('book_submitted', time(), '<='));
512
        }
513
        if (bookshop_getmoduleoption('nostock_display') == 0) {    // Se limiter aux seuls livres encore en stock
514
            $criteria->add(new Criteria('book_stock', 0, '>'));
515
        }
516
        if (is_array($category)) {
517
            $criteria->add(new Criteria('book_cid', '(' . implode(',', $category) . ')', 'IN'));
518
        } elseif ($category != 0) {
519
            $criteria->add(new Criteria('book_cid', (int)$category, '='));
520
        }
521
        $criteria->add(new Criteria('book_discount_price', 0, '>'));
522
        $criteria->setLimit($limit);
523
        $criteria->setStart($start);
524
        $criteria->setSort('book_title');
525
        $criteria->setOrder('DESC');
526
        $tbl_datas =& $this->getObjects($criteria, true);
527
528
        return $tbl_datas;
529
    }
530
531
    /**
532
     * Renvoie les livres dont les stocks sont bas