/**
   * @param ureq
   * @param subscriptionContext
   * @param publisherData
   */
  public ContextualSubscriptionController(
      UserRequest ureq,
      WindowControl wControl,
      SubscriptionContext subscriptionContext,
      PublisherData publisherData) {
    super(ureq, wControl);
    this.subscriptionContext = subscriptionContext;
    this.publisherData = publisherData;
    isNewNotificationService = useNewNotificationService(publisherData);

    myContent = createVelocityContainer("consubs");

    if (subscriptionContext == null) {
      setInitialComponent(new Panel("empty:nosubscription"));
      return;
    }

    detailsPanel = new Panel("subscription_detail");
    allPanel = new Panel("subscription_all");

    subscribeButton = LinkFactory.createButtonSmall("command.subscribe", myContent, this);
    // subscribeButton.setCustomEnabledLinkCSS("b_noti_subscribe_link");

    this.unsubscribeButton = LinkFactory.createButtonSmall("command.unsubscribe", myContent, this);
    // unsubscribeButton.setCustomEnabledLinkCSS("b_noti_unsubscribe_link");

    if (isNewNotificationService) {
      log.info(
          "Notification-Service: " + publisherData.getType() + " is running with NEW notification");
      newNotificationService = getService(LearnServices.notificationLearnService);
      subscriptionContext.setContextId(
          getRepositoryService()
              .getRepositoryEntryIdFromResourceable(
                  subscriptionContext.getResId(),
                  subscriptionContext.getResName())); // TODO: LD: move this at construction of
      // subscriptionContext
      newSubscriptionContext =
          newNotificationService.createNotificationSubscriptionContext(
              ureq.getIdentity(), subscriptionContext, publisherData);
      isSubscribed = newNotificationService.isSubscribed(newSubscriptionContext);
    } else {
      log.info(
          "Notification-Service: "
              + publisherData.getType()
              + " is running with LEGACY notification");
      notifManager = getNotificationService();
      // if subscribed, offer a unsubscribe button and vica versa.
      isSubscribed = notifManager.isSubscribed(ureq.getIdentity(), subscriptionContext);
    }

    updateUI();
    myContent.put("detailsPanel", detailsPanel);
    allPanel.setContent(myContent);
    putInitialPanel(allPanel);
  }
  /**
   * Sent notification mail for signalling that course creation was successful.
   *
   * @param ureq user request
   * @param config course configuration object
   * @return mailer result object
   */
  public static final MailerResult sentNotificationMail(
      final UserRequest ureq, final CourseCreationConfiguration config) {
    final Translator translator =
        PackageUtil.createPackageTranslator(CourseCreationMailHelper.class, ureq.getLocale());
    log.info(
        "Course creation with wizard finished. [User: "******"] [Course name: "
            + config.getCourseTitle()
            + "]");
    final String subject =
        translator.translate("mail.subject", new String[] {config.getCourseTitle()});
    String body = translator.translate("mail.body.0", new String[] {config.getCourseTitle()});
    body += translator.translate("mail.body.1");
    body += translator.translate("mail.body.2", new String[] {config.getExtLink()});
    body += translator.translate("mail.body.3");
    body += translator.translate("mail.body.4");

    int counter = 1;
    if (config.isCreateSinglePage()) {
      body += translator.translate("mail.body.4.2", new String[] {Integer.toString(++counter)});
    }
    if (config.isCreateEnrollment()) {
      body += translator.translate("mail.body.4.3", new String[] {Integer.toString(++counter)});
    }
    if (config.isCreateDownloadFolder()) {
      body += translator.translate("mail.body.4.4", new String[] {Integer.toString(++counter)});
    }
    if (config.isCreateForum()) {
      body += translator.translate("mail.body.4.5", new String[] {Integer.toString(++counter)});
    }
    if (config.isCreateContactForm()) {
      body += translator.translate("mail.body.4.6", new String[] {Integer.toString(++counter)});
    }
    body += translator.translate("mail.body.5");
    body += translator.translate("mail.body.6");
    body += translator.translate("mail.body.greetings");

    final MailTemplate template =
        new MailTemplate(
            subject, body, MailTemplateHelper.getMailFooter(ureq.getIdentity(), null), null) {
          @Override
          @SuppressWarnings("unused")
          public void putVariablesInMailContext(
              final VelocityContext context, final OLATPrincipal identity) {
            // nothing to do
          }
        };
    return MailerWithTemplate.getInstance()
        .sendMail(ureq.getIdentity(), null, null, template, null);
  }
 @Override
 protected void event(UserRequest ureq, Component source, Event event) {
   if (source == subscribeButton) {
     if (isNewNotificationService) {
       subscribeToNewNotificationService();
     } else {
       notifManager.subscribe(ureq.getIdentity(), subscriptionContext, publisherData);
     }
     isSubscribed = true;
     updateUI();
     fireEvent(ureq, event);
   } else if (source == unsubscribeButton) {
     if (isNewNotificationService) {
       unsubscribeFromNewNotificationService();
     } else {
       notifManager.unsubscribe(ureq.getIdentity(), subscriptionContext);
     }
     isSubscribed = false;
     updateUI();
     fireEvent(ureq, event);
   }
 }
Example #4
0
  @Override
  protected void event(final UserRequest urequest, final Controller source, final Event event) {
    if (source == displayController) {
      if (event instanceof IQSubmittedEvent) {
        final IQSubmittedEvent se = (IQSubmittedEvent) event;
        final AssessmentManager am = userCourseEnv.getCourseEnvironment().getAssessmentManager();

        // Save results in case of test
        if (type.equals(AssessmentInstance.QMD_ENTRY_TYPE_ASSESS)) {
          // update scoring overview for the user in the current course
          final Float score = new Float(se.getScore());
          final Boolean passed = new Boolean(se.isPassed());
          final ScoreEvaluation sceval =
              new ScoreEvaluation(score, passed, new Long(se.getAssessmentID()));
          final AssessableCourseNode acn =
              (AssessableCourseNode) courseNode; // assessment nodes are assesable
          final boolean incrementUserAttempts = true;
          acn.updateUserScoreEvaluation(
              sceval, userCourseEnv, urequest.getIdentity(), incrementUserAttempts);
          // userCourseEnv.getScoreAccounting().scoreInfoChanged(acn, sceval);
          exposeUserTestDataToVC(urequest);

          // Mark publisher for notifications
          final Long courseId = userCourseEnv.getCourseEnvironment().getCourseResourceableId();
          notificationHandler.markPublisherNews(urequest.getIdentity(), courseId);
          if (!assessmentStopped) {
            assessmentStopped = true;
            final AssessmentEvent assessmentStoppedEvent =
                new AssessmentEvent(AssessmentEvent.TYPE.STOPPED, userSession);
            singleUserEventCenter.deregisterFor(this, assessmentInstanceOres);
            singleUserEventCenter.fireEventToListenersOf(
                assessmentStoppedEvent, assessmentEventOres);
          }
        }
        // Save results in case of questionnaire
        else if (type.equals(AssessmentInstance.QMD_ENTRY_TYPE_SURVEY)) {
          // save number of attempts
          // although this is not an assessable node we still use the assessment
          // manager since this one uses caching
          am.incrementNodeAttempts(courseNode, urequest.getIdentity(), userCourseEnv);
          exposeUserQuestionnaireDataToVC();
          getWindowControl().pop();
        }
        // Don't save results in case of self-test
        // but do safe attempts !
        else if (type.equals(AssessmentInstance.QMD_ENTRY_TYPE_SELF)) {
          am.incrementNodeAttempts(courseNode, urequest.getIdentity(), userCourseEnv);
        }
      } else if (event.equals(Event.DONE_EVENT)) {
        getWindowControl().pop();
        if (type.equals(AssessmentInstance.QMD_ENTRY_TYPE_ASSESS) && !assessmentStopped) {
          assessmentStopped = true;
          final AssessmentEvent assessmentStoppedEvent =
              new AssessmentEvent(AssessmentEvent.TYPE.STOPPED, userSession);
          singleUserEventCenter.deregisterFor(this, assessmentInstanceOres);
          singleUserEventCenter.fireEventToListenersOf(assessmentStoppedEvent, assessmentEventOres);
        }
        fireEvent(urequest, Event.DONE_EVENT);
      }
    }
  }
Example #5
0
  @Override
  protected void event(final UserRequest ureq, final Component source, final Event event) {
    if (source == startButton && startButton.isEnabled()) {
      final long callingResId =
          userCourseEnv.getCourseEnvironment().getCourseResourceableId().longValue();
      final String callingResDetail = courseNode.getIdent();
      removeAsListenerAndDispose(displayController);
      final Controller returnController =
          IQManager.getInstance()
              .createIQDisplayController(
                  modConfig, secCallback, ureq, getWindowControl(), callingResId, callingResDetail);
      /*
       * either returnController is a MessageController or it is a IQDisplayController this should not serve as pattern to be copy&pasted. FIXME:2008-11-21:pb
       * INTRODUCED because of read/write QTI Lock solution for scalability II, 6.1.x Release
       */
      if (returnController instanceof IQDisplayController) {
        displayController = (IQDisplayController) returnController;
        listenTo(displayController);
        if (displayController.isReady()) {
          // in case displayController was unable to initialize, a message was set by
          // displayController
          // this is the case if no more attempts or security check was unsuccessfull
          final LayoutMain3ColsController layoutCtr =
              new LayoutMain3ColsController(
                  ureq,
                  getWindowControl(),
                  null,
                  null,
                  displayController.getInitialComponent(),
                  null);
          listenTo(layoutCtr); // autodispose

          // need to wrap a course restart controller again, because IQDisplay
          // runs on top of GUIStack
          final ICourse course = CourseFactory.loadCourse(callingResId);
          final RepositoryEntry courseRepositoryEntry =
              RepositoryServiceImpl.getInstance().lookupRepositoryEntry(course, true);
          final Panel empty = new Panel("empty"); // empty panel set as "menu" and "tool"
          final Controller courseCloser =
              CourseFactory.createDisposedCourseRestartController(
                  ureq, getWindowControl(), courseRepositoryEntry.getResourceableId());
          final Controller disposedRestartController =
              new LayoutMain3ColsController(
                  ureq,
                  getWindowControl(),
                  empty,
                  empty,
                  courseCloser.getInitialComponent(),
                  "disposed course whily in iqRun" + callingResId);
          layoutCtr.setDisposedMessageController(disposedRestartController);

          getWindowControl().pushToMainArea(layoutCtr.getInitialComponent());
          if (modConfig
              .get(IQEditController.CONFIG_KEY_TYPE)
              .equals(AssessmentInstance.QMD_ENTRY_TYPE_ASSESS)) {
            assessmentStopped = false;
            singleUserEventCenter.registerFor(this, getIdentity(), assessmentInstanceOres);
            singleUserEventCenter.fireEventToListenersOf(
                new AssessmentEvent(AssessmentEvent.TYPE.STARTED, ureq.getUserSession()),
                assessmentEventOres);
          }
        } // endif isReady
      } else {
        // -> qti file was locked -> show info message
        // user must click again on course node to activate
        mainPanel.pushContent(returnController.getInitialComponent());
      }
    } else if (source == showResultsButton) {
      final AssessmentManager am = userCourseEnv.getCourseEnvironment().getAssessmentManager();
      Long assessmentID = am.getAssessmentID(courseNode, ureq.getIdentity());
      if (assessmentID == null) {
        // fallback solution: if the assessmentID is not available via AssessmentManager than try to
        // get it via IQManager
        final long callingResId =
            userCourseEnv.getCourseEnvironment().getCourseResourceableId().longValue();
        final String callingResDetail = courseNode.getIdent();
        assessmentID =
            IQManager.getInstance()
                .getLastAssessmentID(ureq.getIdentity(), callingResId, callingResDetail);
      }
      if (assessmentID != null && !assessmentID.equals("")) {
        final Document doc =
            IQManager.getInstance()
                .getResultsReportingFromFile(ureq.getIdentity(), type, assessmentID);
        // StringBuilder resultsHTML =
        // LocalizedXSLTransformer.getInstance(ureq.getLocale()).renderResults(doc);
        final String summaryConfig = (String) modConfig.get(IQEditController.CONFIG_KEY_SUMMARY);
        final int summaryType = AssessmentInstance.getSummaryType(summaryConfig);
        final String resultsHTML =
            IQManager.getInstance().transformResultsReporting(doc, ureq.getLocale(), summaryType);
        myContent.contextPut("displayreporting", resultsHTML);
        myContent.contextPut("resreporting", resultsHTML);
        myContent.contextPut("showResults", Boolean.TRUE);
      }
    } else if (source == hideResultsButton) {
      myContent.contextPut("showResults", Boolean.FALSE);
    }
  }