diff --git a/main/admin/skills.php b/main/admin/skills.php index f0146f51b8..0a83142fcd 100644 --- a/main/admin/skills.php +++ b/main/admin/skills.php @@ -20,13 +20,18 @@ $this_section = SECTION_PLATFORM_ADMIN; $htmlHeadXtra[] = api_get_jquery_ui_js(true); $htmlHeadXtra[] = api_get_js('jquery.jsPlumb.all.js'); -Display::display_header(); -//Display::display_reduced_header(); +//Display::display_header(); +Display::display_reduced_header(); $skill = new Skill(); $skills = $skill->get_all(true); $type = 'edit'; //edit -$skill_visualizer = new SkillVisualizer($skills, $type); + +$tree = $skill->get_skills_tree(null, true); + +$skill_visualizer = new SkillVisualizer($tree, $type); + +echo 'Add item'; $skill_visualizer->display_html(); @@ -35,6 +40,13 @@ $url = api_get_path(WEB_AJAX_PATH).'skill.ajax.php?1=1'; ?> -Add item - @@ -444,6 +493,9 @@ function checkLength( o, n, min, max ) {
+ + Gradebook Description +
@@ -459,7 +511,7 @@ function checkLength( o, n, min, max ) {
get_all($load_user_data); echo json_encode($skills); break; + + case 'load_children': + $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null; + $skills = $skill->get_children($id); + $return = array(); + foreach($skills as $skill) { + $return [$skill['data']['id']] = array('name' => $skill['data']['name'], 'id'=>$skill['data']['id']); + } + echo json_encode($return); + break; case 'skill_exists': $skill_data = $skill->get($_REQUEST['skill_id']); if (!empty($skill_data)) { diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index 083db89448..52f4af866a 100644 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -3001,7 +3001,7 @@ function api_display_language_form($hide_if_no_choice = false) { '; $html .= ''; - $html .= "'; foreach ($original_languages as $key => $value) { if ($folder[$key] == $user_selected_language) { $option_end = ' selected="selected" >'; diff --git a/main/inc/lib/skill.lib.php b/main/inc/lib/skill.lib.php index 99576961bc..dc51298922 100644 --- a/main/inc/lib/skill.lib.php +++ b/main/inc/lib/skill.lib.php @@ -51,6 +51,17 @@ class SkillRelSkill extends Model { } return $parents; } + + public function get_children($skill_id, $add_child_info = true) { + $skills = $this->find('all', array('where'=> array('parent_id = ? '=> $skill_id))); + $skill_obj = new Skill(); + if (!empty($skills)) { + foreach ($skills as &$skill) { + $skill['data'] = $skill_obj->get($skill['skill_id']); + } + } + return $skills; + } } /** @@ -116,11 +127,12 @@ class Skill extends Model { ON skill.id = skill_rel_skill.skill_id "; $result = Database::query($sql); $skills = array(); + if (Database::num_rows($result)) { while ($row = Database::fetch_array($result, 'ASSOC')) { $skill_rel_skill = new SkillRelSkill(); $a = $skill_rel_skill->get_skill_parents($row['id']); - $row['level'] = count($a)-1; + $row['level'] = count($a)-1; $row['gradebooks'] = self::get_gradebooks_by_skill($row['id']); $skills[$row['id']] = $row; } @@ -150,6 +162,11 @@ class Skill extends Model { return $result; } + function get_children($skill_id) { + $skill_rel_skill = new SkillRelSkill(); + $skills = $skill_rel_skill->get_children($skill_id, true); + return $skills; + } public function add($params) { if (!isset($params['parent_id'])) { $params['parent_id'] = 1; @@ -180,8 +197,6 @@ class Skill extends Model { } } - - /** * Return true if the user has the skill * @@ -255,38 +270,45 @@ class Skill extends Model { } - public static function get_skills_tree($user_id = null) { - $skills = self::get_all(); + public function get_skills_tree($user_id = null, $return_flat_array = false) { + $skills = $this->get_all(); $refs = array(); $skills_tree = null; // Create references for all nodes + $flat_array = array(); if (!empty($skills)) { foreach($skills as &$skill) { - if ($skill['parent'] == null) { - $skill['parent'] = 'root'; + if ($skill['parent_id'] == 0) { + $skill['parent_id'] = 'root'; } - $skill['data'] = array('parent' => $skill['parent']); // because except main keys (id, name, children) others keys are not saved while in the space tree + $skill['data'] = array('parent_id' => $skill['parent_id']); // because except main keys (id, name, children) others keys are not saved while in the space tree if ($user_id) { - $skill['data']['achieved'] = self::user_has_skill($user_id, $skill['id']); + $skill['data']['achieved'] = $this->user_has_skill($user_id, $skill['id']); } $refs[$skill['id']] = &$skill; + $flat_array[$skill['id']] = &$skill; } // Moving node to the children index of their parents foreach($skills as $skillInd => &$skill) { - $refs[$skill['parent']]['children'][] = &$skill; + $refs[$skill['parent_id']]['children'][] = &$skill; + $flat_array[$skillInd] = $skill; } $skills_tree = array( - 'name' => get_lang('SkillRootName'), - 'id' => 'root', - 'children' => $refs['root']['children'], - 'data' => array() - ); - } + 'name' => get_lang('SkillRootName'), + 'id' => 'root', + 'children' => $refs['root']['children'], + 'data' => array() + ); + } +//var_dump($flat_array);exit; + if ($return_flat_array) { + return $flat_array; + } unset($skills); return $skills_tree; } diff --git a/main/inc/lib/skill.visualizer.lib.php b/main/inc/lib/skill.visualizer.lib.php index 6ea82403b5..c0d5f9597a 100644 --- a/main/inc/lib/skill.visualizer.lib.php +++ b/main/inc/lib/skill.visualizer.lib.php @@ -7,8 +7,8 @@ class SkillVisualizer { - private $offsetX = 100; - private $offsetY = 50; + private $offsetX = 400; + private $offsetY = 0; private $html = ''; private $type = 'read'; @@ -21,20 +21,24 @@ function prepare_skill_box($skill, $position, $class) { $block_id = $skill['id']; - $this->html .= '
'; + $this->html .= '
'; $gradebook_string = ''; if (!empty($skill['gradebooks'])) { foreach($skill['gradebooks'] as $gradebook) { - $gradebook_string .= Display::span($gradebook['name'], array('class'=>'label_tag notice','style'=>'width:50px')); + $gradebook_string .= Display::span($gradebook['name'], array('class'=>'label_tag notice','style'=>'width:50px')).'
'; } } + $skill['name'] = Display::url($skill['name'], '#', array('id'=>'edit_block_'.$block_id, 'class'=>'edit_block')); + $this->html .= $skill['name'].' '.$gradebook_string; if ($this->type == 'edit' && $skill['parent_id'] != 0) { - $this->html .= Display::url(get_lang('Edit'), '#', array('id=>"edit_block_'.$block_id,'class'=>'edit_block')); - $this->html .= Display::url(get_lang('Add'), '#', array('id=>"edit_block_'.$block_id,'class'=>'edit_block')); - $this->html .= Display::url(get_lang('Delete'), '#', array('id=>"edit_block_'.$block_id,'class'=>'edit_block')); + //$this->html .= Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), 22), '#', array('id'=>'edit_block_'.$block_id,'class'=>'edit_block')); + //$this->html .= Display::url(Display::return_icon('add.png', get_lang('Add'), array(), 22), '#', array('id'=>'edit_block_'.$block_id,'class'=>'edit_block')); + //$this->html .= Display::url(Display::return_icon('delete.png', get_lang('Delete'), array(), 22), '#', array('id=>"edit_block_'.$block_id,'class'=>'edit_block')); + //$this->html .= Display::url(Display::return_icon('up.png', get_lang('Close'), array(), 22), '#', array('id'=>'close_block_'.$block_id,'class'=>'close_block')); + //$this->html .= Display::url(Display::return_icon('down.png', get_lang('Open'), array(), 22), '#', array('id'=>'open_block_'.$block_id,'class'=>'open_block')); } $this->html .= '
'; } @@ -43,8 +47,7 @@ * Adds a node using jplumb */ private function add_item($skill, $position) { - $block_id = $skill['id']; - + $block_id = $skill['id']; $end_point = 'readEndpoint'; //var_dump($skill); @@ -88,23 +91,63 @@ $brothers = array(); + $constant = 100; + + $canvas = 1000; //$this->add_item($skill, array('x' => $x + $this->offsetX, 'y' => $y + $this->offsetY)); - foreach ($this->skills as $skill) { - if (isset($brothers[$skill['parent_id']])) { + foreach ($this->skills as &$skill) { + if (!in_array($skill['parent_id'], array(0,1))) { + continue; + } + $childs = isset($skill['children']) ? count($skill['children']) : 0 ; + + + //$x = round($this->offsetX * sin(deg2rad($corner * $count))); + //$y = round($this->offsetY * cos(deg2rad($corner * $count))); + + /*if (isset($brothers[$skill['parent_id']])) { $brothers[$skill['parent_id']] +=2; } else { $brothers[$skill['parent_id']] = 1; - } - //$x = round($this->offsetX * sin(deg2rad($corner * $count))); - //$y = round($this->offsetY * cos(deg2rad($corner * $count))); + }*/ + $my_count = 0; + $brother_count = $brothers[$skill['id']]; - $x = $brothers[$skill['parent_id']]*100; - $y = $skill['level']*120; + $parent_x = 0; + if ($skill['parent_id'] == 0) { + + $x = $constant*$childs/2; + //$this->offsetX = $constant*$childs; + } else { + + $max = isset($this->skills[$skill['parent_id']]['children']) ? count($this->skills[$skill['parent_id']]['children']) : 0; + foreach($this->skills[$skill['parent_id']]['children'] as $id => $sk) { + if ($skill['id'] == $sk['id']) { + break; + } + $my_count++; + } + $parent_x = isset($this->skills[$skill['parent_id']]['x']) ? $this->skills[$skill['parent_id']]['x'] : 0; + $x = $my_count*150 + $parent_x - (150*$max/2) ; + //$x = $my_count*150 + $parent_x - (150*$max/2) - 20*$childs; + //$x = $my_count*150 + $parent_x - 100*$childs; + } + + $y = $skill['level']*150; + + $skill['x'] = $x; + $skill['y'] = $y; + + + // var_dump($skill); //$skill['description'] = "{$brothers[$skill['parent_id']]} $x - $y"; + //$skill['name'] = $skill['name']." | $x = $my_count * 150 + $parent_x - (150* $max/2) - 10*$childs "; $this->add_item($skill, array('x' => $this->offsetX + $x, 'y' => $this->offsetY +$y)); - } + } + echo $this->get_html(); + } /**