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)
|
2019-06-11 18:35:34 +02:00
|
|
|
local cond = {exp = { ["and"] = {{["="] = {cid = id}}, {["= "] = {publish = 1}} }}, order = {start = "DESC"}}
|
2018-08-23 15:22:59 +02:00
|
|
|
local data, a = db:find(cond)
|
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
|
2018-08-28 10:49:12 +02:00
|
|
|
local cond = {exp = {["="] = {pid = 0}}, order = {name = "ASC"}}
|
2018-08-23 15:22:59 +02:00
|
|
|
local data, a = self.category:find(cond)
|
|
|
|
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})
|
|
|
|
cond = {exp = {["="] = {pid = cat.id}}, order = {name = "ASC"}}
|
2018-08-23 15:22:59 +02:00
|
|
|
local children, b = self.category:find(cond)
|
|
|
|
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
|
|
|
|
local mime = std.mimeOf(tmp_file)
|
|
|
|
std.header(mime)
|
2020-06-07 15:20:21 +02:00
|
|
|
std.f(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
|