liquid_feedback_frontend
diff model/unit.lua @ 217:73dbc9e2bfd4
Cummulative patch for enhancements at next generation frontend
author | bsw |
---|---|
date | Sat Mar 12 19:22:50 2011 +0100 (2011-03-12) |
parents | |
children | 7ea52c710503 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/model/unit.lua Sat Mar 12 19:22:50 2011 +0100 1.3 @@ -0,0 +1,53 @@ 1.4 +Unit = mondelefant.new_class() 1.5 +Unit.table = 'unit' 1.6 + 1.7 +function Unit:get_flattened_tree() 1.8 + local units = Unit:new_selector():exec() 1.9 + local tmp_list = {} 1.10 + for i, unit in ipairs(units) do 1.11 + tmp_list[unit.id] = unit 1.12 + end 1.13 + 1.14 + local function get_depth(unit) 1.15 + local depth 1.16 + if unit.parent_id then 1.17 + local parent = tmp_list[unit.parent_id] 1.18 + depth = get_depth(parent) + 1 1.19 + else 1.20 + depth = 0 1.21 + end 1.22 + return depth 1.23 + end 1.24 + 1.25 + 1.26 + for i, unit in ipairs(units) do 1.27 + local depth = get_depth(unit) 1.28 + local name = "" 1.29 + for i = 1, depth do 1.30 + if i < depth then 1.31 + name = name .. " " 1.32 + else 1.33 + name = name .. " ‣ " 1.34 + end 1.35 + end 1.36 + unit.flattened_tree_name = name .. unit.name 1.37 + end 1.38 + 1.39 + local function recurse(units) 1.40 + local list = {} 1.41 + for i, unit in ipairs(units) do 1.42 + list[#list+1] = tmp_list[unit.id] 1.43 + for i, item in ipairs(recurse( 1.44 + Unit:new_selector() 1.45 + :add_where{ "parent_id = ?", unit.id }:add_order_by("name"):exec() 1.46 + )) do 1.47 + list[#list+1] = tmp_list[item.id] 1.48 + end 1.49 + end 1.50 + return list 1.51 + end 1.52 + 1.53 + local list = recurse(Unit:new_selector():add_where("parent_id ISNULL"):add_order_by("name"):exec()) 1.54 + 1.55 + return list 1.56 +end