use of org.olat.resource.accesscontrol.model.PriceMethodBundle in project OpenOLAT by OpenOLAT.
the class AuthoringEntryDataSource method processViewModel.
private List<AuthoringEntryRow> processViewModel(List<RepositoryEntryAuthorView> repoEntries) {
Set<String> newNames = new HashSet<>();
List<OLATResource> resourcesWithAC = new ArrayList<>(repoEntries.size());
for (RepositoryEntryAuthorView entry : repoEntries) {
if (entry.isOfferAvailable()) {
resourcesWithAC.add(entry.getOlatResource());
}
final String author = entry.getAuthor();
if (StringHelper.containsNonWhitespace(author)) {
newNames.add(author);
}
}
Map<String, String> fullNames = userManager.getUserDisplayNamesByUserName(newNames);
List<OLATResourceAccess> resourcesWithOffer = acService.filterResourceWithAC(resourcesWithAC);
Collection<OLATResourceable> resources = repoEntries.stream().map(RepositoryEntryAuthorView::getOlatResource).collect(Collectors.toList());
List<ResourceLicense> licenses = licenseService.loadLicenses(resources);
List<AuthoringEntryRow> items = new ArrayList<>();
for (RepositoryEntryAuthorView entry : repoEntries) {
String fullname = fullNames.get(entry.getAuthor());
if (fullname == null) {
fullname = entry.getAuthor();
}
AuthoringEntryRow row = new AuthoringEntryRow(entry, fullname);
// bookmark
row.setMarked(entry.isMarked());
// access control
List<PriceMethod> types = new ArrayList<>();
if (entry.isMembersOnly()) {
// members only always show lock icon
types.add(new PriceMethod("", "o_ac_membersonly_icon", uifactory.getTranslator().translate("cif.access.membersonly.short")));
} else {
// collect access control method icons
OLATResource resource = entry.getOlatResource();
for (OLATResourceAccess resourceAccess : resourcesWithOffer) {
if (resource.getKey().equals(resourceAccess.getResource().getKey())) {
for (PriceMethodBundle bundle : resourceAccess.getMethods()) {
String type = (bundle.getMethod().getMethodCssClass() + "_icon").intern();
String price = bundle.getPrice() == null || bundle.getPrice().isEmpty() ? "" : PriceFormat.fullFormat(bundle.getPrice());
AccessMethodHandler amh = acModule.getAccessMethodHandler(bundle.getMethod().getType());
String displayName = amh.getMethodName(uifactory.getTranslator().getLocale());
types.add(new PriceMethod(price, type, displayName));
}
}
}
}
if (!types.isEmpty()) {
row.setAccessTypes(types);
}
// license
for (ResourceLicense license : licenses) {
OLATResource resource = entry.getOlatResource();
if (license.getResId().equals(resource.getResourceableId()) && license.getResName().equals(resource.getResourceableTypeName())) {
row.setLicense(license);
}
}
uifactory.forgeLinks(row);
items.add(row);
}
return items;
}
use of org.olat.resource.accesscontrol.model.PriceMethodBundle in project OpenOLAT by OpenOLAT.
the class RepositoryEntryACColumnDescriptor method render.
@Override
public void render(StringOutput sb, Renderer renderer, Object val, Locale locale, int alignment, String action) {
if (val instanceof Collection) {
Collection<?> accessTypes = (Collection<?>) val;
for (Object accessType : accessTypes) {
if (accessType instanceof String) {
String type = (String) accessType;
sb.append("<i class='o_icon ").append(type).append("_icon o_icon-lg'></i>");
}
}
} else if (val instanceof Boolean) {
boolean acessControlled = ((Boolean) val).booleanValue();
if (acessControlled) {
sb.append("<i class='o_icon o_ac_group_icon o_icon-lg'></i>");
}
} else if (val instanceof OLATResourceAccess) {
OLATResourceAccess access = (OLATResourceAccess) val;
for (PriceMethodBundle bundle : access.getMethods()) {
Price price = bundle.getPrice();
String type = bundle.getMethod().getMethodCssClass();
if (price == null || price.isEmpty()) {
sb.append("<i class='o_icon ").append(type).append("_icon o_icon-lg'></i>");
} else {
String p = PriceFormat.fullFormat(price);
sb.append("<span class='o_nowrap'><i class='o_icon ").append(type).append("_icon o_icon-lg'></i> ").append(p).append("</span>");
}
}
}
}
use of org.olat.resource.accesscontrol.model.PriceMethodBundle in project OpenOLAT by OpenOLAT.
the class BusinessGroupDAO method loadOfferAccess.
public void loadOfferAccess(Map<Long, ? extends BusinessGroupRow> resourceKeyToGroup) {
if (resourceKeyToGroup.isEmpty())
return;
final int OFFERS_IN_LIMIT = 255;
// offers
StringBuilder so = new StringBuilder();
so.append("select access.method, resource.key, offer.price from acofferaccess access ").append(" inner join access.offer offer").append(" inner join offer.resource resource");
if (resourceKeyToGroup.size() < OFFERS_IN_LIMIT) {
so.append(" where resource.key in (:resourceKeys)");
} else {
so.append(" where exists (select bgi.key from businessgroup bgi where bgi.resource=resource)");
}
TypedQuery<Object[]> offersQuery = dbInstance.getCurrentEntityManager().createQuery(so.toString(), Object[].class);
if (resourceKeyToGroup.size() < OFFERS_IN_LIMIT) {
List<Long> resourceKeys = new ArrayList<>(resourceKeyToGroup.size());
for (Long resourceKey : resourceKeyToGroup.keySet()) {
resourceKeys.add(resourceKey);
}
offersQuery.setParameter("resourceKeys", resourceKeys);
}
List<Object[]> offers = offersQuery.getResultList();
for (Object[] offer : offers) {
Long resourceKey = (Long) offer[1];
BusinessGroupRow row = resourceKeyToGroup.get(resourceKey);
if (row != null) {
AccessMethod method = (AccessMethod) offer[0];
Price price = (Price) offer[2];
if (row.getBundles() == null) {
row.setBundles(new ArrayList<>(3));
}
row.getBundles().add(new PriceMethodBundle(price, method));
}
}
}
use of org.olat.resource.accesscontrol.model.PriceMethodBundle in project openolat by klemens.
the class RepositoryEntryACColumnDescriptor method render.
@Override
public void render(StringOutput sb, Renderer renderer, Object val, Locale locale, int alignment, String action) {
if (val instanceof Collection) {
Collection<?> accessTypes = (Collection<?>) val;
for (Object accessType : accessTypes) {
if (accessType instanceof String) {
String type = (String) accessType;
sb.append("<i class='o_icon ").append(type).append("_icon o_icon-lg'></i>");
}
}
} else if (val instanceof Boolean) {
boolean acessControlled = ((Boolean) val).booleanValue();
if (acessControlled) {
sb.append("<i class='o_icon o_ac_group_icon o_icon-lg'></i>");
}
} else if (val instanceof OLATResourceAccess) {
OLATResourceAccess access = (OLATResourceAccess) val;
for (PriceMethodBundle bundle : access.getMethods()) {
Price price = bundle.getPrice();
String type = bundle.getMethod().getMethodCssClass();
if (price == null || price.isEmpty()) {
sb.append("<i class='o_icon ").append(type).append("_icon o_icon-lg'></i>");
} else {
String p = PriceFormat.fullFormat(price);
sb.append("<span class='o_nowrap'><i class='o_icon ").append(type).append("_icon o_icon-lg'></i> ").append(p).append("</span>");
}
}
}
}
use of org.olat.resource.accesscontrol.model.PriceMethodBundle in project openolat by klemens.
the class BusinessGroupDAO method loadOfferAccess.
public void loadOfferAccess(Map<Long, ? extends BusinessGroupRow> resourceKeyToGroup) {
if (resourceKeyToGroup.isEmpty())
return;
final int OFFERS_IN_LIMIT = 255;
// offers
StringBuilder so = new StringBuilder();
so.append("select access.method, resource.key, offer.price from acofferaccess access ").append(" inner join access.offer offer").append(" inner join offer.resource resource");
if (resourceKeyToGroup.size() < OFFERS_IN_LIMIT) {
so.append(" where resource.key in (:resourceKeys)");
} else {
so.append(" where exists (select bgi.key from businessgroup bgi where bgi.resource=resource)");
}
TypedQuery<Object[]> offersQuery = dbInstance.getCurrentEntityManager().createQuery(so.toString(), Object[].class);
if (resourceKeyToGroup.size() < OFFERS_IN_LIMIT) {
List<Long> resourceKeys = new ArrayList<>(resourceKeyToGroup.size());
for (Long resourceKey : resourceKeyToGroup.keySet()) {
resourceKeys.add(resourceKey);
}
offersQuery.setParameter("resourceKeys", resourceKeys);
}
List<Object[]> offers = offersQuery.getResultList();
for (Object[] offer : offers) {
Long resourceKey = (Long) offer[1];
BusinessGroupRow row = resourceKeyToGroup.get(resourceKey);
if (row != null) {
AccessMethod method = (AccessMethod) offer[0];
Price price = (Price) offer[2];
if (row.getBundles() == null) {
row.setBundles(new ArrayList<>(3));
}
row.getBundles().add(new PriceMethodBundle(price, method));
}
}
}
Aggregations