Code Duplication    Length = 44-44 lines in 2 locations

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

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