use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class SearchController method get.
@GetMapping({ "/search/{type}/{query}", "/search" })
public String get(@PathVariable(required = false) String type, @PathVariable(required = false) String query, @RequestParam(required = false) String q, HttpServletRequest req, Model model) {
List<Profile> userlist = new ArrayList<Profile>();
List<Post> questionlist = new ArrayList<Post>();
List<Post> answerlist = new ArrayList<Post>();
List<Post> feedbacklist = new ArrayList<Post>();
Pager itemcount = utils.getPager("page", req);
String queryString = StringUtils.isBlank(q) ? query : q;
if ("questions".equals(type)) {
questionlist = pc.findQuery(Utils.type(Question.class), queryString, itemcount);
} else if ("answers".equals(type)) {
answerlist = pc.findQuery(Utils.type(Reply.class), queryString, itemcount);
} else if ("feedback".equals(type)) {
feedbacklist = pc.findQuery(Utils.type(Feedback.class), queryString, itemcount);
} else if ("people".equals(type)) {
userlist = pc.findQuery(Utils.type(Profile.class), queryString, itemcount);
} else {
questionlist = pc.findQuery(Utils.type(Question.class), queryString);
answerlist = pc.findQuery(Utils.type(Reply.class), queryString);
feedbacklist = pc.findQuery(Utils.type(Feedback.class), queryString);
userlist = pc.findQuery(Utils.type(Profile.class), queryString);
}
ArrayList<Post> list = new ArrayList<Post>();
list.addAll(questionlist);
list.addAll(answerlist);
list.addAll(feedbacklist);
utils.fetchProfiles(list);
model.addAttribute("path", "search.vm");
model.addAttribute("title", utils.getLang(req).get("search.title"));
model.addAttribute("searchSelected", "navbtn-hover");
model.addAttribute("showParam", type);
model.addAttribute("searchQuery", queryString);
model.addAttribute("itemcount", itemcount);
model.addAttribute("userlist", userlist);
model.addAttribute("questionlist", questionlist);
model.addAttribute("answerlist", answerlist);
model.addAttribute("feedbacklist", feedbacklist);
return "base";
}
use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class TranslateController method delete.
@PostMapping("/delete/{id}")
public String delete(@PathVariable String id, HttpServletRequest req, Model model) {
if (id != null && utils.isAuthenticated(req)) {
Translation trans = (Translation) pc.read(id);
Profile authUser = utils.getAuthUser(req);
if (authUser.getId().equals(trans.getCreatorid()) || utils.isAdmin(authUser)) {
utils.getLangutils().disapproveTranslation(trans.getLocale(), trans.getId());
pc.delete(trans);
}
if (!utils.isAjaxRequest(req)) {
return "redirect:" + req.getRequestURI();
}
}
return "base";
}
use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class QuestionController method edit.
@PostMapping("/{id}/edit")
public String edit(@PathVariable String id, @RequestParam(required = false) String title, @RequestParam(required = false) String body, @RequestParam(required = false) String tags, HttpServletRequest req) {
Post showPost = pc.read(id);
Profile authUser = utils.getAuthUser(req);
if (!utils.canEdit(showPost, authUser) || showPost == null) {
return "redirect:" + req.getRequestURI();
}
Post beforeUpdate = null;
try {
beforeUpdate = (Post) BeanUtils.cloneBean(showPost);
} catch (Exception ex) {
logger.error(null, ex);
}
if (!StringUtils.isBlank(title) && title.length() > 10) {
showPost.setTitle(title);
}
if (!StringUtils.isBlank(body)) {
showPost.setBody(body);
}
if (!StringUtils.isBlank(tags) && showPost.isQuestion()) {
showPost.setTags(Arrays.asList(StringUtils.split(tags, ",")));
}
showPost.setLasteditby(authUser.getId());
//note: update only happens if something has changed
if (!showPost.equals(beforeUpdate)) {
showPost.update();
utils.addBadgeOnceAndUpdate(authUser, Badge.EDITOR, true);
}
return "redirect:" + showPost.getPostLink(false, false);
}
use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class QuestionsController method getQuestions.
private List<Question> getQuestions(String sortby, String filter, HttpServletRequest req, Model model) {
Pager itemcount = utils.getPager("page", req);
List<Question> questionslist = Collections.emptyList();
String type = Utils.type(Question.class);
String query = "*";
if ("activity".equals(sortby)) {
itemcount.setSortby("updated");
} else if ("votes".equals(sortby)) {
itemcount.setSortby("votes");
} else if ("unanswered".equals(sortby)) {
itemcount.setSortby("timestamp");
itemcount.setDesc(false);
query = "properties.answercount:0";
}
if (!StringUtils.isBlank(filter) && utils.isAuthenticated(req)) {
Profile authUser = utils.getAuthUser(req);
if ("favtags".equals(filter)) {
questionslist = pc.findTermInList(type, Config._TAGS, authUser.getFavtags(), itemcount);
} else if ("favtags".equals(filter)) {
String[] ll = authUser.getLatlng() == null ? new String[0] : authUser.getLatlng().split(",");
if (ll.length == 2) {
double lat = NumberUtils.toDouble(ll[0]);
double lng = NumberUtils.toDouble(ll[1]);
questionslist = pc.findNearby(type, "*", 25, lat, lng, itemcount);
}
}
model.addAttribute("localFilterOn", "local".equals(filter));
model.addAttribute("tagFilterOn", "favtags".equals(filter));
model.addAttribute("filter", "/" + Utils.stripAndTrim(filter));
} else {
questionslist = pc.findQuery(type, query, itemcount);
}
utils.fetchProfiles(questionslist);
model.addAttribute("itemcount", itemcount);
model.addAttribute("questionslist", questionslist);
return questionslist;
}
use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class ReportsController method create.
@PostMapping
public void create(HttpServletRequest req, HttpServletResponse res) {
Report rep = utils.populate(req, new Report(), "link", "description", "parentid", "subType", "authorName");
Map<String, String> error = utils.validate(rep);
if (error.isEmpty()) {
if (utils.isAuthenticated(req)) {
Profile authUser = utils.getAuthUser(req);
rep.setAuthorName(authUser.getName());
rep.setCreatorid(authUser.getId());
utils.addBadgeAndUpdate(authUser, REPORTER, true);
} else {
//allow anonymous reports
rep.setAuthorName(utils.getLang(req).get("anonymous"));
}
rep.create();
res.setStatus(200);
} else {
res.setStatus(400);
}
}
Aggregations