Skills: Profile search is ugly but is working see #1791

skala
Julio Montoya 14 years ago
parent 23cf0fdc47
commit 53a7d3d460
  1. 57
      main/admin/skills_profile.php
  2. 36
      main/inc/ajax/skill.ajax.php
  3. 55
      main/inc/lib/skill.lib.php
  4. 166
      main/template/default/skill/profile.tpl

@ -17,6 +17,7 @@ $this_section = SECTION_PLATFORM_ADMIN;
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>';
$htmlHeadXtra[] = '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/style.css" rel="stylesheet" type="text/css" />';
$htmlHeadXtra[] = api_get_jquery_ui_js();
$skill = new Skill();
@ -33,6 +34,10 @@ $form->addElement('select', 'skills', null, null, array('id'=>'skills'));
$form->addElement('style_submit_button', 'submit', get_lang('Search'), 'class="a_button blue "');
$profiles = $skill_profile->get_all();
$tpl->assign('profiles', $profiles);
$total_skills_to_search = array();
@ -85,36 +90,17 @@ if (!empty($users)) {
foreach($user_list as $user_id => $user_data) {
$ordered_user_list[$user_data['total_found_skills']][] = $user_data;
}
//sort($ordered_user_list);
var_dump($ordered_user_list);
if (!empty($ordered_user_list)) {
asort($ordered_user_list);
}
}
//var_dump($user_list);
$tpl->assign('user_list', $user_list);
//$tpl->assign('user_list', $user_list);
$tpl->assign('order_user_list', $ordered_user_list);
$tpl->assign('total_search_skills', $count_skills);
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
switch ($action) {
case 'remove_skill':
$new_skill = array();
foreach($skills as $skill_id) {
if ($id != $skill_id) {
$new_skill[] = $skill_id;
}
}
$skills = $_SESSION['skills'] = $new_skill;
break;
case 'save_profile':
break;
}
if (!empty($skills)) {
$counter = 0;
foreach($skills as $hidden_skill_id) {
@ -136,6 +122,29 @@ foreach($total_skills_to_search as &$skill_info) {
}
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
switch ($action) {
case 'remove_skill':
$new_skill = array();
foreach($skills as $skill_id) {
if ($id != $skill_id) {
$new_skill[] = $skill_id;
}
}
$skills = $_SESSION['skills'] = $new_skill;
break;
case 'load_profile':
$skill_profile = new SkillRelProfile();
$skills = $skill_profile->get_skills_by_profile($id);
break;
}
$tpl->assign('skill_list', $skill_list);
$tpl->assign('search_skill_list', $skills);

@ -77,20 +77,13 @@ switch ($action) {
$return = array();
foreach($skills as $skill) {
$return [$skill['data']['id']] = array(
$return [$skill['data']['id']] = array (
'id' => $skill['data']['id'],
'parent_id' => $skill['data']['parent_id'],
'name' => $skill['data']['name'],
'id' => $skill['data']['id']);
'name' => $skill['data']['name']
);
}
echo json_encode($return);
break;
case 'skill_exists':
$skill_data = $skill->get($_REQUEST['skill_id']);
if (!empty($skill_data)) {
echo 1;
} else {
echo 0;
}
break;
case 'remove_skill':
if (!empty($_REQUEST['skill_id']) && !empty($_REQUEST['gradebook_id'])) {
@ -102,7 +95,26 @@ switch ($action) {
} else {
echo 0;
}
break;
break;
case 'save_profile':
$skill_profile = new SkillProfile();
$params = $_REQUEST;
$params['skills'] = isset($_SESSION['skills']) ? $_SESSION['skills'] : null;
$skill_data = $skill_profile->save($params);
if (!empty($skill_data)) {
echo 1;
} else {
echo 0;
}
break;
case 'skill_exists':
$skill_data = $skill->get($_REQUEST['skill_id']);
if (!empty($skill_data)) {
echo 1;
} else {
echo 0;
}
break;
default:
echo '';
}

@ -21,7 +21,34 @@ class SkillProfile extends Model {
var $columns = array('id', 'name','description');
public function __construct() {
$this->table = Database::get_main_table(TABLE_MAIN_SKILL_PROFILE);
$this->table_rel_profile = Database::get_main_table(TABLE_MAIN_SKILL_REL_PROFILE);
}
public function get_profiles() {
$sql = "SELECT * FROM $this->table p INNER JOIN $this->table_rel_profile sp ON(p.id = sp.profile_id) ";
$result = Database::query($sql);
$profiles = Database::store_result($result,'ASSOC');
return $profiles;
}
public function save($params) {
if (!empty($params)) {
$profile_id = parent::save($params);
if ($profile_id) {
$skill_rel_profile = new SkillRelProfile();
if (isset($params['skills'])) {
foreach($params['skills'] as $skill_id) {
$attributes = array('skill_id' => $skill_id, 'profile_id'=>$profile_id);
$skill_rel_profile->save($attributes);
}
}
return $profile_id;
}
}
return false;
}
}
class SkillRelProfile extends Model {
@ -29,6 +56,17 @@ class SkillRelProfile extends Model {
public function __construct() {
$this->table = Database::get_main_table(TABLE_MAIN_SKILL_REL_PROFILE);
}
public function get_skills_by_profile($profile_id) {
$skills = $this->get_all(array('where'=>array('profile_id = ? ' => $profile_id)));
$return_array = array();
if (!empty($skills)) {
foreach($skills as $skill_data) {
$return_array[] = $skill_data['skill_id'];
}
}
return $return_array;
}
}
class SkillRelSkill extends Model {
@ -201,13 +239,16 @@ class SkillRelUser extends Model {
}
public function get_user_by_skills($skill_list) {
$skill_list = array_map('intval', $skill_list);
$skill_list = implode("', '", $skill_list);
$sql = "SELECT user_id FROM {$this->table} WHERE skill_id IN ('$skill_list') ";
$result = Database::query($sql);
$users = Database::store_result($result, 'ASSOC');
$users = array();
if (!empty($skill_list)) {
$skill_list = array_map('intval', $skill_list);
$skill_list = implode("', '", $skill_list);
$sql = "SELECT user_id FROM {$this->table} WHERE skill_id IN ('$skill_list') ";
$result = Database::query($sql);
$users = Database::store_result($result, 'ASSOC');
}
return $users;
}

@ -13,6 +13,70 @@ $(document).ready( function() {
filter_selected: true,
newel: true
});
//Open dialog
$("#dialog-form").dialog({
autoOpen: false,
modal : true,
width : 550,
height : 350,
});
var name = $( "#name" ),
description = $( "#description" ),
allFields = $( [] ).add( name ).add( description ), tips = $(".validateTips");
$("#dialog-form").dialog({
buttons: {
"Add" : function() {
var bValid = true;
bValid = bValid && checkLength( name, "name", 1, 255 );
var params = $("#save_profile_form").serialize();
$.ajax({
url: '{$url}?a=save_profile&'+params,
success:function(data) {
/*jsPlumb.connect({
source : "block_2",
target : "block_1",
overlays : overlays
});*/
/*
calEvent.title = $("#name").val();
calEvent.start = calEvent.start;
calEvent.end = calEvent.end;
calEvent.allDay = calEvent.allDay;
calEvent.description = $("#content").val();
calendar.fullCalendar('updateEvent',
calEvent,
true // make the event "stick"
);*/
$("#dialog-form").dialog("close");
}
});
},
},
close: function() {
$("#name").attr('value', '');
$("#description").attr('value', '');
}
});
$("#add_profile").click(function() {
$("#name").attr('value', '');
$("#description").attr('value', '');
$("#dialog-form").dialog("open");
});
});
function check_skills() {
@ -51,11 +115,15 @@ function checkLength( o, n, min, max ) {
} else {
return true;
}
}
}
</script>
<h1>{"SearchSkills"|get_lang}</h1>
{$form}
{if !empty($search_skill_list) }
<h3>{"Skills"|get_lang}</h3>
<ul class="holder">
{foreach $search_skill_list as $search_skill_id}
<li class="bit-box">
@ -64,48 +132,57 @@ function checkLength( o, n, min, max ) {
</li>
{/foreach}
</ul>
<a class="a_button gray small" href="?a=save_profile"> {"SaveThisSearch"|get_lang}</a>
<a id="add_profile" class="a_button gray small" href="#"> {"SaveThisSearch"|get_lang}</a>
{/if}
{if !empty($user_list) }
{foreach $user_list as $user}
<div class="ui-widget">
<div class="ui-widget-header">
{$user['user'].username}
</div>
<div class="ui-widget-content ">
<img src="{$user['user'].avatar_small}" />
{$user['user'].complete_name}
<h3>Skills</h3>
<ul>
{$user.total_found_skills} / {$total_search_skills}
{foreach $user['skills'] as $skill_data}
<li>
<span class="label_tag notice">{$skill_list[$skill_data.skill_id].name}</span>
{if $skill_data.found}
* I have this skill *
{/if}
</li>
{/foreach}
</ul>
</div>
</div>
{/foreach}
{else}
{"No results"|get_lang}
{if !empty($profiles) }
<h3>{"SkillProfiles"|get_lang}</h3>
<ul class="holder">
{foreach $profiles as $profile}
<li class="bit-box">
<a href="?a=load_profile&id={$profile.id}">{$profile.name}</a>
</li>
{/foreach}
</ul>
{/if}
{if !empty($order_user_list) }
{foreach $order_user_list as $count => $user_list}
<h2> {"Matches"|get_lang} {$count}/{$total_search_skills} </h2>
{foreach $user_list as $user}
<div class="ui-widget">
<div class="ui-widget-header">
<h3>
<img src="{$user['user'].avatar_small}" /> {$user['user'].complete_name} ({$user['user'].username})
</h3>
</div>
<div class="ui-widget-content ">
<h4>Skills</h4>
<ul>
{$user.total_found_skills} / {$total_search_skills}
{foreach $user['skills'] as $skill_data}
<li>
<span class="label_tag notice">{$skill_list[$skill_data.skill_id].name}</span>
{if $skill_data.found}
* I have this skill *
{/if}
</li>
{/foreach}
</ul>
</div>
</div>
{/foreach}
{/foreach}
{else}
{"No results"|get_lang}
{/if}
<div id="dialog-form" style="display:none;">
<form id="add_item" name="form">
<input type="hidden" name="id" id="id"/>
<form id="save_profile_form" name="form">
<div class="row">
<div class="label">
<label for="name">Name</label>
@ -114,27 +191,6 @@ function checkLength( o, n, min, max ) {
<input type="text" name="name" id="name" size="40" />
</div>
</div>
<div class="row">
<div class="label">
<label for="name">Parent</label>
</div>
<div class="formw">
<select id="parent_id" name="parent_id" />
</select>
</div>
</div>
<div class="row">
<div class="label">
<label for="name">Gradebook</label>
</div>
<div class="formw">
<select id="gradebook_id" name="gradebook_id[]" multiple="multiple"/>
</select>
<span class="help-block">
Gradebook Description
</span>
</div>
</div>
<div class="row">
<div class="label">
<label for="name">Description</label>

Loading…
Cancel
Save