本文整理汇总了PHP中chat_delete_old_users函数的典型用法代码示例。如果您正苦于以下问题:PHP chat_delete_old_users函数的具体用法?PHP chat_delete_old_users怎么用?PHP chat_delete_old_users使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了chat_delete_old_users函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: print_error
if (!($course = $DB->get_record('course', array('id' => $chatuser->course)))) {
print_error('invalidcourseid');
}
// Get the user theme and enough info to be used in chat_format_message() which passes it along to
// chat_format_message_manually() -- and only id and timezone are used.
// No optimisation here, it would break again in future!
if (!($user = $DB->get_record('user', array('id' => $chatuser->userid, 'deleted' => 0, 'suspended' => 0)))) {
print_error('invaliduser');
}
\core\session\manager::set_user($user);
// Setup course, lang and theme.
$PAGE->set_course($course);
// Force deleting of timed out users if there is a silence in room or just entering.
if (time() - $chatlasttime > $CFG->chat_old_ping) {
// Must be done before chat_get_latest_message!
chat_delete_old_users();
}
// Time to send headers, and lay out the basic JS updater page.
header('Expires: Sun, 28 Dec 1997 09:32:45 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Content-Type: text/html; charset=utf-8');
$refreshurl = "{$CFG->wwwroot}/mod/chat/gui_header_js/jsupdated.php?" . "chat_sid={$chatsid}&chat_lasttime={$chatlasttime}&chat_lastrow={$chatnewrow}&chat_lastid={$chatlastid}";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript">
//<![CDATA[
示例2: chat_cron
/**
* Function to be run periodically according to the moodle cron
* This function searches for things that need to be done, such
* as sending out mail, toggling flags etc ...
*
* @global object
* @return bool
*/
function chat_cron()
{
global $DB;
chat_update_chat_times();
chat_delete_old_users();
/// Delete old messages with a
/// single SQL query.
$subselect = "SELECT c.keepdays\n FROM {chat} c\n WHERE c.id = {chat_messages}.chatid";
$sql = "DELETE\n FROM {chat_messages}\n WHERE ({$subselect}) > 0 AND timestamp < ( " . time() . " -({$subselect}) * 24 * 3600)";
$DB->execute($sql);
$sql = "DELETE\n FROM {chat_messages_current}\n WHERE timestamp < ( " . time() . " - 8 * 3600)";
$DB->execute($sql);
return true;
}
示例3: get_chat_latest_messages
/**
* Get the latest messages from the given chat session.
*
* @param int $chatsid the chat session id
* @param int $chatlasttime last time messages were retrieved (epoch time)
* @return array of warnings and the new message id (0 if the message was empty)
* @since Moodle 3.0
* @throws moodle_exception
*/
public static function get_chat_latest_messages($chatsid, $chatlasttime = 0)
{
global $DB, $CFG;
$params = self::validate_parameters(self::get_chat_latest_messages_parameters(), array('chatsid' => $chatsid, 'chatlasttime' => $chatlasttime));
$warnings = array();
// Request and permission validation.
if (!($chatuser = $DB->get_record('chat_users', array('sid' => $params['chatsid'])))) {
throw new moodle_exception('notlogged', 'chat');
}
$chat = $DB->get_record('chat', array('id' => $chatuser->chatid), '*', MUST_EXIST);
list($course, $cm) = get_course_and_cm_from_instance($chat, 'chat');
$context = context_module::instance($cm->id);
self::validate_context($context);
require_capability('mod/chat:chat', $context);
$chatlasttime = $params['chatlasttime'];
if (time() - $chatlasttime > $CFG->chat_old_ping) {
chat_delete_old_users();
}
// Set default chat last time (to not retrieve all the conversations).
if ($chatlasttime == 0) {
$chatlasttime = time() - $CFG->chat_old_ping;
}
if ($latestmessage = chat_get_latest_message($chatuser->chatid, $chatuser->groupid)) {
$chatnewlasttime = $latestmessage->timestamp;
} else {
$chatnewlasttime = 0;
}
$messages = chat_get_latest_messages($chatuser, $chatlasttime);
$returnedmessages = array();
foreach ($messages as $message) {
// FORMAT_MOODLE is mandatory in the chat plugin.
list($messageformatted, $format) = external_format_text($message->message, FORMAT_MOODLE, $context->id, 'mod_chat', '', 0);
$returnedmessages[] = array('id' => $message->id, 'userid' => $message->userid, 'system' => (bool) $message->system, 'message' => $messageformatted, 'timestamp' => $message->timestamp);
}
// Update our status since we are active in the chat.
$DB->set_field('chat_users', 'lastping', time(), array('id' => $chatuser->id));
$result = array();
$result['messages'] = $returnedmessages;
$result['chatnewlasttime'] = $chatnewlasttime;
$result['warnings'] = $warnings;
return $result;
}
示例4: chat_cron
function chat_cron()
{
/// Function to be run periodically according to the moodle cron
/// This function searches for things that need to be done, such
/// as sending out mail, toggling flags etc ...
global $CFG;
chat_update_chat_times();
chat_delete_old_users();
/// Delete old messages
if ($chats = get_records("chat")) {
foreach ($chats as $chat) {
if ($chat->keepdays) {
$timeold = time() - $chat->keepdays * 24 * 3600;
delete_records_select("chat_messages", "chatid = '{$chat->id}' AND timestamp < '{$timeold}'");
}
}
}
return true;
}
示例5: chat_cron
function chat_cron()
{
/// Function to be run periodically according to the moodle cron
/// This function searches for things that need to be done, such
/// as sending out mail, toggling flags etc ...
global $CFG;
chat_update_chat_times();
chat_delete_old_users();
/// Delete old messages
$sql = "SELECT m.id \n FROM {$CFG->prefix}chat_messages m \n JOIN {$CFG->prefix}chat c\n ON m.chatid = c.id\n WHERE c.keepdays != 0 \n AND m.timestamp < ( " . time() . " - c.keepdays * 24 * 3600)";
delete_records_select("chat_messages", "id IN ({$sql})");
return true;
}
示例6: chat_cron
function chat_cron()
{
/// Function to be run periodically according to the moodle cron
/// This function searches for things that need to be done, such
/// as sending out mail, toggling flags etc ...
global $DB;
chat_update_chat_times();
chat_delete_old_users();
/// Delete old messages with a
/// single SQL query.
$subselect = "SELECT c.keepdays\n FROM {chat} c\n WHERE c.id = {chat_messages}.chatid";
$sql = "DELETE\n FROM {chat_messages}\n WHERE ({$subselect}) > 0 AND timestamp < ( " . time() . " -({$subselect}) * 24 * 3600)";
$DB->execute($sql);
$sql = "DELETE\n FROM {chat_messages_current}\n WHERE timestamp < ( " . time() . " - 8 * 3600)";
$DB->execute($sql);
return true;
}