use of org.olat.portfolio.model.artefacts.AbstractArtefact in project openolat by klemens.
the class EPTOCReadOnlyController method buildTOCModel.
/**
* builds the tocList recursively containing artefacts, pages and
* struct-Elements
*
* @param pStruct
* @param tocList
* list with TOCElement's to use in velocity
* @param level
* @param withArtefacts
* set false, to skip artefacts
*/
private void buildTOCModel(PortfolioStructure pStruct, List<TOCElement> tocList, int level) {
level++;
if (displayArtefactsInTOC) {
List<AbstractArtefact> artList = ePFMgr.getArtefacts(pStruct);
if (artList != null && artList.size() != 0) {
for (AbstractArtefact artefact : artList) {
String key = String.valueOf(artefact.getKey());
String title = StringHelper.escapeHtml(artefact.getTitle());
Link iconLink = LinkFactory.createCustomLink("arte_" + key, LINK_CMD_OPEN_ARTEFACT, "", Link.NONTRANSLATED, vC, this);
iconLink.setIconRightCSS("o_icon o_icon_start");
iconLink.setUserObject(pStruct);
Link titleLink = LinkFactory.createCustomLink("arte_t_" + key, LINK_CMD_OPEN_ARTEFACT, title, Link.NONTRANSLATED, vC, this);
titleLink.setUserObject(pStruct);
TOCElement actualTOCEl = new TOCElement(level, "artefact", titleLink, iconLink, null, null);
tocList.add(actualTOCEl);
}
}
}
List<PortfolioStructure> childs = ePFMgr.loadStructureChildren(pStruct);
if (childs != null && childs.size() != 0) {
for (PortfolioStructure portfolioStructure : childs) {
String type = "";
if (portfolioStructure instanceof EPPage) {
type = CONST_FOR_VC_STYLE_PAGE;
} else {
// a structure element
type = CONST_FOR_VC_STYLE_STRUCT;
}
String key = String.valueOf(portfolioStructure.getKey());
String title = StringHelper.escapeHtml(portfolioStructure.getTitle());
Link iconLink = LinkFactory.createCustomLink("portstruct" + key, LINK_CMD_OPEN_STRUCT, "", Link.NONTRANSLATED, vC, this);
iconLink.setIconRightCSS("o_icon o_icon_start");
iconLink.setUserObject(portfolioStructure);
Link titleLink = LinkFactory.createCustomLink("portstruct_t_" + key, LINK_CMD_OPEN_STRUCT, title, Link.NONTRANSLATED, vC, this);
titleLink.setUserObject(portfolioStructure);
Link commentLink = null;
if (portfolioStructure instanceof EPPage && secCallback.canCommentAndRate()) {
UserCommentsCount comments = getUserCommentsCount(portfolioStructure);
String count = comments == null ? "0" : comments.getCount().toString();
String label = translate("commentLink", new String[] { count });
commentLink = LinkFactory.createCustomLink("commentLink" + key, LINK_CMD_OPEN_COMMENTS, label, Link.NONTRANSLATED, vC, this);
commentLink.setIconLeftCSS("o_icon o_icon_comments");
commentLink.setUserObject(portfolioStructure);
}
// prefetch children to keep reference on them
List<TOCElement> tocChildList = new ArrayList<TOCElement>();
buildTOCModel(portfolioStructure, tocChildList, level);
TOCElement actualTOCEl = new TOCElement(level, type, titleLink, iconLink, commentLink, tocChildList);
tocList.add(actualTOCEl);
if (tocChildList.size() != 0) {
tocList.addAll(tocChildList);
}
}
}
}
use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.
the class EPStructureManager method canAddArtefact.
protected boolean canAddArtefact(EPStructureElement structureEl, AbstractArtefact newArtefact) {
List<CollectRestriction> restrictions = structureEl.getCollectRestrictions();
if (restrictions == null || restrictions.isEmpty())
return true;
boolean allOk = true;
List<String> artefactTypeAllowed = new ArrayList<String>();
List<AbstractArtefact> artefacts = getArtefacts(structureEl);
artefacts.add(newArtefact);
for (CollectRestriction restriction : restrictions) {
String type = restriction.getArtefactType();
int count = countRestrictionType(artefacts, restriction);
artefactTypeAllowed.add(type);
if (type.equals(newArtefact.getResourceableTypeName())) {
if (RestrictionsConstants.MAX.equals(restriction.getRestriction())) {
allOk &= (restriction.getAmount() > 0 && count <= restriction.getAmount());
} else if (RestrictionsConstants.EQUAL.equals(restriction.getRestriction())) {
allOk &= (restriction.getAmount() > 0 && count <= restriction.getAmount());
}
}
}
allOk &= artefactTypeAllowed.contains(newArtefact.getResourceableTypeName());
return allOk;
}
use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.
the class EPStructureManager method checkCollectRestriction.
/**
* Check the collect restriction against the structure element
* @param structure
* @return
*/
protected boolean checkCollectRestriction(PortfolioStructure structure) {
if (structure instanceof EPStructureElement) {
EPStructureElement structureEl = (EPStructureElement) structure;
List<CollectRestriction> restrictions = structureEl.getCollectRestrictions();
if (restrictions == null || restrictions.isEmpty())
return true;
boolean allOk = true;
List<String> artefactTypeAllowed = new ArrayList<String>();
List<AbstractArtefact> artefacts = getArtefacts(structureEl);
for (CollectRestriction restriction : restrictions) {
int count = countRestrictionType(artefacts, restriction);
artefactTypeAllowed.add(restriction.getArtefactType());
boolean ok = true;
if (RestrictionsConstants.MAX.equals(restriction.getRestriction())) {
ok &= (restriction.getAmount() > 0 && count <= restriction.getAmount());
} else if (RestrictionsConstants.MIN.equals(restriction.getRestriction())) {
ok &= (restriction.getAmount() > 0 && count >= restriction.getAmount());
} else if (RestrictionsConstants.EQUAL.equals(restriction.getRestriction())) {
ok &= (restriction.getAmount() > 0 && count == restriction.getAmount());
} else {
ok &= false;
}
allOk &= ok;
}
for (AbstractArtefact artefact : artefacts) {
allOk &= artefactTypeAllowed.contains(artefact.getResourceableTypeName());
}
return allOk;
}
return true;
}
use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.
the class EPFrontendManager method filterArtefactsByFilterSettings.
/**
* filter the provided list of artefacts with different filters
*
* @param allArtefacts the list to manipulate on
* @param filterSettings Settings for the filter to work on
* @return
*/
public List<AbstractArtefact> filterArtefactsByFilterSettings(EPFilterSettings filterSettings, Identity identity, Roles roles) {
List<Long> artefactKeys = fulltextSearchAfterArtefacts(filterSettings, identity, roles);
if (artefactKeys == null || artefactKeys.isEmpty()) {
List<AbstractArtefact> allArtefacts = artefactManager.getArtefactPoolForUser(identity);
return artefactManager.filterArtefactsByFilterSettings(allArtefacts, filterSettings);
}
List<AbstractArtefact> artefacts = artefactManager.getArtefacts(identity, artefactKeys, 0, 500);
// remove the text-filter when the lucene-search got some results before
EPFilterSettings settings = filterSettings.cloneAfterFullText();
return artefactManager.filterArtefactsByFilterSettings(artefacts, settings);
}
use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.
the class EPFrontendManager method checkFeedAccess.
/**
* check if given identity has access to this feed.
* reverse lookup feed -> artefact -> shared map
* @param feed
* @param identity
* @return
*/
public boolean checkFeedAccess(OLATResourceable feed, Identity identity) {
String feedBP = LiveBlogArtefactHandler.LIVEBLOG + feed.getResourceableId() + "]";
List<AbstractArtefact> artefact = loadArtefactsByBusinessPath(feedBP, null);
if (artefact != null && artefact.size() == 1) {
List<PortfolioStructure> linkedMaps = getReferencedMapsForArtefact(artefact.get(0));
for (PortfolioStructure map : linkedMaps) {
if (isMapVisible(identity, map)) {
return true;
}
}
// see OLAT-6282: allow the owner of the artefact to view the feed, even if its not any longer in any map.
if (linkedMaps.size() == 0 && artefact.get(0).getAuthor().equalsByPersistableKey(identity)) {
return true;
}
}
return false;
}
Aggregations