Search in sources :

Example 71 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

the class SimpleMessageModule method enableSmsUserProperty.

private void enableSmsUserProperty() {
    List<UserPropertyHandler> handlers = usrPropCfgMng.getUserPropertiesConfigObject().getPropertyHandlers();
    UserPropertyHandler smsHandler = null;
    UserPropertyHandler mobileHandler = null;
    for (UserPropertyHandler handler : handlers) {
        if (UserConstants.SMSTELMOBILE.equals(handler.getName())) {
            smsHandler = handler;
        } else if (UserConstants.TELMOBILE.equals(handler.getName())) {
            mobileHandler = handler;
        }
    }
    if (smsHandler != null) {
        UserPropertyUsageContext context = usrPropCfgMng.getUserPropertiesConfigObject().getUsageContexts().get("org.olat.user.ProfileFormController");
        if (!context.contains(smsHandler)) {
            if (mobileHandler == null) {
                context.addPropertyHandler(smsHandler);
            } else {
                int index = context.getPropertyHandlers().indexOf(mobileHandler);
                context.addPropertyHandler(index + 1, smsHandler);
            }
        }
    }
}
Also used : UserPropertyUsageContext(org.olat.user.propertyhandlers.UserPropertyUsageContext) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 72 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

the class MailHelper method getMailFooter.

/**
 * Create a mail footer for the given locale and sender.
 *
 * @param locale Defines language of footer text. If null, the systems default
 *          locale is used
 * @param sender Details about sender embedded in mail footer. If null no such
 *          details are attached to the footer
 * @return The mail footer as string
 */
public static String getMailFooter(Locale locale, Identity sender) {
    if (locale == null) {
        locale = I18nModule.getDefaultLocale();
    }
    Translator trans = getTranslator(locale);
    if (sender == null) {
        // mail sent by plattform configured sender address
        return trans.translate("footer.no.userdata", new String[] { Settings.getServerContextPathURI() });
    }
    // mail sent by a system user
    User user = sender.getUser();
    // FXOLAT-356: separate context for mail footer
    // username / server-url are always first [0], [1].
    UserManager um = UserManager.getInstance();
    List<UserPropertyHandler> userPropertyHandlers = um.getUserPropertyHandlersFor(MailHelper.class.getCanonicalName(), false);
    List<String> userPropList = new ArrayList<String>(userPropertyHandlers.size() + 2);
    String email = UserManager.getInstance().getUserDisplayEmail(sender, locale);
    userPropList.add(email);
    userPropList.add(Settings.getServerContextPathURI());
    for (Iterator<UserPropertyHandler> iterator = userPropertyHandlers.iterator(); iterator.hasNext(); ) {
        userPropList.add(iterator.next().getUserProperty(user, locale));
    }
    // add empty strings to prevent non-replaced wildcards like "{5}" etc. in emails.
    while (userPropList.size() < 15) {
        userPropList.add("");
    }
    String[] userPropArr = userPropList.toArray(new String[userPropList.size()]);
    for (int i = userPropArr.length; i-- > 0; ) {
        if (userPropArr[i] == null) {
            userPropArr[i] = "";
        }
    }
    return trans.translate("footer.with.userdata", userPropArr);
}
Also used : User(org.olat.core.id.User) Translator(org.olat.core.gui.translator.Translator) UserManager(org.olat.user.UserManager) ArrayList(java.util.ArrayList) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 73 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

the class ScoreAccountingHelper method createCourseResultsOverviewXMLTable.

/**
 * The results from assessable nodes are written to one row per user into an excel-sheet. An
 * assessable node will only appear if it is producing at least one of the
 * following variables: score, passed, attempts, comments.
 *
 * @param identities The list of identities which results need to be archived.
 * @param myNodes The assessable nodes to archive.
 * @param course The course.
 * @param locale The locale.
 * @param bos The output stream (which will be closed at the end, if you use a zip stream don't forget to shield it).
 */
public static void createCourseResultsOverviewXMLTable(List<Identity> identities, List<AssessableCourseNode> myNodes, ICourse course, Locale locale, OutputStream bos) {
    OpenXMLWorkbook workbook = new OpenXMLWorkbook(bos, 1);
    OpenXMLWorksheet sheet = workbook.nextWorksheet();
    sheet.setHeaderRows(2);
    int headerColCnt = 0;
    Translator t = Util.createPackageTranslator(ScoreAccountingArchiveController.class, locale);
    String sequentialNumber = t.translate("column.header.seqnum");
    String login = t.translate("column.header.businesspath");
    // user properties are dynamic
    String sc = t.translate("column.header.score");
    String pa = t.translate("column.header.passed");
    String co = t.translate("column.header.comment");
    String cco = t.translate("column.header.coachcomment");
    String at = t.translate("column.header.attempts");
    String il = t.translate("column.header.initialLaunchDate");
    String slm = t.translate("column.header.scoreLastModified");
    String na = t.translate("column.field.notavailable");
    String mi = t.translate("column.field.missing");
    String yes = t.translate("column.field.yes");
    String no = t.translate("column.field.no");
    String submitted = t.translate("column.field.submitted");
    Row headerRow1 = sheet.newRow();
    headerRow1.addCell(headerColCnt++, sequentialNumber);
    headerRow1.addCell(headerColCnt++, login);
    // Initial launch date
    headerRow1.addCell(headerColCnt++, il);
    // get user property handlers for this export, translate using the fallback
    // translator configured in the property handler
    List<UserPropertyHandler> userPropertyHandlers = UserManager.getInstance().getUserPropertyHandlersFor(ScoreAccountingHelper.class.getCanonicalName(), true);
    t = UserManager.getInstance().getPropertyHandlerTranslator(t);
    for (UserPropertyHandler propertyHandler : userPropertyHandlers) {
        headerRow1.addCell(headerColCnt++, t.translate(propertyHandler.i18nColumnDescriptorLabelKey()));
    }
    int header1ColCnt = headerColCnt;
    for (AssessableCourseNode acNode : myNodes) {
        headerRow1.addCell(header1ColCnt++, acNode.getShortTitle());
        header1ColCnt += acNode.getType().equals("ita") ? 1 : 0;
        boolean scoreOk = acNode.hasScoreConfigured();
        boolean passedOk = acNode.hasPassedConfigured();
        boolean attemptsOk = acNode.hasAttemptsConfigured();
        boolean commentOk = acNode.hasCommentConfigured();
        if (scoreOk || passedOk || commentOk || attemptsOk) {
            header1ColCnt += scoreOk ? 1 : 0;
            header1ColCnt += passedOk ? 1 : 0;
            header1ColCnt += attemptsOk ? 1 : 0;
            // last modified
            header1ColCnt++;
            header1ColCnt += commentOk ? 1 : 0;
            // coach comment
            header1ColCnt++;
        }
        // column title
        header1ColCnt--;
    }
    int header2ColCnt = headerColCnt;
    Row headerRow2 = sheet.newRow();
    for (AssessableCourseNode acNode : myNodes) {
        if (acNode.getType().equals("ita")) {
            headerRow2.addCell(header2ColCnt++, submitted);
        }
        boolean scoreOk = acNode.hasScoreConfigured();
        boolean passedOk = acNode.hasPassedConfigured();
        boolean attemptsOk = acNode.hasAttemptsConfigured();
        boolean commentOk = acNode.hasCommentConfigured();
        if (scoreOk || passedOk || commentOk || attemptsOk) {
            if (scoreOk) {
                headerRow2.addCell(header2ColCnt++, sc);
            }
            if (passedOk) {
                headerRow2.addCell(header2ColCnt++, pa);
            }
            if (attemptsOk) {
                headerRow2.addCell(header2ColCnt++, at);
            }
            // last modified
            headerRow2.addCell(header2ColCnt++, slm);
            if (commentOk) {
                headerRow2.addCell(header2ColCnt++, co);
            }
            // coach comment
            headerRow2.addCell(header2ColCnt++, cco);
        }
    }
    // preload user properties cache
    CourseEnvironment courseEnvironment = course.getCourseEnvironment();
    int rowNumber = 0;
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm");
    UserCourseInformationsManager mgr = CoreSpringFactory.getImpl(UserCourseInformationsManager.class);
    OLATResource courseResource = courseEnvironment.getCourseGroupManager().getCourseResource();
    Map<Long, Date> firstTimes = mgr.getInitialLaunchDates(courseResource, identities);
    for (Identity identity : identities) {
        Row dataRow = sheet.newRow();
        int dataColCnt = 0;
        ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(identity);
        String uname = BusinessControlFactory.getInstance().getAsURIString(Collections.singletonList(ce), false);
        dataRow.addCell(dataColCnt++, ++rowNumber, null);
        dataRow.addCell(dataColCnt++, uname, null);
        if (firstTimes.containsKey(identity.getKey())) {
            dataRow.addCell(dataColCnt++, firstTimes.get(identity.getKey()), workbook.getStyles().getDateStyle());
        } else {
            dataRow.addCell(dataColCnt++, mi);
        }
        // add dynamic user properties
        for (UserPropertyHandler propertyHandler : userPropertyHandlers) {
            String value = propertyHandler.getUserProperty(identity.getUser(), t.getLocale());
            dataRow.addCell(dataColCnt++, (StringHelper.containsNonWhitespace(value) ? value : na));
        }
        // create a identenv with no roles, no attributes, no locale
        IdentityEnvironment ienv = new IdentityEnvironment();
        ienv.setIdentity(identity);
        UserCourseEnvironment uce = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
        ScoreAccounting scoreAccount = uce.getScoreAccounting();
        scoreAccount.evaluateAll();
        AssessmentManager am = course.getCourseEnvironment().getAssessmentManager();
        for (AssessableCourseNode acnode : myNodes) {
            boolean scoreOk = acnode.hasScoreConfigured();
            boolean passedOk = acnode.hasPassedConfigured();
            boolean attemptsOk = acnode.hasAttemptsConfigured();
            boolean commentOk = acnode.hasCommentConfigured();
            if (acnode.getType().equals("ita")) {
                String log = acnode.getUserLog(uce);
                String date = null;
                Date lastUploaded = null;
                try {
                    log = log.toLowerCase();
                    log = log.substring(0, log.lastIndexOf("submit"));
                    log = log.substring(log.lastIndexOf("date:"));
                    date = log.split("\n")[0].substring(6);
                    lastUploaded = df.parse(date);
                } catch (Exception e) {
                // 
                }
                if (lastUploaded != null) {
                    dataRow.addCell(dataColCnt++, lastUploaded, workbook.getStyles().getDateStyle());
                } else {
                    // date == null
                    dataRow.addCell(dataColCnt++, mi);
                }
            }
            if (scoreOk || passedOk || commentOk || attemptsOk) {
                ScoreEvaluation se = scoreAccount.evalCourseNode(acnode);
                if (scoreOk) {
                    Float score = se.getScore();
                    if (score != null) {
                        dataRow.addCell(dataColCnt++, AssessmentHelper.getRoundedScore(score), null);
                    } else {
                        // score == null
                        dataRow.addCell(dataColCnt++, mi);
                    }
                }
                if (passedOk) {
                    Boolean passed = se.getPassed();
                    if (passed != null) {
                        String yesno;
                        if (passed.booleanValue()) {
                            yesno = yes;
                        } else {
                            yesno = no;
                        }
                        dataRow.addCell(dataColCnt++, yesno);
                    } else {
                        // passed == null
                        dataRow.addCell(dataColCnt++, mi);
                    }
                }
                if (attemptsOk) {
                    Integer attempts = am.getNodeAttempts(acnode, identity);
                    int a = attempts == null ? 0 : attempts.intValue();
                    dataRow.addCell(dataColCnt++, a, null);
                }
                Date lastModified = am.getScoreLastModifiedDate(acnode, identity);
                if (lastModified != null) {
                    dataRow.addCell(dataColCnt++, lastModified, workbook.getStyles().getDateStyle());
                } else {
                    dataRow.addCell(dataColCnt++, mi);
                }
                if (commentOk) {
                    // Comments for user
                    String comment = am.getNodeComment(acnode, identity);
                    if (comment != null) {
                        dataRow.addCell(dataColCnt++, comment);
                    } else {
                        dataRow.addCell(dataColCnt++, mi);
                    }
                }
                // Always export comments for tutors
                String coachComment = am.getNodeCoachComment(acnode, identity);
                if (coachComment != null) {
                    dataRow.addCell(dataColCnt++, coachComment);
                } else {
                    dataRow.addCell(dataColCnt++, mi);
                }
            }
        }
    }
    // min. max. informations
    boolean first = true;
    for (AssessableCourseNode acnode : myNodes) {
        if (!acnode.hasScoreConfigured()) {
            // only show min/max/cut legend when score configured
            continue;
        }
        if (first) {
            sheet.newRow().addCell(0, "");
            sheet.newRow().addCell(0, "");
            sheet.newRow().addCell(0, t.translate("legend"));
            sheet.newRow().addCell(0, "");
            first = false;
        }
        String minVal;
        String maxVal;
        String cutVal;
        if (acnode instanceof STCourseNode || !acnode.hasScoreConfigured()) {
            minVal = maxVal = cutVal = "-";
        } else {
            minVal = acnode.getMinScoreConfiguration() == null ? "-" : AssessmentHelper.getRoundedScore(acnode.getMinScoreConfiguration());
            maxVal = acnode.getMaxScoreConfiguration() == null ? "-" : AssessmentHelper.getRoundedScore(acnode.getMaxScoreConfiguration());
            if (acnode.hasPassedConfigured()) {
                cutVal = acnode.getCutValueConfiguration() == null ? "-" : AssessmentHelper.getRoundedScore(acnode.getCutValueConfiguration());
            } else {
                cutVal = "-";
            }
        }
        sheet.newRow().addCell(0, acnode.getShortTitle());
        Row minRow = sheet.newRow();
        minRow.addCell(2, "minValue");
        minRow.addCell(3, minVal);
        Row maxRow = sheet.newRow();
        maxRow.addCell(2, "maxValue");
        maxRow.addCell(3, maxVal);
        Row cutRow = sheet.newRow();
        cutRow.addCell(2, "cutValue");
        cutRow.addCell(3, cutVal);
    }
    IOUtils.closeQuietly(workbook);
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) AssessmentManager(org.olat.course.assessment.AssessmentManager) ContextEntry(org.olat.core.id.context.ContextEntry) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) Translator(org.olat.core.gui.translator.Translator) STCourseNode(org.olat.course.nodes.STCourseNode) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) ScoreAccounting(org.olat.course.run.scoring.ScoreAccounting) UserCourseInformationsManager(org.olat.course.assessment.manager.UserCourseInformationsManager) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) OLATResource(org.olat.resource.OLATResource) Date(java.util.Date) IOException(java.io.IOException) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) SimpleDateFormat(java.text.SimpleDateFormat)

Example 74 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

the class EfficiencyStatementArchiver method appendIdentityIntro.

private void appendIdentityIntro(StringBuilder buf, Identity identity) {
    for (UserPropertyHandler propertyHandler : userPropertyHandler) {
        String label = translator.translate(propertyHandler.i18nColumnDescriptorLabelKey());
        String value = propertyHandler.getUserProperty(identity.getUser(), translator.getLocale());
        appendLine(buf, label, (StringHelper.containsNonWhitespace(value) ? value : ""));
    }
}
Also used : UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 75 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

the class CertificatePDFFormWorker method fillUserProperties.

private void fillUserProperties(PDAcroForm acroForm) throws IOException {
    User user = identity.getUser();
    List<UserPropertyHandler> userPropertyHandlers = userManager.getAllUserPropertyHandlers();
    for (UserPropertyHandler handler : userPropertyHandlers) {
        String propertyName = handler.getName();
        String value = handler.getUserProperty(user, null);
        fillField(propertyName, value, acroForm);
    }
    String fullName = userManager.getUserDisplayName(identity);
    fillField("fullName", fullName, acroForm);
    String firstName = user.getProperty(UserConstants.FIRSTNAME, null);
    String lastName = user.getProperty(UserConstants.LASTNAME, null);
    StringBuilder firstNameLastName = new StringBuilder();
    StringBuilder lastNameFirstName = new StringBuilder();
    if (StringHelper.containsNonWhitespace(firstName)) {
        firstNameLastName.append(firstName);
    }
    if (StringHelper.containsNonWhitespace(lastName)) {
        if (firstNameLastName.length() > 0)
            firstNameLastName.append(" ");
        firstNameLastName.append(lastName);
        lastNameFirstName.append(lastName);
    }
    if (StringHelper.containsNonWhitespace(firstName)) {
        if (lastNameFirstName.length() > 0)
            lastNameFirstName.append(" ");
        lastNameFirstName.append(firstName);
    }
    fillField("firstNameLastName", firstNameLastName.toString(), acroForm);
    fillField("lastNameFirstName", lastNameFirstName.toString(), acroForm);
}
Also used : User(org.olat.core.id.User) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Aggregations

UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)319 Identity (org.olat.core.id.Identity)84 DefaultFlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)74 FlexiTableColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel)70 ArrayList (java.util.ArrayList)62 FormItem (org.olat.core.gui.components.form.flexible.FormItem)62 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)56 User (org.olat.core.id.User)52 HashMap (java.util.HashMap)40 StaticFlexiCellRenderer (org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer)36 FlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiColumnModel)34 Translator (org.olat.core.gui.translator.Translator)32 Date (java.util.Date)30 UserManager (org.olat.user.UserManager)28 TextFlexiCellRenderer (org.olat.core.gui.components.form.flexible.impl.elements.table.TextFlexiCellRenderer)24 Row (org.olat.core.util.openxml.OpenXMLWorksheet.Row)24 File (java.io.File)22 BusinessGroup (org.olat.group.BusinessGroup)22 SortKey (org.olat.core.commons.persistence.SortKey)18 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)18