Changes for page Per Year

From version 96.1
edited by Andrea Omicini
on 30/10/2021 16:03
Change comment: There is no comment for this version
To version 137.1
edited by Andrea Omicini
on 30/06/2023 16:56
Change comment: There is no comment for this version

Summary

Details

Page properties
Title
... ... @@ -1,1 +1,1 @@
1 -#if($xcontext.language=='it')Tesi per anno#{else}Theses per Year#end
1 +$services.localization.render('peryear')
Default language
... ... @@ -1,1 +1,0 @@
1 -en
Content
... ... @@ -1,147 +1,197 @@
1 -{{include reference="Theses.Environment"/}}{{include reference="Environment"/}}{{velocity}}
2 -#set( $thesisMenu = true )
3 -#set( $oneYear = false )
4 -### START YEAR
5 -## year parameter
6 -#set( $yearPar = $mathtool.toInteger($request.year) )
7 -#set( $fromPar = $mathtool.toInteger($request.from) )
8 -#set( $toPar = $mathtool.toInteger($request.to) )
9 -#set( $firstYear = $mathtool.toInteger($firstYearTh) )
10 -#set( $lastYear = $mathtool.toInteger($lastYearTh) )
11 -#set( $yearList = [$lastYear..$firstYear] )
12 -#if( $yearPar > 0 )
13 - #set( $oneYear = true )
14 - #set( $firstYear = $yearPar )
15 - #set( $lastYear = $toPar )
16 - #set( $yearList = [$yearPar] )
17 -#else
18 - #if( $fromPar != '' && ($fromPar > $firstYear) )
19 - #set( $firstYear = $fromPar )
20 - #set( $yearList = [$lastYear..$firstYear] )
1 +{{velocity}}
2 +#template('apice_theses.vm')
3 +#### HANDLE PARAMETERS / START
4 +##
5 +## inline display
6 +#set( $inlinePar = $request.inline.trim() )
7 +## who
8 +#set( $userNamePar = $request.user.trim() )
9 +#set( $firstNamePar = $request.name.trim() )
10 +#set( $lastNamePar = $request.surname.trim() )
11 +#### handle who
12 +#if( $userName )
13 +## from a personal page, "XWiki.$userName" $userName form
14 + #if( !$xwiki.exists( $userName ) )
15 +{{warning}}User $userName does not exist{{/warning}}
16 + #stop
21 21   #end
22 - #if( $toPar != '' && ($toPar < $lastYear) )
23 - #set( $lastYear = $toPar )
24 - #set( $yearList = [$lastYear..$firstYear] )
25 - #end
26 - #if( $lastYear <= $firstYear )
27 - #set( $oneYear = true )
28 - #set( $selectedYear = $firstYear )
29 - #set( $yearList = [$firstYear] )
18 + #set( $apiceUser = true )
19 + #set( $oneUser = true )
20 + #set( $userdoc = $xwiki.getDocument($userName) )
21 + #set( $userFirstName = $userdoc.display("first_name") )
22 + #set( $userLastName = $userdoc.display("last_name") )
23 +#elseif( $userNamePar )
24 +## from the URL, "user=$userNamePar" parameter
25 + #if( $userNamePar.contains('XWiki.') )
26 + #set( $userName = "$userNamePar" )
30 30   #else
31 - #set( $yearList = [$lastYear..$firstYear] )
28 + #set( $userName = "XWiki.$userNamePar" )
32 32   #end
30 + #if( !$xwiki.exists( $userName ) )
31 + #if( $services.localization.currentLocale == 'it' )
32 +{{warning}}L'utente “$userNamePar” non esiste{{/warning}}
33 + #else
34 +{{warning}}User “$userNamePar” does not exist{{/warning}}
35 + #end
36 + #stop
37 + #end
38 + #set( $apiceUser = true )
39 + #set( $oneUser = true)
40 + #set( $userdoc = $xwiki.getDocument($userName) )
41 + #set( $userFirstName = $userdoc.display("first_name") )
42 + #set( $userLastName = $userdoc.display("last_name") )
43 +#elseif( $firstNamePar && $lastNamePar )
44 +## from the URL, "name=Firstname&surname=Lastname" parameter
45 + #set( $apiceUser = false )
46 + #set( $oneUser = true )
47 + #set( $userFirstName = $firstNamePar )
48 + #set( $userLastName = $lastNamePar )
49 +#else
50 + #set( $apiceUser = false )
51 + #set( $oneUser = false )
52 + #set( $userFirstName = "" )
53 + #set( $userLastName = "" )
33 33  #end
34 -$oneYear
35 -$yearList
36 -### END YEAR
37 -##
38 -### START USER & CYCLE
39 -#set( $userNamePar = $request.user.trim() )
40 -## default values
41 -#set( $oneUser = false )
42 -#set( $oneCycle = false )
43 -#set( $userFirstName = "" )
44 -#set( $userLastName = "" )
45 -#if( $userName || $userNamePar )
46 -## a user is specified for all roles
47 - #if( !$userName )
48 - #set( $selectedUser = "XWiki.$userNamePar" )
55 +#if( $oneUser )
56 + #if( $apiceUser )
57 + #set( $userString = "%$userName%" )
49 49   #else
50 - #set( $selectedUser = $userName )
59 + #set( $userString = "%$userFirstName $userLastName%" )
51 51   #end
52 - #if( $xwiki.exists($selectedUser) )
53 - #set( $oneUser = true )
54 - #set( $userdoc = $xwiki.getDocument($selectedUser) )
55 - #set( $userFirstName = $userdoc.display("first_name") )
56 - #set( $userLastName = $userdoc.display("last_name") )
61 +#else
62 + #set( $userString = "%%" )
63 +#end
64 +#### handle cycle
65 +## $cycleList gets the list of cycles to be shown
66 +## $oneCycle true if just one cycle to be shown
67 +#if( $request.cycle && $request.cycle.trim() != "" )
68 + #set( $cyclePar = $request.cycle.trim().toUpperCase() )
69 + #if( $thesisCycles.contains($cyclePar) )
70 +## 'cycle' parameter is an admissible thesis cycle value
71 + #set( $cycleList = [$cyclePar])
72 + #set( $oneCycle = true )
73 + #set( $cycle = $cyclePar )
57 57   #else
58 -{{warning}} $selectedUser is not an {{apice/}} user{{/warning}}
75 +## 'cycle' parameter is not an admissible thesis cycle value
76 +{{warning}}$cyclePar is not an admissible cycle for APICe theses{{/warning}}
59 59   #stop
60 60   #end
61 -##user selected and existing user page
62 - #set( $cyclePar = $request.cycle.trim().toUpperCase() )
63 - #set( $selectedCycle = '' )
64 - #if( $cyclePar != '' && $allThesisCycles.contains($cyclePar) )
65 - #set( $oneCycle = true )
66 - #set( $selectedCycle = $cyclePar )
79 +#else
80 +## default: all cycles
81 + #set( $cycleList = $showcaseThesisCycles )
82 + #set( $oneCycle = false )
83 + #set( $cycle = "" )
84 +#end
85 +## INVARIANT: $oneCycle and $cycleList are correctly and coherently initialised
86 +##
87 +## when
88 +#set( $yearPar = $request.year.trim() )
89 +#set( $firstYearPar = $request.from.trim() )
90 +#set( $lastYearPar = $request.to.trim() )
91 +#### handle when
92 +#set( $firstYear = $mathtool.toInteger($firstYearThesis) )
93 +#set( $lastYear = $mathtool.toInteger($lastYearThesis) )
94 +#if( $lastYear < $firstYear )
95 + #set( $lastYear = $firstYear )
96 +#end
97 +## parameters takes precedence
98 +#if( $yearPar )
99 + #set( $yearInt = $mathtool.toInteger($yearPar) )
100 + #if( $yearInt > 0 )
101 + #set( $firstYear = $yearInt )
102 + #set( $lastYear = $yearInt )
67 67   #end
68 68  #end
69 -## $oneUser and $oneCycle set properly
70 -$oneUser
71 -$oneCycle
72 -### END USER & CYCLE
105 +#if( $firstYearPar )
106 + #set( $yearInt = $mathtool.toInteger($firstYearPar) )
107 + #if( $yearInt > 0 )
108 + #set( $firstYear = $yearInt )
109 + #end
110 +#end
111 +#if( $lastYearPar )
112 + #set( $yearInt = $mathtool.toInteger($lastYearPar) )
113 + #if( $yearInt > 0 )
114 + #set( $lastYear = $yearInt )
115 + #end
116 +#end
117 +#if( $lastYear < $firstYear )
118 +## swap
119 + #set( $yearTemp = $lastYear )
120 + #set( $lastYear = $firstYear )
121 + #set( $firstYear = $yearTemp )
122 +#end
123 +## invariant: $lastYear >= $firstYear
124 +#if( $lastYear > $firstYear )
125 + #set( $year = -1 )
126 + #set( $yearList = [$lastYear..$firstYear] )
127 + #set( $oneYear = false )
128 +#else
129 +## $lastYear = $firstYear
130 + #set( $year = $lastYear )
131 + #set( $yearList = [$year] )
132 + #set( $oneYear = true )
133 +#end
134 +## handle when / end
73 73  ##
74 -## title
75 ->#if( $oneRole ){{thesisCycle short='no'}}$selecteCycle{{/thesisCycle}}#else{{stringEngIta eng="Theses" ita="Tesi"/}}#end / #if( $oneYear )$selectedYear#else$firstYear–$lastYear#end#if( $oneUser ) / $userFirstName **$userLastName**#end{{id name='top'/}}
76 -## index
77 -#if( !$oneYear )
78 -(% style="font-size: smaller; padding:1em 1.5em 0.25em 1.5em; background-color:$theme.highlightColor" %)(((#foreach( $year in $yearList )#if ($velocityCount > 1) | #end[[$year>>||anchor="$year"]]#end)))
79 -#elseif( $oneUser && !$oneCycle )
80 -(% style="font-size: smaller; padding:1em 1.5em 0.25em 1.5em; background-color:$theme.highlightColor" %)(((#foreach( $cycle in $allThesisCycles )#if ($velocityCount > 1) | #end [[{{thesisCycle}}$cycle{{/thesisCycle}}>>||anchor="$cycle"]]#end)))
81 -#end{{id name='index'/}}
136 +## $oneUser, $apiceUser, $userString, $userFirstName, $userLastName, $oneCycle, $cycleList, $oneYear, $yearList are properly set
137 +##
138 +## handle inline / start
139 +##
140 +## default: false
141 +#set( $showInline = false )
142 +## check $inlinePar
143 +#if( $inlinePar != "" && $trueStringList.contains($inlinePar.toLowerCase()) )
144 + #set( $showInline = true )
145 +#end
146 +##
147 +## handle inline / end
148 +##
149 +#### HANDLE PARAMETERS / END
150 +##
151 +## query to structures
152 +#set( $itemMap = {} )
153 +#set( $itemNo = 0 )
154 +#foreach( $year in $yearList )
155 + #set( $query = ", BaseObject as obj, StringProperty as prop0, DateProperty as prop1, StringProperty as prop2, LargeStringProperty as prop3, LargeStringProperty as prop4, LargeStringProperty as prop5
156 + where obj.name = doc.fullName and obj.className = '${objectSpace}.${objectClass}' and obj.name <> '${objectSpace}.${objectTemplate}' and prop0.id.id = obj.id and prop1.id.id = obj.id and prop2.id.id = obj.id and prop3.id.id = obj.id and prop4.id.id = obj.id and prop5.id.id = obj.id and prop0.name = 'cycle' and prop1.name = 'end' and prop2.name = 'status' and prop3.name = 'supervisors' and prop4.name = 'cosupervisors' and prop5.name = 'contacts' #if( $oneCycle ) and prop0.value = '$cycle'#end and year(prop1.value) = $year and lower(prop2.value) = 'completed' #if( $oneUser )and ( prop3.value like '%$userString%' or prop4.value like '%$userString%' or prop5.value like '%$userString%' )#end order by prop1.value desc" )
157 +## do query
158 + #set( $itemFound = $xwiki.searchDocuments($query) )
159 +## set counters
160 + #set( $itemYearNo = $itemFound.size() )
161 + #if( $itemYearNo > 0 )
162 + #set( $itemMap[$year] = $itemFound )
163 + #set( $itemNo = $itemNo + $itemYearNo )
164 + #end
165 +#end
166 +##
167 +## output results
168 +## page subtitle
169 +{{id name="top"/}}
170 +>(%%)$itemNo #if( $itemNo == 1 )#if( $oneCycle ){{thesisCycle plural="false" uppercase="false"}}$cycle{{/thesisCycle}}#else$services.localization.render('thesis').toLowerCase()#end#{else}#if( $oneCycle ){{thesisCycle plural="true" uppercase="false"}}$cycle{{/thesisCycle}}#else$services.localization.render('theses').toLowerCase()#end#{end} / #if( $oneYear )$year#else$firstYear–$lastYear#{end}#if( $oneUser ) / $userFirstName $userLastName#{end}(%%)
82 82  
83 -#stop
84 -
85 -## search theses
86 -#set( $thesisNo = 0 )
87 -#foreach( $status in $allThesisStatuses )
88 - #if( !$oneStatus || $selectedStatus == $status )
89 - #set( $thesisStatusNo = 0 )
90 - #if( !$oneStatus )
91 -(% style="border-style:solid hidden hidden solid; border-color:$theme.borderColor; text-align:left; font-style:oblique" %)|{{id name='$status'/}}{{thesisStatus plural='true' uppercase='true' short='true'}}$status{{/thesisStatus}}
92 - #end
93 -## some selected status or all statuses / now $status
94 - #if( $oneUser )
95 -## some user selected
96 - #foreach( $role in $allThesisRoles )
97 - #set( $thesisStatusRoleNo = 0 )
98 - #if( !$oneRole || $selectedRole == $role )
99 - #if( $role == "contact" )
100 - #set( $selectedRoleFieldName = "contacts" )
101 - #elseif( $role == "cosupervisor" )
102 - #set( $selectedRoleFieldName = "cosupervisors" )
103 - #else
104 - #set( $selectedRoleFieldName = "supervisors" )
105 - #end
106 -## some selected role or all roles / now $role
107 - #set ($sql = ", BaseObject as obj, StringProperty as prop0, LargeStringProperty as prop1, DateProperty as prop2
108 - where obj.name = doc.fullName and obj.className = 'Theses.ThesisClass' and obj.name <> 'Theses.ThesisClassTemplate' and obj.name <> 'Theses.ThesisTemplate' and prop0.id.id = obj.id and prop1.id.id = obj.id and prop2.id.id = obj.id and prop0.name = 'status' and prop1.name = '$selectedRoleFieldName' and prop2.name = '$orderingDateFieldName' and lower(prop0.value) = '$status' and prop1.value like '%$selectedUser%' order by prop2.value desc" )
109 - #set( $thesisFound = $xwiki.searchDocuments($sql) )
110 - #set( $thesisFoundNo = $thesisFound.size() )
111 - #set( $thesisStatusRoleNo = $thesisStatusRoleNo + $thesisFoundNo )
112 - #if( $thesisFoundNo > 0 && !$oneRole )
113 -(% style="border-style:#if( $oneStatus )solid hidden hidden solid#{else}hidden hidden hidden dotted#end; border-color:$theme.borderColor; text-align:left; font-style:oblique; font-size:smaller" %)|#if( $oneStatus ){{id name='$role'/}}#else{{id name='$status-$role'/}}#end{{thesisRole plural='no' uppercase='yes' short='yes'}}$role{{/thesisRole}}
114 - #end
115 - #foreach( $thesis in $thesisFound )
116 - #set($thesisDoc = $xwiki.getDocument($thesis))
117 - #set($thesisObj = $thesisDoc.getObject('Theses.ThesisClass'))
118 -* [[$thesisObj.title>>$thesisDoc]]#if( $thesisObj.endDate != "" ) //($thesisObj.endDate)//#end#if( $thesisDoc.getValue('studentUserName') != "" ) [[$xwiki.getUserName($thesisDoc.getValue('studentUserName'), false)>>$thesisDoc.getValue('studentUserName')]]#elseif( $thesisObj.studentFirstName != "" && $thesisObj.studentLastName != "" ) $thesisObj.studentFirstName $thesisObj.studentLastName#end
119 -
120 - #end
121 - #if( $thesisFoundNo > 0 && !$oneRole )
122 -(% style="border-style:#if( $oneStatus )hidden solid solid hidden#{else}hidden dotted hidden hidden#end; border-color:$theme.borderColor; text-align:right; font-style:oblique; font-weight:normal; font-size:smaller; color:$theme.textSecondaryColor" %)|#if( $oneStatus ){{id name='$role-bottom'/}}#else{{id name='$role-$status-bottom'/}}#end($thesisStatusRoleNo #if( $thesisStatusRoleNo == 1 ){{thesisStatus plural='no' uppercase='no' short='no'}}$status{{/thesisStatus}}#else{{thesisStatus plural='yes' uppercase='no' short='no'}}$status{{/thesisStatus}}#end {{stringEngIta eng='as' ita='come'/}} {{thesisRole short='yes'}}$role{{/thesisRole}}) [[[{{stringEngIta eng='top' ita='in cima'/}}]>>||anchor="top"]] [[[{{stringEngIta eng='bottom' ita='in fondo'/}}]>>||anchor="bottom"]]
123 - #end
124 - #end
125 - #set( $thesisStatusNo = $thesisStatusNo + $thesisStatusRoleNo )
172 +## stop if no thesis is found
173 +#if( $itemNo == 0 || $itemMap.keySet().size() == 0 )
174 +## redundant double check
175 + #stop
176 +#end
177 +## some theses found
178 +## page index
179 +#if( $itemMap.keySet().size() > 1 )
180 +## found more than one year
181 +{{id name="index"/}}
182 +(% style="font-size:smaller; text-align:right; padding:1em 1.5em 0.25em 1.5em; background-color:$theme.highlightColor" %)(((#foreach( $year in $itemMap.keySet() )#if( !$foreach.first ) | #end[[$year>>$doc||anchor=$year]]#end)))
183 +#end
184 +## theses displayed per year
185 +#foreach( $year in $itemMap.keySet() )
186 +(% style="border-style:solid hidden hidden solid; border-color:$theme.borderColor; text-align:left; font-style:oblique" %)|{{id name='$year'/}}[[$year>>$doc||style="text-decoration:none; color:$theme.textPrimaryColor" queryString='year=$year#if( $oneUser )#if( $apiceUser )&user=$userName#{else}&name=$userFirstName&surname=$userLastName#end#end#if( $oneCycle )&cycle=$cycle#end#if( $showInline )&inline=true#end']]
187 +#foreach( $item in $itemMap[$year] )
188 + #if( $showInline )
189 + #if( $foreach.first )
126 126   #end
127 -## no user selected, no role selected
128 - #else
129 - #set ($sql = ", BaseObject as obj, StringProperty as prop0, DateProperty as prop1
130 - where obj.name = doc.fullName and obj.className = 'Theses.ThesisClass' and obj.name <> 'Theses.ThesisClassTemplate' and obj.name <> 'Theses.ThesisTemplate' and prop0.id.id = obj.id and prop1.id.id = obj.id and prop0.name = 'status' and prop1.name = '$orderingDateFieldName' and lower(prop0.value) = '$status' order by prop1.value desc" )
131 - #set( $thesisFound = $xwiki.searchDocuments($sql) )
132 - #set( $thesisFoundNo = $thesisFound.size() )
133 - #set( $thesisStatusNo = $thesisStatusNo + $thesisFoundNo )
134 - #foreach( $thesis in $thesisFound )
135 - #set($thesisDoc = $xwiki.getDocument($thesis))
136 - #set($thesisObj = $thesisDoc.getObject('Theses.ThesisClass'))
137 -* [[$thesisObj.title>>$thesisDoc]]#if( $thesisObj.endDate != "" ) //($thesisObj.endDate)//#end#if( $thesisDoc.getValue('studentUserName') != "" ) [[$xwiki.getUserName($thesisDoc.getValue('studentUserName'), false)>>$thesisDoc.getValue('studentUserName')]]#elseif( $thesisObj.studentFirstName != "" && $thesisObj.studentLastName != "" ) $thesisObj.studentFirstName $thesisObj.studentLastName#end
138 -
139 - #end
140 - #end
141 - #if( !$oneStatus )
142 -(% style="border-style:hidden solid solid hidden; border-color:$theme.borderColor; text-align:right; font-style:oblique; font-weight:normal; font-size:smaller; color:$theme.textSecondaryColor" %)|($thesisStatusNo #if($thesisStatusNo == 1){{thesisStatus plural='false' uppercase='false' short='no'}}$status{{/thesisStatus}}#else{{thesisStatus plural='true' uppercase='false' short='no'}}$status{{/thesisStatus}}#end{{id name='$status-bottom'/}}) [[[{{stringEngIta eng='top' ita='in cima'/}}]>>||anchor="top"]] [[[{{stringEngIta eng='bottom' ita='in fondo'/}}]>>||anchor="bottom"]]
143 - #end
191 +* #else(% style="border-style:hidden hidden hidden hidden; font-style:normal" %)|#end{{thesis inline=$showInline linked='title'}}$item{{/thesis}}
144 144   #end
193 + #set( $itemYearNo = $itemMap[$year].size() )
194 +(% style="border-style:hidden solid solid hidden; border-color:$theme.borderColor; text-align:right; font-style:oblique; font-size:smaller" %)|($itemYearNo #if( $oneCycle )#if( $itemYearNo == 1 ){{thesisCycle plural="false" uppercase="false"}}$cycle{{/thesisCycle}}#{else}{{thesisCycle plural="true" uppercase="false"}}$cycle{{/thesisCycle}}#end#else#if( $itemYearNo == 1 )$services.localization.render('thesis').toLowerCase()#else$services.localization.render('theses').toLowerCase()#end#end / $year) [[[{{stringEngIta eng='top' ita='in cima'/}}]>>||anchor="top"]] [[[{{stringEngIta eng='bottom' ita='in fondo'/}}]>>||anchor="bottom"]]
145 145  #end
146 -{{id name='bottom'/}}
147 147  {{/velocity}}
197 +{{id name="bottom"/}}