/** * deletes a users messages, when a user is deleted * * @param type $event * @param type $user */ public static function eventlistener_on_deleteuser($event, $user) { if ('deleteuser' !== $event) { return; } $userid = $user['id']; db_begin(); $recievedmessageids = get_message_ids_mr($userid, 'recipient', null, null, null); if (count($recievedmessageids) > 0) { delete_messages_mr($recievedmessageids, $userid); } $sentmessageids = get_message_ids_mr($userid, 'sender', null, null, 100); if (count($sentmessageids) > 0) { delete_messages_mr($sentmessageids, $userid); } db_commit(); }
$deleteunread = 0; // Remember the number of unread messages being deleted foreach ($_GET as $k => $v) { if (preg_match('/^delete\\-([a-zA-Z_]+)\\-(\\d+)$/', $k, $m)) { $table = $m[1]; $ids[$table][] = $m[2]; if (isset($_GET['unread-' . $table . '-' . $m[2]])) { $deleteunread++; } } } db_begin(); $countdeleted = 0; foreach ($ids as $table => $idspertable) { if ('artefact_multirecipient_notification' === $table) { delete_messages_mr($idspertable, $USER->get('id')); } else { if ('notification_internal_activity' === $table) { $strids = join(',', array_map('db_quote', $idspertable)); $userid = $USER->get('id'); // Remove parent pointers to messages we're about to delete // Use temp table in subselect for Mysql compat. execute_sql("\n UPDATE {notification_internal_activity}\n SET parent = NULL\n WHERE parent IN (\n SELECT id FROM (\n SELECT id FROM {notification_internal_activity} WHERE id IN ({$strids}) AND usr = ?\n ) AS temp\n )", array($userid)); delete_records_select('notification_internal_activity', "id IN ({$strids}) AND usr = ?", array($userid)); if ($deleteunread) { $newunread = $USER->add_unread(-$deleteunread); } } } $countdeleted += count($idspertable); }
function delete_all_notifications_submit() { global $USER, $SESSION; $userid = $USER->get('id'); $type = param_variable('type', 'all'); $count = 0; if (in_array($type, array('all', 'usermessage'))) { if ($type !== 'all') { $at = activity_locate_typerecord($type); $typecond = 'AND msg.type = ' . $at->id; } else { $typecond = ''; } $query = 'SELECT msg.id AS id FROM {artefact_multirecipient_notification} as msg INNER JOIN {artefact_multirecipient_userrelation} as rel ON msg.id = rel.notification AND rel.usr = ? AND rel.role = ? AND rel.deleted = \'0\' ' . $typecond; $result = get_records_sql_array($query, array($userid, 'sender')); $msgids = array(); if (is_array($result)) { foreach ($result as $record) { $msgids[] = $record->id; } db_begin(); delete_messages_mr($msgids, $userid); db_commit(); } $count = count($msgids); } $SESSION->add_ok_msg(get_string('deletednotifications1', 'artefact.multirecipientnotification', $count)); redirect(get_config('wwwroot') . 'artefact/multirecipientnotification/outbox.php?type=' . $type); }
$ids = array(); $deleteunread = 0; // Remember the number of unread messages being deleted foreach ($_GET as $k => $v) { if (preg_match('/^select\\-([a-zA-Z_]+)\\-(\\d+)$/', $k, $m)) { $list = $m[1]; $ids[$list][] = $m[2]; if (isset($_GET['unread-' . $list . '-' . $m[2]])) { $deleteunread++; } } } db_begin(); $countdeleted = 0; foreach ($ids as $list => $idsperlist) { if ('artefact_multirecipient_notification' === $list) { delete_messages_mr($idsperlist, $USER->get('id')); $countdeleted += count($idsperlist); } } db_commit(); $message = get_string('deletednotifications1', 'activity', $countdeleted); } // ------------ Change ------------ // use the new function to show from - and to user $newhtml = activitylistout_html($type, $limit, $offset); // --------- End Change ----------- if (isset($newunread)) { $newhtml['newunreadcount'] = $newunread; } json_reply(false, (object) array('message' => $message, 'data' => $newhtml));
function delete_all_notifications_submit() { global $USER, $SESSION; $userid = $USER->get('id'); $type = param_variable('type', 'all'); db_begin(); // delete multirecipient-message separately $count = 0; if (in_array($type, array('all', 'usermessage'))) { if ($type !== 'all') { $at = activity_locate_typerecord($type); $typecond = 'AND {msg}.{type} = ' . $at->id; } else { $typecond = ''; } $query = 'SELECT msg.id AS id FROM {module_multirecipient_notification} as msg INNER JOIN {module_multirecipient_userrelation} as rel ON msg.id = rel.notification AND rel.usr = ? AND rel.role = ? AND rel.deleted = \'0\' ' . $typecond; $result = get_records_sql_array($query, array($userid, 'recipient')); $msgids = array(); if (is_array($result)) { foreach ($result as $record) { $msgids[] = $record->id; } delete_messages_mr($msgids, $userid); } $count = count($msgids); } $typesql = ''; if ($type != 'all') { // Treat as comma-separated list of activity type names $types = split(',', preg_replace('/[^a-z,]+/', '', $type)); if ($types) { $typesql = ' at.name IN (' . join(',', array_map('db_quote', $types)) . ')'; if (in_array('adminmessages', $types)) { $typesql = '(' . $typesql . ' OR at.admin = 1)'; } $typesql = ' AND ' . $typesql; } } // changed to meesage from usr $fromexpression = "FROM {notification_internal_activity} a\n INNER JOIN {activity_type} at ON a.type = at.id\n WHERE a.usr = ? {$typesql}"; $values = array($userid); $records = get_records_sql_array('SELECT a.id ' . $fromexpression, $values); if ($records) { $count += sizeof($records); $ids = array(); foreach ($records as $row) { $ids[] = $row->id; } // Remove parent pointers to messages we're about to delete execute_sql(' UPDATE {notification_internal_activity} SET parent = NULL WHERE parent IN (' . join(',', array_map('db_quote', $ids)) . ')'); // delete execute_sql(' DELETE FROM {notification_internal_activity} WHERE id IN (' . join(',', array_map('db_quote', $ids)) . ')'); // The update_unread_delete db trigger on notification_internal_activity // will update the unread column on the usr table. } db_commit(); $SESSION->add_ok_msg(get_string('deletednotifications1', 'activity', $count)); redirect(get_config('wwwroot') . 'module/multirecipientnotification/inbox.php?type=' . $type); }