$modar['contentType'] = $module->contentType; $modar['name'] = $module->name; $modar['lesson_status'] = $module->lesson_status; $modar['raw'] = $module->raw; $modar['scoreMax'] = $module->scoreMax; $modar['credit'] = $module->credit; $modar['session_time'] = $module->session_time; $modar['total_time'] = $module->total_time; $modar['path'] = $module->path; $extendedList[] = $modar; } // build the array of modules // build_element_list return a multi-level array, where children is an array with all nested modules // build_display_element_list return an 1-level array where children is the deep of the module $flatElementList = build_display_element_list(build_element_list($extendedList, 'parent', 'learnPath_module_id')); $moduleNb = 0; $globalProg = 0; $global_time = "0000:00:00"; // look for maxDeep $maxDeep = 1; // used to compute colspan of <td> cells for ($i = 0; $i < sizeof($flatElementList); $i++) { if ($flatElementList[$i]['children'] > $maxDeep) { $maxDeep = $flatElementList[$i]['children']; } } $tool_content .= action_bar(array( array('title' => $langBack,
/** * return a flattened tree of the modules of a learnPath after having add * 'up' and 'down' fields to let know if the up and down arrows have to be * displayed. (recursive function) * * @param $elementList a tree array as one returned by build_element_list * @param $deepness * @return array containing infos of the learningpath, each module is an element of this array and each one has 'up' and 'down' boolean and deepness added in * * @author Piraux Sebastien <*****@*****.**> */ function build_display_element_list($elementList, $deepness = 0) { $count = 0; $first = true; $last = false; $displayElementList = array(); foreach ($elementList as $thisElement) { $count++; // temporary save the children before overwritten it if (isset($thisElement['children'])) { $temp = $thisElement['children']; } else { $temp = NULL; // re init temp value if there is nothing to put in it } // we use 'children' to calculate the deepness of the module, it will be displayed // using a spacing multiply by deepness $thisElement['children'] = $deepness; //--- up and down arrows displayed ? if ($count == count($elementList)) { $last = true; } $thisElement['up'] = $first ? false : true; $thisElement['down'] = $last ? false : true; //--- $first = false; $displayElementList[] = $thisElement; if (isset($temp) && sizeof($temp) > 0) { $displayElementList = array_merge($displayElementList, build_display_element_list($temp, $deepness + 1)); } } return $displayElementList; }