Ejemplo n.º 1
0
 public function get_id()
 {
     if (!isset($this->id)) {
         $tmp = activity_locate_typerecord($this->get_type(), $this->get_plugintype(), $this->get_pluginname());
         $this->id = $tmp->id;
     }
     return $this->id;
 }
Ejemplo n.º 2
0
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);
}
Ejemplo n.º 3
0
function get_message_ids_mr($usr = null, $role = 'recipient', $type = null, $sortby = null, $limit = 20, $offset = 0)
{
    if (null === $type) {
        $at = activity_locate_typerecord('usermessage');
        $type = $at->id;
    } else {
        if (!is_int($type)) {
            $at = activity_locate_typerecord($type);
            $type = $at->id;
        }
    }
    $messageids = array();
    if (null === $usr) {
        global $USER;
        $usr = $USER->get('id');
    }
    if (null === $sortby) {
        $sortby = 'ctime';
    }
    $values = array($usr, $role, $type, $sortby);
    $query = '
        SELECT msg.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 = ?
        WHERE msg.type = ?
        ORDER BY ?';
    $result = get_records_sql_array($query, $values, $offset, $limit);
    if (is_array($result)) {
        foreach ($result as $res) {
            $messageids[] = $res->id;
        }
    }
    return $messageids;
}
Ejemplo n.º 4
0
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);
}