本文整理汇总了PHP中get_log_manager函数的典型用法代码示例。如果您正苦于以下问题:PHP get_log_manager函数的具体用法?PHP get_log_manager怎么用?PHP get_log_manager使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_log_manager函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Redirect all events to this log manager, but only if this
* log manager is actually used.
*
* @param \core\event\base $event
*/
public static function store(\core\event\base $event)
{
$logmanager = get_log_manager();
if (get_class($logmanager) === 'tool_log\\log\\manager') {
/** @var \tool_log\log\manager $logmanager */
$logmanager->process($event);
}
}
示例2: execute
/**
* Do the job.
* Throw exceptions on errors (the job will be retried).
*/
public function execute()
{
global $DB;
$manager = get_log_manager();
$store = new store($manager);
$events = $DB->get_records('logstore_xapi_log');
$store->process_events($events);
$DB->delete_records_list('logstore_xapi_log', 'id', array_keys($events));
mtrace("Sent learning records to LRS.");
}
示例3: add_to_log
/**
* Add an entry to the legacy log table.
*
* @deprecated since 2.7 use new events instead
*
* @param int $courseid The course id
* @param string $module The module name e.g. forum, journal, resource, course, user etc
* @param string $action 'view', 'update', 'add' or 'delete', possibly followed by another word to clarify.
* @param string $url The file and parameters used to see the results of the action
* @param string $info Additional description information
* @param int $cm The course_module->id if there is one
* @param int|stdClass $user If log regards $user other than $USER
* @return void
*/
function add_to_log($courseid, $module, $action, $url = '', $info = '', $cm = 0, $user = 0)
{
debugging('add_to_log() has been deprecated, please rewrite your code to the new events API', DEBUG_DEVELOPER);
// This is a nasty hack that allows us to put all the legacy stuff into legacy storage,
// this way we may move all the legacy settings there too.
$manager = get_log_manager();
if (method_exists($manager, 'legacy_add_to_log')) {
$manager->legacy_add_to_log($courseid, $module, $action, $url, $info, $cm, $user);
}
}
示例4: oauth_add_to_log
/**
* oauth_add_to_log is a quick hack to avoid add_to_log debugging
*/
function oauth_add_to_log($courseid, $module, $action, $url = '', $info = '', $cm = 0, $user = 0)
{
if (function_exists('get_log_manager')) {
$manager = get_log_manager();
$manager->legacy_add_to_log($courseid, $module, $action, $url, $info, $cm, $user);
} else {
if (function_exists('add_to_log')) {
add_to_log($courseid, $module, $action, $url, $info, $cm, $user);
}
}
}
示例5: test_report_participation_supports_logstore
/**
* Test report_log_supports_logstore.
*/
public function test_report_participation_supports_logstore()
{
$logmanager = get_log_manager();
$allstores = \core_component::get_plugin_list_with_class('logstore', 'log\\store');
$supportedstores = array('logstore_legacy' => '\\logstore_legacy\\log\\store', 'logstore_standard' => '\\logstore_standard\\log\\store');
// Make sure all supported stores are installed.
$expectedstores = array_keys(array_intersect($allstores, $supportedstores));
$stores = $logmanager->get_supported_logstores('report_outline');
$stores = array_keys($stores);
foreach ($expectedstores as $expectedstore) {
$this->assertContains($expectedstore, $stores);
}
}
示例6: report_participation_get_log_table_name
/**
* Returns log table name of preferred reader, if leagcy then return empty string.
*
* @return string table name
*/
function report_participation_get_log_table_name()
{
// Get prefered sql_internal_table_reader reader (if enabled).
$logmanager = get_log_manager();
$readers = $logmanager->get_readers();
$logtable = '';
// Get preferred reader.
if (!empty($readers)) {
foreach ($readers as $readerpluginname => $reader) {
// If legacy reader is preferred reader.
if ($readerpluginname == 'logstore_legacy') {
break;
}
// If sql_internal_table_reader is preferred reader.
if ($reader instanceof \core\log\sql_internal_table_reader) {
$logtable = $reader->get_internal_log_table_name();
break;
}
}
}
return $logtable;
}
示例7: report_outline_get_common_log_variables
/**
* Returns an array of the commonly used log variables by the outline report.
*
* @return array the array of variables used
*/
function report_outline_get_common_log_variables()
{
global $DB;
static $uselegacyreader;
static $useinternalreader;
static $minloginternalreader;
static $logtable = null;
if (isset($uselegacyreader) && isset($useinternalreader) && isset($minloginternalreader)) {
return array($uselegacyreader, $useinternalreader, $minloginternalreader, $logtable);
}
$uselegacyreader = false;
// Flag to determine if we should use the legacy reader.
$useinternalreader = false;
// Flag to determine if we should use the internal reader.
$minloginternalreader = 0;
// Set this to 0 for now.
// Get list of readers.
$logmanager = get_log_manager();
$readers = $logmanager->get_readers();
// Get preferred reader.
if (!empty($readers)) {
foreach ($readers as $readerpluginname => $reader) {
// If legacy reader is preferred reader.
if ($readerpluginname == 'logstore_legacy') {
$uselegacyreader = true;
break;
}
// If sql_internal_reader is preferred reader.
if ($reader instanceof \core\log\sql_internal_reader) {
$useinternalreader = true;
$logtable = $reader->get_internal_log_table_name();
$minloginternalreader = $DB->get_field_sql('SELECT min(timecreated) FROM {' . $logtable . '}');
break;
}
}
}
return array($uselegacyreader, $useinternalreader, $minloginternalreader, $logtable);
}
示例8: test_get_log_manager
public function test_get_log_manager()
{
global $CFG;
$this->resetAfterTest();
$manager = get_log_manager();
$this->assertInstanceOf('core\\log\\manager', $manager);
$stores = $manager->get_readers();
$this->assertInternalType('array', $stores);
$this->assertCount(0, $stores);
$this->assertFileExists("{$CFG->dirroot}/{$CFG->admin}/tool/log/store/standard/version.php");
$this->assertFileExists("{$CFG->dirroot}/{$CFG->admin}/tool/log/store/legacy/version.php");
set_config('enabled_stores', 'logstore_standard,logstore_legacy', 'tool_log');
$manager = get_log_manager(true);
$this->assertInstanceOf('core\\log\\manager', $manager);
$stores = $manager->get_readers();
$this->assertInternalType('array', $stores);
$this->assertCount(2, $stores);
foreach ($stores as $key => $store) {
$this->assertInternalType('string', $key);
$this->assertInstanceOf('core\\log\\sql_select_reader', $store);
}
$stores = $manager->get_readers('core\\log\\sql_internal_reader');
$this->assertInternalType('array', $stores);
$this->assertCount(1, $stores);
foreach ($stores as $key => $store) {
$this->assertInternalType('string', $key);
$this->assertSame('logstore_standard', $key);
$this->assertInstanceOf('core\\log\\sql_internal_reader', $store);
}
$stores = $manager->get_readers('core\\log\\sql_select_reader');
$this->assertInternalType('array', $stores);
$this->assertCount(2, $stores);
foreach ($stores as $key => $store) {
$this->assertInternalType('string', $key);
$this->assertInstanceOf('core\\log\\sql_select_reader', $store);
}
}
示例9: trigger
/**
* Trigger event.
*/
public final function trigger()
{
global $CFG;
if ($this->restored) {
throw new \coding_exception('Can not trigger restored event');
}
if ($this->triggered or $this->dispatched) {
throw new \coding_exception('Can not trigger event twice');
}
$this->validate_before_trigger();
$this->triggered = true;
if (isset($CFG->loglifetime) and $CFG->loglifetime != -1) {
if ($data = $this->get_legacy_logdata()) {
$manager = get_log_manager();
if (method_exists($manager, 'legacy_add_to_log')) {
if (is_array($data[0])) {
// Some events require several entries in 'log' table.
foreach ($data as $d) {
call_user_func_array(array($manager, 'legacy_add_to_log'), $d);
}
} else {
call_user_func_array(array($manager, 'legacy_add_to_log'), $data);
}
}
}
}
if (PHPUNIT_TEST and \phpunit_util::is_redirecting_events()) {
$this->dispatched = true;
\phpunit_util::event_triggered($this);
return;
}
\core\event\manager::dispatch($this);
$this->dispatched = true;
if ($legacyeventname = static::get_legacy_eventname()) {
events_trigger_legacy($legacyeventname, $this->get_legacy_eventdata());
}
}
示例10: stats_temp_table_fill
/**
* Fills the temporary stats tables with new data
*
* This function is meant to be called to get a new day of data
*
* @param int timestamp of the start time of logs view
* @param int timestamp of the end time of logs view
* @return bool success (true) or failure(false)
*/
function stats_temp_table_fill($timestart, $timeend)
{
global $DB;
// First decide from where we want the data.
$params = array('timestart' => $timestart, 'timeend' => $timeend, 'participating' => \core\event\base::LEVEL_PARTICIPATING, 'teaching' => \core\event\base::LEVEL_TEACHING, 'loginevent1' => '\\core\\event\\user_loggedin', 'loginevent2' => '\\core\\event\\user_loggedin');
$filled = false;
$manager = get_log_manager();
$stores = $manager->get_readers();
foreach ($stores as $store) {
if ($store instanceof \core\log\sql_internal_table_reader) {
$logtable = $store->get_internal_log_table_name();
if (!$logtable) {
continue;
}
$sql = "SELECT COUNT('x')\n FROM {{$logtable}}\n WHERE timecreated >= :timestart AND timecreated < :timeend";
if (!$DB->get_field_sql($sql, $params)) {
continue;
}
// Let's fake the old records using new log data.
// We want only data relevant to educational process
// done by real users.
$sql = "INSERT INTO {temp_log1} (userid, course, action)\n\n SELECT userid,\n CASE\n WHEN courseid IS NULL THEN " . SITEID . "\n WHEN courseid = 0 THEN " . SITEID . "\n ELSE courseid\n END,\n CASE\n WHEN eventname = :loginevent1 THEN 'login'\n WHEN crud = 'r' THEN 'view'\n ELSE 'update'\n END\n FROM {{$logtable}}\n WHERE timecreated >= :timestart AND timecreated < :timeend\n AND (origin = 'web' OR origin = 'ws')\n AND (edulevel = :participating OR edulevel = :teaching OR eventname = :loginevent2)";
$DB->execute($sql, $params);
$filled = true;
}
}
if (!$filled) {
// Fallback to legacy data.
$sql = "INSERT INTO {temp_log1} (userid, course, action)\n\n SELECT userid, course, action\n FROM {log}\n WHERE time >= :timestart AND time < :timeend";
$DB->execute($sql, $params);
}
$sql = 'INSERT INTO {temp_log2} (userid, course, action)
SELECT userid, course, action FROM {temp_log1}';
$DB->execute($sql);
// We have just loaded all the temp tables, collect statistics for that.
$DB->update_temp_table_stats();
return true;
}
示例11: __construct
function __construct()
{
$this->logger = get_log_manager()->get_readers()['logstore_standard'];
}
示例12: get_course_time
/**
* Get the time the user has spent in the course
*
* @param int $userid User ID (default= $USER->id)
* @return int the total time spent in seconds
*/
public function get_course_time($user = null)
{
global $CFG, $USER;
if (empty($user)) {
$userid = $USER->id;
} else {
if (is_object($user)) {
$userid = $user->id;
} else {
$userid = $user;
}
}
$manager = get_log_manager();
$selectreaders = $manager->get_readers('\\core\\log\\sql_reader');
$reader = reset($selectreaders);
//This can take a log time to process, but it's accurate
// it's can be done by get only first and last log entry creation time,
// but it's far more inaccurate, could have an option to choose.
set_time_limit(0);
$totaltime = 0;
$sql = "action = 'viewed' AND target = 'course' AND courseid = :courseid AND userid = :userid";
if ($logs = $reader->get_events_select($sql, array('courseid' => $this->get_course()->id, 'userid' => $userid), 'timecreated ASC', '', '')) {
foreach ($logs as $log) {
if (empty($login)) {
// For the first time $login is not set so the first log is also the first login
$login = $log->timecreated;
$lasthit = $log->timecreated;
}
$delay = $log->timecreated - $lasthit;
if (!($delay > $CFG->sessiontimeout)) {
// The difference between the last log and the current log is more than
// the timeout
//Register session value so that we have found a new session!
$totaltime += $delay;
}
// Now the actual log became the previous log for the next cycle
$lasthit = $log->timecreated;
}
}
return $totaltime / 60;
}
示例13: test_get_supported_reports
/**
* Test logmanager::get_supported_reports returns all reports that require this store.
*/
public function test_get_supported_reports()
{
$logmanager = get_log_manager();
$allreports = \core_component::get_plugin_list('report');
$supportedreports = array('report_log' => '/report/log', 'report_loglive' => '/report/loglive', 'report_outline' => '/report/outline', 'report_participation' => '/report/participation', 'report_stats' => '/report/stats');
// Make sure all supported reports are installed.
$expectedreports = array_keys(array_intersect_key($allreports, $supportedreports));
$reports = $logmanager->get_supported_reports('logstore_standard');
$reports = array_keys($reports);
foreach ($expectedreports as $expectedreport) {
$this->assertContains($expectedreport, $reports);
}
}
示例14: local_my_get_logstore_info
function local_my_get_logstore_info()
{
$logmanager = get_log_manager();
$readers = $logmanager->get_readers('\\core\\log\\sql_select_reader');
$reader = reset($readers);
if (empty($reader)) {
return false;
// No log reader found.
}
$logstoreinfo = new StdClass();
if ($reader instanceof \logstore_standard\log\store) {
$logstoreinfo->table = 'logstore_standard_log';
$logstoreinfo->courseparam = 'courseid';
$logstoreinfo->timeparam = 'timecreated';
} else {
if ($reader instanceof \logstore_legacy\log\store) {
$logstoreinfo->table = 'log';
$logstoreinfo->courseparam = 'course';
$logstoreinfo->timeparam = 'time';
} else {
return;
}
}
return $logstoreinfo;
}
示例15: process_log
protected function process_log($data)
{
global $DB;
$data = (object) $data;
$data->time = $this->apply_date_offset($data->time);
$data->userid = $this->get_mappingid('user', $data->userid);
$data->course = $this->get_courseid();
$data->cmid = $this->task->get_moduleid();
// For any reason user wasn't remapped ok, stop processing this
if (empty($data->userid)) {
return;
}
// Everything ready, let's delegate to the restore_logs_processor
// Set some fixed values that will save tons of DB requests
$values = array('course' => $this->get_courseid(), 'course_module' => $this->task->get_moduleid(), $this->task->get_modulename() => $this->task->get_activityid());
// Get instance and process log record
$data = restore_logs_processor::get_instance($this->task, $values)->process_log_record($data);
// If we have data, insert it, else something went wrong in the restore_logs_processor
if ($data) {
if (empty($data->url)) {
$data->url = '';
}
if (empty($data->info)) {
$data->info = '';
}
// Store the data in the legacy log table if we are still using it.
$manager = get_log_manager();
if (method_exists($manager, 'legacy_add_to_log')) {
$manager->legacy_add_to_log($data->course, $data->module, $data->action, $data->url, $data->info, $data->cmid, $data->userid);
}
}
}