liquid_feedback_frontend

view model/unit.lua @ 218:7ea52c710503

Some little changes for next generation frontend
author bsw
date Sun Mar 13 16:53:33 2011 +0100 (2011-03-13)
parents 73dbc9e2bfd4
children
line source
1 Unit = mondelefant.new_class()
2 Unit.table = 'unit'
4 function Unit:get_flattened_tree()
5 local units = Unit:new_selector():exec()
6 local tmp_list = {}
7 for i, unit in ipairs(units) do
8 tmp_list[unit.id] = unit
9 end
11 local function get_depth(unit)
12 local depth
13 if unit.parent_id then
14 local parent = tmp_list[unit.parent_id]
15 depth = get_depth(parent) + 1
16 else
17 depth = 0
18 end
19 return depth
20 end
23 for i, unit in ipairs(units) do
24 local depth = get_depth(unit)
25 local name = ""
26 for i = 1, depth do
27 if i < depth then
28 name = name .. "     "
29 else
30 name = name .. "   ‣ "
31 end
32 end
33 unit.flattened_tree_name = name .. unit.name
34 end
36 local function recurse(units)
37 local list = {}
38 for i, unit in ipairs(units) do
39 list[#list+1] = tmp_list[unit.id]
40 for i, item in ipairs(recurse(
41 Unit:new_selector()
42 :add_where{ "parent_id = ?", unit.id }:add_order_by("name"):exec()
43 )) do
44 list[#list+1] = tmp_list[item.id]
45 end
46 end
47 return list
48 end
50 local list = recurse(Unit:new_selector():add_where("parent_id ISNULL"):add_order_by("name"):exec())
52 return list
53 end
55 function Unit.object_get:name_with_path()
56 local name = ""
57 if self.parent then
58 name = self.parent.name_with_path .. " / "
59 end
60 name = name .. self.name
61 return name
62 end

Impressum / About Us