Package org.olat.ims.qti.editor

Source Code of org.olat.ims.qti.editor.AssessmentController

/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/

package org.olat.ims.qti.editor;

import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.Component;
import org.olat.core.gui.components.tabbedpane.TabbedPane;
import org.olat.core.gui.components.velocity.VelocityContainer;
import org.olat.core.gui.control.ControllerEventListener;
import org.olat.core.gui.control.Event;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.gui.control.generic.tabbable.TabbableDefaultController;
import org.olat.core.gui.translator.Translator;
import org.olat.ims.qti.editor.beecom.objects.Assessment;
import org.olat.ims.qti.editor.beecom.objects.Control;
import org.olat.ims.qti.editor.beecom.objects.Duration;
import org.olat.ims.qti.editor.beecom.objects.OutcomesProcessing;

/**
* Initial Date: Oct 21, 2004 <br>
*
* @author mike
*/
public class AssessmentController extends TabbableDefaultController implements ControllerEventListener {
 
  private VelocityContainer main;
 
  private Assessment assessment;
  private QTIEditorPackage qtiPackage;
  private boolean surveyMode = false;
  private boolean restrictedEdit;

  /**
   * @param assessment
   * @param qtiPackage
   * @param trnsltr
   * @param wControl
   */
  public AssessmentController(Assessment assessment, QTIEditorPackage qtiPackage, UserRequest ureq, WindowControl wControl,
      boolean restrictedEdit) {
    super(ureq, wControl);

    this.restrictedEdit = restrictedEdit;
    this.assessment = assessment;
    this.qtiPackage = qtiPackage;
       
    main = this.createVelocityContainer("tab_assess");
    main.contextPut("assessment", assessment);
    main.contextPut("mediaBaseURL", qtiPackage.getMediaBaseURL());
    main.contextPut("control", QTIEditHelper.getControl(assessment));
    main.contextPut("isRestrictedEdit", restrictedEdit ? Boolean.TRUE : Boolean.FALSE);
    surveyMode = qtiPackage.getQTIDocument().isSurvey();
    main.contextPut("isSurveyMode", surveyMode ? "true" : "false");

    if (!surveyMode && !restrictedEdit) {
      if (assessment.getDuration() != null) main.contextPut("duration", assessment.getDuration());
    }

    // Adding outcomes processing parameters
    OutcomesProcessing outcomesProcessing = assessment.getOutcomes_processing();
    if (outcomesProcessing == null) {
      main.contextPut(OutcomesProcessing.CUTVALUE, "0.0");
    } else {
      main.contextPut(OutcomesProcessing.CUTVALUE, outcomesProcessing.getField(OutcomesProcessing.CUTVALUE));
    }   
    this.putInitialPanel(main);
  }

  /**
   * @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)
   */
  public void event(UserRequest ureq, Component source, Event event) {
    if (source == main) {
      if (event.getCommand().equals("sao")) { // asessment options submitted
        // Handle all data that is useless in survey mode
        String newTitle = ureq.getParameter("title");
        String oldTitle = assessment.getTitle();
        boolean hasTitleChange = newTitle != null && !newTitle.equals(oldTitle);
        String newObjectives = ureq.getParameter("objectives");
        String oldObjectives = assessment.getObjectives();
        boolean hasObjectivesChange = newObjectives != null && !newObjectives.equals(oldObjectives);
        NodeBeforeChangeEvent nce = new NodeBeforeChangeEvent();
        if (hasTitleChange) {
          nce.setNewTitle(newTitle);
        }
        if (hasObjectivesChange) {
          nce.setNewObjectives(newObjectives);
        }
        if (hasTitleChange || hasObjectivesChange) {
          // create a memento first
          fireEvent(ureq, nce);
          // then apply changes
          assessment.setTitle(newTitle);
          assessment.setObjectives(newObjectives);
        }
        //
        if (!surveyMode && !restrictedEdit) {
          Control tmpControl = (Control) QTIEditHelper.getControl(assessment);
          boolean oldInheritControls = assessment.isInheritControls();
          boolean newInheritControls = ureq.getParameter("inheritswitch").equals("Yes");
          assessment.setInheritControls(newInheritControls);

          String feedbackswitchTmp = ureq.getParameter("feedbackswitch");
          String hintswitchTmp = ureq.getParameter("hintswitch");
          String solutionswitchTmp = ureq.getParameter("solutionswitch");
          tmpControl.setSwitches(feedbackswitchTmp, hintswitchTmp, solutionswitchTmp);
          if (tmpControl.getHint() != Control.CTRL_UNDEF || tmpControl.getHint() != Control.CTRL_UNDEF
              || tmpControl.getSolution() != Control.CTRL_UNDEF) assessment.setInheritControls(true);

          if (oldInheritControls && !newInheritControls) {
            tmpControl.setSwitches(Control.CTRL_UNDEF, Control.CTRL_UNDEF, Control.CTRL_UNDEF);
            assessment.setInheritControls(false);
          }

          OutcomesProcessing outcomesProcessing = assessment.getOutcomes_processing();
          if (outcomesProcessing == null) {
            // Create outcomes processing object if it doesn't already exist.
            // Happens
            // when creating a new assessment
            outcomesProcessing = new OutcomesProcessing();
            assessment.setOutcomes_processing(outcomesProcessing);
          }
          String cutval = ureq.getParameter(OutcomesProcessing.CUTVALUE);
          try {
            Float.parseFloat(cutval);
          } catch (NumberFormatException nfe) {
            cutval = "0.0";           
            this.showWarning("error.cutval");
          }
          outcomesProcessing.setField(OutcomesProcessing.CUTVALUE, cutval);
          main.contextPut(OutcomesProcessing.CUTVALUE, cutval);

          if (ureq.getParameter("duration").equals("Yes")) {
            String durationMin = ureq.getParameter("duration_min");
            String durationSec = ureq.getParameter("duration_sec");
            try {
              Integer.parseInt(durationMin);
              int sec = Integer.parseInt(durationSec);
              if (sec > 60) throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
              durationMin = "0";
              durationSec = "0";             
              this.showWarning("error.duration");
            }
            Duration d = new Duration(durationMin, durationSec);
            assessment.setDuration(d);
            main.contextPut("duration", assessment.getDuration());
          } else {
            assessment.setDuration(null);
            main.contextRemove("duration");
          }
        }
        qtiPackage.serializeQTIDocument();
      }
    }
  }

  /**
   * @see org.olat.core.gui.control.DefaultController#doDispose(boolean)
   */
  protected void doDispose() {
    main = null;   
  }

  /**
   * @see org.olat.core.gui.control.generic.tabbable.TabbableController#addTabs(org.olat.core.gui.components.TabbedPane)
   */
  public void addTabs(TabbedPane tabbedPane) {
    tabbedPane.addTab(translate(surveyMode ? "tab.survey" : "tab.assessment"), main);
  }

}
TOP

Related Classes of org.olat.ims.qti.editor.AssessmentController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.