Zum Inhalt springen

Modul:Quickbar Fluggesellschaft/Test

Aus Wikivoyage
Dokumentation für das Modul Quickbar Fluggesellschaft/Test[Ansicht] [Bearbeiten] [Versionsgeschichte] [Aktualisieren]

Verwendung

Das Submodul ist eine Testversion des Moduls Quickbar Fluggesellschaft und nicht für den Produktivbetrieb geeignet. Es dient der Weiterentwicklung des Moduls Quickbar Fluggesellschaft, damit sich Änderungen nicht auf alle Artikel auswirken, die das Modul benutzen.

Neu- und Weiterentwicklung des Moduls für die {{Quickbar Fluggesellschaft}}

Testobjekte

Thai Airways International:

Thai Airways International
IATATG
SitzChatuchak
DrehkreuzFlughafen Bangkok-Suvarnabhumi
Passagieraufkommen24,6 Mio. (2017)
ZieleAsien, Europa
AllianzStar Alliance
Bonusprogr.Royal Orchid Plus
Tochterges.Thai Smile,
Nok Air
Webseitewww.thaiairways.com

{{#invoke:Quickbar Fluggesellschaft/Test|qb_airline
|id=Q188710
|Passagieraufkommen = 24,6 Mio. (2017)
|Ziele = Asien, Europa
}}


Hinweise
local pstring  = require( 'Module:GetString' )
local p856     = require( 'Module:GetP856' )
local images   = require( 'Module:GetImage' )
local items    = require( 'Module:GetItem' )

-- returns nil, if both values are equal, otherwise the value
-- similar to the SQL function nullif()
local function nilIf ( value, equalValue )

   if ( value == nil ) then
      return nil
   elseif ( tostring ( value ) == tostring ( equalValue ) ) then
      return nil
   else
      return value
   end

end

-- returns the first value that is not nil
-- similar to the SQL function coalesce()
local function coalesce ( value1, value2, value3 )
   return value1 or value2 or value3
end

-- returns a manually created quickbar row
local function createTr ( text, label, trClass )

   -- check for valid text
   -- if there is no text, then display nothing
   if text == '' then 

      return ''

   else

      -- displaying the given info
      local tr = mw.html.create ( 'tr' )
      tr:addClass('voy-qb-item ' .. trClass )
         :tag('th')
         :addClass('voy-qb-item-key')
         :wikitext( label )
      tr:tag('td')
         :addClass( 'voy-qb-item-value1' )
         :wikitext( text )
      return tostring ( tr )
   end

end

local qbAirline = {}

function qbAirline.qb_airline ( frame )
  
   -- copying and lowering the given parameters
   local templateArgs = {}
   for key,value in pairs ( frame.args ) do
      templateArgs[string.lower(key)] = value
   end
   for key,value in pairs ( frame:getParent().args ) do
      templateArgs[string.lower(key)] = value
   end

   -- variables for the whole quickbar content and the categories
   local display = ''
   
   -- getting or determining (if needed) the wikidata-ID
   if templateArgs.id == '' then templateArgs.id = nil end
   local qbID = nilIf ( nilIf ( templateArgs.id, 'self' ), '' ) or mw.wikibase.getEntityIdForCurrentPage() or ''

   -- starting the quickbar table
   display = display .. '<div class="voy-qb-rightdiv"><table cellspacing="0" class="voy-qb voy-qb-airline">'

   -- Logo
   -- always taken from Wikidata
   display = display .. images.GetImage().getEmblemsQuickbar ( qbID, 'L' )

   -- the main image
   -- taken from Wikidata, if not provided
   display = display .. images.GetImage().getMainImageQuickbar ( qbID, coalesce ( templateArgs["bild"], '' ) )

   -- heading
   -- is mandatory, even if you do not provide it, its shown (with the sitename)
   -- initialising with given heading
   local qbNamen = coalesce ( templateArgs["namen"], '' )
   
   -- if no heading is provided, get the sitename
   if qbNamen == '' then
      local page = {}
      page = mw.title.getCurrentTitle()  
      if qbID ~= '' then 
         qbNamen = coalesce ( mw.wikibase.getSitelink( qbID, 'dewikivoyage' ), page.text, 'Fluggesellschaft')
      else
         qbNamen = coalesce ( page.text, 'Fluggesellschaft')
      end
   end
   
   -- creating the row with the heading
   local trHeader = mw.html.create ( 'tr' )
   trHeader:addClass( 'voy-qb-item' )
   trHeader:tag('td')
      :attr('colspan', 2 )
      :addClass('voy-qb-header' )
      :wikitext(qbNamen)
   -- adding it to the quickbar
   display = display .. tostring ( trHeader )

   -- variable for a single quickbar row
   local tr = ''
   
   -- general information:
   -- an entry is only added when the parameter is used
   -- if the parameter is empty, the information is fetched from Wikidata
   -- if the parameter is not empty, the local information is used, but mostly compared Wikidata, and maintenance categories are used
   -- the parameter with the value "no" deactivates the entry

   -- IATA Code
   -- always shown and take from Wikidata
   display = display .. pstring.GetString().getStringsQuickbar ( qbID, 'P229', nil, coalesce ( templateArgs["iata"], '' ) )

   -- headquarters
   display = display .. items.GetItem().getItemsQuickbar ( qbID, 'P159', coalesce ( templateArgs["sitz"], ''), 'Sitz' )

   -- main hub
   display = display .. items.GetItem().getItemsQuickbar ( qbID, 'P113', coalesce ( templateArgs["drehkreuz"], '' ) )

   -- passengers
   display = display .. createTr ( coalesce ( templateArgs["passagieraufkommen"], '' ), 'Passagieraufkommen', 'voy-qb-passengers' )

   -- destinations
   display = display .. createTr ( coalesce ( templateArgs["ziele"], '' ), 'Ziele', 'voy-qb-destinations' )

   -- alliance
   display = display .. items.GetItem().getItemsQuickbar ( qbID, 'P114', coalesce ( templateArgs["allianz"], '' ) )

   -- reward program
   display = display .. items.GetItem().getItemsQuickbar ( qbID, 'P4446', coalesce ( templateArgs["bonusprogramm"], '' ) )
   
   -- subsidiaries
   display = display .. items.GetItem().getItemsQuickbar ( qbID, 'P355', coalesce ( templateArgs["tochtergesellschaften"], '' ) )
   
   -- website
   display = display .. p856.GetP856().getUrlAsLinkWithHostQuickbar ( qbID, coalesce ( templateArgs["webseite"], '' ) )

   -- phone number
   -- not from Wikidata because it's country specific
   display = display .. createTr ( coalesce ( templateArgs["telefon"], '' ), 'Telefon', 'voy-qb-phone' )

   -- finishing the HTML table
   display = display .. '</table></div>'

   return display
   
end

return qbAirline