Code Duplication    Length = 44-44 lines in 2 locations

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

@@ 467-510 (lines=44) @@
464
     * @param Session $session The session
465
     * @return string
466
     */
467
    private function getUserStatusForSession($userId, Session $session)
468
    {
469
        if (empty($userId)) {
470
            return 'NO';
471
        }
472
473
        $entityManager = Database::getManager();
474
        $scuRepo = $entityManager->getRepository('ChamiloCoreBundle:SessionRelCourseRelUser');
475
476
        $buySaleTable = Database::get_main_table(self::TABLE_SALE);
477
478
        // Check if user bought the course
479
        $sale = Database::select(
480
            'COUNT(1) as qty',
481
            $buySaleTable,
482
            [
483
                'where' => [
484
                    'user_id = ? AND product_type = ? AND product_id = ? AND status = ?' => [
485
                        $userId,
486
                        self::PRODUCT_TYPE_SESSION,
487
                        $session->getId(),
488
                        self::SALE_STATUS_PENDING,
489
                    ],
490
                ],
491
            ],
492
            'first'
493
        );
494
495
        if ($sale['qty'] > 0) {
496
            return "TMP";
497
        }
498
499
        // Check if user is already subscribe to session
500
        $userSubscription = $scuRepo->findBy([
501
            'session' => $session,
502
            'user' => $userId,
503
        ]);
504
505
        if (!empty($userSubscription)) {
506
            return 'YES';
507
        }
508
509
        return 'NO';
510
    }
511
512
    /**
513
     * Lists current user session details, including each session course details
@@ 577-620 (lines=44) @@
574
     *
575
     * @return string
576
     */
577
    private function getUserStatusForCourse($userId, Course $course)
578
    {
579
        if (empty($userId)) {
580
            return 'NO';
581
        }
582
583
        $entityManager = Database::getManager();
584
        $cuRepo = $entityManager->getRepository('ChamiloCoreBundle:CourseRelUser');
585
586
        $buySaleTable = Database::get_main_table(self::TABLE_SALE);
587
588
        // Check if user bought the course
589
        $sale = Database::select(
590
            'COUNT(1) as qty',
591
            $buySaleTable,
592
            [
593
                'where' => [
594
                    'user_id = ? AND product_type = ? AND product_id = ? AND status = ?' => [
595
                        $userId,
596
                        self::PRODUCT_TYPE_COURSE,
597
                        $course->getId(),
598
                        self::SALE_STATUS_PENDING,
599
                    ],
600
                ],
601
            ],
602
            'first'
603
        );
604
605
        if ($sale['qty'] > 0) {
606
            return "TMP";
607
        }
608
609
        // Check if user is already subscribe to course
610
        $userSubscription = $cuRepo->findBy([
611
            'course' => $course,
612
            'user' => $userId,
613
        ]);
614
615
        if (!empty($userSubscription)) {
616
            return 'YES';
617
        }
618
619
        return 'NO';
620
    }
621
622
    /**
623
     * Lists current user course details