use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class InitialAttemptsRuleEditor method initForm.
@Override
public FormItem initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
String page = Util.getPackageVelocityRoot(this.getClass()) + "/initial_attempts.html";
String id = Long.toString(CodeHelper.getRAMUniqueID());
Translator trans = formLayout.getTranslator();
FormLayoutContainer ruleCont = FormLayoutContainer.createCustomFormLayout("attempts.".concat(id), formLayout.getTranslator(), page);
ruleCont.setRootForm(formLayout.getRootForm());
formLayout.add(ruleCont);
ruleCont.getFormItemComponent().contextPut("id", id);
ICourse course = CourseFactory.loadCourse(entry);
String currentValue = null;
String currentUnit = null;
String currentCourseNode = null;
if (rule instanceof ReminderRuleImpl) {
ReminderRuleImpl r = (ReminderRuleImpl) rule;
currentUnit = r.getRightUnit();
currentValue = r.getRightOperand();
currentCourseNode = r.getLeftOperand();
}
List<CourseNode> attemptableNodes = new ArrayList<>();
searchAttemptableNodes(course.getRunStructure().getRootNode(), attemptableNodes);
String[] nodeKeys = new String[attemptableNodes.size()];
String[] nodeValues = new String[attemptableNodes.size()];
for (int i = 0; i < attemptableNodes.size(); i++) {
CourseNode attemptableNode = attemptableNodes.get(i);
nodeKeys[i] = attemptableNode.getIdent();
nodeValues[i] = attemptableNode.getShortTitle() + " ( " + attemptableNode.getIdent() + " )";
}
courseNodeEl = uifactory.addDropdownSingleselect("coursenodes.".concat(id), null, ruleCont, nodeKeys, nodeValues, null);
courseNodeEl.setDomReplacementWrapperRequired(false);
boolean nodeSelected = false;
if (currentCourseNode != null) {
for (String nodeKey : nodeKeys) {
if (currentCourseNode.equals(nodeKey)) {
courseNodeEl.select(nodeKey, true);
nodeSelected = true;
}
}
}
if (!nodeSelected && nodeKeys.length > 0) {
courseNodeEl.select(nodeKeys[0], true);
}
if (StringHelper.containsNonWhitespace(currentCourseNode) && !nodeSelected) {
courseNodeEl.setErrorKey("error.course.node.found", null);
}
valueEl = uifactory.addTextElement("attemptvalue.".concat(id), null, 128, currentValue, ruleCont);
valueEl.setDomReplacementWrapperRequired(false);
valueEl.setDisplaySize(3);
String[] unitValues = new String[] { trans.translate(LaunchUnit.day.name()), trans.translate(LaunchUnit.week.name()), trans.translate(LaunchUnit.month.name()), trans.translate(LaunchUnit.year.name()) };
unitEl = uifactory.addDropdownSingleselect("attemptunit.".concat(id), null, ruleCont, unitKeys, unitValues, null);
unitEl.setDomReplacementWrapperRequired(false);
boolean selected = false;
if (currentUnit != null) {
for (String unitKey : unitKeys) {
if (currentUnit.equals(unitKey)) {
unitEl.select(unitKey, true);
selected = true;
}
}
}
if (!selected) {
unitEl.select(unitKeys[1], true);
}
return ruleCont;
}
use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class CourseSite method createController.
@Override
protected MainLayoutController createController(UserRequest ureq, WindowControl wControl, SiteConfiguration config) {
RepositoryManager rm = RepositoryManager.getInstance();
RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry entry = rm.lookupRepositoryEntryBySoftkey(repositorySoftKey, false);
if (entry == null) {
return getAlternativeController(ureq, wControl, config);
}
MainLayoutController c;
ICourse course = CourseFactory.loadCourse(entry);
UserSession usess = ureq.getUserSession();
// course-launch-state depending course-settings
RepositoryEntrySecurity reSecurity = rm.isAllowed(ureq, entry);
boolean isAllowedToLaunch = reSecurity.canLaunch();
boolean hasAccess = false;
if (isAllowedToLaunch) {
// either check with securityCallback or use access-settings from course-nodes
if (siteSecCallback != null) {
hasAccess = siteSecCallback.isAllowedToLaunchSite(ureq);
} else if (usess.isInAssessmentModeProcess() && !usess.matchLockResource(course)) {
hasAccess = false;
} else {
// check within course: accessibility of course root node
CourseNode rootNode = course.getRunStructure().getRootNode();
UserCourseEnvironmentImpl uce = new UserCourseEnvironmentImpl(ureq.getUserSession().getIdentityEnvironment(), course.getCourseEnvironment());
NodeEvaluation nodeEval = rootNode.eval(uce.getConditionInterpreter(), new TreeEvaluation(), new VisibleTreeFilter());
boolean mayAccessWholeTreeUp = NavigationHandler.mayAccessWholeTreeUp(nodeEval);
hasAccess = mayAccessWholeTreeUp && nodeEval.isVisible();
}
}
// load course (admins always see content) or alternative controller if course is not launchable
if (hasAccess || usess.getRoles().isOLATAdmin()) {
rs.incrementLaunchCounter(entry);
// build up the context path for linked course
WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ureq, entry, new StateSite(this), wControl, true);
CourseRuntimeController runCtr = new CourseRuntimeController(ureq, bwControl, entry, reSecurity, new RuntimeControllerCreator() {
@Override
public Controller create(UserRequest uureq, WindowControl wwControl, TooledStackedPanel toolbarPanel, RepositoryEntry re, RepositoryEntrySecurity security, AssessmentMode assessmentMode) {
return new RunMainController(uureq, wwControl, toolbarPanel, CourseFactory.loadCourse(re), re, security, assessmentMode);
}
}, false, true);
// Configure run controller
// a: don't show close link, is opened as site not tab
runCtr.setCourseCloseEnabled(false);
// b: don't show toolbar
if (!showToolController) {
runCtr.setToolControllerEnabled(false);
}
c = runCtr;
} else {
// access restricted (not in group / author) -> show controller
// defined in olat_extensions (type autoCreator)
c = getAlternativeController(ureq, wControl, config);
}
return c;
}
use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class AttemptsRuleSPI method filter.
@Override
public void filter(RepositoryEntry entry, List<Identity> identities, ReminderRule rule) {
if (rule instanceof ReminderRuleImpl) {
ReminderRuleImpl r = (ReminderRuleImpl) rule;
String nodeIdent = r.getLeftOperand();
String operator = r.getOperator();
int value = Integer.parseInt(r.getRightOperand());
ICourse course = CourseFactory.loadCourse(entry);
CourseNode courseNode = course.getRunStructure().getNode(nodeIdent);
if (courseNode == null) {
identities.clear();
log.error("Attempts rule in course " + entry.getKey() + " (" + entry.getDisplayname() + ") is missing a course element");
return;
}
Map<Long, Integer> attempts = helperDao.getAttempts(entry, courseNode, identities);
for (Iterator<Identity> identityIt = identities.iterator(); identityIt.hasNext(); ) {
Identity identity = identityIt.next();
Integer attempt = attempts.get(identity.getKey());
if (attempt == null) {
attempt = 0;
}
if (!evaluateAttempt(attempt.intValue(), operator, value)) {
identityIt.remove();
}
}
}
}
use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class QTI21ArchiveFormat method exportCourseElement.
/**
* @param exportStream
*/
public void exportCourseElement(ZipOutputStream exportStream) {
ICourse course = CourseFactory.loadCourse(searchParams.getCourseEntry());
courseNode = course.getRunStructure().getNode(searchParams.getNodeIdent());
String label = StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + "_" + Formatter.formatDatetimeWithMinutes(new Date()) + ".xlsx";
exportCourseElement(label, exportStream);
}
use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class PortfolioServiceImpl method getAssessmentStatus.
@Override
public AssessmentEntryStatus getAssessmentStatus(Identity assessedIdentity, BinderRef binderRef) {
Binder binder = binderDao.loadByKey(binderRef.getKey());
RepositoryEntry entry = binder.getEntry();
AssessmentEntryStatus status = null;
if ("CourseModule".equals(entry.getOlatResource().getResourceableTypeName())) {
ICourse course = CourseFactory.loadCourse(entry);
CourseNode courseNode = course.getRunStructure().getNode(binder.getSubIdent());
if (courseNode instanceof PortfolioCourseNode) {
PortfolioCourseNode pfNode = (PortfolioCourseNode) courseNode;
UserCourseEnvironment userCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(assessedIdentity, course);
AssessmentEvaluation eval = pfNode.getUserScoreEvaluation(userCourseEnv);
status = eval.getAssessmentStatus();
}
} else {
OLATResource resource = ((BinderImpl) binder.getTemplate()).getOlatResource();
RepositoryEntry referenceEntry = repositoryService.loadByResourceKey(resource.getKey());
AssessmentEntry assessmentEntry = assessmentService.getOrCreateAssessmentEntry(assessedIdentity, null, binder.getEntry(), binder.getSubIdent(), referenceEntry);
status = assessmentEntry.getAssessmentStatus();
}
return status;
}
Aggregations