private function _save() {
        if ($this->timeenrolled === null) {
            $this->timeenrolled = 0;
        }

        $result = false;
        // Save record
        if ($this->id) {
            $result = $this->update();
        } else {
            // Make sure reaggregate field is not null
            if (!$this->reaggregate) {
                $this->reaggregate = 0;
            }

            // Make sure timestarted is not null
            if (!$this->timestarted) {
                $this->timestarted = 0;
            }

            $result = $this->insert();
        }

        if ($result) {
            // Update the cached record.
            $cache = cache::make('core', 'coursecompletion');
            $data = $this->get_record_data();
            $key = $data->userid . '_' . $data->course;
            $cache->set($key, ['value' => $data]);
        }

        return $result;
    }