Search in sources :

Example 21 with Subscriber

use of org.olat.core.commons.services.notifications.Subscriber in project openolat by klemens.

the class DateChooserController method setSubscribers.

public void setSubscribers(List<Subscriber> subscribers) {
    String selectedKey = typeSelection.isOneSelected() ? typeSelection.getSelectedKey() : null;
    Set<String> types = new HashSet<String>();
    for (Subscriber subscriber : subscribers) {
        String type = subscriber.getPublisher().getType();
        types.add(type);
    }
    typeKeys = new String[types.size() + 1];
    typeValues = new String[types.size() + 1];
    typeKeys[0] = "all";
    typeValues[0] = translate("news.type.all");
    int count = 1;
    for (String type : types) {
        String typeName = NewControllerFactory.translateResourceableTypeName(type, getLocale());
        typeKeys[count] = type;
        typeValues[count++] = typeName;
    }
    typeSelection.setKeysAndValues(typeKeys, typeValues, null);
    if (selectedKey != null) {
        // select the current key but check if it still exists
        for (String typeKey : typeKeys) {
            if (typeKey.equals(selectedKey)) {
                typeSelection.select(selectedKey, true);
                break;
            }
        }
    }
    if (!typeSelection.isOneSelected()) {
        typeSelection.select("all", true);
    }
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) HashSet(java.util.HashSet)

Example 22 with Subscriber

use of org.olat.core.commons.services.notifications.Subscriber in project openolat by klemens.

the class NotificationNewsController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.components.Component,
 *      org.olat.core.gui.control.Event)
 */
@Override
protected void event(UserRequest ureq, Component source, Event event) {
    if (source == emailLink) {
        // send email to user with the currently visible date
        NotificationsManager man = NotificationsManager.getInstance();
        List<SubscriptionItem> infoList = new ArrayList<>();
        List<Subscriber> subsList = new ArrayList<>();
        for (Subscriber subscriber : subsInfoMap.keySet()) {
            subsList.add(subscriber);
            SubscriptionItem item = man.createSubscriptionItem(subscriber, getLocale(), SubscriptionInfo.MIME_HTML, SubscriptionInfo.MIME_HTML, compareDate);
            if (item != null) {
                infoList.add(item);
            }
        }
        if (man.sendMailToUserAndUpdateSubscriber(subscriberIdentity, infoList, getTranslator(), subsList)) {
            showInfo("email.ok");
        } else {
            showError("email.nok");
        }
    }
}
Also used : SubscriptionItem(org.olat.core.commons.services.notifications.SubscriptionItem) Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) ArrayList(java.util.ArrayList)

Example 23 with Subscriber

use of org.olat.core.commons.services.notifications.Subscriber in project openolat by klemens.

the class NotificationNewsController method updateNewsDataModel.

/**
 * Update the new data model and refresh the GUI
 */
protected List<Subscriber> updateNewsDataModel() {
    if (compareDate == null) {
        // compare date is mandatory
        return Collections.emptyList();
    }
    List<String> notiTypes = new ArrayList<>();
    if (StringHelper.containsNonWhitespace(newsType) && !newsType.equals("all")) {
        notiTypes.add(newsType);
    }
    NotificationsManager man = NotificationsManager.getInstance();
    List<Subscriber> subs = man.getSubscribers(subscriberIdentity, notiTypes);
    newsVC.contextPut("subs", subs);
    subsInfoMap = NotificationHelper.getSubscriptionMap(getLocale(), true, compareDate, subs);
    NotificationSubscriptionAndNewsFormatter subsFormatter = new NotificationSubscriptionAndNewsFormatter(getTranslator(), subsInfoMap);
    newsVC.contextPut("subsFormatter", subsFormatter);
    return subs;
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) ArrayList(java.util.ArrayList)

Example 24 with Subscriber

use of org.olat.core.commons.services.notifications.Subscriber in project openolat by klemens.

the class NotificationSubscriptionTableDataModel method getValueAt.

/**
 * @see org.olat.core.gui.components.table.DefaultTableDataModel#getValueAt(int,
 *      int)
 */
@Override
public Object getValueAt(int row, int col) {
    Subscriber sub = getObject(row);
    Publisher pub = sub.getPublisher();
    switch(col) {
        case 0:
            return sub.getKey();
        case 1:
            String innerType = pub.getType();
            return NewControllerFactory.translateResourceableTypeName(innerType, getLocale());
        case 2:
            String containerType = pub.getResName();
            return NewControllerFactory.translateResourceableTypeName(containerType, getLocale());
        case 3:
            NotificationsHandler handler = NotificationsManager.getInstance().getNotificationsHandler(pub);
            if (handler == null) {
                return "";
            }
            String title = handler.createTitleInfo(sub, getLocale());
            if (title == null) {
                return "";
            }
            return title;
        case 4:
            return sub.getCreationDate();
        case 5:
            return sub.getLatestEmailed();
        default:
            return "ERROR";
    }
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsHandler(org.olat.core.commons.services.notifications.NotificationsHandler) Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 25 with Subscriber

use of org.olat.core.commons.services.notifications.Subscriber in project openolat by klemens.

the class NotificationsPortletRunController method event.

/**
 * @see org.olat.core.gui.control.ControllerEventListener#dispatchEvent(org.olat.core.gui.UserRequest, org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
public void event(UserRequest ureq, Controller source, Event event) {
    super.event(ureq, source, event);
    if (source == tableCtr) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent te = (TableEvent) event;
            String actionid = te.getActionId();
            if (actionid.equals(CMD_LAUNCH)) {
                int rowid = te.getRowId();
                Subscriber sub = notificationListModel.getSubscriberAt(rowid);
                if (actionid.equals(CMD_LAUNCH)) {
                    NotificationUIFactory.launchSubscriptionResource(ureq, getWindowControl(), sub);
                }
            }
        }
    }
}
Also used : TableEvent(org.olat.core.gui.components.table.TableEvent) Subscriber(org.olat.core.commons.services.notifications.Subscriber)

Aggregations

Subscriber (org.olat.core.commons.services.notifications.Subscriber)82 Publisher (org.olat.core.commons.services.notifications.Publisher)42 Identity (org.olat.core.id.Identity)30 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)26 ArrayList (java.util.ArrayList)24 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)22 HashSet (java.util.HashSet)18 Test (org.junit.Test)18 PublisherData (org.olat.core.commons.services.notifications.PublisherData)18 Date (java.util.Date)16 GET (javax.ws.rs.GET)16 Produces (javax.ws.rs.Produces)16 ICourse (org.olat.course.ICourse)16 CourseTreeVisitor (org.olat.course.run.userview.CourseTreeVisitor)16 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)16 SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)10 Roles (org.olat.core.id.Roles)10 FOCourseNode (org.olat.course.nodes.FOCourseNode)10 List (java.util.List)8 Locale (java.util.Locale)8