Code Duplication    Length = 6-6 lines in 3 locations

main/inc/lib/course.lib.php 3 locations

@@ 753-758 (lines=6) @@
750
751
        // Check in advance whether the user has already been registered on the platform.
752
        $sql = "SELECT status FROM " . $user_table . " WHERE user_id = $user_id ";
753
        if (Database::num_rows(Database::query($sql)) == 0) {
754
            if ($debug) {
755
                error_log('The user has not been registered to the platform');
756
            }
757
            return false; // The user has not been registered to the platform.
758
        }
759
760
        // Check whether the user has already been subscribed to this course.
761
        $sql = "SELECT * FROM $course_user_table
@@ 766-771 (lines=6) @@
763
                    user_id = $user_id AND
764
                    relation_type <> " . COURSE_RELATION_TYPE_RRHH . " AND
765
                    c_id = $courseId";
766
        if (Database::num_rows(Database::query($sql)) > 0) {
767
            if ($debug) {
768
                error_log('The user has been already subscribed to the course');
769
            }
770
            return false; // The user has been subscribed to the course.
771
        }
772
773
        if (!api_is_course_admin()) {
774
            // Check in advance whether subscription is allowed or not for this course.
@@ 777-782 (lines=6) @@
774
            // Check in advance whether subscription is allowed or not for this course.
775
            $sql = "SELECT code, visibility FROM $course_table
776
                    WHERE id = $courseId AND subscribe = '" . SUBSCRIBE_NOT_ALLOWED . "'";
777
            if (Database::num_rows(Database::query($sql)) > 0) {
778
                if ($debug) {
779
                    error_log('Subscription is not allowed for this course');
780
                }
781
                return false; // Subscription is not allowed for this course.
782
            }
783
        }
784
785
        // Ok, subscribe the user.