public function getModules($freshData) { $moduleId = null; $moduleItemId = null; $includeContentDetails = true; $includeContentItems = true; $module = null; $moduleItem = null; $req = new ModulesRequest(ActionType::GET, $moduleId, $moduleItemId, $includeContentItems, $includeContentDetails, $module, $moduleItem, $freshData); $roots = new Roots(); $moduleData = $roots->modules($req); $modArr = $moduleData->toArray(); $simpleModules = array(); foreach ($modArr as $item) { $mod = new \stdClass(); $mod->id = $item['module_id']; $mod->value = $item['name']; $simpleModules[] = $mod; } $this->page['rawData'] = json_encode($simpleModules); $iris = new IrisClass(); $result = $iris->buildTree($modArr); $tempArray = array(); if (count($result) < 1) { $parent; $allChildren; $final = array(); //The parent will be the first PUBLISHED item $firstItem; foreach ($moduleData as $item) { if ($item['published'] == "1") { $firstItem = $item; break; } } $newArr = $this->unsetValue($modArr, $firstItem); //remove parent from array $firstParentId = $firstItem["module_id"]; $i = 0; foreach ($newArr as $item) { $item["parent_id"] = $firstParentId; //each item must have a parentId of the first module $item["children"] = []; $item["order"] = $i; $final[] = $item; $i++; } //remove the first Item (which is the parent) $firstItem["parent_id"] = 1; $firstItem["children"] = $final; $firstItem["order"] = 0; $tempArray[] = $firstItem; } else { $tempArray = $result; } return $tempArray; }
private function flatten(array $array, $courseId) { //we will pass this value by reference $flatArray = array(); $order = 0; $iris = new IrisClass(); $iris->recursive($courseId, $array, $flatArray); return $flatArray; }