public function filter_by_non_approved($constant, $userid = null) {
        global $USER;
        if (!$userid) {
            $userid = $USER->id;
        }

        if ($constant === self::NON_APPROVED_ALL) {
            // Nothing to do.

        } else if ($constant === self::NON_APPROVED_SELF) {
            $this->where[] = sprintf('%s != 0 OR %s = :toapproveuserid',
                self::resolve_field('approved', 'entries'), self::resolve_field('userid', 'entries'));
            $this->params['toapproveuserid'] = $USER->id;

        } else if ($constant === self::NON_APPROVED_NONE) {
            $this->where[] = sprintf('%s != 0', self::resolve_field('approved', 'entries'));

        } else if ($constant === self::NON_APPROVED_ONLY) {
            $this->where[] = sprintf('%s = 0', self::resolve_field('approved', 'entries'));

        } else {
            throw new coding_exception('Invalid constant');
        }
    }