@@ -21,12 +21,12 @@ local LeagueIcon = Lua.import('Module:LeagueIcon')
2121local Region = Lua .import (' Module:Region' )
2222local String = Lua .import (' Module:StringUtils' )
2323local Table = Lua .import (' Module:Table' )
24+ local Tournament = Lua .import (' Module:Tournament' )
2425
2526local Opponent = Lua .import (' Module:Opponent/Custom' )
2627local OpponentDisplay = Lua .import (' Module:OpponentDisplay/Custom' )
2728
2829local Conditions = Lua .import (' Module:TournamentsListing/Conditions' )
29- local HighlightConditions = Lua .import (' Module:HighlightConditions' )
3030local Tier = Lua .import (' Module:Tier/Custom' )
3131
3232local TableWidgets = Lua .import (' Module:Widget/Table2/All' )
@@ -56,6 +56,7 @@ local DEFAULT_LIMIT = 5000
5656--- @field showRank boolean
5757--- @field noLis boolean
5858--- @field offset number
59+ --- @field limit number
5960--- @field allowedPlacements string[]
6061--- @field dynamicPlacements boolean
6162--- @field onlyHighlightOnValue string ?
@@ -123,6 +124,7 @@ function BaseTournamentsListing:readConfig()
123124 showRank = Logic .readBool (Logic .nilOr (args .showRank )),
124125 noLis = Logic .readBool (args .noLis ),
125126 offset = tonumber (args .offset ) or 0 ,
127+ limit = tonumber (args .limit ) or DEFAULT_LIMIT ,
126128 allowedPlacements = self :_allowedPlacements (),
127129 dynamicPlacements = Logic .readBool (args .dynamicPlacements ),
128130 onlyHighlightOnValue = args .onlyHighlightOnValue ,
@@ -138,22 +140,19 @@ end
138140
139141--- @return self
140142function BaseTournamentsListing :create ()
141- local data = self .args .data or self :_query ()
143+ local data = self .args .data and Array . map ( self . args . data , Tournament . tournamentFromRecord ) or self :_query ()
142144 if Table .isNotEmpty (data ) then
143145 self .data = data
144146 end
145147
146148 return self
147149end
148150
149- --- @return table
151+ --- @return StandardTournament[]
150152function BaseTournamentsListing :_query ()
151- return mw .ext .LiquipediaDB .lpdb (' tournament' , {
152- conditions = self :buildConditions (),
153- query = ' pagename, name, icon, icondark, organizers, startdate, enddate, status, locations, series, '
154- .. ' prizepool, participantsnumber, game, liquipediatier, liquipediatiertype, extradata, publishertier, type' ,
153+ return Tournament .getAllTournaments (self :buildConditions (), nil , {
155154 order = self .args .order ,
156- limit = self .args .limit or DEFAULT_LIMIT ,
155+ limit = self .config .limit ,
157156 offset = self .config .offset ,
158157 })
159158end
@@ -248,20 +247,20 @@ function BaseTournamentsListing:_header()
248247end
249248
250249--- @private
251- --- @param tournamentData table
250+ --- @param tournamentData StandardTournament
252251--- @return Widget
253252function BaseTournamentsListing :_row (tournamentData )
254253 local config = self .config
255254
256- local highlight = config .showHighlight and self : getHighlightClass ( tournamentData ) or nil
255+ local highlight = config .showHighlight and tournamentData : isHighlighted ( self . config ) or nil
257256 local status = tournamentData .status and tournamentData .status :lower ()
258257
259258 if config .showRank then
260259 self :_calculateRank (tonumber (tournamentData .prizepool ) or 0 )
261260 end
262261
263262 local prizeValue = tonumber (tournamentData .prizepool ) or 0
264- local participantNumber = tonumber (tournamentData .participantsnumber ) or - 1
263+ local participantNumber = tonumber (tournamentData .participantsNumber ) or - 1
265264
266265 local placements = self :_fetchPlacementData (tournamentData )
267266
@@ -277,13 +276,13 @@ function BaseTournamentsListing:_row(tournamentData)
277276 } or nil ,
278277 TableWidgets .Cell {
279278 attributes = {
280- [' data-sort-value' ] = tournamentData .name
279+ [' data-sort-value' ] = tournamentData .fullName
281280 },
282281 children = LeagueIcon .display {
283282 icon = tournamentData .icon ,
284- iconDark = tournamentData .icondark ,
285- link = tournamentData .parent ,
286- name = tournamentData .name ,
283+ iconDark = tournamentData .iconDark ,
284+ link = tournamentData .pageName ,
285+ name = tournamentData .fullName ,
287286 options = {noTemplate = true },
288287 }
289288 },
@@ -292,11 +291,11 @@ function BaseTournamentsListing:_row(tournamentData)
292291 [' text-decoration' ] = status == CANCELLED and ' line-through' or nil ,
293292 },
294293 attributes = {
295- [' data-sort-value' ] = tournamentData .name ,
294+ [' data-sort-value' ] = tournamentData .fullName ,
296295 },
297296 children = LinkWidget {
298- children = tournamentData .name ,
299- link = tournamentData .pagename ,
297+ children = tournamentData .fullName ,
298+ link = tournamentData .pageName ,
300299 }
301300 },
302301 config .showOrganizer
@@ -309,7 +308,7 @@ function BaseTournamentsListing:_row(tournamentData)
309308 css = {
310309 [' font-style' ] = (status == POSTPONED or status == DELAYED ) and ' italic' or nil ,
311310 },
312- children = BaseTournamentsListing ._dateDisplay (tournamentData .startdate , tournamentData .enddate , status )
311+ children = BaseTournamentsListing ._dateDisplay (tournamentData .startDate , tournamentData .endDate , status )
313312 },
314313 TableWidgets .Cell {
315314 children = prizeValue > 0
@@ -378,7 +377,7 @@ function BaseTournamentsListing:_calculateRank(prize)
378377end
379378
380379--- @private
381- --- @param tournamentData table
380+ --- @param tournamentData StandardTournament
382381--- @return string[]
383382function BaseTournamentsListing ._organizerDisplay (tournamentData )
384383 local organizers = Logic .emptyOr (tournamentData .organizers ) or {}
@@ -446,8 +445,8 @@ function BaseTournamentsListing._displayLocation(locationData, locationIndex)
446445end
447446
448447--- @private
449- --- @param startDate string
450- --- @param endDate string
448+ --- @param startDate DateRecord
449+ --- @param endDate DateRecord
451450--- @param status string ?
452451--- @return Widget | string
453452function BaseTournamentsListing ._dateDisplay (startDate , endDate , status )
@@ -459,7 +458,7 @@ function BaseTournamentsListing._dateDisplay(startDate, endDate, status)
459458end
460459
461460--- @private
462- --- @param tournamentData table
461+ --- @param tournamentData StandardTournament
463462--- @return { qualified : table[] ?, [1] : table[] ?, [2] : table[] ?}
464463function BaseTournamentsListing :_fetchPlacementData (tournamentData )
465464 local placements = {}
@@ -501,7 +500,7 @@ function BaseTournamentsListing:_fetchPlacementData(tournamentData)
501500
502501 local opponent = Opponent .fromLpdbStruct (item )
503502 if not opponent then
504- mw .logObject ({pageName = tournamentData .pagename , place = item .placement }, ' Invalid Prize Pool Data returned from' )
503+ mw .logObject ({pageName = tournamentData .pageName , place = item .placement }, ' Invalid Prize Pool Data returned from' )
505504 elseif Opponent .isTbd (opponent ) then
506505 opponent = Opponent .tbd (Opponent .team )
507506 end
@@ -531,26 +530,18 @@ function BaseTournamentsListing.participantsNumber(number)
531530 return LANG :formatNum (number )
532531end
533532
534- -- overwritable in case wikis want several highlight options
535- --- @protected
536- --- @param tournamentData table
537- --- @return boolean
538- function BaseTournamentsListing :getHighlightClass (tournamentData )
539- return HighlightConditions .tournament (tournamentData , self .config )
540- end
541-
542- --- @param tournamentData table
533+ --- @param tournamentData StandardTournament
543534--- @return string ?
544535function BaseTournamentsListing :displayTier (tournamentData )
545- local tier , tierType , options = Tier . parseFromQueryData ( tournamentData )
536+ local options = tournamentData . tierOptions
546537 options .link = true
547538 if self .config .onlyTierTypeIfBoth then
548539 options .onlyTierTypeIfBoth = true
549540 else
550541 options .tierTypeShort = true
551542 end
552543
553- return Tier .display (tier , tierType , options )
544+ return Tier .display (tournamentData . liquipediaTier , tournamentData . liquipediaTierType , options )
554545end
555546
556547return BaseTournamentsListing
0 commit comments