Ejemplo n.º 1
1
 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('module_installed', 'name', 'multirecipientnotification', 'active', '1') && safe_require_plugin('module', 'multirecipientnotification')) {
         global $USER;
         $userid = $USER->get('id');
         $activitylist = activityblocklistin(join(',', $desiredtypes), $maxitems);
         $records = $activitylist->records;
         $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]);
         }
         if ($records) {
             foreach ($records as &$r) {
                 $r->message = format_notification_whitespace($r->message, $r->type);
             }
         }
         $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);
         }
     }
     $smarty = smarty_core();
     if ($showmore) {
         $smarty->assign('morelink', self::get_link($instance) . '?type=' . implode(',', $desiredtypes));
     }
     $smarty->assign('blockid', 'blockinstance_' . $instance->get('id'));
     $smarty->assign('items', $records);
     return $smarty->fetch($smartytemplate);
 }
Ejemplo n.º 2
0
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     global $USER;
     $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;
     $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]);
     }
     if ($records) {
         require_once 'activity.php';
         foreach ($records as &$r) {
             $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);
     return $smarty->fetch('blocktype:inbox:inbox.tpl');
 }
Ejemplo n.º 3
0
/**
 * Get one page of notifications and return html
 */
function activitylist_html($type = 'all', $limit = 10, $offset = 0)
{
    global $USER;
    $userid = $USER->get('id');
    $typesql = '';
    if ($type != 'all') {
        // Treat as comma-separated list of activity type names
        $types = explode(',', 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;
        }
    }
    $from = "\n        FROM {notification_internal_activity} a\n        JOIN {activity_type} at ON a.type = at.id\n        WHERE a.usr = ? {$typesql}";
    $values = array($userid);
    $count = count_records_sql('SELECT COUNT(*)' . $from, $values);
    $pagination = build_pagination(array('id' => 'activitylist_pagination', 'url' => get_config('wwwroot') . 'account/activity/index.php?type=' . $type, 'jsonscript' => 'account/activity/index.json.php', 'datatable' => 'activitylist', 'count' => $count, 'limit' => $limit, 'offset' => $offset, 'jumplinks' => 6, 'numbersincludeprevnext' => 2));
    $result = array('count' => $count, 'limit' => $limit, 'offset' => $offset, 'type' => $type, 'tablerows' => '', 'pagination' => $pagination['html'], 'pagination_js' => $pagination['javascript']);
    if ($count < 1) {
        return $result;
    }
    $records = get_records_sql_array('
        SELECT
            a.*, at.name AS type, at.plugintype, at.pluginname' . $from . '
        ORDER BY a.ctime DESC', $values, $offset, $limit);
    if ($records) {
        foreach ($records as &$r) {
            $r->date = format_date(strtotime($r->ctime), 'strfdaymonthyearshort');
            $section = empty($r->plugintype) ? 'activity' : "{$r->plugintype}.{$r->pluginname}";
            $r->strtype = get_string('type' . $r->type, $section);
            $r->message = format_notification_whitespace($r->message);
        }
    }
    $smarty = smarty_core();
    $smarty->assign('data', $records);
    $result['tablerows'] = $smarty->fetch('account/activity/activitylist.tpl');
    return $result;
}
Ejemplo n.º 4
0
/**
 * creates a result-array with the number, limit, offset and notification-type(s)
 * of the returned htmlrepresentation of the notifications in the outbox, as well
 * as the html representation itself. The return array has the following format:
 *
 * array (
 *   'count' => '17',
 *   'limit' => 10,
 *   'offset' => 0,
 *   'type' => 'all',
 *   'tablerows' => '//html ...
 *   'pagination' => '// html
 *   'pagination_js' => '// javascript
 * )
 *
 * @global User $USER
 * @param type $type
 * @param type $limit
 * @param type $offset
 * @return array
 */
function activitylistout_html($type = 'all', $limit = 10, $offset = 0)
{
    global $USER;
    $userid = $USER->get('id');
    $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;
        }
    }
    $notificationtargetcolumn = 'from';
    $notificationtargetrole = 'sender';
    $msgidquery = "\n        (\n        SELECT a.id, a.ctime, 'notification_internal_activity' AS msgtable\n        FROM {notification_internal_activity} AS a\n        INNER JOIN {activity_type} AS at ON a.type = at.id\n        WHERE a." . $notificationtargetcolumn . " = ?\n        " . $typesql . "\n        AND at.name != 'newpost'\n        )\n        UNION\n        (\n        SELECT a.id, a.ctime, 'artefact_multirecipient_notification' AS msgtable\n        FROM {artefact_multirecipient_notification} AS a\n        INNER JOIN {artefact_multirecipient_userrelation} AS b\n            ON a.id = b.notification\n        INNER JOIN {activity_type} AS at ON a.type = at.id\n        WHERE b.usr = ?\n        AND b.deleted = '0'\n        AND b.role = '" . $notificationtargetrole . "'\n        " . $typesql . "\n        )";
    $countquery = 'SELECT COUNT(*) FROM (' . $msgidquery . ') AS dummytable';
    $count = count_records_sql($countquery, array($userid, $userid));
    $pagination = build_pagination(array('id' => 'activitylist_pagination', 'url' => get_config('wwwroot') . 'artefact/multirecipientnotification/outbox.php?type=' . hsc($type), 'jsonscript' => 'artefact/multirecipientnotification/indexout.json.php', 'datatable' => 'activitylist', 'count' => $count, 'limit' => $limit, 'offset' => $offset, 'jumplinks' => 6, 'numbersincludeprevnext' => 2, 'setlimit' => true));
    $result = array('count' => $count, 'limit' => $limit, 'offset' => $offset, 'type' => $type, 'tablerows' => '', 'pagination' => $pagination['html'], 'pagination_js' => $pagination['javascript']);
    if ($count < 1) {
        return $result;
    }
    $records = array();
    $msgidquery .= "\n    ORDER BY ctime DESC";
    $msgidrecords = get_records_sql_array($msgidquery, array($userid, $userid), $offset, $limit);
    if (!is_array($msgidrecords)) {
        $msgidrecords = array();
    }
    foreach ($msgidrecords as $msgidrecord) {
        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)) {
                log_warn('inconsistent message-id in notification_internal_activity, id: ' . $msgidrecord->id);
                continue;
            }
            $record = $recordsarray[0];
            $record->canreplyall = false;
            $record->canreply = false;
            $record->startnewthread = true;
            // read out receiver name
            if (isset($record->usr)) {
                $tousrarray = array('display' => display_name($record->usr), 'link' => null);
                if (!get_user($record->usr)->deleted) {
                    $tousrarray['link'] = profile_url($record->usr);
                    $record->canreply = true;
                }
                $record->tousr = array($tousrarray);
            } else {
                $record->tousr = array(array('display' => get_string('system'), 'link' => null));
            }
            // read out sender name
            if (isset($record->from)) {
                $record->fromusr = $record->from;
            } else {
                // we're in the outbox, so basically, this should hold for all messages
                $record->fromusr = $USER->get('id');
            }
            $record->date = format_date(strtotime($record->ctime), 'strfdaymonthyearshort');
            $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';
            $records[] = $record;
        } else {
            if ($msgidrecord->msgtable === 'artefact_multirecipient_notification') {
                $record = get_message_mr($userid, $msgidrecord->id);
                if (null === $record) {
                    continue;
                }
                $record->strtype = $record->type;
                $record->date = format_date(strtotime($record->ctime), 'strfdaymonthyearshort');
                // We fill $record->tousr with an array per userentry, that holds the
                // display name of the user and the link to the users profile, if
                // applicable - we don't link to deleted users. Those will be summed
                // up in a single entry at the end of the list
                $deletedcount = 0;
                $record->canreply = false;
                $record->canreplyall = false;
                $record->startnewthread = false;
                for ($i = 0; $i < count($record->userids); $i++) {
                    $tousr = get_user($record->userids[$i]);
                    if ($tousr->deleted) {
                        $deletedcount++;
                    } else {
                        $record->tousr[] = array('display' => display_name($record->userids[$i]), 'link' => profile_url($record->userids[$i]));
                    }
                }
                if ($deletedcount > 0) {
                    $record->tousr[] = array('display' => $deletedcount . ' ' . get_string('deleteduser', 'artefact.multirecipientnotification'), 'link' => null);
                }
                if ($deletedcount < count($record->userids)) {
                    if (count($record->userids) - $deletedcount == 1) {
                        $record->canreply = true;
                    } else {
                        $record->canreplyall = true;
                    }
                }
                if (isset($record->fromid)) {
                    $record->fromusr = $record->fromid;
                } 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';
                $records[] = $record;
            }
        }
    }
    $smarty = smarty_core();
    $smarty->assign('data', $records);
    $smarty->assign('USER', $USER);
    $smarty->assign('maxnamestrlength', PluginArtefactMultirecipientnotification::MAX_USERNAME_IN_LIST_LENGTH);
    $result['tablerows'] = $smarty->fetch('artefact:multirecipientnotification:activitylistout.tpl');
    return $result;
}