protected function get_structural_changes() {
        global $DB;
        $course = $this->page->course;
        $context = context_course::instance($course->id);
        $canviewdeleted = has_capability('block/recent_activity:viewdeletemodule', $context);
        $canviewupdated = has_capability('block/recent_activity:viewaddupdatemodule', $context);
        if (!$canviewdeleted && !$canviewupdated) {
            return;
        }

        $timestart = $this->get_timestart();
        $changelist = array();
        // The following query will retrieve the latest action for each course module in the specified course.
        // Also the query filters out the modules that were created and then deleted during the given interval.
        $sql = "SELECT
                    cmid, MIN(action) AS minaction, MAX(action) AS maxaction, MAX(modname) AS modname
                FROM {block_recent_activity}
                WHERE timecreated > ? AND courseid = ?
                GROUP BY cmid
                ORDER BY MAX(timecreated) ASC";
        $params = array($timestart, $course->id);
        $logs = $DB->get_records_sql($sql, $params);
        if (isset($logs[0])) {
            // If special record for this course and cmid=0 is present, migrate logs.
            self::migrate_logs($course);
            $logs = $DB->get_records_sql($sql, $params);
        }
        if ($logs) {
            $modinfo = get_fast_modinfo($course);
            foreach ($logs as $log) {
                // We used aggregate functions since constants CM_CREATED, CM_UPDATED and CM_DELETED have ascending order (0,1,2).
                $wasdeleted = ($log->maxaction == block_recent_activity_observer::CM_DELETED);
                $wascreated = ($log->minaction == block_recent_activity_observer::CM_CREATED);

                if ($wasdeleted && $wascreated) {
                    // Activity was created and deleted within this interval. Do not show it.
                    continue;
                } else if ($wasdeleted && $canviewdeleted) {
                    if (plugin_supports('mod', $log->modname, FEATURE_NO_VIEW_LINK, false)) {
                        // Better to call cm_info::has_view() because it can be dynamic.
                        // But there is no instance of cm_info now.
                        continue;
                    }
                    // Unfortunately we do not know if the mod was visible.
                    $modnames = get_module_types_names();
                    $changelist[$log->cmid] = array('action' => 'delete mod',
                        'module' => (object)array(
                            'modname' => $log->modname,
                            'modfullname' => isset($modnames[$log->modname]) ? $modnames[$log->modname] : $log->modname
                         ));

                } else if (!$wasdeleted && isset($modinfo->cms[$log->cmid]) && $canviewupdated) {
                    // Module was either added or updated during this interval and it currently exists.
                    // If module was both added and updated show only "add" action.
                    $cm = $modinfo->cms[$log->cmid];
                    if ($cm->has_view() && $cm->uservisible) {
                        $changelist[$log->cmid] = array(
                            'action' => $wascreated ? 'add mod' : 'update mod',
                            'module' => $cm
                        );
                    }
                }
            }
        }
        return $changelist;
    }