BrightSide Workbench Full Report + Source Code
ChallengeContentProvider.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.students.content;
20 
21 import java.io.StringWriter;
22 import java.io.Writer;
23 import org.turro.action.content.AbstractContentProvider;
24 import org.turro.action.content.ContentRenderer;
25 import org.turro.action.content.IContentIterator;
26 import org.turro.annotation.ContentProvider;
27 import org.turro.command.MacroCommand;
28 import org.turro.elephant.context.HeadlessApplication;
29 import org.turro.plugin.contacts.IContact;
30 
35 @ContentProvider
37 
39  addCommands();
40  }
41 
42  private void addCommands() {
43  // challenges
44  MacroCommand mc = new MacroCommand("challenges");
45  mc.addParameter("status", "active", true)
46  .setPossibleValuesString("active|closed|all");
47  mc.addParameter("context", "", true);
48  mc.addParameter("count", Integer.valueOf(10), true);
49  mc.addParameter("restricted", Boolean.FALSE, true);
50  mc.addParameter("studentRelated", Boolean.FALSE, true);
51  mc.addParameter("challengerRelated", Boolean.FALSE, true);
52  mc.addParameter("responseFrom", Integer.valueOf(15), true);
53  mc.addParameter("template", "summary", true);
54  commands.add(mc);
55  }
56 
57  @Override
58  public ContentRenderer loadCommand(MacroCommand macroCommand, IContact contact, String idContext) {
59  if(macroCommand.itsMe("challenges(")) {
60  StringWriter sw = new StringWriter();
63  sw, contact, true,
64  macroCommand.getParameterValue(String.class, "context"));
65  ci.setStatus(macroCommand.getParameterValue(String.class, "status"));
66  ci.setPage(macroCommand.getParameterValue(Integer.class, "count"));
67  ci.setAllowAttachments(true);
68  ci.setAllowFiles(true);
69  ci.setAllowDescriptions(true);
70  ci.setAllowInterest(true);
71  ci.setAllowVotes(true);
72  ci.setAllowComments(true);
73  ci.setAllowPolls(true);
74  ci.setSummaryTemplate(macroCommand.getParameterValue(String.class, "template"));
75  ci.setRestricted(macroCommand.getParameterValue(Boolean.class, "restricted"));
76  ci.setStudentRelated(macroCommand.getParameterValue(Boolean.class, "studentRelated"));
77  ci.setChallengerRelated(macroCommand.getParameterValue(Boolean.class, "challengerRelated"));
78  ci.setResponseFrom(macroCommand.getParameterValue(Integer.class, "responseFrom"));
79  ci.setNavigatorTop(false);
80  ci.setNavigatorBottom(false);
81  ci.load();
82  return new ContentRenderer(macroCommand, ci, sw, (IContentIterator iterator, Writer writer) -> {
83  iterator.render();
84  return writer.toString();
85  });
86  }
87  return null;
88  }
89 
90 }
void setAllowAttachments(boolean allowAttachments)
void setAllowInterest(boolean allowInterest)
void setAllowDescriptions(boolean allowDescriptions)
void setAllowComments(boolean allowComments)
void setNavigatorBottom(boolean navigatorBottom)
void setSummaryTemplate(String summaryTemplate)
void setNavigatorTop(boolean navigatorTop)
ContentRenderer loadCommand(MacroCommand macroCommand, IContact contact, String idContext)