I am working on a Grails project where I need to display team icons on the home page based on the current week. There are three different images for three different teams, and the teams rotate every 3 weeks. For example, Team 1's logo will show on the first (1) and last (4) weeks of the month, and so on. I initially attempted to store all 52 weeks along with team numbers in a database table and retrieve them using sessions.
Here is the code snippet from my service:
sql.query("SELECT * FROM tbl_ImageForTeamUser where weekno=?",[wkno])
{ rs ->
while (rs.next()) {
def userinf = new UserInfo()
userinf.weekno= rs.getInt("weekno")
userinf.teamname= rs.getString("teamname")
userinf.teamno= rs.getInt("teamno")
items.add(userinf)
}
}
And then saving it in the session:
session.weekno= items[0].teamno()
The current UI implementation includes logic like this:
<tr>
<g:if test="${session.weekno == "1" }">
<td class="team1" align="right" nowrap></br></br></td>
</g:if>
<g:if test="${session.weekno == "2"}">
<td class="team2" align="right" nowrap></br></br></td>
</g:if>
<g:if test="${session.weekno == "3" }">
<td class="team3" align="right" nowrap></br></br></td>
</g:if>
However, I feel that this solution is not optimal. I am seeking better coding suggestions to achieve the same functionality without relying on the database and handling it more efficiently on the UI side.