Code Duplication    Length = 6-6 lines in 3 locations

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

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