public function override_exists($userid) {
        global $DB;

        // Gets an assoc array containing the keys for defined user overrides only.
        $getuseroverride = function($userid) use ($DB) {
            $useroverride = $DB->get_record('assign_overrides', ['assignid' => $this->get_instance()->id, 'userid' => $userid]);
            return $useroverride ? get_object_vars($useroverride) : [];
        };

        // Gets an assoc array containing the keys for defined group overrides only.
        $getgroupoverride = function($userid) use ($DB) {
            $groupings = groups_get_user_groups($this->get_instance()->course, $userid);

            if (empty($groupings[0])) {
                return [];
            }

            // Select all overrides that apply to the User's groups.
            list($extra, $params) = $DB->get_in_or_equal(array_values($groupings[0]));
            $sql = "SELECT * FROM {assign_overrides}
                    WHERE groupid $extra AND assignid = ? ORDER BY sortorder ASC";
            $params[] = $this->get_instance()->id;
            $groupoverride = $DB->get_record_sql($sql, $params, IGNORE_MULTIPLE);

            return $groupoverride ? get_object_vars($groupoverride) : [];
        };

        // Later arguments clobber earlier ones with array_merge. The two helper functions
        // return arrays containing keys for only the defined overrides. So we get the
        // desired behaviour as per the algorithm.
        return (object)array_merge(
            ['duedate' => null, 'cutoffdate' => null, 'allowsubmissionsfromdate' => null],
            $getgroupoverride($userid),
            $getuseroverride($userid)
        );
    }