19 package org.turro.contacts.content;
21 import java.io.Writer;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collection;
25 import org.turro.string.Strings;
26 import org.turro.attach.www.AttachCtrl;
27 import org.turro.contacts.ContactService;
28 import org.turro.contacts.ContactServiceRole;
29 import org.turro.contacts.db.ContactsPU;
30 import org.turro.contacts.service.ServiceContext;
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.view.ViewMode;
38 import org.turro.elephant.web.SocialImageMap;
39 import org.turro.elephant.web.SocialNet;
40 import org.turro.entities.Entities;
41 import org.turro.file.util.FileAttach;
42 import org.turro.indicator.Statistics;
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.util.Enums;
50 import org.turro.www.commentit.CommentItCtrl;
51 import org.turro.www.describeit.DescribeItCtrl;
52 import org.turro.www.starit.StarItCtrl;
53 import org.turro.www.voteit.VoteItCtrl;
61 private boolean withDate, active, lastEntries;
65 private final boolean all, allowQuestion;
78 this.withDate = withDate;
94 this.lastEntries = lastEntries;
125 dhs.
setAttribute(
constructor,
"types",
dao.getResultList(
"select distinct service.type from ContactService as service order by 1"));
126 dhs.
setAttribute(
constructor,
"thematics",
dao.getResultList(
"select distinct service.thematic from ContactService as service order by 1"));
134 wc.
addClause(
"select distinct service from ContactService as service");
137 wc.
addClause(
"order by service.startDate desc, service.title");
138 }
else if(lastEntries) {
140 wc.
addClause(
"order by service.creation desc, service.title");
147 .setEntityFields(
"service",
"id")
148 .setDefaultSorting(
"service.title")
149 .onCriteria(w -> addCriteria(w))
158 wc.
addClause(
"select count(distinct service) from ContactService as service");
167 prepareValues(e, page);
175 prepareValues(e, page);
187 wc.
addClause(
"select distinct service from ContactService as service");
201 String searchValue = dsk.
getValue();
202 if(!Strings.isBlank(searchValue)) {
203 dsk.
applyToQuery(wc, Arrays.asList(
"service.title",
"service.thematic",
"service.contact.name"),
true);
206 dsk = dhs.get(
"role");
208 role = Enums.valueOf(ContactServiceRole.class, dsk.
getValue(),
null);
210 dsk = dhs.get(
"type");
214 dsk = dhs.get(
"actives");
216 active =
"true".equals(dsk.
getValue());
218 dsk = dhs.get(
"with-date");
220 withDate =
"true".equals(dsk.
getValue());
225 wc.
addClause(
"and service.role = :role");
228 if(!Strings.isBlank(type) && !
"all".equals(type)) {
229 wc.
addClause(
"and service.type = :type");
233 wc.
addClause(
"and service.startDate is not null");
236 wc.
addClause(
"and (service.endDate is null or service.endDate >= current_date)");
239 wc.
addClause(
"and (service.contact = :contact");
241 wc.
addClause(
"select r from BusinessRelation as r");
242 wc.
addClause(
"where r.business = service.contact");
243 wc.
addClause(
"and r.contact = :contact");
248 wc.
addClause(
"and service.timesSent > 0");
254 return super.isValid(e);
257 private void prepareValues(
final ContactService service,
int page) {
259 marker.
put(
"allowQuestion", allowQuestion);
264 if(!Strings.isBlank(e.
getTitle())) {
272 ArrayList<RepositoryFile> files =
new ArrayList<>();
287 return isMail() ?
"content/newsletter/sections/services" :
"service";
340 if(Strings.isBlank(path)) {
343 if(Strings.isBlank(path)) {
351 return "/user/services";
Object doCommentsCtrl(ContactService e)
boolean isValid(ContactService e)
WhereClause getWhereClause()
Object doVotesCtrl(ContactService e)
Object doPollsCtrl(ContactService e)
void setActive(boolean active)
boolean isInBusiness(ContactService service, IContact contact)
ContactServiceRole getRole()
Object doInterestCtrl(ContactService e)
void setWithDate(boolean withDate)
String title(ContactService e)
Object doDescriptionsCtrl(ContactService e)
void setLastEntries(boolean lastEntries)
String getItemLink(ContactService e)
void renderSummary(ElephantMarker marker, ContactService e, int page)
void renderItem(ElephantMarker marker, ContactService e, int page)
void setType(String type)
Collection< String > metas(ContactService e)
Object doFilesCtrl(ContactService e)
Object doAttachmentsCtrl(ContactService e)
ContactServiceContentIterator(IConstructor constructor, Writer writer, IContact contact, boolean mail, String pubPath)
void setRole(ContactServiceRole role)
ContactService entity(String value)
WhereClause getCountClause()
String getRestrictedLink()
static boolean getAllowQuestion(IConstructor constructor)
static boolean getAllowSingle()
static boolean getAllowNew(IConstructor constructor)
boolean isInRole(String role)
static Application getApplication()
static String getContextVariable(IConstructor constructor)
static String getEntityWebContext(String path)
void addClause(String clause)
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)
Object getSingleResultOrNull(SqlClause sc)
void prepareControls(E entity, int page)
String doItemLink(E entity, ID id, boolean obfuscated)
boolean isAllowMatching()
String getSummaryTemplate()
void setAttribute(IConstructor constructor, String attribute, Object value)
static DaoHtmlSearch getInstance(IConstructor constructor, String context)
boolean hasAttribute(IConstructor constructor, String attribute)
boolean applyToQuery(WhereClause wc, List< String > fields, boolean withSynonyms)
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)
Object configureCtrl(Object ctrl, IContact contact)