Module:GenerateDescription/Person

From TwogPedia
Revision as of 17:12, 30 April 2024 by Couchor (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:GenerateDescription/Person/doc

local getArgs = require('Module:Arguments').getArgs
local cargo = mw.ext.cargo
local p = {}


function p.main(frame)
  local args = getArgs(frame)
  local currentTitle = mw.title.getCurrentTitle().text
  local currentTitleSplit = mw.text.split(currentTitle, '/')

  -- Check if 
  local tables = 'Transfers'
  local fields = '_pageName, position'
  local cargoArgs = {
	where = 'id= "' .. mw.title.getCurrentTitle().text .. '" AND leavedate IS NULL AND inactivedate IS NULL'
  }
  transferResults = cargo.query(tables, fields, cargoArgs)	
  
  local name = args.romanized and args.romanized or args.name and args.name or (args.title or '')
  -- Find the position of the first space in the name
  local firstSpaceIndex = string.find(name , " ")
  -- If a space is found, insert the title before it
  if firstSpaceIndex then
    name = string.sub(name, 1, firstSpaceIndex) .. '"' .. args.title .. '" ' .. string.sub(name, firstSpaceIndex + 1)
  end
  
  local div = mw.html.create('div')
  local str = name
  if args.birthdate then str = str .. ', born on ' .. args.birthdate .. ',' end
  if args.activeRoles then str = str .. ' is a ' .. string.lower(args.activeRoles) end
  if args.nationality then str = str .. (args.activeRoles and ' from ' or ' is from ' ) .. args.nationality end
  if #transferResults > 0 then
    str = str .. ' and is currently fulfilling the position of ' .. transferResults[1].position.. ' in [[' .. transferResults[1]._pageName .. ']]'
  end
  str = str .. '.'
  div:wikitext(str)

  return div
end

return p