Module:AuthorNews: Difference between revisions

From TwogPedia
(Created page with "local getArgs = require('Module:Arguments').getArgs local News = require('Module:NewsItem') local cargo = mw.ext.cargo local limit = 100000 local p = {} function p.main(frame) local args = getArgs(frame) local results = p.query( args) if #results > 0 then local container = mw.html.create('div'):attr('id', 'news-search-container') local ul = mw.html.create('ul') for r = 1, #results do ul:node(mw.html.create('li'):node(News.main(newsObject(results[r]...")
(No difference)

Revision as of 14:42, 29 April 2024

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

local getArgs = require('Module:Arguments').getArgs
local News = require('Module:NewsItem')
local cargo = mw.ext.cargo

local limit = 100000

local p = {}

function p.main(frame)
	local args = getArgs(frame)
	local results = p.query( args)
	
	if #results > 0 then
		local container = mw.html.create('div'):attr('id', 'news-search-container')
		
		local ul = mw.html.create('ul')
		
		for r = 1, #results do
			ul:node(mw.html.create('li'):node(News.main(newsObject(results[r]))))
		end

		container:node(ul)
		
		return container
	end
end

function p.query(args)
	local whereStr = ''
    local author = args.author
	
	local tables = 'News'
	local fields = '_pageName, date, category, game, image, content'
	local cargoArgs = {
		where = 'author ="' .. author .. '"',
		orderBy = 'date DESC',
		limit = limit
	}
	local results = cargo.query(tables, fields, cargoArgs)
	
    return results
end

function newsObject(result) 
	local object = {
		date = result.date,
		_pageName  = result._pageName,
		category = result.category,
		game = result.game,
		content = result.content,
		author = result.author
	}
	
	return object
end

return p