function content_unlock_generate_events_list($showeventname = false)
{
    global $DB;
    $eventsarray = array();
    $eventsarray['\\block_game_content_unlock\\event\\content_unlocked'] = $showeventname === true ? \block_game_content_unlock\event\content_unlocked::get_name() . " (\\block_game_content_unlockvent\\content_unlocked)" : \block_game_content_unlock\event\content_unlocked::get_name();
    $game_achievements_installed = $DB->record_exists('block', array('name' => 'game_achievements'));
    if ($game_achievements_installed) {
        $eventsarray['\\block_game_achievements\\event\\achievement_reached'] = $showeventname === true ? \block_game_achievements\event\achievement_reached::get_name() . " (\\block_game_achievementsvent\\achievement_reached)" : \block_game_achievements\event\achievement_reached::get_name();
    }
    $game_points_installed = $DB->record_exists('block', array('name' => 'game_points'));
    if ($game_points_installed) {
        $eventsarray['\\block_game_points\\event\\points_earned'] = $showeventname === true ? \block_game_points\event\points_earned::get_name() . " (\\block_game_pointsvent\\points_earned)" : \block_game_points\event\points_earned::get_name();
    }
    $eventslist = report_eventlist_list_generator::get_non_core_event_list();
    foreach ($eventslist as $value) {
        $description = explode("\\", explode(".", strip_tags($value['fulleventname']))[0]);
        $eventsarray[$value['eventname']] = $showeventname === true ? $description[0] . " (" . $value['eventname'] . ")" : $description[0];
    }
    return $eventsarray;
}
 public static function observer(\core\event\base $event)
 {
     global $DB;
     $unlocked_content = false;
     if (!block_game_content_unlock_helper::is_student($event->userid)) {
         return;
     }
     $uss = $DB->get_records_sql("SELECT * FROM {content_unlock_system} WHERE deleted = ? AND " . $DB->sql_compare_text('conditions') . " = " . $DB->sql_compare_text('?'), array('deleted' => 0, 'conditions' => $event->eventname));
     foreach ($uss as $unlocksystem) {
         $ccm = get_course_and_cm_from_cmid($unlocksystem->coursemoduleid);
         if ($event->courseid != $ccm[0]->id) {
             continue;
         }
         if (!(content_unlock_satisfies_conditions($unlocksystem->restrictions, $event->courseid, $event->userid) && content_unlock_satisfies_advanced_conditions($unlocksystem, $event) && content_unlock_satisfies_block_conditions($unlocksystem, $event->courseid, $event->userid))) {
             continue;
         }
         $blockcontextid = $DB->get_field('block_instances', 'parentcontextid', array('id' => $unlocksystem->blockinstanceid));
         if (!$blockcontextid) {
             continue;
         }
         $blockcontext = context::instance_by_id($blockcontextid);
         $context = context::instance_by_id($event->contextid);
         if (strpos($context->path, $blockcontext->path) !== 0 && $blockcontext->instanceid != SITEID) {
             continue;
         }
         $sql = "SELECT count(c.id)\n\t\t\t\tFROM {content_unlock_log} c\n\t\t\t\t\tINNER JOIN {logstore_standard_log} l ON c.logid = l.id\n\t\t\t\tWHERE l.userid = :userid\n\t\t\t\t\tAND c.unlocksystemid = :unlocksystemid";
         $params['userid'] = $event->userid;
         $params['unlocksystemid'] = $unlocksystem->id;
         if ($DB->count_records_sql($sql, $params) > 0) {
             continue;
         }
         $manager = get_log_manager();
         $selectreaders = $manager->get_readers('\\core\\log\\sql_reader');
         if ($selectreaders) {
             $reader = reset($selectreaders);
         }
         $selectwhere = "eventname = :eventname\n\t\t\t\tAND component = :component\n\t\t\t\tAND action = :action\n\t\t\t\tAND target = :target\n\t\t\t\tAND crud = :crud\n\t\t\t\tAND edulevel = :edulevel\n\t\t\t\tAND contextid = :contextid\n\t\t\t\tAND contextlevel = :contextlevel\n\t\t\t\tAND contextinstanceid = :contextinstanceid\n\t\t\t\tAND userid = :userid \n\t\t\t\tAND anonymous = :anonymous\n\t\t\t\tAND timecreated = :timecreated";
         $params['eventname'] = $event->eventname;
         $params['component'] = $event->component;
         $params['action'] = $event->action;
         $params['target'] = $event->target;
         $params['crud'] = $event->crud;
         $params['edulevel'] = $event->edulevel;
         $params['contextid'] = $event->contextid;
         $params['contextlevel'] = $event->contextlevel;
         $params['contextinstanceid'] = $event->contextinstanceid;
         $params['userid'] = $event->userid;
         $params['anonymous'] = $event->anonymous;
         $params['timecreated'] = $event->timecreated;
         $logid = $reader->get_events_select($selectwhere, $params, '', 0, 0);
         $logid = array_keys($logid)[0];
         $record = new stdClass();
         $record->logid = $logid;
         $record->unlocksystemid = $unlocksystem->id;
         $DB->insert_record('content_unlock_log', $record);
         $unlocked_content = true;
         if ($unlocksystem->mode == 0) {
             if ($unlocksystem->coursemodulevisibility == 1) {
                 set_section_visible($event->courseid, $ccm[1]->sectionnum, 1);
             }
             set_coursemodule_visible($unlocksystem->coursemoduleid, $unlocksystem->coursemodulevisibility);
         } else {
             groups_add_member($unlocksystem->groupid, $event->userid);
         }
     }
     if ($unlocked_content) {
         $params = array('context' => $context);
         $event = \block_game_content_unlock\event\content_unlocked::create($params);
         $event->trigger();
     }
 }