Improving navigation in the skill wheel see #1791

skala
Julio Montoya 13 years ago
parent f16b8eab10
commit 9abd80377d
  1. 125
      main/inc/lib/skill.lib.php
  2. 82
      main/template/default/skill/skill_wheel.js.tpl
  3. 3
      main/template/default/skill/skill_wheel_student.tpl

@ -393,6 +393,7 @@ class Skill extends Model {
return $result;
}
/* Get one level childrens */
function get_children($skill_id, $load_user_data = false) {
$skill_rel_skill = new SkillRelSkill();
if ($load_user_data) {
@ -404,11 +405,10 @@ class Skill extends Model {
return $skills;
}
/* Get all children of the current node (recursive)*/
function get_all_children($skill_id) {
$skill_rel_skill = new SkillRelSkill();
$children = $skill_rel_skill->get_children($skill_id);
foreach ($children as $child) {
$sub_children = $this->get_all_children($child['skill_id']);
}
@ -420,7 +420,7 @@ class Skill extends Model {
/**
* All parents from root to n
* Gets all parents from from the wanted skill
*/
function get_parents($skill_id) {
$skill_rel_skill = new SkillRelSkill();
@ -445,6 +445,9 @@ class Skill extends Model {
return $skills;
}
/*
* Adds a new skill
*/
public function add($params) {
if (!isset($params['parent_id'])) {
$params['parent_id'] = 1;
@ -489,6 +492,26 @@ class Skill extends Model {
return null;
}
public function add_skill_to_user($user_id, $gradebook_id) {
$skill_gradebook = new SkillRelGradebook();
$skill_rel_user = new SkillRelUser();
$skill_gradebooks = $skill_gradebook->get_all(array('where'=>array('gradebook_id = ?' =>$gradebook_id)));
if (!empty($skill_gradebooks)) {
foreach ($skill_gradebooks as $skill_gradebook) {
$user_has_skill = $this->user_has_skill($user_id, $skill_gradebook['skill_id']);
if (!$user_has_skill) {
$params = array( 'user_id' => $user_id,
'skill_id' => $skill_gradebook['skill_id'],
'acquired_skill_at' => api_get_utc_datetime(),
);
$skill_rel_user->save($params);
}
}
}
}
/* Deletes a skill */
public function delete($skill_id) {
/*$params = array('skill_id' => $skill_id);
@ -544,43 +567,6 @@ class Skill extends Model {
return null;
}
/**
* Return true if the user has the skill
*
* @param int $userId User's id
* @param int $skillId Skill's id
* @param int $checkInParents if true, function will search also in parents of the given skill id
*
* @return bool
*/
public function user_has_skill($user_id, $skill_id) {
$skills = $this->get_user_skills($user_id);
foreach($skills as $my_skill_id) {
if ($my_skill_id == $skill_id) {
return true;
}
}
return false;
}
public function add_skill_to_user($user_id, $gradebook_id) {
$skill_gradebook = new SkillRelGradebook();
$skill_rel_user = new SkillRelUser();
$skill_gradebooks = $skill_gradebook->get_all(array('where'=>array('gradebook_id = ?' =>$gradebook_id)));
if (!empty($skill_gradebooks)) {
foreach ($skill_gradebooks as $skill_gradebook) {
$user_has_skill = $this->user_has_skill($user_id, $skill_gradebook['skill_id']);
if (!$user_has_skill) {
$params = array( 'user_id' => $user_id,
'skill_id' => $skill_gradebook['skill_id'],
'acquired_skill_at' => api_get_utc_datetime(),
);
$skill_rel_user->save($params);
}
}
}
}
/**
* Get user's skills
@ -610,6 +596,9 @@ class Skill extends Model {
}
public function get_skills_tree($user_id = null, $skill_id = null, $return_flat_array = false, $add_root = false) {
if ($skill_id == 1 ) {
$skill_id = 0;
}
if (isset($user_id) && !empty($user_id)) {
$skills = $this->get_all(true, $user_id, null, $skill_id);
} else {
@ -624,18 +613,20 @@ class Skill extends Model {
if (!empty($skill_id)) {
if ($add_root) {
if (!empty($skill_id)) {
//Default root node
$skills[1] = array('id' => '1', 'name' => get_lang('Root'), 'parent_id' => '0');
$skill_info = $this->get_skill_info($skill_id);
//2nd node
$skills[$skill_id] = $skill_info;
//Uncomment code below to hide the searched skill
//$skills[$skill_id]['parent_id'] = $skill_info['extra']['parent_id'];
$skills[$skill_id]['data']['parent_id'] = $skill_info['parent_id'];
$skills[$skill_id]['parent_id'] = 1;
}
}
}
//var_dump($skills);
$refs = array();
$skills_tree = null;
@ -648,17 +639,10 @@ class Skill extends Model {
if ($skill['parent_id'] == 0) {
$skill['parent_id'] = 'root';
}
/*
if (empty($skill_id)) {
if ($skill['parent_id'] == 0) {
$skill['parent_id'] = 'root';
}
} else {
if ($skill['id'] == $skill_id) {
$skill['parent_id'] = 'root';
}
}
*/
// 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']);
//In order to paint all members of a family with the same color
if (empty($skill_id)) {
if ($skill['parent_id'] == 1) {
@ -668,10 +652,16 @@ class Skill extends Model {
if ($skill['parent_id'] == $skill_id) {
$family[$skill['id']] = $this->get_all_children($skill['id']);
}
/*if ($skill_id == $skill['id']) {
$skill['parent_id'] = 1;
}*/
}
// 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']);
if (!isset($skill['data']['real_parent_id'])) {
$skill['data']['real_parent_id'] = $skill['parent_id'];
}
//User achieved the skill (depends in the gradebook with certification)
$skill['data']['achieved'] = false;
@ -725,7 +715,6 @@ class Skill extends Model {
'data' => array()
);
}
if ($return_flat_array) {
return $flat_array;
}
@ -739,7 +728,6 @@ class Skill extends Model {
*/
public function get_skills_tree_json($user_id = null, $skill_id = null, $return_flat_array = false, $main_depth = 2) {
$tree = $this->get_skills_tree($user_id, $skill_id, $return_flat_array, true);
$simple_tree = array();
if (!empty($tree['children'])) {
foreach ($tree['children'] as $element) {
@ -748,6 +736,7 @@ class Skill extends Model {
);
}
}
//var_dump($simple_tree[0]['children']);
return json_encode($simple_tree[0]['children']);
}
@ -855,4 +844,24 @@ class Skill extends Model {
$result = Database::query($sql);
return Database::store_result($result, 'ASSOC');
}
/**
* Return true if the user has the skill
*
* @param int $userId User's id
* @param int $skillId Skill's id
* @param int $checkInParents if true, function will search also in parents of the given skill id
*
* @return bool
*/
public function user_has_skill($user_id, $skill_id) {
$skills = $this->get_user_skills($user_id);
foreach($skills as $my_skill_id) {
if ($my_skill_id == $skill_id) {
return true;
}
}
return false;
}
}

@ -1,13 +1,13 @@
<script>
/* Skill wheel settings */
var debug = true;
var url = '{{ url }}';
var skill_to_load_from_get = '{{ skill_id_to_load }}';
//Just in case we want to use it
var main_depth = 4;
var main_parent_id = false;
var main_parent_id = 0;
// Used to split in two word or not
var max_size_text_length = 14;
@ -190,21 +190,39 @@ for (i= 0; i < color_loops; i++) {
}
/* When you click a skill partition */
function click_partition(d, path, text, icon, arc, x, y, r, p) {
function click_partition(d, path, text, icon, arc, x, y, r, p, vis) {
//console.log(d.depth);
console.log(d);
if (d.id) {
console.log(d.real_parent_id + ' ' +d.parent_id);
main_parent_id = d.real_parent_id;
if (debug) {
console.log('Clicking a partition skill id: '+d.id);
console.log(d);
console.log('real parent_id: '+d.real_parent_id + ' parent_id: ' +d.parent_id);
console.log('depth ' + d.depth);
console.log('main_depth ' + main_depth);
}
console.log('main_parent_id: ' + main_parent_id);
if (d.depth >= main_depth) {
//main_depth += main_depth;
load_nodes(d.id, main_depth);
if (main_parent_id) {
load_nodes(main_parent_id, main_depth);
} else {
load_nodes(d.id, main_depth);
}
}
if (d.id) {
console.log('Getting skill info');
skill_info = get_skill_info(d.parent_id);
console.log(skill_info);
main_parent_id = skill_info.extra.parent_id;
main_parent_id = d.parent_id;
console.log('Setting main_parent_id: ' + main_parent_id);
}
//console.log(main_parent_id);
@ -213,6 +231,8 @@ for (i= 0; i < color_loops; i++) {
load_nodes(main_parent_id, main_depth);
}
console.log('Continue to click_partition');
//console.log(main_parent_id);
//Duration of the transition
@ -376,11 +396,11 @@ for (i= 0; i < color_loops; i++) {
}
/* Handles mouse clicks */
function handle_mousedown_event(d, path, text, icon, arc, x, y, r, padding) {
function handle_mousedown_event(d, path, text, icon, arc, x, y, r, padding, vis) {
switch (d3.event.which) {
case 1:
//alert('Left mouse button pressed');
click_partition(d, path, text, icon, arc, x, y, r, padding);
click_partition(d, path, text, icon, arc, x, y, r, padding, vis);
break;
case 2:
//alert('Middle mouse button pressed');
@ -397,7 +417,24 @@ for (i= 0; i < color_loops; i++) {
/*
Loads the skills partitions thanks to a json call
*/
function load_nodes(load_skill_id, main_depth) {
function load_nodes(load_skill_id, main_depth, extra_parent_id) {
if (debug) {
console.log('Load nodes');
console.log('Loading skill id: '+load_skill_id+' with depth ' + main_depth);
console.log('main_parent_id ' + main_parent_id);
}
if (main_parent_id && load_skill_id) {
skill_info = get_skill_info(load_skill_id);
if (skill_info && skill_info.extra) {
main_parent_id = skill_info.extra.parent_id;
} else {
main_parent_id = 0;
}
console.log('main_parent_id 2' + main_parent_id);
}
/** Define constants and size of the wheel */
/** Total width of the wheel (also counts for the height) */
@ -493,6 +530,7 @@ function load_nodes(load_skill_id, main_depth) {
/* Setting icons */
var icon = vis.selectAll("icon").data(nodes);
/* Path settings */
path.enter().append("path")
.attr("id", function(d, i) {
@ -516,12 +554,20 @@ function load_nodes(load_skill_id, main_depth) {
})
.on("mousedown", function(d, i) {
//Handles mouse clicks
handle_mousedown_event(d, path, text, icon, arc, x, y, r, padding);
handle_mousedown_event(d, path, text, icon, arc, x, y, r, padding, vis);
})
.on("click", function(d){
//click_partition(d, path, text, icon, arc, x, y, r, padding);
});
/*//Redefine the root
path_zero = vis.selectAll("#path-0").on("mousedown", function(d){
d = get_skill_info(extra_parent_id);
d.parent_id = d.extra.parent_id;
click_partition(d, path, text, icon, arc, x, y, r, padding, vis);
});*/
/* End setting skills */
/* Text settings */
@ -549,10 +595,10 @@ function load_nodes(load_skill_id, main_depth) {
})
.on("mousedown", function(d, i) {
//Handles 2 mouse clicks
handle_mousedown_event(d, path, text, icon, arc, x, y, r, padding);
handle_mousedown_event(d, path, text, icon, arc, x, y, r, padding, vis);
})
.on("click", function(d){
//click_partition(d, path, text, icon, arc, x, y, r, padding);
});
/** Managing text - maximum two words */
@ -568,7 +614,6 @@ function load_nodes(load_skill_id, main_depth) {
insert_two_words = false;
return d.depth ? d.name : "";
}
});
if (insert_two_words) {
@ -576,7 +621,7 @@ function load_nodes(load_skill_id, main_depth) {
.attr("x", 0)
.attr("dy", "1em")
.text(function(d) {
return d.depth ? d.name.split(" ")[1] || "" : "";
return d.depth && d.name.length > max_size_text_length ? d.name.split(" ")[1] || "" : "";
});
}
@ -645,7 +690,6 @@ function get_gradebook_info(id) {
return item;
}
$(document).ready(function() {
});

@ -77,7 +77,6 @@ $(document).ready(function() {
add_skill_in_profile_list(skill_id, skill_name);
});
/* URL link when searching skills */
$("#skill_holder").on("click", "a.load_wheel", function() {
skill_id = $(this).attr('rel');
@ -246,7 +245,6 @@ $(document).ready(function() {
});
</script>
<div class="container-fluid">
<div class="row-fluid">
@ -267,7 +265,6 @@ $(document).ready(function() {
<br /><br />
<div class="btn-group">
<a class="btn load_root" rel="0" href="#">{{ "SkillRoot"|get_lang }}</a>
<!-- <a id="clear_selection" class="btn">{{ "Clear"|get_lang }}</a> -->
</div>
<ul id="skill_holder" class="holder holder_simple">
</ul>

Loading…
Cancel
Save