19 package org.turro.students.content;
21 import java.io.Writer;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collection;
25 import java.util.List;
26 import java.util.stream.Collectors;
27 import org.turro.string.Strings;
28 import org.turro.attach.www.AttachCtrl;
29 import org.turro.contacts.db.ContactsPU;
30 import org.turro.contacts.profile.Profile;
31 import org.turro.elephant.context.Application;
32 import org.turro.elephant.context.ElephantContext;
33 import org.turro.elephant.context.IConstructor;
34 import org.turro.elephant.db.WhereClause;
35 import org.turro.elephant.impl.repository.Repository;
36 import org.turro.elephant.impl.repository.RepositoryFile;
37 import org.turro.elephant.web.SocialImageMap;
38 import org.turro.elephant.web.SocialNet;
39 import org.turro.entities.Entities;
40 import org.turro.file.util.FileAttach;
41 import org.turro.indicator.Statistics;
42 import org.turro.jobboard.PracticalWorkContext;
43 import org.turro.jpa.content.EntityDaoContentIterator;
44 import org.turro.jpa.search.DaoHtmlSearch;
45 import org.turro.jpa.search.DaoSearchKey;
46 import org.turro.marker.ElephantMarker;
47 import org.turro.plugin.contacts.IContact;
48 import org.turro.polls.PollsCtrl;
49 import org.turro.students.db.StudentsPU;
50 import org.turro.students.entities.PracticalWork;
51 import org.turro.students.entities.PracticalWorkRole;
52 import org.turro.util.Enums;
53 import org.turro.www.commentit.CommentItCtrl;
54 import org.turro.www.describeit.DescribeItCtrl;
55 import org.turro.www.starit.StarItCtrl;
56 import org.turro.www.voteit.VoteItCtrl;
64 private boolean withDate, active, lastEntries;
68 private final boolean all, allowQuestion;
81 this.withDate = withDate;
97 this.lastEntries = lastEntries;
124 wc.
addClause(
"select distinct practicalwork from PracticalWork as practicalwork");
127 wc.
addClause(
"order by practicalwork.startDate desc, practicalwork.title");
128 }
else if(lastEntries) {
130 wc.
addClause(
"order by practicalwork.creation desc, practicalwork.title");
137 .setEntityFields(
"practicalwork",
"id")
138 .setDefaultSorting(
"practicalwork.title")
139 .onCriteria(w -> addCriteria(w))
148 wc.
addClause(
"select count(distinct practicalwork) from PracticalWork as practicalwork");
157 prepareValues(e, page);
165 prepareValues(e, page);
171 return "practicalwork";
177 wc.
addClause(
"select distinct practicalwork from PracticalWork as practicalwork");
179 wc.
addClause(
"and practicalwork.id = :id");
191 String searchValue = dsk.
getValue();
192 if(!Strings.isBlank(searchValue)) {
193 dsk.
applyToQuery(wc, Arrays.asList(
"practicalwork.title"),
true);
196 dsk = dhs.get(
"role");
198 role = Enums.valueOf(PracticalWorkRole.class, dsk.
getValue(),
null);
200 dsk = dhs.get(
"type");
204 dsk = dhs.get(
"actives");
206 active =
"true".equals(dsk.
getValue());
208 dsk = dhs.get(
"with-date");
210 withDate =
"true".equals(dsk.
getValue());
215 wc.
addClause(
"and practicalwork.role = :role");
218 if(!Strings.isBlank(type) && !
"all".equals(type)) {
219 wc.
addClause(
"and practicalwork.type = :type");
223 wc.
addClause(
"and practicalwork.startDate is not null");
226 wc.
addClause(
"and (practicalwork.endDate is null or practicalwork.endDate >= current_date)");
229 wc.
addClause(
"and (practicalwork.idContact = :idContact");
230 wc.
addIn(
"or",
"practicalwork.idContact", getBusinessIds(
getContact()));
235 wc.
addClause(
"and practicalwork.published = TRUE");
239 private List<String> getBusinessIds(IContact contact) {
240 Profile profile = (Profile) contact.getProfile();
241 return profile.getCurrentCompanies().stream()
242 .map(r -> r.getBusiness().getContact().getId()).collect(Collectors.toList());
247 return super.isValid(e);
250 private void prepareValues(
final PracticalWork practicalWork,
int page) {
252 marker.
put(
"allowQuestion", allowQuestion);
257 if(!Strings.isBlank(e.
getTitle())) {
265 ArrayList<RepositoryFile> files =
new ArrayList<>();
280 return isMail() ?
"content/newsletter/sections/practicalworks" :
"practicalwork";
333 if(Strings.isBlank(path)) {
336 if(Strings.isBlank(path)) {
344 return "/user/mypracticalworks";
boolean isInRole(String role)
static Application getApplication()
static String getContextVariable(IConstructor constructor)
static String getEntityWebContext(String path)
void addClause(String clause)
void addIn(String operator, String field, List values)
void addNamedValue(String name, Object value)
Set< RepositoryFile > getRepositoryFiles(String pattern)
static boolean hasImage(String url)
List< String > getMetas()
static IElephantEntity getController(String path)
Repository getPublishableRepository(IConstructor constructor)
static Statistics load(IConstructor constructor, String rankingInstance, String matchingInstance, WhereClause wc)
static boolean getAllowSingle()
static boolean getAllowQuestion(IConstructor constructor)
Object getSingleResultOrNull(SqlClause sc)
void prepareControls(E entity, int page)
String doItemLink(E entity, ID id, boolean obfuscated)
boolean isAllowMatching()
String getSummaryTemplate()
static DaoHtmlSearch getInstance(IConstructor constructor, String context)
boolean applyToQuery(WhereClause wc, List< String > fields, boolean withSynonyms)
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)
Collection< String > metas(PracticalWork e)
String getItemLink(PracticalWork e)
Object doPollsCtrl(PracticalWork e)
PracticalWork entity(Long value)
void setLastEntries(boolean lastEntries)
Object doInterestCtrl(PracticalWork e)
PracticalWorkRole getRole()
void setType(String type)
void setWithDate(boolean withDate)
Object doDescriptionsCtrl(PracticalWork e)
PracticalWorkContentIterator(IConstructor constructor, Writer writer, IContact contact, boolean mail, String pubPath)
void setActive(boolean active)
Object doFilesCtrl(PracticalWork e)
Object doAttachmentsCtrl(PracticalWork e)
void renderItem(ElephantMarker marker, PracticalWork e, int page)
String getRestrictedLink()
Object doCommentsCtrl(PracticalWork e)
Object doVotesCtrl(PracticalWork e)
void setRole(PracticalWorkRole role)
WhereClause getWhereClause()
String title(PracticalWork e)
boolean isValid(PracticalWork e)
WhereClause getCountClause()
boolean isInBusiness(PracticalWork practicalWork, IContact contact)
void renderSummary(ElephantMarker marker, PracticalWork e, int page)
Object configureCtrl(Object ctrl, IContact contact)