Пример #1
0
/**
 * return an object with a list of records to feed the inbox-blocktype template.
 * The object has the following format:
 *
 * stdClass::__set_state(array(
 *   'records' =>
 *   array (
 *     0 =>
 *     stdClass::__set_state(array(
 * ...
 *
 *   ),
 *    'count' => '17',
 * ))
 *
 *
 * @param type $type
 * @param type $limit
 * @param type $offset
 * @return array
 */
function activityblocklistin($type = 'all', $limit = 10, $offset = 0)
{
    global $USER;
    $userid = $USER->get('id');
    $return = new stdClass();
    $return->records = array();
    $activitylist = activitylistin($type, $limit, $offset);
    $return->count = $activitylist->count;
    foreach ($activitylist->msgidrecords as $msgidrecord) {
        // old messages without plugin
        if ($msgidrecord->msgtable == 'notification_internal_activity') {
            $recordsarray = get_records_sql_array("SELECT a.*, at.name AS type, at.plugintype, at.pluginname\n                                      FROM {notification_internal_activity} a\n                                      INNER JOIN {activity_type} at ON a.type = at.id\n                                      WHERE a.id = ?", array($msgidrecord->id));
            if (1 !== count($recordsarray)) {
                continue;
            }
            $record = $recordsarray[0];
            $record->canreply = false;
            $record->canreplyall = false;
            $record->startnewthread = true;
            // read out sender name
            if ('usermessage' === $record->type) {
                $record->url = false;
                $record->urltext = false;
            }
            if (isset($record->from)) {
                $record->fromusr = $record->from;
                $fromuser = get_user($record->fromusr);
                if ($fromuser->deleted === '0') {
                    if ('usermessage' === $record->type) {
                        $record->canreply = true;
                    }
                }
            } else {
                $record->fromusr = 0;
            }
            $record->return = null;
            $section = empty($record->plugintype) ? 'activity' : "{$record->plugintype}.{$record->pluginname}";
            $record->strtype = get_string('type' . $record->type, $section);
            $record->message = format_notification_whitespace($record->message);
            // used to identify notification as internal for json-calls
            $record->table = 'notification_internal_activity';
            $return->records[] = $record;
            // messages from plugin
        } else {
            if ($msgidrecord->msgtable === 'artefact_multirecipient_notification') {
                $record = get_message_mr($userid, $msgidrecord->id);
                if (null === $record) {
                    continue;
                }
                $record->strtype = $record->type;
                $record->tousr = array();
                $record->canreply = false;
                $record->startnewthread = false;
                if (count($record->userids) > 1) {
                    $record->canreplyall = true;
                } else {
                    $record->canreplyall = false;
                }
                // preformat from user
                if (isset($record->fromid)) {
                    $record->fromusr = $record->fromid;
                    $fromuser = get_user($record->fromid);
                    if ($fromuser->deleted === '0') {
                        $record->canreply = true;
                    }
                } else {
                    $record->fromusr = 0;
                }
                $record->message = format_notification_whitespace($record->message);
                // used to identify notification as from this plugin for json-calls
                $record->table = 'artefact_multirecipient_notification';
                $return->records[] = $record;
            }
        }
    }
    return $return;
}
Пример #2
0
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     global $USER, $THEME;
     $configdata = $instance->get('configdata');
     $desiredtypes = array();
     foreach ($configdata as $k => $v) {
         if (!empty($v) && $k != 'maxitems') {
             $type = preg_replace('/[^a-z]+/', '', $k);
             $desiredtypes[$type] = $type;
         }
     }
     if ($USER->get('admin') && !empty($desiredtypes['adminmessages'])) {
         unset($desiredtypes['adminmessages']);
         $desiredtypes += get_column('activity_type', 'name', 'admin', 1);
     }
     $maxitems = isset($configdata['maxitems']) ? $configdata['maxitems'] : 5;
     // check if multirecipientnotification plugin is active or if we proceed here
     if (record_exists('artefact_installed', 'name', 'multirecipientnotification', 'active', '1')) {
         global $USER;
         $userid = $USER->get('id');
         safe_require('artefact', 'multirecipientnotification');
         $activitylist = activitylistin(join(',', $desiredtypes), $maxitems);
         $records = array();
         foreach ($activitylist->msgidrecords as $msgidrecord) {
             if ($msgidrecord->msgtable == 'notification_internal_activity') {
                 $sql = "\n                        SELECT n.id, n.subject, n.message, n.url, n.urltext, n.read, t.name AS type\n                        FROM {notification_internal_activity} n JOIN {activity_type} t ON n.type = t.id\n                        WHERE n.id = ?";
                 $notificationrecords = get_records_sql_array($sql, array($msgidrecord->id));
                 if (count($notificationrecords) === 1) {
                     $record = $notificationrecords[0];
                     $record->msgtable = $msgidrecord->msgtable;
                     $records[] = $record;
                 }
             } else {
                 $record = get_message_mr($userid, $msgidrecord->id);
                 if (null === $record) {
                     continue;
                 }
                 $record->url = 'artefact/multirecipientnotification/sendmessage.php?replyto=' . $msgidrecord->id . '&returnto=outbox';
                 if (count($record->userids) > 1) {
                     $record->urltext = get_string('replyurltext', 'artefact.multirecipientnotification');
                 } else {
                     $record->urltext = get_string('returnurltext', 'artefact.multirecipientnotification');
                 }
                 $record->msgtable = $msgidrecord->msgtable;
                 $records[] = $record;
             }
         }
         $showmore = $activitylist->count > $maxitems;
         // use a different template
         $smartytemplate = 'blocktype:inbox:inboxmr.tpl';
     } else {
         $records = array();
         if ($desiredtypes) {
             $sql = "\n                    SELECT n.id, n.subject, n.message, n.url, n.urltext, n.read, t.name AS type\n                    FROM {notification_internal_activity} n JOIN {activity_type} t ON n.type = t.id\n                    WHERE n.usr = ?\n                    AND t.name IN (" . join(',', array_map('db_quote', $desiredtypes)) . ")\n                    ORDER BY n.ctime DESC\n                    LIMIT ?;";
             $records = get_records_sql_array($sql, array($USER->get('id'), $maxitems + 1));
         }
         // Hack to decide whether to show the More... link
         if ($showmore = count($records) > $maxitems) {
             unset($records[$maxitems]);
         }
         $smartytemplate = 'blocktype:inbox:inbox.tpl';
     }
     if ($records) {
         require_once 'activity.php';
         foreach ($records as &$r) {
             $section = empty($r->plugintype) ? 'activity' : "{$r->plugintype}.{$r->pluginname}";
             $r->strtype = get_string('type' . $r->type, $section);
             $r->message = format_notification_whitespace($r->message, $r->type);
         }
     }
     $smarty = smarty_core();
     if ($showmore) {
         $smarty->assign('desiredtypes', implode(',', $desiredtypes));
     }
     $smarty->assign('blockid', 'blockinstance_' . $instance->get('id'));
     $smarty->assign('items', $records);
     $smarty->assign('readicon', $THEME->get_url('images/readusermessage.png'));
     return $smarty->fetch($smartytemplate);
 }
/**
 * return an object with a list of records to feed the inbox-blocktype template.
 * The object has the following format:
 *
 * stdClass::__set_state(array(
 *   'records' =>
 *   array (
 *     0 =>
 *     stdClass::__set_state(array(
 * ...
 *
 *   ),
 *    'count' => '17',
 * ))
 *
 *
 * @param type $type
 * @param type $limit
 * @param type $offset
 * @return array
 */
function activityblocklistin($type = 'all', $limit = 10, $offset = 0)
{
    global $USER;
    $userid = $USER->get('id');
    $return = new stdClass();
    $return->records = array();
    $activitylist = activitylistin($type, $limit, $offset);
    $return->count = $activitylist->count;
    foreach ($activitylist->msgidrecords as $msgidrecord) {
        if ($msgidrecord->msgtable == 'notification_internal_activity') {
            $sql = "\n                SELECT n.id, n.subject, n.message, n.url, n.urltext, n.read, t.name AS type\n                FROM {notification_internal_activity} n JOIN {activity_type} t ON n.type = t.id\n                WHERE n.id = ?";
            $records = get_records_sql_array($sql, array($msgidrecord->id));
            if (count($records == '1')) {
                $record = $records[0];
                $record->msgtable = $msgidrecord->msgtable;
                $return->records[] = $record;
            }
        } else {
            $record = get_message_mr($userid, $msgidrecord->id);
            if (null === $record) {
                continue;
            }
            $record->url = 'artefact/multirecipientnotification/sendmessage.php?replyto=' . $msgidrecord->id . '&returnto=outbox';
            if (count($record->userids) > 1) {
                $record->urltext = get_string('replyurltext', 'artefact.multirecipientnotification');
            } else {
                $record->urltext = get_string('returnurltext', 'artefact.multirecipientnotification');
            }
            $record->msgtable = $msgidrecord->msgtable;
            $return->records[] = $record;
        }
    }
    return $return;
}