Returns HTML menu for challenges. Challenges are only referenced by their id, The user will have to go through another servlet to get the module's View address @param ApplicationRoot The current running context of the application @return HTML menu for challenges
(String ApplicationRoot, String userId, Locale lang)
| 271 | * @return HTML menu for challenges |
| 272 | */ |
| 273 | public static String getChallenges (String ApplicationRoot, String userId, Locale lang) |
| 274 | { |
| 275 | log.debug("*** Getter.getChallenges ***"); |
| 276 | String output = new String(); |
| 277 | //Getting Translated Level Names |
| 278 | ResourceBundle bundle = ResourceBundle.getBundle("i18n.moduleGenerics.moduleNames", lang); |
| 279 | //Encoder to prevent XSS |
| 280 | Connection conn = Database.getCoreConnection(ApplicationRoot); |
| 281 | try |
| 282 | { |
| 283 | CallableStatement callstmt = conn.prepareCall("call moduleAllInfo(?, ?)"); |
| 284 | callstmt.setString(1, "challenge"); |
| 285 | callstmt.setString(2, userId); |
| 286 | log.debug("Gathering moduleAllInfo ResultSet"); |
| 287 | ResultSet challenges = callstmt.executeQuery(); |
| 288 | log.debug("Opening Result Set from moduleAllInfo"); |
| 289 | String challengeCategory = new String(); |
| 290 | int rowNumber = 0; // Identifies the first row, ie the start of the list. This is slightly different output to every other row |
| 291 | while(challenges.next()) |
| 292 | { |
| 293 | if(!challengeCategory.equalsIgnoreCase(challenges.getString(2))) |
| 294 | { |
| 295 | challengeCategory = challenges.getString(2); |
| 296 | //log.debug("New Category Detected: " + challengeCategory); |
| 297 | if(rowNumber > 0) //output prepared for Every row after row 1 |
| 298 | output += "</ul></li><li><a href='javascript:;' class='challengeHeader' >" + Encode.forHtml(bundle.getString("category." + challengeCategory))+ "</a><ul class='challengeList' style='display: none;'>"; |
| 299 | else //output prepared for First row in entire challenge |
| 300 | output += "<li><a href='javascript:;' class='challengeHeader'>" + Encode.forHtml(bundle.getString("category." + challengeCategory))+ "</a><ul class='challengeList' style='display: none;'>"; |
| 301 | //log.debug("Compiling Challenge Category - " + challengeCategory); |
| 302 | } |
| 303 | output += "<li>"; //Starts next LI element |
| 304 | if(challenges.getString(4) != null) |
| 305 | { |
| 306 | output += "<img src='css/images/completed.png'/>"; //Completed marker |
| 307 | } |
| 308 | else |
| 309 | { |
| 310 | output+= "<img src='css/images/uncompleted.png'/>"; //Incomplete marker |
| 311 | } |
| 312 | //Final out put compilation |
| 313 | output +="<a class='lesson' id='" |
| 314 | + Encode.forHtmlAttribute(challenges.getString(3)) |
| 315 | + "' href='javascript:;'>" |
| 316 | + Encode.forHtml(bundle.getString(challenges.getString(1))) |
| 317 | + "</a>"; |
| 318 | output += "</li>"; |
| 319 | rowNumber++; |
| 320 | } |
| 321 | //Check if output is empty |
| 322 | if(output.isEmpty()) |
| 323 | { |
| 324 | output = "<li><a href='javascript:;'>No challenges found</a></li>"; |
| 325 | } |
| 326 | else |
| 327 | { |
| 328 | log.debug("Appending End tags"); |
| 329 | output += "</ul></li>"; |
| 330 | } |