2018-08-28 10:49:12 +02:00
|
|
|
BaseController:subclass(
|
|
|
|
"IndexController",
|
2018-08-27 20:10:53 +02:00
|
|
|
{
|
|
|
|
registry = {},
|
2018-08-28 10:49:12 +02:00
|
|
|
models = {"sections", "category"}
|
|
|
|
}
|
|
|
|
)
|
2018-08-23 11:43:42 +02:00
|
|
|
|
2018-08-23 15:22:59 +02:00
|
|
|
local sectionsByCid = function(db, id)
|
2023-04-26 18:51:03 +02:00
|
|
|
local data, a = db:find({
|
|
|
|
where = {
|
|
|
|
cid = id,
|
|
|
|
publish = 1
|
|
|
|
},
|
|
|
|
order = {"start$desc"}
|
|
|
|
})
|
2018-08-28 10:49:12 +02:00
|
|
|
return data, a
|
2018-08-23 15:22:59 +02:00
|
|
|
end
|
|
|
|
|
2018-08-23 11:43:42 +02:00
|
|
|
function IndexController:index(...)
|
|
|
|
local args = {...}
|
2018-08-23 15:22:59 +02:00
|
|
|
-- now read all the data
|
|
|
|
-- get all root sections as the toc
|
2023-04-26 18:51:03 +02:00
|
|
|
local data, a = self.category:find({
|
|
|
|
where = {
|
|
|
|
pid = 0
|
|
|
|
},
|
|
|
|
order = {"name$asc"}
|
|
|
|
})
|
2018-08-23 15:22:59 +02:00
|
|
|
local toc = {}
|
|
|
|
if not data then
|
|
|
|
return self:error("Cannot query the ToC")
|
|
|
|
end
|
|
|
|
-- find all children category of the toc
|
2018-08-28 10:49:12 +02:00
|
|
|
for key, cat in pairs(data) do
|
|
|
|
cat.name = cat.name:gsub("^%d+%.", "")
|
|
|
|
table.insert(toc, {cat.name, cat.id})
|
2023-04-26 18:51:03 +02:00
|
|
|
local children, b = self.category:find({
|
|
|
|
where = {
|
|
|
|
pid = cat.id
|
|
|
|
},
|
|
|
|
order = {"name$asc"}
|
|
|
|
})
|
2018-08-23 15:22:59 +02:00
|
|
|
if children and #children > 0 then
|
2018-08-28 10:49:12 +02:00
|
|
|
for k, v in pairs(children) do
|
|
|
|
v.sections = sectionsByCid(self.sections, v.id)
|
2018-08-23 15:22:59 +02:00
|
|
|
end
|
|
|
|
cat.children = children
|
|
|
|
else
|
2018-08-28 10:49:12 +02:00
|
|
|
cat.sections = sectionsByCid(self.sections, cat.id)
|
2018-08-23 15:22:59 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
self.template:set("data", data)
|
|
|
|
self.template:set("toc", toc)
|
2018-08-23 11:43:42 +02:00
|
|
|
return true
|
|
|
|
end
|
2018-08-23 15:22:59 +02:00
|
|
|
|
|
|
|
function IndexController:notoc(...)
|
|
|
|
self.template:setView("index")
|
|
|
|
return self:index(table.unpack({...}))
|
|
|
|
end
|
|
|
|
|
2018-08-23 15:50:55 +02:00
|
|
|
function IndexController:actionnotfound(...)
|
|
|
|
return self:notoc(table.unpack({...}))
|
2018-08-28 10:49:12 +02:00
|
|
|
end
|
2018-09-11 10:35:02 +02:00
|
|
|
|
|
|
|
function IndexController:pdf(...)
|
2020-06-07 19:46:59 +02:00
|
|
|
local tmp_file = WWW_ROOT.."/cv_exported.pdf"
|
2021-01-05 20:12:35 +01:00
|
|
|
local cmd = "wkhtmltopdf "..HTTP_ROOT.."/"..self.registry.user.."/index/notoc "..tmp_file
|
|
|
|
print(cmd)
|
2018-09-11 10:35:02 +02:00
|
|
|
local r = os.execute(cmd)
|
|
|
|
if r then
|
2022-11-08 10:32:26 +01:00
|
|
|
std.sendFile(tmp_file)
|
2018-09-11 10:35:02 +02:00
|
|
|
return false
|
|
|
|
else
|
|
|
|
return self:error("Sorry.Problem generate PDF file")
|
|
|
|
end
|
2020-06-07 15:20:21 +02:00
|
|
|
end
|