Code Duplication    Length = 44-44 lines in 2 locations

plugin/buycourses/src/buy_course_plugin.class.php 2 locations

@@ 413-456 (lines=44) @@
410
     * @param Session $session The session
411
     * @return string
412
     */
413
    private function getUserStatusForSession($userId, Session $session)
414
    {
415
        if (empty($userId)) {
416
            return 'NO';
417
        }
418
419
        $entityManager = Database::getManager();
420
        $scuRepo = $entityManager->getRepository('ChamiloCoreBundle:SessionRelCourseRelUser');
421
422
        $buySaleTable = Database::get_main_table(self::TABLE_SALE);
423
424
        // Check if user bought the course
425
        $sale = Database::select(
426
            'COUNT(1) as qty',
427
            $buySaleTable,
428
            [
429
                'where' => [
430
                    'user_id = ? AND product_type = ? AND product_id = ? AND status = ?' => [
431
                        $userId,
432
                        self::PRODUCT_TYPE_SESSION,
433
                        $session->getId(),
434
                        self::SALE_STATUS_PENDING
435
                    ]
436
                ]
437
            ],
438
            'first'
439
        );
440
441
        if ($sale['qty'] > 0) {
442
            return "TMP";
443
        }
444
445
        // Check if user is already subscribe to session
446
        $userSubscription = $scuRepo->findBy([
447
            'session' => $session,
448
            'user' => $userId
449
        ]);
450
451
        if (!empty($userSubscription)) {
452
            return 'YES';
453
        }
454
455
        return 'NO';
456
    }
457
458
    /**
459
     * Lists current user session details, including each session course details
@@ 523-566 (lines=44) @@
520
     *
521
     * @return string
522
     */
523
    private function getUserStatusForCourse($userId, Course $course)
524
    {
525
        if (empty($userId)) {
526
            
527
            return 'NO';
528
        }
529
530
        $entityManager = Database::getManager();
531
        $cuRepo = $entityManager->getRepository('ChamiloCoreBundle:CourseRelUser');
532
533
        $buySaleTable = Database::get_main_table(self::TABLE_SALE);
534
535
        // Check if user bought the course
536
        $sale = Database::select(
537
            'COUNT(1) as qty',
538
            $buySaleTable,
539
            [
540
                'where' => [
541
                    'user_id = ? AND product_type = ? AND product_id = ? AND status = ?' => [
542
                        $userId,
543
                        self::PRODUCT_TYPE_COURSE,
544
                        $course->getId(),
545
                        self::SALE_STATUS_PENDING
546
                    ]
547
                ]
548
            ],
549
            'first'
550
        );
551
552
        if ($sale['qty'] > 0) {
553
            return "TMP";
554
        }
555
556
        // Check if user is already subscribe to course
557
        $userSubscription = $cuRepo->findBy([
558
            'course' => $course,
559
            'user' => $userId
560
        ]);
561
562
        if (!empty($userSubscription)) {
563
            return 'YES';
564
        }
565
566
        return 'NO';
567
    }
568
569
    /**