Code Duplication    Length = 44-44 lines in 2 locations

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

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