public function count_entries() {
        global $DB;
        if ($this->totalentries === null) {
            if ($sqlarray = $this->get_entry_fetch_sql(true)) {
                $this->totalentries = $DB->count_records_sql($sqlarray['sql'], $sqlarray['params']);
            } else {
                $this->totalentries = 0;
            }
        }
        return $this->totalentries;
    }