Code Duplication    Length = 44-44 lines in 2 locations

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

@@ 426-469 (lines=44) @@
423
     * @param Session $session The session
424
     * @return string
425
     */
426
    private function getUserStatusForSession($userId, Session $session)
427
    {
428
        if (empty($userId)) {
429
            return 'NO';
430
        }
431
432
        $entityManager = Database::getManager();
433
        $scuRepo = $entityManager->getRepository('ChamiloCoreBundle:SessionRelCourseRelUser');
434
435
        $buySaleTable = Database::get_main_table(self::TABLE_SALE);
436
437
        // Check if user bought the course
438
        $sale = Database::select(
439
            'COUNT(1) as qty',
440
            $buySaleTable,
441
            [
442
                'where' => [
443
                    'user_id = ? AND product_type = ? AND product_id = ? AND status = ?' => [
444
                        $userId,
445
                        self::PRODUCT_TYPE_SESSION,
446
                        $session->getId(),
447
                        self::SALE_STATUS_PENDING
448
                    ]
449
                ]
450
            ],
451
            'first'
452
        );
453
454
        if ($sale['qty'] > 0) {
455
            return "TMP";
456
        }
457
458
        // Check if user is already subscribe to session
459
        $userSubscription = $scuRepo->findBy([
460
            'session' => $session,
461
            'user' => $userId
462
        ]);
463
464
        if (!empty($userSubscription)) {
465
            return 'YES';
466
        }
467
468
        return 'NO';
469
    }
470
471
    /**
472
     * Lists current user session details, including each session course details
@@ 536-579 (lines=44) @@
533
     *
534
     * @return string
535
     */
536
    private function getUserStatusForCourse($userId, Course $course)
537
    {
538
        if (empty($userId)) {
539
            
540
            return 'NO';
541
        }
542
543
        $entityManager = Database::getManager();
544
        $cuRepo = $entityManager->getRepository('ChamiloCoreBundle:CourseRelUser');
545
546
        $buySaleTable = Database::get_main_table(self::TABLE_SALE);
547
548
        // Check if user bought the course
549
        $sale = Database::select(
550
            'COUNT(1) as qty',
551
            $buySaleTable,
552
            [
553
                'where' => [
554
                    'user_id = ? AND product_type = ? AND product_id = ? AND status = ?' => [
555
                        $userId,
556
                        self::PRODUCT_TYPE_COURSE,
557
                        $course->getId(),
558
                        self::SALE_STATUS_PENDING
559
                    ]
560
                ]
561
            ],
562
            'first'
563
        );
564
565
        if ($sale['qty'] > 0) {
566
            return "TMP";
567
        }
568
569
        // Check if user is already subscribe to course
570
        $userSubscription = $cuRepo->findBy([
571
            'course' => $course,
572
            'user' => $userId
573
        ]);
574
575
        if (!empty($userSubscription)) {
576
            return 'YES';
577
        }
578
579
        return 'NO';
580
    }
581
582
    /**