[svn r13994] Adding development version of gradebook extension to be integrated in Dokeos core. This code isn't complete yet but is added in order to benefit from the SVN repository during the code revision and extension.
parent
13368f6763
commit
85f30e54b9
@ -0,0 +1,45 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Sets needed course variables and then jumps to the exercises result page. |
||||
* This intermediate page is needed because the user is not inside a course |
||||
* when visiting the gradebook, and several course scripts rely on these |
||||
* variables. |
||||
* Most code here is ripped from /main/course_home/course_home.php |
||||
* @author Bert Steppé |
||||
*/ |
||||
|
||||
|
||||
$cidReq = $_GET['cid']; |
||||
|
||||
include ('../inc/global.inc.php'); |
||||
|
||||
api_block_anonymous_users(); |
||||
|
||||
$this_section=SECTION_COURSES; |
||||
|
||||
include_once (api_get_path(LIBRARY_PATH).'course.lib.php'); |
||||
|
||||
$course_code = $_course['sysCode']; |
||||
$course_info = Database::get_course_info($course_code); |
||||
$return_result = CourseManager::determine_course_title_from_course_info($_user['user_id'], $course_info); |
||||
$course_title = $return_result['title']; |
||||
$course_code = $return_result['code']; |
||||
|
||||
$dbname = $course_info['db_name']; |
||||
|
||||
$_course['name'] = $course_title; |
||||
$_course['official_code'] = $course_code; |
||||
|
||||
if (isset($_GET['doexercise'])) |
||||
{ |
||||
header('Location: ../exercice/exercice_submit.php?cidReq='.$cidReq.'&origin=&learnpath_id=&learnpath_item_id=&exerciseId='.$_GET['doexercise']); |
||||
exit; |
||||
} |
||||
else |
||||
{ |
||||
header('Location: ../exercice/exercice.php?show=result'); |
||||
exit; |
||||
} |
||||
|
||||
?> |
@ -0,0 +1,535 @@ |
||||
<?php |
||||
// $Id: gradebook.php 1020 2007-05-11 08:20:27Z stijn $ |
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2006 Dokeos S.A. |
||||
Copyright (c) 2006 Ghent University (UGent) |
||||
Copyright (c) various contributors |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
as published by the Free Software Foundation; either version 2 |
||||
of the License, or (at your option) any later version. |
||||
|
||||
See the GNU General Public License for more details. |
||||
|
||||
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium |
||||
Mail: info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
$language_file= 'gradebook'; |
||||
$cidReset= true; |
||||
include_once ('../inc/global.inc.php'); |
||||
$this_section = SECTION_MYGRADEBOOK; |
||||
include_once ('lib/be.inc.php'); |
||||
include_once ('lib/scoredisplay.class.php'); |
||||
include_once ('lib/gradebook_functions.inc.php'); |
||||
include_once ('lib/fe/catform.class.php'); |
||||
include_once ('lib/fe/evalform.class.php'); |
||||
include_once ('lib/fe/linkform.class.php'); |
||||
include_once ('lib/gradebook_data_generator.class.php'); |
||||
include_once ('lib/fe/gradebooktable.class.php'); |
||||
include_once ('lib/fe/displaygradebook.php'); |
||||
include_once ('lib/fe/userform.class.php'); |
||||
include_once (api_get_path(LIBRARY_PATH).'ezpdf/class.ezpdf.php'); |
||||
api_block_anonymous_users(); |
||||
|
||||
$htmlHeadXtra[]= '<script type="text/javascript"> |
||||
function confirmation () |
||||
{ |
||||
if (confirm("' . get_lang('DeleteAll') . '?")) |
||||
{return true;} |
||||
else |
||||
{return false;} |
||||
} |
||||
</script>'; |
||||
|
||||
// -------------------------------------------------------------------------------- |
||||
// - ACTIONS - |
||||
// -------------------------------------------------------------------------------- |
||||
|
||||
//this is called when there is no data for the course admin |
||||
if (isset ($_GET['createallcategories'])) |
||||
{ |
||||
block_students(); |
||||
$coursecat= Category :: get_not_created_course_categories(api_get_user_id()); |
||||
if (!count($coursecat) == 0) |
||||
{ |
||||
foreach ($coursecat as $row) |
||||
{ |
||||
$cat= new Category(); |
||||
$cat->set_name($row[1]); |
||||
$cat->set_course_code($row[0]); |
||||
$cat->set_description(null); |
||||
$cat->set_user_id(api_get_user_id()); |
||||
$cat->set_parent_id(0); |
||||
$cat->set_weight(0); |
||||
$cat->set_visible(0); |
||||
$cat->add(); |
||||
unset ($cat); |
||||
} |
||||
} |
||||
header('Location: gradebook.php?addallcat=&selectcat=0'); |
||||
exit; |
||||
} |
||||
|
||||
//move a category |
||||
if (isset ($_GET['movecat'])) |
||||
{ |
||||
block_students(); |
||||
$cats= Category :: load($_GET['movecat']); |
||||
if (!isset ($_GET['targetcat'])) |
||||
{ |
||||
$move_form= new CatForm(CatForm :: TYPE_MOVE, |
||||
$cats[0], |
||||
'move_cat_form', |
||||
null, |
||||
api_get_self() . '?movecat=' . $_GET['movecat'] |
||||
. '&selectcat=' . $_GET['selectcat']); |
||||
if ($move_form->validate()) |
||||
{ |
||||
header('Location: ' . api_get_self() . '?selectcat=' . $_GET['selectcat'] |
||||
. '&movecat=' . $_GET['movecat'] |
||||
. '&targetcat=' . $move_form->exportValue('move_cat')); |
||||
exit; |
||||
} |
||||
} |
||||
|
||||
else |
||||
{ |
||||
$targetcat= Category :: load($_GET['targetcat']); |
||||
$course_to_crsind = ($cats[0]->get_course_code() != null && $targetcat[0]->get_course_code() == null); |
||||
|
||||
if (!($course_to_crsind && !isset($_GET['confirm']))) |
||||
{ |
||||
$cats[0]->move_to_cat($targetcat[0]); |
||||
header('Location: ' . api_get_self() . '?categorymoved=&selectcat=' . $_GET['selectcat']); |
||||
exit; |
||||
} |
||||
unset ($targetcat); |
||||
} |
||||
unset ($cats); |
||||
} |
||||
|
||||
//move an evaluation |
||||
if (isset ($_GET['moveeval'])) |
||||
{ |
||||
block_students(); |
||||
$evals= Evaluation :: load($_GET['moveeval']); |
||||
if (!isset ($_GET['targetcat'])) |
||||
{ |
||||
|
||||
$move_form= new EvalForm(EvalForm :: TYPE_MOVE, |
||||
$evals[0], |
||||
null, |
||||
'move_eval_form', |
||||
null, |
||||
api_get_self() . '?moveeval=' . $_GET['moveeval'] |
||||
. '&selectcat=' . $_GET['selectcat']); |
||||
|
||||
if ($move_form->validate()) |
||||
{ |
||||
header('Location: ' .api_get_self() . '?selectcat=' . $_GET['selectcat'] |
||||
. '&moveeval=' . $_GET['moveeval'] |
||||
. '&targetcat=' . $move_form->exportValue('move_cat')); |
||||
exit; |
||||
} |
||||
} |
||||
|
||||
else |
||||
{ |
||||
$targetcat= Category :: load($_GET['targetcat']); |
||||
$course_to_crsind = ($evals[0]->get_course_code() != null && $targetcat[0]->get_course_code() == null); |
||||
|
||||
if (!($course_to_crsind && !isset($_GET['confirm']))) |
||||
{ |
||||
$evals[0]->move_to_cat($targetcat[0]); |
||||
header('Location: ' . api_get_self() . '?evaluationmoved=&selectcat=' . $_GET['selectcat']); |
||||
exit; |
||||
} |
||||
unset ($targetcat); |
||||
} |
||||
unset ($evals); |
||||
} |
||||
|
||||
//move a link |
||||
if (isset ($_GET['movelink'])) |
||||
{ |
||||
block_students(); |
||||
$link= LinkFactory :: load($_GET['movelink']); |
||||
$move_form= new LinkForm(LinkForm :: TYPE_MOVE, null, $link[0], 'move_link_form', null, api_get_self() . '?movelink=' . $_GET['movelink'] . '&selectcat=' . $_GET['selectcat']); |
||||
if ($move_form->validate()) |
||||
{ |
||||
$targetcat= Category :: load($move_form->exportValue('move_cat')); |
||||
$link[0]->move_to_cat($targetcat[0]); |
||||
unset ($link); |
||||
header('Location: ' . api_get_self(). '?linkmoved=&selectcat=' . $_GET['selectcat']); |
||||
exit; |
||||
} |
||||
} |
||||
|
||||
|
||||
//parameters for categories |
||||
if (isset ($_GET['visiblecat'])) |
||||
{ |
||||
block_students(); |
||||
if (isset ($_GET['set_visible'])) |
||||
$visibility_command= 1; |
||||
else |
||||
$visibility_command= 0; |
||||
$cats= Category :: load($_GET['visiblecat']); |
||||
$cats[0]->set_visible($visibility_command); |
||||
$cats[0]->save(); |
||||
$cats[0]->apply_visibility_to_children(); |
||||
unset ($cats); |
||||
if ($visibility_command) |
||||
$confirmation_message = get_lang('ViMod'); |
||||
else |
||||
$confirmation_message = get_lang('InViMod'); |
||||
} |
||||
if (isset ($_GET['deletecat'])) |
||||
{ |
||||
block_students(); |
||||
$cats= Category :: load($_GET['deletecat']); |
||||
//delete all categories,subcategories and results |
||||
if ($cats[0] != null) |
||||
{ |
||||
if ($cats[0]->get_id() != 0) // better don't try to delete the root... |
||||
$cats[0]->delete_all(); |
||||
} |
||||
$confirmation_message = get_lang('CategoryDeleted'); |
||||
} |
||||
//parameters for evaluations |
||||
if (isset ($_GET['visibleeval'])) |
||||
{ |
||||
block_students(); |
||||
if (isset ($_GET['set_visible'])) |
||||
$visibility_command= 1; |
||||
else |
||||
$visibility_command= 0; |
||||
$eval= Evaluation :: load($_GET['visibleeval']); |
||||
$eval[0]->set_visible($visibility_command); |
||||
$eval[0]->save(); |
||||
unset ($eval); |
||||
if ($visibility_command) |
||||
$confirmation_message = get_lang('ViMod'); |
||||
else |
||||
$confirmation_message = get_lang('InViMod'); |
||||
} |
||||
if (isset ($_GET['deleteeval'])) |
||||
{ |
||||
block_students(); |
||||
$eval= Evaluation :: load($_GET['deleteeval']); |
||||
if ($eval[0] != null) |
||||
$eval[0]->delete_with_results(); |
||||
$confirmation_message = get_lang('EvaluationDeleted'); |
||||
} |
||||
//parameters for links |
||||
if (isset ($_GET['visiblelink'])) |
||||
{ |
||||
block_students(); |
||||
if (isset ($_GET['set_visible'])) |
||||
$visibility_command= 1; |
||||
else |
||||
$visibility_command= 0; |
||||
$link= LinkFactory :: load($_GET['visiblelink']); |
||||
$link[0]->set_visible($visibility_command); |
||||
$link[0]->save(); |
||||
unset ($link); |
||||
if ($visibility_command) |
||||
$confirmation_message = get_lang('ViMod'); |
||||
else |
||||
$confirmation_message = get_lang('InViMod'); |
||||
} |
||||
if (isset ($_GET['deletelink'])) |
||||
{ |
||||
block_students(); |
||||
$link= LinkFactory :: load($_GET['deletelink']); |
||||
if ($link[0] != null) |
||||
$link[0]->delete(); |
||||
unset ($link); |
||||
$confirmation_message = get_lang('LinkDeleted'); |
||||
} |
||||
|
||||
if ($course_to_crsind && !isset($_GET['confirm'])) |
||||
{ |
||||
block_students(); |
||||
if (!isset($_GET['movecat']) && !isset($_GET['moveeval'])) |
||||
die ('Error: movecat or moveeval not defined'); |
||||
|
||||
$button = '<form name="confirm" |
||||
method="post" |
||||
action="'.api_get_self() .'?confirm=' |
||||
.(isset($_GET['movecat']) ? '&movecat=' . $_GET['movecat'] |
||||
: '&moveeval=' . $_GET['moveeval'] ) |
||||
.'&selectcat=' . $_GET['selectcat'] |
||||
.'&targetcat=' . $_GET['targetcat'].'"> |
||||
<input type="submit" value="'.get_lang('Ok').'"> |
||||
</form>'; |
||||
|
||||
$warning_message = get_lang('MoveWarning').'<br><br>'.$button; |
||||
} |
||||
|
||||
|
||||
//actions on the sortabletable |
||||
if (isset ($_POST['action'])) |
||||
{ |
||||
block_students(); |
||||
$number_of_selected_items= count($_POST['id']); |
||||
if ($number_of_selected_items == '0') |
||||
$warning_message = get_lang('NoItemsSelected'); |
||||
else |
||||
{ |
||||
switch ($_POST['action']) |
||||
{ |
||||
case 'delete' : |
||||
$number_of_deleted_categories= 0; |
||||
$number_of_deleted_evaluations= 0; |
||||
$number_of_deleted_links= 0; |
||||
foreach ($_POST['id'] as $indexstr) |
||||
{ |
||||
if (substr($indexstr, 0, 4) == 'CATE') |
||||
{ |
||||
$cats= Category :: load(substr($indexstr, 4)); |
||||
if ($cats[0] != null) |
||||
$cats[0]->delete_all(); |
||||
$number_of_deleted_categories++; |
||||
} |
||||
if (substr($indexstr, 0, 4) == 'EVAL') |
||||
{ |
||||
$eval= Evaluation :: load(substr($indexstr, 4)); |
||||
if ($eval[0] != null) |
||||
$eval[0]->delete_with_results(); |
||||
$number_of_deleted_evaluations++; |
||||
} |
||||
if (substr($indexstr, 0, 4) == 'LINK') |
||||
{ |
||||
$link= LinkFactory :: load(substr($indexstr, 4)); |
||||
if ($link[0] != null) |
||||
$link[0]->delete(); |
||||
$number_of_deleted_links++; |
||||
} |
||||
} |
||||
$confirmation_message = get_lang('DeletedCategories') . ' : <b>' . $number_of_deleted_categories . '</b><br>' . get_lang('DeletedEvaluations') . ' : <b>' . $number_of_deleted_evaluations . '</b><br>' . get_lang('DeletedLinks') . ' : <b>' . $number_of_deleted_links . '</b><br><br>' . get_lang('TotalItems') . ' : <b>' . $number_of_selected_items . '</b>'; |
||||
break; |
||||
case 'setvisible' : |
||||
foreach ($_POST['id'] as $indexstr) |
||||
{ |
||||
if (substr($indexstr, 0, 4) == 'CATE') |
||||
{ |
||||
$cats= Category :: load(substr($indexstr, 4)); |
||||
$cats[0]->set_visible(1); |
||||
$cats[0]->save(); |
||||
$cats[0]->apply_visibility_to_children(); |
||||
} |
||||
if (substr($indexstr, 0, 4) == 'EVAL') |
||||
{ |
||||
$eval= Evaluation :: load(substr($indexstr, 4)); |
||||
$eval[0]->set_visible(1); |
||||
$eval[0]->save(); |
||||
} |
||||
if (substr($indexstr, 0, 4) == 'LINK') |
||||
{ |
||||
$link= LinkFactory :: load(substr($indexstr, 4)); |
||||
$link[0]->set_visible(1); |
||||
$link[0]->save(); |
||||
} |
||||
} |
||||
$confirmation_message = get_lang('ItemsVisible'); |
||||
break; |
||||
case 'setinvisible' : |
||||
foreach ($_POST['id'] as $indexstr) |
||||
{ |
||||
if (substr($indexstr, 0, 4) == 'CATE') |
||||
{ |
||||
$cats= Category :: load(substr($indexstr, 4)); |
||||
$cats[0]->set_visible(0); |
||||
$cats[0]->save(); |
||||
$cats[0]->apply_visibility_to_children(); |
||||
} |
||||
if (substr($indexstr, 0, 4) == 'EVAL') |
||||
{ |
||||
$eval= Evaluation :: load(substr($indexstr, 4)); |
||||
$eval[0]->set_visible(0); |
||||
$eval[0]->save(); |
||||
} |
||||
if (substr($indexstr, 0, 4) == 'LINK') |
||||
{ |
||||
$link= LinkFactory :: load(substr($indexstr, 4)); |
||||
$link[0]->set_visible(0); |
||||
$link[0]->save(); |
||||
} |
||||
} |
||||
$confirmation_message = get_lang('ItemsInVisible'); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (isset ($_POST['submit']) && isset ($_POST['keyword'])) |
||||
{ |
||||
header('Location: ' . api_get_self() . '?selectcat=' . $_GET['selectcat'] |
||||
. '&search='.$_POST['keyword']); |
||||
exit; |
||||
} |
||||
|
||||
|
||||
// -------------------------------------------------------------------------------- |
||||
// - DISPLAY HEADERS AND MESSAGES - |
||||
// -------------------------------------------------------------------------------- |
||||
|
||||
if (!isset($_GET['exportpdf'])) |
||||
{ |
||||
if (isset ($_GET['studentoverview'])) |
||||
{ |
||||
$interbreadcrumb[]= array ( |
||||
'url' => 'gradebook.php?selectcat=' . $_GET['selectcat'], |
||||
'name' => get_lang('Gradebook' |
||||
)); |
||||
Display :: display_header(get_lang('FlatView')); |
||||
} |
||||
elseif (isset ($_GET['search'])) |
||||
{ |
||||
$interbreadcrumb[]= array ( |
||||
'url' => 'gradebook.php?selectcat=' . $_GET['selectcat'], |
||||
'name' => get_lang('Gradebook' |
||||
)); |
||||
Display :: display_header(get_lang('SearchResults')); |
||||
} else |
||||
{ |
||||
Display :: display_header(get_lang('Gradebook')); |
||||
} |
||||
} |
||||
|
||||
if (isset ($_GET['categorymoved'])) |
||||
Display :: display_confirmation_message(get_lang('CategoryMoved'),false); |
||||
if (isset ($_GET['evaluationmoved'])) |
||||
Display :: display_confirmation_message(get_lang('EvaluationMoved'),false); |
||||
if (isset ($_GET['linkmoved'])) |
||||
Display :: display_confirmation_message(get_lang('LinkMoved'),false); |
||||
if (isset ($_GET['addcat'])) |
||||
Display :: display_confirmation_message(get_lang('CategoryAdded'),false); |
||||
if (isset ($_GET['linkadded'])) |
||||
Display :: display_confirmation_message(get_lang('LinkAdded'),false); |
||||
if (isset ($_GET['addresult'])) |
||||
Display :: display_confirmation_message(get_lang('ResultAdded'),false); |
||||
if (isset ($_GET['editcat'])) |
||||
Display :: display_confirmation_message(get_lang('CategoryEdited'),false); |
||||
if (isset ($_GET['editeval'])) |
||||
Display :: display_confirmation_message(get_lang('EvaluationEdited'),false); |
||||
if (isset ($_GET['linkedited'])) |
||||
Display :: display_confirmation_message(get_lang('LinkEdited'),false); |
||||
if (isset ($_GET['nolinkitems'])) |
||||
Display :: display_warning_message(get_lang('NoLinkItems'),false); |
||||
if (isset ($_GET['addallcat'])) |
||||
Display :: display_normal_message(get_lang('AddAllCat'),false); |
||||
|
||||
if (isset ($confirmation_message)) |
||||
Display :: display_confirmation_message($confirmation_message); |
||||
if (isset ($warning_message)) |
||||
Display :: display_warning_message($warning_message); |
||||
|
||||
if (isset ($move_form)) |
||||
Display :: display_normal_message($move_form->toHtml(),false); |
||||
|
||||
|
||||
// -------------------------------------------------------------------------------- |
||||
// - LOAD DATA & DISPLAY TABLE - |
||||
// -------------------------------------------------------------------------------- |
||||
|
||||
|
||||
$is_platform_admin= api_is_platform_admin(); |
||||
$is_course_admin= api_is_allowed_to_create_course(); |
||||
|
||||
|
||||
//load data for category, evaluation and links |
||||
if (!isset ($_GET['selectcat']) || empty ($_GET['selectcat'])) |
||||
$category= 0; |
||||
else |
||||
$category= $_GET['selectcat']; |
||||
|
||||
// search form |
||||
$simple_search_form= new UserForm(UserForm :: TYPE_SIMPLE_SEARCH, null, 'simple_search_form', null, api_get_self() . '?selectcat=' . $_GET['selectcat']); |
||||
$values= $simple_search_form->exportValues(); |
||||
$keyword = ''; |
||||
if (isset($_GET['search']) && !empty($_GET['search'])) |
||||
$keyword = $_GET['search']; |
||||
if ($simple_search_form->validate() && (empty($keyword))) |
||||
$keyword = $values['keyword']; |
||||
|
||||
|
||||
if (!empty($keyword)) |
||||
{ |
||||
$cats= Category :: load($category); |
||||
$allcat= array (); |
||||
$alleval= Evaluation :: find_evaluations($keyword, $cats[0]->get_id()); |
||||
$alllink= LinkFactory :: find_links($keyword, $cats[0]->get_id()); |
||||
} |
||||
elseif (isset ($_GET['studentoverview'])) |
||||
{ |
||||
$cats= Category :: load($category); |
||||
$stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id()); |
||||
$allcat= array (); |
||||
$alleval= $cats[0]->get_evaluations($stud_id, true); |
||||
$alllink= $cats[0]->get_links($stud_id, true); |
||||
if (isset ($_GET['exportpdf'])) |
||||
{ |
||||
$datagen = new GradebookDataGenerator ($allcat,$alleval, $alllink); |
||||
$header_names = array(get_lang('Name'),get_lang('Description'),get_lang('Weight'),get_lang('Date'),get_lang('Results')); |
||||
$data_array = $datagen->get_data(GradebookDataGenerator :: GDG_SORT_NAME,0,null,true); |
||||
$newarray = array(); |
||||
foreach ($data_array as $data) |
||||
$newarray[] = array_slice($data, 1); |
||||
|
||||
$pdf= new Cezpdf(); |
||||
$pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Helvetica.afm'); |
||||
$pdf->ezSetMargins(30, 30, 50, 30); |
||||
$pdf->ezSetY(810); |
||||
$pdf->ezText(get_lang('FlatView').' ('. date('j/n/Y g:i') .')',12,array('justification'=>'center')); |
||||
$pdf->line(50,790,550,790); |
||||
$pdf->line(50,40,550,40); |
||||
$pdf->ezSetY(750); |
||||
$pdf->ezTable($newarray,$header_names,'',array('showHeadings'=>1,'shaded'=>1,'showLines'=>1,'rowGap'=>3,'width'=> 500)); |
||||
$pdf->ezStream(); |
||||
exit; |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
$cats= Category :: load($category); |
||||
$stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id()); |
||||
$allcat= $cats[0]->get_subcategories($stud_id); |
||||
$alleval= $cats[0]->get_evaluations($stud_id); |
||||
$alllink= $cats[0]->get_links($stud_id); |
||||
} |
||||
|
||||
$addparams = array ('selectcat' => $cats[0]->get_id()); |
||||
if (isset($_GET['search'])) |
||||
$addparams['search'] = $keyword; |
||||
if (isset ($_GET['studentoverview'])) |
||||
$addparams['studentoverview'] = ''; |
||||
|
||||
|
||||
$gradebooktable= new GradebookTable($cats[0], $allcat, $alleval, $alllink, $addparams); |
||||
if ((empty ($allcat)) && (empty ($alleval)) && (empty ($alllink)) && (!$is_platform_admin) && ($is_course_admin) && (!isset ($_GET['selectcat']))) |
||||
{ |
||||
Display :: display_normal_message(get_lang('WelcomeMessage') . '<br><br><form name=createcat method=post action="' . api_get_self() . '?createallcategories="><input type="submit" value="' . get_lang('CreateAllCat') . '"></form>',false); |
||||
} |
||||
//here we are in a sub category |
||||
if ($category != '0') |
||||
{ |
||||
DisplayGradebook :: display_header_gradebook($cats[0], 1, $_GET['selectcat'], $is_course_admin, $is_platform_admin, $simple_search_form); |
||||
} |
||||
//this is the root category |
||||
else |
||||
{ |
||||
DisplayGradebook :: display_header_gradebook($cats[0], (((count($allcat) == '0') && (!isset ($_GET['search']))) ? 0 : 1), 0, $is_course_admin, $is_platform_admin, $simple_search_form); |
||||
} |
||||
$gradebooktable->display(); |
||||
Display :: display_footer(); |
||||
?> |
@ -0,0 +1,77 @@ |
||||
<?php |
||||
|
||||
// $Id: gradebook_add_cat.php 880 2007-05-07 09:32:52Z bert $ |
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2006 Dokeos S.A. |
||||
Copyright (c) 2006 Ghent University (UGent) |
||||
Copyright (c) various contributors |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
as published by the Free Software Foundation; either version 2 |
||||
of the License, or (at your option) any later version. |
||||
|
||||
See the GNU General Public License for more details. |
||||
|
||||
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium |
||||
Mail: info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
|
||||
$language_file = 'gradebook'; |
||||
$cidReset = true; |
||||
include_once ('../inc/global.inc.php'); |
||||
include_once ('lib/be.inc.php'); |
||||
include_once ('lib/gradebook_functions.inc.php'); |
||||
include_once ('lib/fe/catform.class.php'); |
||||
api_block_anonymous_users(); |
||||
block_students(); |
||||
|
||||
$catadd = new Category(); |
||||
$catadd->set_user_id($_user['user_id']); |
||||
$catadd->set_parent_id($_GET['selectcat']); |
||||
$catcourse = Category :: load ($_GET['selectcat']); |
||||
$catadd->set_course_code($catcourse[0]->get_course_code()); |
||||
$form = new CatForm(CatForm :: TYPE_ADD, $catadd, 'add_cat_form', null, api_get_self() . '?selectcat=' . $_GET['selectcat']); |
||||
if ($form->validate()) { |
||||
$values = $form->exportValues(); |
||||
$cat = new Category(); |
||||
if ($values['hid_parent_id'] == '0') { |
||||
if ($values['select_course'] == 'COURSEINDEPENDENT') { |
||||
$cat->set_name($values['name']); |
||||
$cat->set_course_code(null); |
||||
} else { |
||||
$cat->set_course_code($values['select_course']); |
||||
$cat->set_name($values['name']); |
||||
} |
||||
} else { |
||||
$cat->set_name($values['name']); |
||||
$cat->set_course_code($values['course_code']);//? |
||||
} |
||||
$cat->set_description($values['description']); |
||||
$cat->set_user_id($values['hid_user_id']); |
||||
$cat->set_parent_id($values['hid_parent_id']); |
||||
$cat->set_weight($values['weight']); |
||||
if (empty ($values['visible'])) |
||||
$visible = 0; |
||||
else |
||||
$visible = 1; |
||||
$cat->set_visible($visible); |
||||
$cat->add(); |
||||
header('Location: gradebook.php?addcat=&selectcat=' . $cat->get_parent_id()); |
||||
exit; |
||||
} |
||||
$interbreadcrumb[] = array ( |
||||
'url' => 'gradebook.php?selectcat='.$_GET['selectcat'], |
||||
'name' => get_lang('Gradebook' |
||||
)); |
||||
Display :: display_header(get_lang('NewCategory')); |
||||
$form->display(); |
||||
Display :: display_footer(); |
||||
?> |
@ -0,0 +1,97 @@ |
||||
<?php |
||||
|
||||
|
||||
// $Id: gradebook_add_eval.php 880 2007-05-07 09:32:52Z bert $ |
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2006 Dokeos S.A. |
||||
Copyright (c) 2006 Ghent University (UGent) |
||||
Copyright (c) various contributors |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
as published by the Free Software Foundation; either version 2 |
||||
of the License, or (at your option) any later version. |
||||
|
||||
See the GNU General Public License for more details. |
||||
|
||||
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium |
||||
Mail: info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
$language_file = 'gradebook'; |
||||
$cidReset = true; |
||||
include_once ('../inc/global.inc.php'); |
||||
include_once ('lib/be.inc.php'); |
||||
include_once ('lib/gradebook_functions.inc.php'); |
||||
include_once ('lib/fe/evalform.class.php'); |
||||
api_block_anonymous_users(); |
||||
block_students(); |
||||
|
||||
$this_section = SECTION_GRADEBOOK; |
||||
$is_allowedToEdit = $is_courseAdmin; |
||||
$evaladd = new Evaluation(); |
||||
$evaladd->set_user_id($_user['user_id']); |
||||
if (isset ($_GET['selectcat']) && (!empty ($_GET['selectcat']))) { |
||||
$evaladd->set_category_id($_GET['selectcat']); |
||||
$cat = Category :: load($_GET['selectcat']); |
||||
$evaladd->set_course_code($cat[0]->get_course_code()); |
||||
} else { |
||||
$evaladd->set_category_id(0); |
||||
} |
||||
$form = new EvalForm(EvalForm :: TYPE_ADD, $evaladd, null, 'add_eval_form',null,api_get_self() . '?selectcat=' . $_GET['selectcat']); |
||||
if ($form->validate()) { |
||||
$values = $form->exportValues(); |
||||
$eval = new Evaluation(); |
||||
$eval->set_name($values['name']); |
||||
$eval->set_description($values['description']); |
||||
$eval->set_user_id($values['hid_user_id']); |
||||
if (!empty ($values['hid_course_code'])) |
||||
$eval->set_course_code($values['hid_course_code']); |
||||
$eval->set_category_id($values['hid_category_id']); |
||||
$eval->set_weight($values['weight']); |
||||
//converts the date back to unix timestamp format |
||||
$eval->set_date(strtotime($values['date'])); |
||||
$eval->set_max($values['max']); |
||||
if (empty ($values['visible'])) |
||||
$visible = 0; |
||||
else |
||||
$visible = 1; |
||||
$eval->set_visible($visible); |
||||
$eval->add(); |
||||
if ($eval->get_course_code() == null) { |
||||
if ($values['adduser'] == 1) { |
||||
header('Location: gradebook_add_user.php?selecteval=' . $eval->get_id()); |
||||
exit; |
||||
} else { |
||||
header('Location: gradebook.php?selectcat=' . $eval->get_category_id()); |
||||
exit; |
||||
} |
||||
} else { |
||||
if ($values['addresult'] == 1) { |
||||
header('Location: gradebook_add_result.php?selecteval=' . $eval->get_id()); |
||||
exit; |
||||
} else { |
||||
header('Location: gradebook.php?selectcat=' . $eval->get_category_id()); |
||||
exit; |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
$interbreadcrumb[] = array ( |
||||
'url' => 'gradebook.php?selectcat='.$_GET['selectcat'], |
||||
'name' => get_lang('Gradebook' |
||||
)); |
||||
Display :: display_header(get_lang('NewEvaluation')); |
||||
if ($evaladd->get_course_code() == null) { |
||||
Display :: display_normal_message(get_lang('CourseIndependentEvaluation'),false); |
||||
} |
||||
$form->display(); |
||||
Display :: display_footer(); |
||||
?> |
@ -0,0 +1,71 @@ |
||||
<?php |
||||
|
||||
// $Id: gradebook_add_result.php 905 2007-05-07 14:00:29Z stijn $ |
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2006 Dokeos S.A. |
||||
Copyright (c) 2006 Ghent University (UGent) |
||||
Copyright (c) various contributors |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
as published by the Free Software Foundation; either version 2 |
||||
of the License, or (at your option) any later version. |
||||
|
||||
See the GNU General Public License for more details. |
||||
|
||||
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium |
||||
Mail: info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
$language_file = 'gradebook'; |
||||
$cidReset = true; |
||||
include_once ('../inc/global.inc.php'); |
||||
include_once ('lib/be.inc.php'); |
||||
include_once ('lib/gradebook_functions.inc.php'); |
||||
include_once ('lib/fe/evalform.class.php'); |
||||
include_once ('lib/fe/displaygradebook.php'); |
||||
include_once ('lib/scoredisplay.class.php'); |
||||
api_block_anonymous_users(); |
||||
block_students(); |
||||
|
||||
$resultadd = new Result(); |
||||
$resultadd->set_evaluation_id($_GET['selecteval']); |
||||
$evaluation = Evaluation :: load($_GET['selecteval']); |
||||
$add_result_form = new EvalForm(EvalForm :: TYPE_RESULT_ADD, $evaluation[0], $resultadd, 'add_result_form', null, api_get_self() . '?selectcat=' . $_GET['selectcat'] . '&selecteval=' . $_GET['selecteval']); |
||||
if ($add_result_form->validate()) { |
||||
$values = $add_result_form->exportValues(); |
||||
$nr_users = $values['nr_users']; |
||||
if ($nr_users == '0') { |
||||
header('Location: gradebook_view_result.php?addresultnostudents=&selecteval=' . $_GET['selecteval']); |
||||
exit; |
||||
} |
||||
$scores = ($values['score']); |
||||
foreach ($scores as $row) { |
||||
$res = new Result(); |
||||
$res->set_evaluation_id($values['evaluation_id']); |
||||
$res->set_user_id(key($scores)); |
||||
//if no scores are given, don't set the score |
||||
if ((!empty ($row)) || ($row == '0')) $res->set_score($row); |
||||
$res->add(); |
||||
next($scores); |
||||
} |
||||
header('Location: gradebook_view_result.php?addresult=&selecteval=' . $_GET['selecteval']); |
||||
exit; |
||||
} |
||||
$interbreadcrumb[] = array ( |
||||
'url' => 'gradebook.php', |
||||
'name' => get_lang('Gradebook' |
||||
)); |
||||
Display :: display_header(get_lang('AddResult')); |
||||
DisplayGradebook :: display_header_result ($evaluation[0], null, 0,0); |
||||
echo '<div class="main">'; |
||||
echo $add_result_form->toHtml(); |
||||
echo '</div>'; |
||||
Display :: display_footer(); |
||||
?> |
@ -0,0 +1,109 @@ |
||||
<?php |
||||
// $Id: gradebook_add_result.php 328 2007-04-04 14:02:48Z stijn $ |
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2006 Dokeos S.A. |
||||
Copyright (c) 2006 Ghent University (UGent) |
||||
Copyright (c) various contributors |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
as published by the Free Software Foundation; either version 2 |
||||
of the License, or (at your option) any later version. |
||||
|
||||
See the GNU General Public License for more details. |
||||
|
||||
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium |
||||
Mail: info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
$language_file = 'gradebook'; |
||||
$cidReset = true; |
||||
include_once ('../inc/global.inc.php'); |
||||
$this_section = SECTION_MYGRADEBOOK; |
||||
include_once ('lib/be.inc.php'); |
||||
include_once ('lib/fe/displaygradebook.php'); |
||||
include_once ('lib/gradebook_functions.inc.php'); |
||||
include_once ('lib/fe/evalform.class.php'); |
||||
include_once ('lib/scoredisplay.class.php'); |
||||
api_block_anonymous_users(); |
||||
block_students(); |
||||
|
||||
$evaluation= Evaluation :: load($_GET['selecteval']); |
||||
$newstudents = $evaluation[0]->get_not_subscribed_students(); |
||||
if (count($newstudents) == '0') |
||||
{ |
||||
header('Location: gradebook_view_result.php?nouser=&selecteval=' . $_GET['selecteval']); |
||||
exit; |
||||
} |
||||
$add_user_form= new EvalForm(EvalForm :: TYPE_ADD_USERS_TO_EVAL, |
||||
$evaluation[0], |
||||
null, |
||||
'add_users_to_evaluation', |
||||
null, |
||||
api_get_self() . '?selecteval=' . $_GET['selecteval'], |
||||
$_GET['firstletter'], |
||||
$newstudents); |
||||
|
||||
if ($_POST['submit_button']) |
||||
{ |
||||
$users= is_array($_POST['add_users']) ? $_POST['add_users'] : array (); |
||||
foreach ($users as $key => $value) |
||||
$users[$key]= intval($value); |
||||
|
||||
if (count($users) == 0) |
||||
{ |
||||
header('Location: ' . api_get_self() . '?erroroneuser=&selecteval=' . $_GET['selecteval']); |
||||
exit; |
||||
} |
||||
else |
||||
{ |
||||
foreach ($users as $user_id) |
||||
{ |
||||
$result= new Result(); |
||||
$result->set_user_id($user_id); |
||||
$result->set_evaluation_id($_GET['selecteval']); |
||||
$result->set_date(time()); |
||||
$result->add(); |
||||
} |
||||
} |
||||
header('Location: gradebook_view_result.php?adduser=&selecteval=' . $_GET['selecteval']); |
||||
exit; |
||||
|
||||
} |
||||
elseif ($_POST['firstLetterUser']) |
||||
{ |
||||
$firstletter= $_POST['firstLetterUser']; |
||||
if (!empty ($firstletter)) |
||||
{ |
||||
header('Location: ' . api_get_self() . '?firstletter=' . $firstletter . '&selecteval=' . $_GET['selecteval']); |
||||
exit; |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
$interbreadcrumb[]= array ( |
||||
'url' => 'gradebook.php', |
||||
'name' => get_lang('Gradebook' |
||||
)); |
||||
$interbreadcrumb[]= array ( |
||||
'url' => 'gradebook_view_result.php?selecteval=' . $_GET['selecteval'], |
||||
'name' => get_lang('ViewResult' |
||||
)); |
||||
Display :: display_header(get_lang('AddUserToEval')); |
||||
if (isset ($_GET['erroroneuser'])) |
||||
{ |
||||
Display :: display_warning_message(get_lang('AtLeastOneUser'),false); |
||||
} |
||||
DisplayGradebook :: display_header_result($evaluation[0], null, 0,0); |
||||
echo '<div class="main">'; |
||||
echo $add_user_form->toHtml(); |
||||
echo '</div>'; |
||||
Display :: display_footer(); |
||||
?> |
@ -0,0 +1,70 @@ |
||||
<?php |
||||
|
||||
// $Id: gradebook_edit_cat.php 880 2007-05-07 09:32:52Z bert $ |
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2006 Dokeos S.A. |
||||
Copyright (c) 2006 Ghent University (UGent) |
||||
Copyright (c) various contributors |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
as published by the Free Software Foundation; either version 2 |
||||
of the License, or (at your option) any later version. |
||||
|
||||
See the GNU General Public License for more details. |
||||
|
||||
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium |
||||
Mail: info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
$language_file = 'gradebook'; |
||||
$cidReset = true; |
||||
include_once ('../inc/global.inc.php'); |
||||
include_once ('lib/be.inc.php'); |
||||
include_once ('lib/gradebook_functions.inc.php'); |
||||
include_once ('lib/fe/catform.class.php'); |
||||
api_block_anonymous_users(); |
||||
block_students(); |
||||
|
||||
$catedit = Category :: load($_GET['editcat']); |
||||
$form = new CatForm(CatForm :: TYPE_EDIT, $catedit[0], 'edit_cat_form'); |
||||
if ($form->validate()) { |
||||
$values = $form->exportValues(); |
||||
$cat = new Category(); |
||||
$cat->set_id($values['hid_id']); |
||||
$cat->set_name($values['name']); |
||||
if (empty ($values['course_code'])) |
||||
{ |
||||
$cat->set_course_code(null); |
||||
} |
||||
else |
||||
{ |
||||
$cat->set_course_code($values['course_code']); |
||||
} |
||||
$cat->set_description($values['description']); |
||||
$cat->set_user_id($values['hid_user_id']); |
||||
$cat->set_parent_id($values['hid_parent_id']); |
||||
$cat->set_weight($values['weight']); |
||||
if (empty ($values['visible'])) |
||||
$visible = 0; |
||||
else |
||||
$visible = 1; |
||||
$cat->set_visible($visible); |
||||
$cat->save(); |
||||
header('Location: gradebook.php?editcat=&selectcat=' . $cat->get_parent_id()); |
||||
exit; |
||||
} |
||||
$interbreadcrumb[] = array ( |
||||
'url' => 'gradebook.php?selectcat='.$_GET['selectcat'], |
||||
'name' => get_lang('Gradebook' |
||||
)); |
||||
Display :: display_header(get_lang('EditCategory')); |
||||
$form->display(); |
||||
Display :: display_footer(); |
||||
?> |
@ -0,0 +1,68 @@ |
||||
<?php |
||||
|
||||
|
||||
// $Id: gradebook_edit_eval.php 880 2007-05-07 09:32:52Z bert $ |
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2006 Dokeos S.A. |
||||
Copyright (c) 2006 Ghent University (UGent) |
||||
Copyright (c) various contributors |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
as published by the Free Software Foundation; either version 2 |
||||
of the License, or (at your option) any later version. |
||||
|
||||
See the GNU General Public License for more details. |
||||
|
||||
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium |
||||
Mail: info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
$language_file = 'gradebook'; |
||||
$cidReset = true; |
||||
include_once ('../inc/global.inc.php'); |
||||
include_once ('lib/be.inc.php'); |
||||
include_once ('lib/gradebook_functions.inc.php'); |
||||
include_once ('lib/fe/evalform.class.php'); |
||||
api_block_anonymous_users(); |
||||
block_students(); |
||||
|
||||
$evaledit = Evaluation :: load($_GET['editeval']); |
||||
$form = new EvalForm(EvalForm :: TYPE_EDIT, $evaledit[0], null, 'edit_eval_form',null,api_get_self() . '?editeval=' . $_GET['editeval']); |
||||
if ($form->validate()) { |
||||
$values = $form->exportValues(); |
||||
$eval = new Evaluation(); |
||||
$eval->set_id($values['hid_id']); |
||||
$eval->set_name($values['name']); |
||||
$eval->set_description($values['description']); |
||||
$eval->set_user_id($values['hid_user_id']); |
||||
$eval->set_course_code($values['hid_course_code']); |
||||
$eval->set_category_id($values['hid_category_id']); |
||||
$eval->set_weight($values['weight']); |
||||
$eval->set_date(strtotime($values['date'])); |
||||
$eval->set_max($values['max']); |
||||
if (empty ($values['visible'])) |
||||
$visible = 0; |
||||
else |
||||
$visible = 1; |
||||
$eval->set_visible($visible); |
||||
$eval->save(); |
||||
//var_dump($values); |
||||
//echo 'visible :' . $visible; |
||||
header('Location: gradebook.php?editeval=&selectcat=' . $eval->get_category_id()); |
||||
exit; |
||||
} |
||||
$interbreadcrumb[] = array ( |
||||
'url' => 'gradebook.php?selectcat='.$_GET['selectcat'], |
||||
'name' => get_lang('Gradebook' |
||||
)); |
||||
Display :: display_header(get_lang('EditEvaluation')); |
||||
$form->display(); |
||||
Display :: display_footer(); |
||||
?> |
@ -0,0 +1,65 @@ |
||||
<?php |
||||
// $Id: gradebook_add_result.php 252 2007-03-29 13:46:31Z stijn $ |
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2006 Dokeos S.A. |
||||
Copyright (c) 2006 Ghent University (UGent) |
||||
Copyright (c) various contributors |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
as published by the Free Software Foundation; either version 2 |
||||
of the License, or (at your option) any later version. |
||||
|
||||
See the GNU General Public License for more details. |
||||
|
||||
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium |
||||
Mail: info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
$language_file = 'gradebook'; |
||||
$cidReset = true; |
||||
include_once ('../inc/global.inc.php'); |
||||
include_once ('lib/be.inc.php'); |
||||
include_once ('lib/fe/displaygradebook.php'); |
||||
include_once ('lib/gradebook_functions.inc.php'); |
||||
include_once ('lib/fe/evalform.class.php'); |
||||
include_once ('lib/scoredisplay.class.php'); |
||||
api_block_anonymous_users(); |
||||
block_students(); |
||||
|
||||
$resultedit = Result :: load (null,null,$_GET['selecteval']); |
||||
$evaluation = Evaluation :: load ($_GET['selecteval']); |
||||
$edit_result_form = new EvalForm(EvalForm :: TYPE_ALL_RESULTS_EDIT, $evaluation[0], $resultedit, 'edit_result_form', null, api_get_self() . '?&selecteval=' . $_GET['selecteval']); |
||||
if ($edit_result_form->validate()) { |
||||
$values = $edit_result_form->exportValues(); |
||||
$scores = ($values['score']); |
||||
foreach ($scores as $row){ |
||||
$resultedit = Result :: load (key($scores)); |
||||
if ((!empty ($row)) || ($row == '0')) $resultedit[0]->set_score($row); |
||||
$resultedit[0]->save(); |
||||
next($scores); |
||||
} |
||||
header('Location: gradebook_view_result.php?selecteval='.$_GET['selecteval'].'&editallresults='); |
||||
exit; |
||||
} |
||||
$interbreadcrumb[] = array ( |
||||
'url' => 'gradebook.php', |
||||
'name' => get_lang('Gradebook' |
||||
)); |
||||
$interbreadcrumb[]= array ( |
||||
'url' => 'gradebook_view_result.php?selecteval='.$_GET['selecteval'], |
||||
'name' => get_lang('ViewResult' |
||||
)); |
||||
Display :: display_header(get_lang('EditResult')); |
||||
DisplayGradebook :: display_header_result ($evaluation[0],null,0,0); |
||||
echo '<div class="main">'; |
||||
echo $edit_result_form->toHtml(); |
||||
echo '</div>'; |
||||
Display :: display_footer(); |
||||
?> |
@ -0,0 +1,153 @@ |
||||
<?php |
||||
// $Id: gradebook_view_result.php 479 2007-04-12 11:50:58Z stijn $ |
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2006 Dokeos S.A. |
||||
Copyright (c) 2006 Ghent University (UGent) |
||||
Copyright (c) various contributors |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
as published by the Free Software Foundation; either version 2 |
||||
of the License, or (at your option) any later version. |
||||
|
||||
See the GNU General Public License for more details. |
||||
|
||||
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium |
||||
Mail: info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
$language_file= 'gradebook'; |
||||
$cidReset= true; |
||||
include_once ('../inc/global.inc.php'); |
||||
include_once ('lib/be.inc.php'); |
||||
include_once ('lib/gradebook_functions.inc.php'); |
||||
include_once ('lib/fe/dataform.class.php'); |
||||
include_once ('lib/fe/userform.class.php'); |
||||
include_once ('lib/flatview_data_generator.class.php'); |
||||
include_once ('lib/fe/flatviewtable.class.php'); |
||||
include_once ('lib/fe/displaygradebook.php'); |
||||
include_once ('lib/fe/exportgradebook.php'); |
||||
include_once (api_get_path(LIBRARY_PATH).'ezpdf/class.ezpdf.php'); |
||||
include_once ('lib/scoredisplay.class.php'); |
||||
api_block_anonymous_users(); |
||||
block_students(); |
||||
|
||||
|
||||
if (isset ($_POST['submit']) && isset ($_POST['keyword'])) |
||||
{ |
||||
header('Location: ' . api_get_self() . '?selectcat=' . $_GET['selectcat'] |
||||
. '&search='.$_POST['keyword']); |
||||
exit; |
||||
} |
||||
|
||||
|
||||
$interbreadcrumb[]= array ( |
||||
'url' => 'gradebook.php', |
||||
'name' => get_lang('Gradebook' |
||||
)); |
||||
$showeval= (isset ($_POST['showeval']) ? '1' : '0'); |
||||
$showlink= (isset ($_POST['showlink']) ? '1' : '0'); |
||||
if (($showlink == '0') && ($showeval == '0')) |
||||
{ |
||||
$showlink= '1'; |
||||
$showeval= '1'; |
||||
} |
||||
$cat= Category :: load($_GET['selectcat']); |
||||
if ($showeval) |
||||
$alleval= $cat[0]->get_evaluations($_GET['userid'], true); |
||||
if ($showlink) |
||||
$alllinks= $cat[0]->get_links($_GET['userid'], true); |
||||
if (isset ($export_flatview_form) && (!$file_type == 'pdf')) |
||||
Display :: display_normal_message($export_flatview_form->toHtml(),false); |
||||
$simple_search_form= new UserForm(UserForm :: TYPE_SIMPLE_SEARCH, null, 'simple_search_form', null, api_get_self() . '?selectcat=' . $_GET['selectcat']); |
||||
$values= $simple_search_form->exportValues(); |
||||
$keyword = ''; |
||||
if (isset($_GET['search']) && !empty($_GET['search'])) |
||||
$keyword = $_GET['search']; |
||||
if ($simple_search_form->validate() && (empty($keyword))) |
||||
$keyword = $values['keyword']; |
||||
|
||||
if (!empty($keyword)) |
||||
$users= find_students($keyword); |
||||
else |
||||
$users= get_all_users($alleval, $alllinks); |
||||
|
||||
if (isset ($_GET['exportpdf'])) |
||||
{ |
||||
$interbreadcrumb[]= array ( |
||||
'url' => api_get_self().'?selectcat=' . $_GET['selectcat'], |
||||
'name' => get_lang('FlatView' |
||||
)); |
||||
$export_pdf_form= new DataForm(DataForm :: TYPE_EXPORT_PDF, 'export_pdf_form', null, api_get_self() . '?exportpdf=&offset='.$_GET['offset'].'&selectcat=' . $_GET['selectcat'],'_blank'); |
||||
if (!$export_pdf_form->validate()) |
||||
Display :: display_header(get_lang('ExportPDF')); |
||||
if ($export_pdf_form->validate()) |
||||
{ |
||||
$printable_data = get_printable_data ($users,$alleval, $alllinks); |
||||
|
||||
$export= $export_pdf_form->exportValues(); |
||||
$format = $export['orientation']; |
||||
$pdf =& new Cezpdf('a4',$format); |
||||
export_pdf($pdf,$printable_data[1],$printable_data[0],$format); |
||||
exit; |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
if (isset ($_GET['print'])) |
||||
{ |
||||
$printable_data = get_printable_data ($users,$alleval, $alllinks); |
||||
echo print_table($printable_data[1],$printable_data[0], get_lang('FlatView'), $cat[0]->get_name()); |
||||
exit; |
||||
} |
||||
|
||||
|
||||
$addparams= array ('selectcat' => $cat[0]->get_id()); |
||||
if (isset($_GET['search'])) |
||||
$addparams['search'] = $keyword; |
||||
|
||||
|
||||
$offset = (isset($_GET['offset'])?$_GET['offset']:'0'); |
||||
$flatviewtable= new FlatViewTable($cat[0], $users, $alleval, $alllinks, true, $offset, $addparams); |
||||
|
||||
if (isset($_GET['exportpdf'])) |
||||
{ |
||||
echo '<div class="normal-message">'; |
||||
$export_pdf_form->display(); |
||||
echo '</div>'; |
||||
} |
||||
else |
||||
Display :: display_header(get_lang('FlatView')); |
||||
|
||||
DisplayGradebook :: display_header_flatview($cat[0], $showeval, $showlink, $simple_search_form); |
||||
$flatviewtable->display(); |
||||
Display :: display_footer(); |
||||
|
||||
|
||||
function get_printable_data ($users,$alleval, $alllinks) |
||||
{ |
||||
$datagen = new FlatViewDataGenerator ($users,$alleval, $alllinks); |
||||
|
||||
$offset = (isset($_GET['offset'])?$_GET['offset']:'0'); |
||||
|
||||
$count = (($offset+10) > $datagen->get_total_items_count()) ? |
||||
($datagen->get_total_items_count()-$offset) : 10; |
||||
|
||||
$header_names = $datagen->get_header_names($offset,$count); |
||||
$data_array = $datagen->get_data(FlatViewDataGenerator :: FVDG_SORT_LASTNAME,0,null,$offset,$count,true); |
||||
|
||||
$newarray = array(); |
||||
foreach ($data_array as $data) |
||||
$newarray[] = array_slice($data, 1); |
||||
|
||||
return array ($header_names, $newarray); |
||||
} |
||||
|
||||
?> |
@ -0,0 +1,137 @@ |
||||
<?php |
||||
// $Id: gradebook_view_result.php 725 2007-04-24 07:27:11Z stijn $ |
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2006 Dokeos S.A. |
||||
Copyright (c) 2006 Ghent University (UGent) |
||||
Copyright (c) various contributors |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
as published by the Free Software Foundation; either version 2 |
||||
of the License, or (at your option) any later version. |
||||
|
||||
See the GNU General Public License for more details. |
||||
|
||||
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium |
||||
Mail: info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
$language_file= 'gradebook'; |
||||
$cidReset= true; |
||||
include_once ('../inc/global.inc.php'); |
||||
include_once ('lib/be.inc.php'); |
||||
include_once ('lib/gradebook_functions.inc.php'); |
||||
include_once ('lib/fe/scoredisplayform.class.php'); |
||||
include_once ('lib/scoredisplay.class.php'); |
||||
api_block_anonymous_users(); |
||||
api_protect_admin_script(); |
||||
|
||||
$htmlHeadXtra[]= ' |
||||
<script language="JavaScript"> |
||||
function plusItem(item) |
||||
{ |
||||
document.getElementById(item).style.display = "inline"; |
||||
document.getElementById("plus-"+item).style.display = "none"; |
||||
document.getElementById("min-"+(item-1)).style.display = "none"; |
||||
document.getElementById("min-"+(item)).style.display = "inline"; |
||||
document.getElementById("plus-"+(item+1)).style.display = "inline"; |
||||
document.getElementById("txta-"+(item)).value = "100"; |
||||
document.getElementById("txta-"+(item-1)).value = ""; |
||||
} |
||||
|
||||
function minItem(item) |
||||
{ |
||||
if (item != 1) |
||||
{ |
||||
document.getElementById(item).style.display = "none"; |
||||
document.getElementById("txta-"+item).value = ""; |
||||
document.getElementById("txtb-"+item).value = ""; |
||||
document.getElementById("plus-"+item).style.display = "inline"; |
||||
document.getElementById("min-"+(item-1)).style.display = "inline"; |
||||
document.getElementById("txta-"+(item-1)).value = "100"; |
||||
|
||||
} |
||||
if (item = 1) |
||||
{ |
||||
document.getElementById("min-"+(item)).style.display = "none"; |
||||
} |
||||
} |
||||
</script>'; |
||||
|
||||
$interbreadcrumb[]= array ( |
||||
'url' => 'gradebook.php', |
||||
'name' => get_lang('Gradebook' |
||||
)); |
||||
$displayscore= ScoreDisplay :: instance(); |
||||
$customdisplays = $displayscore->get_custom_score_display_settings(); |
||||
$nr_items =(count($customdisplays)!='0')?count($customdisplays):'1'; |
||||
|
||||
$scoreform= new ScoreDisplayForm('scoring_system_form', |
||||
api_get_self() . '?selectcat=' . $_GET['selectcat'] |
||||
); |
||||
if ($scoreform->validate()) |
||||
{ |
||||
$values= $scoreform->exportValues(); |
||||
|
||||
|
||||
// create new array of custom display settings |
||||
// this loop also checks if all score ranges are unique |
||||
|
||||
$scoringdisplay= array (); |
||||
$ranges_ok = true; |
||||
$endscore= $values['endscore']; |
||||
$displaytext= $values['displaytext']; |
||||
for ($counter= 1; $ranges_ok && $counter <= 20; $counter++) |
||||
{ |
||||
$setting= array (); |
||||
$setting['score']= $endscore[$counter]; |
||||
$setting['display']= $displaytext[$counter]; |
||||
if (!empty($setting['score'])) |
||||
{ |
||||
foreach ($scoringdisplay as $passed_entry) |
||||
{ |
||||
if ($passed_entry['score'] == $setting['score']) |
||||
$ranges_ok = false; |
||||
} |
||||
$scoringdisplay[]= $setting; |
||||
} |
||||
} |
||||
|
||||
if (!$ranges_ok) |
||||
{ |
||||
header('Location: ' . api_get_self() . '?nouniqueranges=&selectcat=' . $_GET['selectcat']); |
||||
exit; |
||||
} |
||||
|
||||
|
||||
// update color settings |
||||
$displayscore->set_coloring_enabled(($values['enablescorecolor'] == '1') ? true : false); |
||||
if ($displayscore->is_coloring_enabled()) |
||||
$displayscore->set_color_split_value($values['scorecolpercent']); |
||||
|
||||
// update custom display settings |
||||
$displayscore->set_custom(($values['enablescore'] == '1') ? true : false); |
||||
$displayscore->set_upperlimit_included(($values['includeupperlimit'] == '1') ? true : false); |
||||
if ($displayscore->is_custom() && !empty($scoringdisplay)) |
||||
$displayscore->update_custom_score_display_settings($scoringdisplay); |
||||
|
||||
header('Location: ' . api_get_self() . '?scoringupdated=&selectcat=' . $_GET['selectcat']); |
||||
exit; |
||||
} |
||||
|
||||
Display :: display_header(get_lang('ScoreEdit')); |
||||
if (isset ($_GET['scoringupdated'])) |
||||
Display :: display_confirmation_message(get_lang('ScoringUpdated'),false); |
||||
if (isset ($_GET['nouniqueranges'])) |
||||
Display :: display_error_message(get_lang('NoUniqueScoreRanges'),false); |
||||
echo '<div class="maincontent">'; |
||||
$scoreform->display(); |
||||
echo '</div>'; |
||||
Display :: display_footer(); |
||||
?> |
@ -0,0 +1,122 @@ |
||||
<?php |
||||
// $Id: gradebook_view_result.php 725 2007-04-24 07:27:11Z stijn $ |
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2006 Dokeos S.A. |
||||
Copyright (c) 2006 Ghent University (UGent) |
||||
Copyright (c) various contributors |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
as published by the Free Software Foundation; either version 2 |
||||
of the License, or (at your option) any later version. |
||||
|
||||
See the GNU General Public License for more details. |
||||
|
||||
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium |
||||
Mail: info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
$language_file= 'gradebook'; |
||||
$cidReset= true; |
||||
include_once ('../inc/global.inc.php'); |
||||
include_once ('lib/be.inc.php'); |
||||
include_once ('lib/gradebook_functions.inc.php'); |
||||
include_once ('lib/fe/dataform.class.php'); |
||||
include_once ('lib/scoredisplay.class.php'); |
||||
include_once ('lib/fe/displaygradebook.php'); |
||||
api_block_anonymous_users(); |
||||
$eval= Evaluation :: load($_GET['selecteval']); |
||||
if ($eval[0]->get_category_id() < 0) |
||||
{ |
||||
// if category id is negative, then the evaluation's origin is a link |
||||
$link= LinkFactory :: get_evaluation_link($eval[0]->get_id()); |
||||
$currentcat= Category :: load($link->get_category_id()); |
||||
} else |
||||
$currentcat= Category :: load($eval[0]->get_category_id()); |
||||
|
||||
$interbreadcrumb[]= array ( |
||||
'url' => 'gradebook.php?selectcat=' . $currentcat[0]->get_id(), 'name' => get_lang('Gradebook')); |
||||
|
||||
if (api_is_allowed_to_create_course()) |
||||
{ |
||||
$interbreadcrumb[]= array ( |
||||
'url' => 'gradebook_view_result.php?selecteval=' . $_GET['selecteval'], |
||||
'name' => get_lang('ViewResult' |
||||
)); |
||||
} |
||||
$displayscore= ScoreDisplay :: instance(); |
||||
|
||||
Display :: display_header(get_lang('EvaluationStatistics')); |
||||
DisplayGradebook :: display_header_result($eval[0], $currentcat[0]->get_id(), 0, 0); |
||||
|
||||
|
||||
|
||||
if (!$displayscore->is_custom()) |
||||
Display :: display_error_message(get_lang('PleaseEnableScoringSystem'),false); |
||||
else |
||||
{ |
||||
// generate data |
||||
|
||||
$displays= $displayscore->get_custom_score_display_settings(); |
||||
$allresults = Result :: load(null,null,$eval[0]->get_id()); |
||||
$nr_items = array(); |
||||
foreach ($displays as $itemsdisplay) |
||||
$nr_items[$itemsdisplay['display']] = 0; |
||||
|
||||
$resultcount = 0; |
||||
foreach ($allresults as $result) |
||||
{ |
||||
$score = $result->get_score(); |
||||
if (isset($score)) |
||||
{ |
||||
$display = $displayscore->display_score(array($score, $eval[0]->get_max()),SCORE_DIV | SCORE_IGNORE_SPLIT, SCORE_ONLY_CUSTOM); |
||||
$nr_items[$display] ++; |
||||
$resultcount ++; |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
$keys = array_keys($nr_items); |
||||
|
||||
|
||||
// find the region with the most scores, this is 100% of the bar |
||||
|
||||
$highest_ratio = 0; |
||||
foreach ($keys as $key) |
||||
{ |
||||
if ($nr_items[$key] > $highest_ratio) |
||||
$highest_ratio = $nr_items[$key]; |
||||
} |
||||
|
||||
|
||||
// generate table |
||||
|
||||
$stattable= '<br><table class="data_table" cellspacing="0" cellpadding="3">'; |
||||
$stattable .= '<tr><th colspan="4">' . get_lang('Statistics') . '</th></tr>'; |
||||
|
||||
$counter=0; |
||||
foreach ($keys as $key) |
||||
{ |
||||
//var_dump ($key); |
||||
$bar = ($nr_items[$key] / $highest_ratio) * 100; |
||||
|
||||
$stattable .= '<tr class="row_' . ($counter % 2 == 0 ? 'odd' : 'even') . '">'; |
||||
$stattable .= '<td width="150">' . $key . '</td>'; |
||||
|
||||
$stattable .= '<td width="550"><img src="../img/bar_1u.gif" width="' . $bar . '%" height="10"/></td>'; |
||||
$stattable .= '<td align="right">' . $nr_items[$key] . '</td>'; |
||||
$stattable .= '<td align="right"> ' . round( ($nr_items[$key] / $resultcount) * 100 ) . '%</td>'; |
||||
$counter++; |
||||
} |
||||
$stattable .= '</tr></table>'; |
||||
echo $stattable; |
||||
} |
||||
Display :: display_footer(); |
||||
?> |
@ -0,0 +1,507 @@ |
||||
<?php |
||||
// $Id: gradebook_view_result.php 1020 2007-05-11 08:20:27Z stijn $ |
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2006 Dokeos S.A. |
||||
Copyright (c) 2006 Ghent University (UGent) |
||||
Copyright (c) various contributors |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
as published by the Free Software Foundation; either version 2 |
||||
of the License, or (at your option) any later version. |
||||
|
||||
See the GNU General Public License for more details. |
||||
|
||||
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium |
||||
Mail: info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
$language_file= 'gradebook'; |
||||
$cidReset= true; |
||||
include_once ('../inc/global.inc.php'); |
||||
include_once ('lib/be.inc.php'); |
||||
include_once ('lib/gradebook_functions.inc.php'); |
||||
include_once ('lib/fe/displaygradebook.php'); |
||||
include_once ('lib/fe/evalform.class.php'); |
||||
include_once ('lib/fe/dataform.class.php'); |
||||
include_once (api_get_path(LIBRARY_PATH) . 'fileManage.lib.php'); |
||||
include_once (api_get_path(LIBRARY_PATH) . 'export.lib.inc.php'); |
||||
include_once (api_get_path(LIBRARY_PATH) . 'import.lib.php'); |
||||
include_once ('lib/results_data_generator.class.php'); |
||||
include_once ('lib/fe/resulttable.class.php'); |
||||
include_once ('lib/fe/exportgradebook.php'); |
||||
include_once ('lib/scoredisplay.class.php'); |
||||
include_once (api_get_path(LIBRARY_PATH).'ezpdf/class.ezpdf.php'); |
||||
api_block_anonymous_users(); |
||||
block_students(); |
||||
$interbreadcrumb[]= array ( |
||||
'url' => 'gradebook.php', |
||||
'name' => get_lang('Gradebook' |
||||
)); |
||||
//load the evaluation & category |
||||
$displayscore = Scoredisplay :: instance(); |
||||
$eval= Evaluation :: load($_GET['selecteval']); |
||||
$overwritescore= 0; |
||||
if ($eval[0]->get_category_id() < 0) |
||||
{ |
||||
// if category id is negative, then the evaluation's origin is a link |
||||
$link= LinkFactory :: get_evaluation_link($eval[0]->get_id()); |
||||
$currentcat= Category :: load($link->get_category_id()); |
||||
} else |
||||
$currentcat= Category :: load($eval[0]->get_category_id()); |
||||
//load the result with the evaluation id |
||||
function overwritescore($resid, $importscore, $eval_max) |
||||
{ |
||||
$result= Result :: load($resid); |
||||
if ($importscore > $eval_max) |
||||
{ |
||||
header('Location: gradebook_view_result.php?selecteval=' . $_GET['selecteval'] . '&overwritemax='); |
||||
exit; |
||||
} |
||||
$result[0]->set_score($importscore); |
||||
$result[0]->save(); |
||||
unset ($result); |
||||
} |
||||
if (isset ($_GET['selecteval'])) |
||||
{ |
||||
$allresults= Result :: load(null, null, $_GET['selecteval']); |
||||
$iscourse= $currentcat[0]->get_course_code() == null ? 1 : 0; |
||||
} |
||||
/** |
||||
* XML-parser: handle start of element |
||||
*/ |
||||
function element_start($parser, $data) |
||||
{ |
||||
global $user; |
||||
global $current_tag; |
||||
switch ($data) |
||||
{ |
||||
case 'Result' : |
||||
$user= array (); |
||||
break; |
||||
default : |
||||
$current_tag= $data; |
||||
} |
||||
} |
||||
/** |
||||
* XML-parser: handle end of element |
||||
*/ |
||||
function element_end($parser, $data) |
||||
{ |
||||
global $user; |
||||
global $users; |
||||
global $current_value; |
||||
switch ($data) |
||||
{ |
||||
case 'Result' : |
||||
$users[]= $user; |
||||
break; |
||||
default : |
||||
$user[$data]= $current_value; |
||||
break; |
||||
} |
||||
} |
||||
/** |
||||
* XML-parser: handle character data |
||||
*/ |
||||
function character_data($parser, $data) |
||||
{ |
||||
global $current_value; |
||||
$current_value= $data; |
||||
} |
||||
/** |
||||
* Read the XML-file |
||||
* @param string $file Path to the XML-file |
||||
* @return array All userinformation read from the file |
||||
*/ |
||||
function parse_xml_data($file) |
||||
{ |
||||
global $current_tag; |
||||
global $current_value; |
||||
global $user; |
||||
global $users; |
||||
$users= array (); |
||||
$parser= xml_parser_create(); |
||||
xml_set_element_handler($parser, 'element_start', 'element_end'); |
||||
xml_set_character_data_handler($parser, "character_data"); |
||||
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false); |
||||
xml_parse($parser, file_get_contents($file)); |
||||
xml_parser_free($parser); |
||||
return $users; |
||||
} |
||||
if (isset ($_GET['editres'])) |
||||
{ |
||||
$resultedit= Result :: load($_GET['editres']); |
||||
$edit_res_form= new EvalForm(EvalForm :: TYPE_RESULT_EDIT, $eval[0], $resultedit[0], 'edit_result_form', null, api_get_self() . '?editres=' . $resultedit[0]->get_id() . '&selecteval=' . $_GET['selecteval']); |
||||
if ($edit_res_form->validate()) |
||||
{ |
||||
$values= $edit_res_form->exportValues(); |
||||
$result= new Result(); |
||||
$result->set_id($_GET['editres']); |
||||
$result->set_user_id($values['hid_user_id']); |
||||
$result->set_evaluation_id($_GET['selecteval']); |
||||
if ((!empty ($values['score'])) || ($values['score'] == '0')) |
||||
$result->set_score($values['score']); |
||||
$result->save(); |
||||
unset ($result); |
||||
header('Location: gradebook_view_result.php?selecteval=' . $_GET['selecteval'] . '&editresmessage='); |
||||
exit; |
||||
} |
||||
} |
||||
if (isset ($_GET['import'])) |
||||
{ |
||||
$interbreadcrumb[]= array ( |
||||
'url' => 'gradebook_view_result.php?selecteval=' . $_GET['selecteval'], |
||||
'name' => get_lang('ViewResult' |
||||
)); |
||||
$import_result_form= new DataForm(DataForm :: TYPE_IMPORT, 'import_result_form', null, api_get_self() . '?import=&selecteval=' . $_GET['selecteval']); |
||||
if (!$import_result_form->validate()) |
||||
Display :: display_header(get_lang('Import')); |
||||
if ($_POST['formSent']) |
||||
{ |
||||
if (!empty ($_FILES['import_file']['name'])) |
||||
{ |
||||
$values= $import_result_form->exportValues(); |
||||
$file_type= $_POST['file_type']; |
||||
$file_name= $_FILES['import_file']['tmp_name']; |
||||
if ($file_type == 'csv') |
||||
{ |
||||
$results= Import :: csv_to_array($file_name); |
||||
} else |
||||
{ |
||||
$results= parse_xml_data($file_name); |
||||
} |
||||
//var_dump($results); |
||||
$nr_results_added= 0; |
||||
foreach ($results as $index => $importedresult) |
||||
{ |
||||
//check username & score |
||||
$added= '0'; |
||||
foreach ($allresults as $allresult) |
||||
{ |
||||
if (($importedresult['user_id'] == $allresult->get_user_id())) |
||||
{ |
||||
if ($importedresult['score'] != $allresult->get_score()) |
||||
{ |
||||
if (!isset ($values['overwrite'])) |
||||
{ |
||||
header('Location: gradebook_view_result.php?selecteval=' . $_GET['selecteval'] . '&import_score_error=' . $importedresult['user_id']); |
||||
exit; |
||||
break; |
||||
} else |
||||
{ |
||||
overwritescore($allresult->get_id(), $importedresult['score'], $eval[0]->get_max()); |
||||
$overwritescore++; |
||||
$added= '1'; |
||||
} |
||||
} else |
||||
$added= '1'; |
||||
} |
||||
} |
||||
if ($importedresult['user_id'] == null) |
||||
{ |
||||
header('Location: gradebook_view_result.php?selecteval=' . $_GET['selecteval'] . '&incorrectdata='); |
||||
exit; |
||||
} |
||||
$userinfo= get_user_info_from_id($importedresult['user_id']); |
||||
if ($userinfo['lastname'] != $importedresult['lastname'] || $userinfo['firstname'] != $importedresult['firstname'] || $userinfo['official_code'] != $importedresult['official_code']) |
||||
{ |
||||
if (!isset ($values['ignoreerrors'])) |
||||
{ |
||||
header('Location: gradebook_view_result.php?selecteval=' . $_GET['selecteval'] . '&import_user_error=' . $importedresult['user_id']); |
||||
exit; |
||||
} |
||||
} |
||||
if ($added != '1') |
||||
{ |
||||
if ($importedresult['score'] > $eval[0]->get_max()) |
||||
{ |
||||
header('Location: gradebook_view_result.php?selecteval=' . $_GET['selecteval'] . '&overwritemax='); |
||||
exit; |
||||
} |
||||
$result= new Result(); |
||||
$result->set_user_id($importedresult['user_id']); |
||||
if (!empty ($importedresult['score'])) |
||||
{ |
||||
$result->set_score($importedresult['score']); |
||||
} |
||||
if (!empty ($importedresult['date'])) |
||||
{ |
||||
$result->set_date(strtotime($importedresult['date'])); |
||||
} else |
||||
{ |
||||
$result->set_date(time()); |
||||
} |
||||
$result->set_evaluation_id($_GET['selecteval']); //var_dump($result); |
||||
$result->add(); |
||||
$nr_results_added++; |
||||
} |
||||
} |
||||
} else |
||||
{ |
||||
header('Location: ' . api_get_self() . '?import=&selecteval=' . $_GET['selecteval'] . '&importnofile='); |
||||
exit; |
||||
} |
||||
if ($overwritescore != 0) |
||||
{ |
||||
header('Location: ' . api_get_self() . '?selecteval=' . $_GET['selecteval'] . '&importoverwritescore=' . $overwritescore); |
||||
exit; |
||||
} |
||||
if ($nr_results_added == 0) |
||||
{ |
||||
header('Location: ' . api_get_self() . '?selecteval=' . $_GET['selecteval'] . '¬hingadded='); |
||||
exit; |
||||
} |
||||
header('Location: ' . api_get_self() . '?selecteval=' . $_GET['selecteval'] . '&importok='); |
||||
exit; |
||||
} |
||||
} |
||||
if (isset ($_GET['export'])) |
||||
{ |
||||
$interbreadcrumb[]= array ( |
||||
'url' => 'gradebook_view_result.php?selecteval=' . $_GET['selecteval'], |
||||
'name' => get_lang('ViewResult' |
||||
)); |
||||
$export_result_form= new DataForm(DataForm :: TYPE_EXPORT, 'export_result_form', null, api_get_self() . '?export=&selecteval=' . $_GET['selecteval'], '_blank'); |
||||
if (!$export_result_form->validate()) |
||||
Display :: display_header(get_lang('Export')); |
||||
if ($export_result_form->validate()) |
||||
{ |
||||
$export= $export_result_form->exportValues(); |
||||
$file_type= $export['file_type']; |
||||
$filename= 'export_results_' . date('Y-m-d_H-i-s'); |
||||
$results= Result :: load(null, null, $_GET['selecteval']); |
||||
$data= array (); //when file type is csv, add a header to the output file |
||||
if ($file_type == 'csv') |
||||
{ |
||||
$alldata[]= array ( |
||||
'user_id', |
||||
'official_code', |
||||
'lastname', |
||||
'firstname', |
||||
'score', |
||||
'date' |
||||
); |
||||
} |
||||
if ($file_type == 'pdf') |
||||
{ |
||||
if (($eval[0]->has_results())) |
||||
{ |
||||
$score= $eval[0]->calc_score(); |
||||
if ($score != null) |
||||
$average= get_lang('Average') . ' : ' . round(100 * ($score[0] / $score[1])) . ' %'; |
||||
} |
||||
if ($eval[0]->get_course_code() == null) |
||||
$course= get_lang('CourseIndependent'); |
||||
else |
||||
$course= get_course_name_from_code($eval[0]->get_course_code()); |
||||
$pdf= new Cezpdf(); |
||||
$pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Helvetica.afm'); |
||||
$pdf->ezSetMargins(30, 30, 50, 30); |
||||
$pdf->ezSetY(800); |
||||
$pdf->ezText(get_lang('EvaluationName') . ' : ' . $eval[0]->get_name() . ' (' . date('j/n/Y g:i', $eval[0]->get_date()) . ')', 12, array ( |
||||
'justification' => 'left' |
||||
)); |
||||
$pdf->ezText(get_lang('Description') . ' : ' . $eval[0]->get_description()); |
||||
$pdf->ezText(get_lang('Course') . ' : ' . $course, 12, array ( |
||||
'justification' => 'left' |
||||
)); |
||||
$pdf->ezText(get_lang('Weight') . ' : ' . $eval[0]->get_weight(), 12, array ( |
||||
'justification' => 'left' |
||||
)); |
||||
$pdf->ezText(get_lang('Max') . ' : ' . $eval[0]->get_max(), 12, array ( |
||||
'justification' => 'left' |
||||
)); |
||||
$pdf->ezText($average, 12, array ( |
||||
'justification' => 'left' |
||||
)); |
||||
|
||||
$datagen = new ResultsDataGenerator ($eval[0],$allresults); |
||||
$data_array = $datagen->get_data(ResultsDataGenerator :: RDG_SORT_LASTNAME,0,null,true); |
||||
$newarray = array(); |
||||
foreach ($data_array as $data) |
||||
{ |
||||
$newitem = array(); |
||||
$newitem[] = $data['lastname']; |
||||
$newitem[] = $data['firstname']; |
||||
$newitem[] = $data['score']; |
||||
if ($displayscore->is_custom()) |
||||
$newitem[] = $data['display']; |
||||
$newarray[] = $newitem; |
||||
} |
||||
$pdf->ezSetY(650); |
||||
if ($displayscore->is_custom()) |
||||
$header_names = array(get_lang('LastName'),get_lang('FirstName'),get_lang('Score'),get_lang('Display')); |
||||
else |
||||
$header_names = array(get_lang('LastName'),get_lang('FirstName'),get_lang('Score')); |
||||
|
||||
$pdf->ezTable($newarray,$header_names,'',array('showHeadings'=>1,'shaded'=>1,'showLines'=>1,'rowGap'=>3,'width'=> 500)); |
||||
$pdf->ezStream(); |
||||
exit; |
||||
} |
||||
foreach ($results as $result) |
||||
{ |
||||
$userinfo= get_user_info_from_id($result->get_user_id()); |
||||
$data['user_id']= $result->get_user_id(); |
||||
$data['official_code']= $userinfo['official_code']; |
||||
$data['lastname']= $userinfo['lastname']; |
||||
$data['firstname']= $userinfo['firstname']; |
||||
$data['score']= $result->get_score(); |
||||
$data['date']= date('Y-n-j g:i', $result->get_date()); |
||||
$alldata[]= $data; |
||||
} |
||||
switch ($file_type) |
||||
{ |
||||
case 'xml' : |
||||
Export :: export_table_xml($alldata, $filename, 'Result', 'XMLResults'); |
||||
break; |
||||
case 'csv' : |
||||
Export :: export_table_csv($alldata, $filename); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
if (isset ($_GET['resultdelete'])) |
||||
{ |
||||
$result= Result :: load($_GET['resultdelete']); |
||||
$result[0]->delete(); |
||||
header('Location: gradebook_view_result.php?deleteresult=&selecteval=' . $_GET['selecteval']); |
||||
exit; |
||||
} |
||||
if (isset ($_POST['action'])) |
||||
{ |
||||
$number_of_selected_items= count($_POST['id']); |
||||
if ($number_of_selected_items == '0') |
||||
Display :: display_warning_message(get_lang('NoItemsSelected'),false); |
||||
else |
||||
{ |
||||
switch ($_POST['action']) |
||||
{ |
||||
case 'delete' : |
||||
$number_of_deleted_results= 0; |
||||
foreach ($_POST['id'] as $indexstr) |
||||
{ |
||||
$result= Result :: load($indexstr); |
||||
$result[0]->delete(); |
||||
$number_of_deleted_results++; |
||||
} |
||||
header('Location: gradebook_view_result.php?massdelete=&selecteval=' . $_GET['selecteval']); |
||||
exit; |
||||
break; |
||||
} |
||||
} |
||||
} // TODO - what if selecteval not set ? |
||||
$addparams= array ( |
||||
'selecteval' => $eval[0]->get_id()); |
||||
if (isset ($_GET['print'])) |
||||
{ |
||||
$datagen = new ResultsDataGenerator ($eval[0],$allresults); |
||||
$data_array = $datagen->get_data(ResultsDataGenerator :: RDG_SORT_LASTNAME,0,null,true); |
||||
if ($displayscore->is_custom()) |
||||
$header_names = array(get_lang('LastName'),get_lang('FirstName'),get_lang('Score'),get_lang('Display')); |
||||
else |
||||
$header_names = array(get_lang('LastName'),get_lang('FirstName'),get_lang('Score')); |
||||
$newarray = array(); |
||||
foreach ($data_array as $data) |
||||
$newarray[] = array_slice($data, 2); |
||||
|
||||
echo print_table($newarray, $header_names,get_lang('ViewResult'), $eval[0]->get_name()); |
||||
exit; |
||||
} else |
||||
$resulttable= new ResultTable($eval[0], $allresults, $iscourse, $addparams); |
||||
$htmlHeadXtra[]= '<script type="text/javascript"> |
||||
function confirmationuser () |
||||
{ |
||||
if (confirm("' . get_lang('DeleteUser') . '?")) |
||||
{return true;} |
||||
else |
||||
{return false;} |
||||
} |
||||
function confirmationall () |
||||
{ |
||||
if (confirm("' . get_lang('DeleteAll') . '?")) |
||||
{return true;} |
||||
else |
||||
{return false;} |
||||
} |
||||
</script>'; |
||||
if (isset ($_GET['deleteall'])) |
||||
{ |
||||
$eval[0]->delete_results(); |
||||
header('Location: gradebook_view_result.php?allresdeleted=&selecteval=' . $_GET['selecteval']); |
||||
exit; |
||||
} |
||||
if ((!isset ($_GET['export'])) && (!isset ($_GET['import']))) |
||||
Display :: display_header(get_lang('ViewResult')); |
||||
if (isset ($_GET['addresultnostudents'])) |
||||
Display :: display_warning_message(get_lang('AddResultNoStudents'),false); |
||||
if (isset ($_GET['editresmessage'])) |
||||
Display :: display_confirmation_message(get_lang('ResultEdited'),false); |
||||
if (isset ($_GET['addresult'])) |
||||
Display :: display_confirmation_message(get_lang('ResultAdded'),false); |
||||
if (isset ($_GET['adduser'])) |
||||
Display :: display_confirmation_message(get_lang('UserAdded'),false); |
||||
if (isset ($_GET['deleteresult'])) |
||||
Display :: display_confirmation_message(get_lang('ResultDeleted'),false); |
||||
if (isset ($_GET['editallresults'])) |
||||
Display :: display_confirmation_message(get_lang('AllResultsEdited'),false); |
||||
if (isset ($_GET['importok'])) |
||||
Display :: display_confirmation_message(get_lang('ImportOk'),false); |
||||
if (isset ($_GET['importnofile'])) |
||||
Display :: display_warning_message(get_lang('ImportNoFile'),false); |
||||
if (isset ($_GET['incorrectdata'])) |
||||
Display :: display_warning_message(get_lang('IncorrectData'),false); |
||||
if (isset ($_GET['nothingadded'])) |
||||
Display :: display_warning_message(get_lang('NothingAdded'),false); |
||||
if (isset ($_GET['massdelete'])) |
||||
Display :: display_confirmation_message(get_lang('ResultsDeleted'),false); |
||||
if (isset ($_GET['nouser'])) |
||||
Display :: display_warning_message(get_lang('NoUser'),false); |
||||
if (isset ($_GET['overwritemax'])) |
||||
Display :: display_warning_message(get_lang('OverWriteMax'),false); |
||||
if (isset ($_GET['importoverwritescore'])) |
||||
Display :: display_confirmation_message(get_lang('ImportOverwriteScore') . ' ' . $_GET['importoverwritescore']); |
||||
if (isset ($_GET['import_user_error'])) |
||||
{ |
||||
$userinfo= get_user_info_from_id($_GET['import_user_error']); |
||||
Display :: display_warning_message(get_lang('UserInfoDoesNotMatch') . '<br /><br /><b>' . $userinfo['lastname'] . ' ' . $userinfo['firstname'] . '</b>'); |
||||
} |
||||
if (isset ($_GET['allresdeleted'])) |
||||
Display :: display_confirmation_message(get_lang('AllResultDeleted')); |
||||
if (isset ($_GET['import_score_error'])) |
||||
{ |
||||
$userinfo= get_user_info_from_id($_GET['import_score_error']); |
||||
Display :: display_warning_message(get_lang('ScoreDoesNotMatch') . '<br /><br /><b>' . $userinfo['lastname'] . ' ' . $userinfo['firstname'] . '</b>'); |
||||
} |
||||
if ($file_type == null) |
||||
{ //show the result header |
||||
if (isset ($export_result_form) && !(isset ($edit_res_form))) |
||||
{ |
||||
echo '<div class ="normal-message">'; |
||||
echo $export_result_form->display(); |
||||
echo '</div>'; |
||||
DisplayGradebook :: display_header_result($eval[0], $currentcat[0]->get_id(), 1); |
||||
} else |
||||
{ |
||||
if (isset ($import_result_form)) |
||||
{ |
||||
echo '<div class ="normal-message">'; |
||||
echo $import_result_form->display(); |
||||
echo '</div>'; |
||||
} |
||||
if (isset ($edit_res_form)) |
||||
{ |
||||
Display :: display_normal_message($edit_res_form->toHtml(),false); |
||||
} |
||||
DisplayGradebook :: display_header_result($eval[0], $currentcat[0]->get_id(), 1); |
||||
} |
||||
$resulttable->display(); |
||||
Display :: display_footer(); |
||||
} |
||||
?> |
@ -0,0 +1,7 @@ |
||||
<html> |
||||
<head> |
||||
<meta http-equiv="refresh" content="0; url=gradebook.php"> |
||||
</head> |
||||
<body> |
||||
</body> |
||||
</html> |
@ -0,0 +1,13 @@ |
||||
<?php |
||||
|
||||
// include this file to have access to all backend classes |
||||
// @author Bert Steppé |
||||
|
||||
include_once ('be/gradebookitem.class.php'); |
||||
include_once ('be/category.class.php'); |
||||
include_once ('be/evaluation.class.php'); |
||||
include_once ('be/result.class.php'); |
||||
include_once ('be/linkfactory.class.php'); // this contains the include declarations |
||||
// to all link classes |
||||
|
||||
?> |
@ -0,0 +1,431 @@ |
||||
<?php |
||||
|
||||
|
||||
/** |
||||
* Defines a gradebook AbstractLink object. |
||||
* To implement specific links, |
||||
* extend this class and define a type in LinkFactory. |
||||
* Use the methods in LinkFactory to create link objects. |
||||
* @author Bert Steppé |
||||
* @package dokeos.gradebook |
||||
*/ |
||||
abstract class AbstractLink implements GradebookItem |
||||
{ |
||||
|
||||
// PROPERTIES |
||||
|
||||
protected $id; |
||||
protected $type; |
||||
protected $ref_id; |
||||
protected $user_id; |
||||
protected $course_code; |
||||
protected $category; |
||||
protected $link_date; |
||||
protected $weight; |
||||
protected $visible; |
||||
|
||||
// CONSTRUCTORS |
||||
|
||||
function AbstractLink() |
||||
{ |
||||
} |
||||
|
||||
// GETTERS AND SETTERS |
||||
|
||||
public function get_id() |
||||
{ |
||||
return $this->id; |
||||
} |
||||
|
||||
public function get_type() |
||||
{ |
||||
return $this->type; |
||||
} |
||||
|
||||
public function get_ref_id() |
||||
{ |
||||
return $this->ref_id; |
||||
} |
||||
|
||||
public function get_user_id() |
||||
{ |
||||
return $this->user_id; |
||||
} |
||||
|
||||
public function get_course_code() |
||||
{ |
||||
return $this->course_code; |
||||
} |
||||
|
||||
public function get_category_id() |
||||
{ |
||||
return $this->category; |
||||
} |
||||
|
||||
public function get_date() |
||||
{ |
||||
return $this->link_date; |
||||
} |
||||
|
||||
public function get_weight() |
||||
{ |
||||
return $this->weight; |
||||
} |
||||
|
||||
public function is_visible() |
||||
{ |
||||
return $this->visible; |
||||
} |
||||
|
||||
|
||||
|
||||
public function set_id ($id) |
||||
{ |
||||
$this->id = $id; |
||||
} |
||||
|
||||
public function set_type ($type) |
||||
{ |
||||
$this->type = $type; |
||||
} |
||||
|
||||
public function set_ref_id ($ref_id) |
||||
{ |
||||
$this->ref_id = $ref_id; |
||||
} |
||||
|
||||
public function set_user_id ($user_id) |
||||
{ |
||||
$this->user_id = $user_id; |
||||
} |
||||
|
||||
public function set_course_code ($course_code) |
||||
{ |
||||
$this->course_code = $course_code; |
||||
} |
||||
|
||||
public function set_category_id ($category_id) |
||||
{ |
||||
$this->category = $category_id; |
||||
} |
||||
|
||||
public function set_date ($date) |
||||
{ |
||||
$this->link_date = $date; |
||||
} |
||||
|
||||
public function set_weight ($weight) |
||||
{ |
||||
$this->weight = $weight; |
||||
} |
||||
|
||||
public function set_visible ($visible) |
||||
{ |
||||
$this->visible = $visible; |
||||
} |
||||
|
||||
|
||||
// CRUD FUNCTIONS |
||||
|
||||
/** |
||||
* Retrieve links and return them as an array of extensions of AbstractLink. |
||||
* To keep consistency, do not call this method but LinkFactory::load instead. |
||||
*/ |
||||
public function load ($id = null, $type = null, $ref_id = null, $user_id = null, $course_code = null, $category_id = null, $visible = null) |
||||
{ |
||||
$tbl_grade_links = Database :: get_gradebook_table(TABLE_GRADEBOOK_LINK); |
||||
$sql='SELECT id,type,ref_id,user_id,course_code,category_id,date,weight,visible FROM '.$tbl_grade_links; |
||||
$paramcount = 0; |
||||
if (isset ($id)) |
||||
{ |
||||
$sql.= ' WHERE id = '.$id; |
||||
$paramcount ++; |
||||
} |
||||
if (isset ($type)) |
||||
{ |
||||
if ($paramcount != 0) $sql .= ' AND'; |
||||
else $sql .= ' WHERE'; |
||||
$sql .= ' type = '.$type; |
||||
$paramcount ++; |
||||
} |
||||
if (isset ($ref_id)) |
||||
{ |
||||
if ($paramcount != 0) $sql .= ' AND'; |
||||
else $sql .= ' WHERE'; |
||||
$sql .= ' ref_id = '.$ref_id; |
||||
$paramcount ++; |
||||
} |
||||
if (isset ($user_id)) |
||||
{ |
||||
if ($paramcount != 0) $sql .= ' AND'; |
||||
else $sql .= ' WHERE'; |
||||
$sql .= ' user_id = '.$user_id; |
||||
$paramcount ++; |
||||
} |
||||
if (isset ($course_code)) |
||||
{ |
||||
if ($paramcount != 0) $sql .= ' AND'; |
||||
else $sql .= ' WHERE'; |
||||
$sql .= " course_code = '".$course_code."'"; |
||||
$paramcount ++; |
||||
} |
||||
if (isset ($category_id)) |
||||
{ |
||||
if ($paramcount != 0) $sql .= ' AND'; |
||||
else $sql .= ' WHERE'; |
||||
$sql .= ' category_id = '.$category_id; |
||||
$paramcount ++; |
||||
} |
||||
if (isset ($visible)) |
||||
{ |
||||
if ($paramcount != 0) $sql .= ' AND'; |
||||
else $sql .= ' WHERE'; |
||||
$sql .= ' visible = '.$visible; |
||||
$paramcount ++; |
||||
} |
||||
|
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
$links = AbstractLink::create_objects_from_mysql_result($result); |
||||
return $links; |
||||
} |
||||
|
||||
private function create_objects_from_mysql_result($result) |
||||
{ |
||||
$links=array(); |
||||
while ($data=mysql_fetch_array($result)) |
||||
{ |
||||
$link = LinkFactory::create(intval($data['type'])); |
||||
$link->set_id($data['id']); |
||||
$link->set_type($data['type']); |
||||
$link->set_ref_id($data['ref_id']); |
||||
$link->set_user_id($data['user_id']); |
||||
$link->set_course_code($data['course_code']); |
||||
$link->set_category_id($data['category_id']); |
||||
$link->set_date($data['date']); |
||||
$link->set_weight($data['weight']); |
||||
$link->set_visible($data['visible']); |
||||
$links[]=$link; |
||||
} |
||||
return $links; |
||||
} |
||||
|
||||
/** |
||||
* Insert this link into the database |
||||
*/ |
||||
public function add() |
||||
{ |
||||
$this->add_linked_data(); |
||||
|
||||
if (isset($this->type) && isset($this->ref_id) && isset($this->user_id) && isset($this->course_code) |
||||
&& isset($this->category) && isset($this->weight) && isset($this->visible)) |
||||
{ |
||||
$tbl_grade_links = Database :: get_gradebook_table(TABLE_GRADEBOOK_LINK); |
||||
|
||||
$sql = 'INSERT INTO '.$tbl_grade_links |
||||
.' (type,ref_id,user_id,course_code,category_id,weight,visible'; |
||||
if (isset($this->link_date)) $sql .= ',date'; |
||||
$sql .= ') VALUES (' |
||||
.$this->get_type() |
||||
.','.$this->get_ref_id() |
||||
.','.$this->get_user_id() |
||||
.",'".$this->get_course_code()."'" |
||||
.','.$this->get_category_id() |
||||
.','.$this->get_weight() |
||||
.','.$this->is_visible(); |
||||
if (isset($this->link_date)) $sql .= ','.$this->get_date(); |
||||
$sql .= ")"; |
||||
|
||||
api_sql_query($sql, __FILE__, __LINE__); |
||||
$this->set_id(mysql_insert_id()); |
||||
} |
||||
else |
||||
die('Error in AbstractLink add: required field empty'); |
||||
} |
||||
|
||||
/** |
||||
* Update the properties of this link in the database |
||||
*/ |
||||
public function save() |
||||
{ |
||||
$this->save_linked_data(); |
||||
|
||||
$tbl_grade_links = Database :: get_gradebook_table(TABLE_GRADEBOOK_LINK); |
||||
$sql = 'UPDATE '.$tbl_grade_links |
||||
.' SET type = '.$this->get_type() |
||||
.', ref_id = '.$this->get_ref_id() |
||||
.', user_id = '.$this->get_user_id() |
||||
.", course_code = '".$this->get_course_code()."'" |
||||
.', category_id = '.$this->get_category_id() |
||||
.', date = '; |
||||
if (isset($this->link_date)) |
||||
$sql .= $this->get_date(); |
||||
else |
||||
$sql .= 'null'; |
||||
|
||||
$sql .= ', weight = '.$this->get_weight() |
||||
.', visible = '.$this->is_visible() |
||||
.' WHERE id = '.$this->id; |
||||
api_sql_query($sql, __FILE__, __LINE__); |
||||
} |
||||
|
||||
/** |
||||
* Delete this link from the database |
||||
*/ |
||||
public function delete() |
||||
{ |
||||
$this->delete_linked_data(); |
||||
|
||||
$tbl_grade_links = Database :: get_gradebook_table(TABLE_GRADEBOOK_LINK); |
||||
$sql = 'DELETE FROM '.$tbl_grade_links.' WHERE id = '.$this->id; |
||||
api_sql_query($sql, __FILE__, __LINE__); |
||||
} |
||||
|
||||
|
||||
// OTHER FUNCTIONS |
||||
|
||||
/** |
||||
* Generate an array of possible categories where this link can be moved to. |
||||
* Notice: its own parent will be included in the list: it's up to the frontend |
||||
* to disable this element. |
||||
* @return array 2-dimensional array - every element contains 3 subelements (id, name, level) |
||||
*/ |
||||
public function get_target_categories() |
||||
{ |
||||
// links can only be moved to categories inside this course |
||||
|
||||
$targets = array(); |
||||
$level = 0; |
||||
|
||||
$crscats = Category::load(null,null,$this->get_course_code(),0); |
||||
foreach ($crscats as $cat) |
||||
{ |
||||
$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
||||
$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
||||
} |
||||
|
||||
return $targets; |
||||
} |
||||
|
||||
/** |
||||
* Internal function used by get_target_categories() |
||||
*/ |
||||
private function add_target_subcategories($targets, $level, $catid) |
||||
{ |
||||
$subcats = Category::load(null,null,null,$catid); |
||||
foreach ($subcats as $cat) |
||||
{ |
||||
$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
||||
$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
||||
} |
||||
return $targets; |
||||
} |
||||
|
||||
/** |
||||
* Move this link to the given category. |
||||
* If this link moves to outside a course, delete it. |
||||
*/ |
||||
public function move_to_cat($cat) |
||||
{ |
||||
if ($this->get_course_code() != $cat->get_course_code()) |
||||
{ |
||||
$this->delete(); |
||||
} |
||||
else |
||||
{ |
||||
$this->set_category_id($cat->get_id()); |
||||
$this->save(); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Find links by name |
||||
* To keep consistency, do not call this method but LinkFactory::find_links instead. |
||||
* @todo can be written more efficiently using a new (but very complex) sql query |
||||
*/ |
||||
public function find_links ($name_mask,$selectcat) |
||||
{ |
||||
$rootcat = Category::load($selectcat); |
||||
$links = $rootcat[0]->get_links((api_is_allowed_to_create_course() ? null : api_get_user_id()), true); |
||||
$foundlinks = array(); |
||||
foreach ($links as $link) |
||||
{ |
||||
if (!(strpos(strtolower($link->get_name()), strtolower($name_mask)) === false)) |
||||
$foundlinks[] = $link; |
||||
} |
||||
return $foundlinks; |
||||
} |
||||
|
||||
|
||||
// Other methods implementing GradebookItem |
||||
|
||||
public function get_item_type() |
||||
{ |
||||
return 'L'; |
||||
} |
||||
|
||||
public function get_icon_name() |
||||
{ |
||||
return 'link'; |
||||
} |
||||
|
||||
|
||||
// ABSTRACT FUNCTIONS - to be implemented by subclass |
||||
|
||||
abstract function has_results(); |
||||
abstract function get_link(); |
||||
abstract function is_valid_link(); |
||||
abstract function get_type_name(); |
||||
|
||||
// The following methods are already defined in GradebookItem, |
||||
// and must be implemented by the subclass as well ! |
||||
// abstract function get_name(); |
||||
// abstract function get_description(); |
||||
// abstract function calc_score($stud_id = null); |
||||
|
||||
abstract function needs_name_and_description(); |
||||
abstract function needs_max(); |
||||
abstract function needs_results(); |
||||
abstract function is_allowed_to_change_name(); |
||||
|
||||
|
||||
// TRIVIAL FUNCTIONS - to be overwritten by subclass if needed |
||||
|
||||
public function get_not_created_links() |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
|
||||
public function add_linked_data() |
||||
{ |
||||
} |
||||
|
||||
public function save_linked_data() |
||||
{ |
||||
} |
||||
|
||||
public function delete_linked_data() |
||||
{ |
||||
} |
||||
|
||||
|
||||
public function set_name ($name) |
||||
{ |
||||
} |
||||
|
||||
public function set_description ($description) |
||||
{ |
||||
} |
||||
|
||||
public function set_max ($max) |
||||
{ |
||||
} |
||||
|
||||
public function get_view_url ($stud_id) |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
} |
||||
?> |
@ -0,0 +1,969 @@ |
||||
<?php |
||||
|
||||
|
||||
/** |
||||
* Defines a gradebook Category object |
||||
* @author Bert Steppé, Stijn Konings |
||||
* @package dokeos.gradebook |
||||
*/ |
||||
class Category implements GradebookItem |
||||
{ |
||||
|
||||
// PROPERTIES |
||||
|
||||
private $id; |
||||
private $name; |
||||
private $description; |
||||
private $user_id; |
||||
private $course_code; |
||||
private $parent; |
||||
private $weight; |
||||
private $visible; |
||||
|
||||
|
||||
// CONSTRUCTORS |
||||
|
||||
function Category() |
||||
{ |
||||
} |
||||
|
||||
|
||||
// GETTERS AND SETTERS |
||||
|
||||
public function get_id() |
||||
{ |
||||
return $this->id; |
||||
} |
||||
|
||||
public function get_name() |
||||
{ |
||||
return $this->name; |
||||
} |
||||
|
||||
public function get_description() |
||||
{ |
||||
return $this->description; |
||||
} |
||||
|
||||
public function get_user_id() |
||||
{ |
||||
return $this->user_id; |
||||
} |
||||
|
||||
public function get_course_code() |
||||
{ |
||||
return $this->course_code; |
||||
} |
||||
|
||||
public function get_parent_id() |
||||
{ |
||||
return $this->parent; |
||||
} |
||||
|
||||
public function get_weight() |
||||
{ |
||||
return $this->weight; |
||||
} |
||||
|
||||
public function is_visible() |
||||
{ |
||||
return $this->visible; |
||||
} |
||||
|
||||
public function set_id ($id) |
||||
{ |
||||
$this->id = $id; |
||||
} |
||||
|
||||
public function set_name ($name) |
||||
{ |
||||
$this->name = $name; |
||||
} |
||||
|
||||
public function set_description ($description) |
||||
{ |
||||
$this->description = $description; |
||||
} |
||||
|
||||
public function set_user_id ($user_id) |
||||
{ |
||||
$this->user_id = $user_id; |
||||
} |
||||
|
||||
public function set_course_code ($course_code) |
||||
{ |
||||
$this->course_code = $course_code; |
||||
} |
||||
|
||||
public function set_parent_id ($parent) |
||||
{ |
||||
$this->parent = $parent; |
||||
} |
||||
|
||||
public function set_weight ($weight) |
||||
{ |
||||
$this->weight = $weight; |
||||
} |
||||
|
||||
public function set_visible ($visible) |
||||
{ |
||||
$this->visible = $visible; |
||||
} |
||||
|
||||
|
||||
// CRUD FUNCTIONS |
||||
|
||||
/** |
||||
* Retrieve categories and return them as an array of Category objects |
||||
* @param $id category id |
||||
* @param $user_id user id (category owner) |
||||
* @param $course_code course code |
||||
* @param $parent_id parent category |
||||
* @param $visible visible |
||||
*/ |
||||
public function load ($id = null, $user_id = null, $course_code = null, $parent_id = null, $visible = null) |
||||
{ |
||||
if ($id == '0') |
||||
{ |
||||
$cats = array(); |
||||
$cats[] = Category::create_root_category(); |
||||
return $cats; |
||||
} |
||||
|
||||
$tbl_grade_categories = Database :: get_gradebook_table(TABLE_GRADEBOOK_CATEGORY); |
||||
$sql='SELECT id,name,description,user_id,course_code,parent_id,weight,visible FROM '.$tbl_grade_categories; |
||||
$paramcount = 0; |
||||
if (isset ($id)) |
||||
{ |
||||
$sql.= ' WHERE id = '.$id; |
||||
$paramcount ++; |
||||
} |
||||
if (isset ($user_id)) |
||||
{ |
||||
if ($paramcount != 0) $sql .= ' AND'; |
||||
else $sql .= ' WHERE'; |
||||
$sql .= ' user_id = '.$user_id; |
||||
$paramcount ++; |
||||
} |
||||
if (isset ($course_code)) |
||||
{ |
||||
if ($paramcount != 0) $sql .= ' AND'; |
||||
else $sql .= ' WHERE'; |
||||
if ($course_code == '0') $sql .= ' course_code is null '; |
||||
else $sql .= " course_code = '".$course_code."'"; |
||||
$paramcount ++; |
||||
} |
||||
if (isset ($parent_id)) |
||||
{ |
||||
if ($paramcount != 0) $sql .= ' AND'; |
||||
else $sql .= ' WHERE'; |
||||
$sql .= ' parent_id = '.$parent_id; |
||||
$paramcount ++; |
||||
} |
||||
if (isset ($visible)) |
||||
{ |
||||
if ($paramcount != 0) $sql .= ' AND'; |
||||
else $sql .= ' WHERE'; |
||||
$sql .= ' visible = '.$visible; |
||||
$paramcount ++; |
||||
} |
||||
|
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
$allcat = Category::create_category_objects_from_mysql_result($result); |
||||
return $allcat; |
||||
} |
||||
|
||||
private function create_root_category() |
||||
{ |
||||
$cat= new Category(); |
||||
$cat->set_id(0); |
||||
$cat->set_name(get_lang('RootCat')); |
||||
$cat->set_description(null); |
||||
$cat->set_user_id(0); |
||||
$cat->set_course_code(null); |
||||
$cat->set_parent_id(null); |
||||
$cat->set_weight(0); |
||||
$cat->set_visible(1); |
||||
return $cat; |
||||
} |
||||
|
||||
private function create_category_objects_from_mysql_result($result) |
||||
{ |
||||
$allcat=array(); |
||||
while ($data=mysql_fetch_array($result)) |
||||
{ |
||||
$cat= new Category(); |
||||
$cat->set_id($data['id']); |
||||
$cat->set_name($data['name']); |
||||
$cat->set_description($data['description']); |
||||
$cat->set_user_id($data['user_id']); |
||||
$cat->set_course_code($data['course_code']); |
||||
$cat->set_parent_id($data['parent_id']); |
||||
$cat->set_weight($data['weight']); |
||||
$cat->set_visible($data['visible']); |
||||
$allcat[]=$cat; |
||||
} |
||||
return $allcat; |
||||
} |
||||
|
||||
/** |
||||
* Insert this category into the database |
||||
*/ |
||||
public function add() |
||||
{ |
||||
if (isset($this->name) && isset($this->user_id) && isset($this->weight) && isset($this->visible)) |
||||
{ |
||||
$tbl_grade_categories = Database :: get_gradebook_table(TABLE_GRADEBOOK_CATEGORY); |
||||
$sql = 'INSERT INTO '.$tbl_grade_categories |
||||
.' (name,user_id,weight,visible'; |
||||
if (isset($this->description)) $sql .= ',description'; |
||||
if (isset($this->course_code)) $sql .= ',course_code'; |
||||
if (isset($this->parent)) $sql .= ',parent_id'; |
||||
$sql .= ") VALUES ('".mysql_real_escape_string($this->get_name())."'" |
||||
.','.$this->get_user_id() |
||||
.','.$this->get_weight() |
||||
.','.$this->is_visible(); |
||||
if (isset($this->description)) $sql .= ",'".mysql_real_escape_string($this->get_description())."'"; |
||||
if (isset($this->course_code)) $sql .= ",'".$this->get_course_code()."'"; |
||||
if (isset($this->parent)) $sql .= ','.$this->get_parent_id(); |
||||
$sql .= ')'; |
||||
|
||||
api_sql_query($sql, __FILE__, __LINE__); |
||||
$this->set_id(mysql_insert_id()); |
||||
} |
||||
else |
||||
die('Error in Category add: required field empty'); |
||||
} |
||||
|
||||
/** |
||||
* Update the properties of this category in the database |
||||
*/ |
||||
public function save() |
||||
{ |
||||
$tbl_grade_categories = Database :: get_gradebook_table(TABLE_GRADEBOOK_CATEGORY); |
||||
$sql = 'UPDATE '.$tbl_grade_categories |
||||
." SET name = '".mysql_real_escape_string($this->get_name())."'" |
||||
.', description = '; |
||||
if (isset($this->description)) |
||||
$sql .= "'".mysql_real_escape_string($this->get_description())."'"; |
||||
else |
||||
$sql .= 'null'; |
||||
|
||||
$sql .= ', user_id = '.$this->get_user_id() |
||||
.', course_code = '; |
||||
if (isset($this->course_code)) |
||||
$sql .= "'".$this->get_course_code()."'"; |
||||
else |
||||
$sql .= 'null'; |
||||
|
||||
$sql .= ', parent_id = '; |
||||
if (isset ($this->parent)) |
||||
$sql .= $this->get_parent_id(); |
||||
else |
||||
$sql .= 'null'; |
||||
|
||||
$sql .= ', weight = '.$this->get_weight() |
||||
.', visible = '.$this->is_visible() |
||||
.' WHERE id = '.$this->id; |
||||
|
||||
api_sql_query($sql, __FILE__, __LINE__); |
||||
} |
||||
|
||||
/** |
||||
* Delete this evaluation from the database |
||||
*/ |
||||
public function delete() |
||||
{ |
||||
$tbl_grade_categories = Database :: get_gradebook_table(TABLE_GRADEBOOK_CATEGORY); |
||||
$sql = 'DELETE FROM '.$tbl_grade_categories.' WHERE id = '.$this->id; |
||||
api_sql_query($sql, __FILE__, __LINE__); |
||||
} |
||||
|
||||
|
||||
// OTHER FUNCTIONS |
||||
|
||||
/** |
||||
* Check if a category name (with the same parent category) already exists |
||||
* @param $name name to check (if not given, the name property of this object will be checked) |
||||
* @param $parent parent category |
||||
*/ |
||||
public function does_name_exist($name, $parent) |
||||
{ |
||||
if (!isset ($name)) |
||||
{ |
||||
$name = $this->name; |
||||
$parent = $this->parent; |
||||
} |
||||
$tbl_grade_categories = Database :: get_gradebook_table(TABLE_GRADEBOOK_CATEGORY); |
||||
$sql = 'SELECT count(id) AS number' |
||||
.' FROM '.$tbl_grade_categories |
||||
." WHERE name = '".$name."'"; |
||||
|
||||
if (api_is_allowed_to_create_course()) |
||||
{ |
||||
$parent = Category::load($parent); |
||||
$code = $parent[0]->get_course_code(); |
||||
if (isset($code) && $code != '0') |
||||
{ |
||||
$main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); |
||||
$sql .= ' AND user_id IN (' |
||||
.' SELECT user_id FROM '.$main_course_user_table |
||||
." WHERE course_code = '".$code."'" |
||||
.' AND status = '.COURSEMANAGER |
||||
.')'; |
||||
} |
||||
else |
||||
$sql .= ' AND user_id = '.api_get_user_id(); |
||||
} |
||||
else |
||||
$sql .= ' AND user_id = '.api_get_user_id(); |
||||
|
||||
if (!isset ($parent)) |
||||
$sql.= ' AND parent_id is null'; |
||||
else |
||||
$sql.= ' AND parent_id = '.$parent; |
||||
|
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
$number=mysql_fetch_row($result); |
||||
return ($number[0] != 0); |
||||
} |
||||
|
||||
/** |
||||
* Is this category a course ? |
||||
* A category is a course if it has a course code and no parent category. |
||||
*/ |
||||
public function is_course() |
||||
{ |
||||
return (isset($this->course_code) && !empty($this->course_code) |
||||
&& (!isset($this->parent) || $this->parent == 0)); |
||||
} |
||||
|
||||
/** |
||||
* Calculate the score of this category |
||||
* @param $stud_id student id (default: all students - then the average is returned) |
||||
* @return array (score sum, weight sum) |
||||
* or null if no scores available |
||||
*/ |
||||
public function calc_score ($stud_id = null) |
||||
{ |
||||
// get appropriate subcategories, evaluations and links |
||||
|
||||
$cats = $this->get_subcategories($stud_id); |
||||
$evals = $this->get_evaluations($stud_id); |
||||
$links = $this->get_links($stud_id); |
||||
|
||||
|
||||
// calculate score |
||||
|
||||
$rescount = 0; |
||||
$ressum = 0; |
||||
$weightsum = 0; |
||||
|
||||
foreach ($cats as $cat) |
||||
{ |
||||
$catres = $cat->calc_score ($stud_id); // recursive call |
||||
if (isset($catres) && $cat->get_weight() != 0) |
||||
{ |
||||
$catweight = $cat->get_weight(); |
||||
$rescount++; |
||||
$weightsum += $catweight; |
||||
$ressum += (($catres[0]/$catres[1]) * $catweight); |
||||
} |
||||
} |
||||
|
||||
foreach ($evals as $eval) |
||||
{ |
||||
$evalres = $eval->calc_score ($stud_id); |
||||
if (isset($evalres) && $eval->get_weight() != 0) |
||||
{ |
||||
$evalweight = $eval->get_weight(); |
||||
$rescount++; |
||||
$weightsum += $evalweight; |
||||
$ressum += (($evalres[0]/$evalres[1]) * $evalweight); |
||||
} |
||||
} |
||||
|
||||
foreach ($links as $link) |
||||
{ |
||||
$linkres = $link->calc_score ($stud_id); |
||||
if (isset($linkres) && $link->get_weight() != 0) |
||||
{ |
||||
$linkweight = $link->get_weight(); |
||||
$rescount++; |
||||
$weightsum += $linkweight; |
||||
$ressum += (($linkres[0]/$linkres[1]) * $linkweight); |
||||
} |
||||
} |
||||
|
||||
|
||||
if ($rescount == 0) |
||||
return null; |
||||
else |
||||
return array ($ressum, $weightsum); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Delete this category and every subcategory, evaluation and result inside |
||||
*/ |
||||
public function delete_all () |
||||
{ |
||||
$cats = Category::load(null, null, $this->course_code, $this->id, null); |
||||
$evals = Evaluation::load(null, null, $this->course_code, $this->id, null); |
||||
$links = LinkFactory::load(null,null,null,null,$this->course_code,$this->id,null); |
||||
|
||||
foreach ($cats as $cat) |
||||
{ |
||||
$cat->delete_all(); |
||||
$cat->delete(); |
||||
} |
||||
|
||||
foreach ($evals as $eval) |
||||
$eval->delete_with_results(); |
||||
|
||||
foreach ($links as $link) |
||||
$link->delete(); |
||||
|
||||
$this->delete(); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Return array of Category objects where a student is subscribed to. |
||||
* @param $stud_id student id |
||||
*/ |
||||
public function get_root_categories_for_student ($stud_id) |
||||
{ |
||||
// courses |
||||
|
||||
$main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); |
||||
$tbl_grade_categories = Database :: get_gradebook_table(TABLE_GRADEBOOK_CATEGORY); |
||||
|
||||
$sql = 'SELECT *' |
||||
.' FROM '.$tbl_grade_categories |
||||
.' WHERE parent_id = 0'; |
||||
if (!api_is_allowed_to_create_course()) |
||||
$sql .= ' AND visible = 1'; |
||||
$sql .= ' AND course_code in' |
||||
.' (SELECT course_code' |
||||
.' FROM '.$main_course_user_table |
||||
.' WHERE user_id = '.$stud_id |
||||
.' AND status = '.STUDENT |
||||
.')'; |
||||
|
||||
if (api_is_allowed_to_create_course() && !api_is_platform_admin()) |
||||
$sql .= ' AND course_code in' |
||||
.' (SELECT course_code' |
||||
.' FROM '.$main_course_user_table |
||||
.' WHERE user_id = '.api_get_user_id() |
||||
.' AND status = '.COURSEMANAGER |
||||
.')'; |
||||
|
||||
|
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
$cats = Category::create_category_objects_from_mysql_result($result); |
||||
|
||||
// course independent categories |
||||
|
||||
$cats = Category::get_independent_categories_with_result_for_student (0, $stud_id, $cats); |
||||
|
||||
return $cats; |
||||
|
||||
} |
||||
|
||||
/** |
||||
* Return array of Category objects where a teacher is admin for. |
||||
* @param $user_id user id (to return everything, use 'null' here) |
||||
*/ |
||||
public function get_root_categories_for_teacher ($user_id) |
||||
{ |
||||
if ($user_id == null) |
||||
return Category::load(null,null,null,0); |
||||
|
||||
|
||||
// courses |
||||
|
||||
$main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); |
||||
$tbl_grade_categories = Database :: get_gradebook_table(TABLE_GRADEBOOK_CATEGORY); |
||||
|
||||
$sql = 'SELECT *' |
||||
.' FROM '.$tbl_grade_categories |
||||
.' WHERE parent_id = 0' |
||||
.' AND course_code in' |
||||
.' (SELECT course_code' |
||||
.' FROM '.$main_course_user_table |
||||
.' WHERE user_id = '.$user_id |
||||
.' AND status = '.COURSEMANAGER |
||||
.')'; |
||||
|
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
$cats = Category::create_category_objects_from_mysql_result($result); |
||||
|
||||
// course independent categories |
||||
|
||||
$indcats = Category::load(null,$user_id,0,0); |
||||
$cats = array_merge($cats, $indcats); |
||||
|
||||
return $cats; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Can this category be moved to somewhere else ? |
||||
* The root and courses cannot be moved. |
||||
*/ |
||||
public function is_movable () |
||||
{ |
||||
return (!(!isset ($this->id) || $this->id == 0 || $this->is_course())); |
||||
} |
||||
|
||||
/** |
||||
* Generate an array of possible categories where this category can be moved to. |
||||
* Notice: its own parent will be included in the list: it's up to the frontend |
||||
* to disable this element. |
||||
* @return array 2-dimensional array - every element contains 3 subelements (id, name, level) |
||||
*/ |
||||
public function get_target_categories() |
||||
{ |
||||
// the root or a course -> not movable |
||||
if (!$this->is_movable()) |
||||
{ |
||||
return null; |
||||
} |
||||
// otherwise: |
||||
// - course independent category |
||||
// -> movable to root or other independent categories |
||||
// - category inside a course |
||||
// -> movable to root, independent categories or categories inside the course |
||||
else |
||||
{ |
||||
$user = (api_is_platform_admin() ? null : api_get_user_id()); |
||||
$targets = array(); |
||||
$level = 0; |
||||
|
||||
$root = array(0, get_lang('RootCat'), $level); |
||||
$targets[] = $root; |
||||
|
||||
if (isset($this->course_code) && !empty($this->course_code)) |
||||
{ |
||||
$crscats = Category::load(null,null,$this->course_code,0); |
||||
foreach ($crscats as $cat) |
||||
{ |
||||
if ($this->can_be_moved_to_cat($cat)) |
||||
{ |
||||
$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
||||
$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
$indcats = Category::load(null,$user,0,0); |
||||
foreach ($indcats as $cat) |
||||
{ |
||||
if ($this->can_be_moved_to_cat($cat)) |
||||
{ |
||||
$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
||||
$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
||||
} |
||||
} |
||||
|
||||
return $targets; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Internal function used by get_target_categories() |
||||
*/ |
||||
private function add_target_subcategories($targets, $level, $catid) |
||||
{ |
||||
$subcats = Category::load(null,null,null,$catid); |
||||
foreach ($subcats as $cat) |
||||
{ |
||||
if ($this->can_be_moved_to_cat($cat)) |
||||
{ |
||||
$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
||||
$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
||||
} |
||||
} |
||||
return $targets; |
||||
} |
||||
|
||||
/** |
||||
* Internal function used by get_target_categories() and add_target_subcategories() |
||||
* Can this category be moved to the given category ? |
||||
* Impossible when origin and target are the same... children won't be processed |
||||
* either. (a category can't be moved to one of its own children) |
||||
*/ |
||||
private function can_be_moved_to_cat ($cat) |
||||
{ |
||||
return ($cat->get_id() != $this->get_id()); |
||||
} |
||||
|
||||
/** |
||||
* Move this category to the given category. |
||||
* If this category moves from inside a course to outside, |
||||
* its course code must be changed, as well as the course code |
||||
* of all underlying categories and evaluations. All links will |
||||
* be deleted as well ! |
||||
*/ |
||||
public function move_to_cat ($cat) |
||||
{ |
||||
$this->set_parent_id($cat->get_id()); |
||||
if ($this->get_course_code() != $cat->get_course_code()) |
||||
{ |
||||
$this->set_course_code($cat->get_course_code()); |
||||
$this->apply_course_code_to_children(); |
||||
} |
||||
$this->save(); |
||||
} |
||||
|
||||
/** |
||||
* Internal function used by move_to_cat() |
||||
*/ |
||||
private function apply_course_code_to_children () |
||||
{ |
||||
$cats = Category::load(null, null, null, $this->id, null); |
||||
$evals = Evaluation::load(null, null, null, $this->id, null); |
||||
$links = LinkFactory::load(null,null,null,null,null,$this->id,null); |
||||
|
||||
foreach ($cats as $cat) |
||||
{ |
||||
$cat->set_course_code($this->get_course_code()); |
||||
$cat->save(); |
||||
$cat->apply_course_code_to_children(); |
||||
} |
||||
|
||||
foreach ($evals as $eval) |
||||
{ |
||||
$eval->set_course_code($this->get_course_code()); |
||||
$eval->save(); |
||||
} |
||||
|
||||
foreach ($links as $link) |
||||
$link->delete(); |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* Generate an array of all categories the user can navigate to |
||||
*/ |
||||
public function get_tree () |
||||
{ |
||||
$targets = array(); |
||||
$level = 0; |
||||
|
||||
$root = array(0, get_lang('RootCat'), $level); |
||||
$targets[] = $root; |
||||
|
||||
// course or platform admin |
||||
if (api_is_allowed_to_create_course()) |
||||
{ |
||||
$user = (api_is_platform_admin() ? null : api_get_user_id()); |
||||
|
||||
$cats = Category::get_root_categories_for_teacher($user); |
||||
foreach ($cats as $cat) |
||||
{ |
||||
$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
||||
$targets = Category::add_subtree($targets, $level+1, $cat->get_id(),null); |
||||
} |
||||
} |
||||
// student |
||||
else |
||||
{ |
||||
$cats = Category::get_root_categories_for_student(api_get_user_id()); |
||||
foreach ($cats as $cat) |
||||
{ |
||||
$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
||||
$targets = Category::add_subtree($targets, $level+1, $cat->get_id(), 1); |
||||
} |
||||
} |
||||
|
||||
return $targets; |
||||
} |
||||
|
||||
/** |
||||
* Internal function used by get_tree() |
||||
*/ |
||||
private function add_subtree ($targets, $level, $catid, $visible) |
||||
{ |
||||
$subcats = Category::load(null,null,null,$catid,$visible); |
||||
foreach ($subcats as $cat) |
||||
{ |
||||
$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
||||
$targets = Category::add_subtree($targets, $level+1, $cat->get_id(),$visible); |
||||
} |
||||
return $targets; |
||||
} |
||||
|
||||
/** |
||||
* Generate an array of courses that a teacher hasn't created a category for. |
||||
* @return array 2-dimensional array - every element contains 2 subelements (code, title) |
||||
*/ |
||||
public function get_not_created_course_categories ($user_id) |
||||
{ |
||||
$tbl_main_courses = Database :: get_main_table(TABLE_MAIN_COURSE); |
||||
$tbl_main_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); |
||||
$tbl_grade_categories = Database :: get_gradebook_table(TABLE_GRADEBOOK_CATEGORY); |
||||
|
||||
$sql = 'SELECT * FROM '.$tbl_main_courses.' cc, '.$tbl_main_course_user.' cu' |
||||
.' WHERE cc.code = cu.course_code' |
||||
.' AND cu.status = '.COURSEMANAGER; |
||||
if (!api_is_platform_admin()) |
||||
$sql .= ' AND cu.user_id = '.$user_id; |
||||
$sql .= ' AND cc.code NOT IN' |
||||
.' (SELECT course_code FROM '.$tbl_grade_categories |
||||
.' WHERE parent_id = 0' |
||||
// .' AND user_id = '.$user_id |
||||
.' AND course_code IS NOT null)'; |
||||
|
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
|
||||
$cats=array(); |
||||
while ($data=mysql_fetch_array($result)) |
||||
{ |
||||
$cats[] = array ($data['code'], $data['title']); |
||||
} |
||||
return $cats; |
||||
|
||||
} |
||||
|
||||
|
||||
/** |
||||
* Apply the same visibility to every subcategory, evaluation and link |
||||
*/ |
||||
public function apply_visibility_to_children () |
||||
{ |
||||
$cats = Category::load(null, null, null, $this->id, null); |
||||
$evals = Evaluation::load(null, null, null, $this->id, null); |
||||
$links = LinkFactory::load(null,null,null,null,null,$this->id,null); |
||||
|
||||
foreach ($cats as $cat) |
||||
{ |
||||
$cat->set_visible($this->is_visible()); |
||||
$cat->save(); |
||||
$cat->apply_visibility_to_children(); |
||||
} |
||||
|
||||
foreach ($evals as $eval) |
||||
{ |
||||
$eval->set_visible($this->is_visible()); |
||||
$eval->save(); |
||||
} |
||||
|
||||
foreach ($links as $link) |
||||
{ |
||||
$link->set_visible($this->is_visible()); |
||||
$link->save(); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Check if a category contains evaluations with a result for a given student |
||||
*/ |
||||
public function has_evaluations_with_results_for_student ($stud_id) |
||||
{ |
||||
$evals = Evaluation::get_evaluations_with_result_for_student($this->id, $stud_id); |
||||
if (count($evals) != 0) |
||||
{ |
||||
return true; |
||||
} |
||||
else |
||||
{ |
||||
$cats = Category::load(null, null, null, $this->id, |
||||
api_is_allowed_to_create_course() ? null : 1); |
||||
foreach ($cats as $cat) |
||||
{ |
||||
if ($cat->has_evaluations_with_results_for_student ($stud_id)) |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Retrieve all categories inside a course independent category |
||||
* that should be visible to a student. |
||||
* @param $cat_id parent category |
||||
* @param $stud_id student id |
||||
* @param $cats optional: if defined, the categories will be added to this array |
||||
*/ |
||||
public function get_independent_categories_with_result_for_student ($cat_id, $stud_id, $cats = array()) |
||||
{ |
||||
$creator = (api_is_allowed_to_create_course() && !api_is_platform_admin()) ? api_get_user_id() : null; |
||||
|
||||
$crsindcats = Category::load(null,$creator,'0',$cat_id, |
||||
api_is_allowed_to_create_course() ? null : 1); |
||||
foreach ($crsindcats as $crsindcat) |
||||
{ |
||||
if ($crsindcat->has_evaluations_with_results_for_student($stud_id)) |
||||
$cats[] = $crsindcat; |
||||
} |
||||
return $cats; |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* Get appropriate subcategories visible for the user |
||||
* @param int $stud_id student id (default: all students) |
||||
*/ |
||||
public function get_subcategories ($stud_id = null) |
||||
{ |
||||
$cats = array(); |
||||
|
||||
// 1 student |
||||
if (isset($stud_id)) |
||||
{ |
||||
// special case: this is the root |
||||
if ($this->id == 0) |
||||
return Category::get_root_categories_for_student ($stud_id); |
||||
else |
||||
{ |
||||
return Category::load(null,null,null,$this->id, |
||||
api_is_allowed_to_create_course() ? null : 1); |
||||
} |
||||
} |
||||
|
||||
// all students |
||||
else |
||||
{ |
||||
// course admin |
||||
if (api_is_allowed_to_create_course() && !api_is_platform_admin()) |
||||
{ |
||||
// root |
||||
if ($this->id == 0) |
||||
return $this->get_root_categories_for_teacher (api_get_user_id()); |
||||
// inside a course |
||||
elseif (isset($this->course_code) && !empty($this->course_code)) |
||||
return Category::load(null, null, $this->course_code, $this->id, null); |
||||
// course independent |
||||
else |
||||
return Category::load(null, api_get_user_id(), 0, $this->id, null); |
||||
} |
||||
|
||||
// platform admin |
||||
elseif (api_is_platform_admin()) |
||||
return Category::load(null, null, null, $this->id, null); |
||||
} |
||||
|
||||
return array(); |
||||
|
||||
} |
||||
|
||||
|
||||
/** |
||||
* Get appropriate evaluations visible for the user |
||||
* @param int $stud_id student id (default: all students) |
||||
* @param boolean $recursive process subcategories (default: no recursion) |
||||
*/ |
||||
public function get_evaluations ($stud_id = null, $recursive = false) |
||||
{ |
||||
$evals = array(); |
||||
|
||||
// 1 student |
||||
if (isset($stud_id)) |
||||
{ |
||||
// special case: this is the root |
||||
if ($this->id == 0) |
||||
$evals = Evaluation::get_evaluations_with_result_for_student(0,$stud_id); |
||||
else |
||||
$evals = Evaluation::load(null,null,null,$this->id, |
||||
api_is_allowed_to_create_course() ? null : 1); |
||||
} |
||||
|
||||
// all students |
||||
else |
||||
{ |
||||
// course admin |
||||
if (api_is_allowed_to_create_course() && !api_is_platform_admin()) |
||||
{ |
||||
// root |
||||
if ($this->id == 0) |
||||
$evals = Evaluation::load(null, api_get_user_id(), null, $this->id, null); |
||||
// inside a course |
||||
elseif (isset($this->course_code) && !empty($this->course_code)) |
||||
$evals = Evaluation::load(null, null, $this->course_code, $this->id, null); |
||||
// course independent |
||||
else |
||||
$evals = Evaluation::load(null, api_get_user_id(), null, $this->id, null); |
||||
} |
||||
|
||||
// platform admin |
||||
elseif (api_is_platform_admin()) |
||||
$evals = Evaluation::load(null, null, null, $this->id, null); |
||||
} |
||||
|
||||
if ($recursive) |
||||
{ |
||||
$subcats = $this->get_subcategories($stud_id); |
||||
foreach ($subcats as $subcat) |
||||
{ |
||||
$subevals = $subcat->get_evaluations($stud_id, true); |
||||
//$this->debugprint($subevals); |
||||
$evals = array_merge($evals, $subevals); |
||||
} |
||||
} |
||||
|
||||
return $evals; |
||||
|
||||
} |
||||
|
||||
/** |
||||
* Get appropriate links visible for the user |
||||
* @param int $stud_id student id (default: all students) |
||||
* @param boolean $recursive process subcategories (default: no recursion) |
||||
*/ |
||||
public function get_links ($stud_id = null, $recursive = false) |
||||
{ |
||||
$links = array(); |
||||
|
||||
// no links in root or course independent categories |
||||
if ($this->id == 0 || !isset($this->course_code) || empty($this->course_code)) |
||||
; |
||||
|
||||
// 1 student |
||||
elseif (isset($stud_id)) |
||||
$links = LinkFactory::load(null,null,null,null,$this->course_code,$this->id, |
||||
api_is_allowed_to_create_course() ? null : 1); |
||||
|
||||
// all students -> only for course/platform admin |
||||
elseif (api_is_allowed_to_create_course()) |
||||
$links = LinkFactory::load(null,null,null,null,$this->course_code,$this->id, null); |
||||
|
||||
if ($recursive) |
||||
{ |
||||
$subcats = $this->get_subcategories($stud_id); |
||||
foreach ($subcats as $subcat) |
||||
{ |
||||
$sublinks = $subcat->get_links($stud_id, true); |
||||
$links = array_merge($links, $sublinks); |
||||
} |
||||
} |
||||
|
||||
return $links; |
||||
|
||||
} |
||||
|
||||
|
||||
// Other methods implementing GradebookItem |
||||
|
||||
public function get_item_type() |
||||
{ |
||||
return 'C'; |
||||
} |
||||
|
||||
public function get_date() |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public function get_icon_name() |
||||
{ |
||||
return 'cat'; |
||||
} |
||||
|
||||
|
||||
} |
||||
?> |
@ -0,0 +1,85 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Gradebook link to dropbox item |
||||
* @author Bert Steppé |
||||
* @package dokeos.gradebook |
||||
*/ |
||||
class DropboxLink extends EvalLink |
||||
{ |
||||
|
||||
// INTERNAL VARIABLES |
||||
|
||||
private $dropbox_table = null; |
||||
|
||||
// CONSTRUCTORS |
||||
|
||||
function DropboxLink() |
||||
{ |
||||
$this->set_type(LINK_DROPBOX); |
||||
} |
||||
|
||||
|
||||
// FUNCTIONS IMPLEMENTING ABSTRACTLINK |
||||
|
||||
public function get_view_url ($stud_id) |
||||
{ |
||||
// find a file uploaded by the given student, |
||||
// with the same title as the evaluation name |
||||
|
||||
$eval = $this->get_evaluation(); |
||||
|
||||
$sql = 'SELECT filename' |
||||
.' FROM '.$this->get_dropbox_table() |
||||
.' WHERE uploader_id = '.$stud_id |
||||
." AND title = '".mysql_real_escape_string($eval->get_name())."'"; |
||||
|
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
if ($fileurl = mysql_fetch_row($result)) |
||||
{ |
||||
$course_info = Database :: get_course_info($this->get_course_code()); |
||||
|
||||
$url = api_get_path(WEB_PATH) |
||||
.'main/gradebook/open_document.php?file=' |
||||
.$course_info['directory'] |
||||
.'/' |
||||
.$fileurl[0]; |
||||
|
||||
return $url; |
||||
} |
||||
else |
||||
return null; |
||||
|
||||
} |
||||
|
||||
public function get_type_name() |
||||
{ |
||||
return get_lang('DokeosDropbox'); |
||||
} |
||||
|
||||
public function is_allowed_to_change_name() |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
|
||||
// INTERNAL FUNCTIONS |
||||
|
||||
/** |
||||
* Lazy load function to get the dropbox database table |
||||
*/ |
||||
private function get_dropbox_table () |
||||
{ |
||||
if (!isset($this->dropbox_table)) |
||||
{ |
||||
$course_info = Database :: get_course_info($this->get_course_code()); |
||||
$database_name = $course_info['db_name']; |
||||
$this->dropbox_table = Database :: get_course_table(TABLE_DROPBOX_FILE, $database_name); |
||||
} |
||||
return $this->dropbox_table; |
||||
} |
||||
|
||||
|
||||
|
||||
} |
||||
?> |
@ -0,0 +1,192 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Class to be used as basis for links referring to Evaluation objects. |
||||
* @author Bert Steppé |
||||
* @package dokeos.gradebook |
||||
*/ |
||||
abstract class EvalLink extends AbstractLink |
||||
{ |
||||
|
||||
protected $evaluation = null; |
||||
|
||||
/** |
||||
* Constructor |
||||
*/ |
||||
function EvalLink() |
||||
{ |
||||
|
||||
} |
||||
|
||||
|
||||
// Functions implementing AbstractLink |
||||
|
||||
public function has_results() |
||||
{ |
||||
$eval = $this->get_evaluation(); |
||||
return $eval->has_results(); |
||||
} |
||||
|
||||
public function calc_score($stud_id = null) |
||||
{ |
||||
$eval = $this->get_evaluation(); |
||||
return $eval->calc_score($stud_id); |
||||
} |
||||
|
||||
public function get_link() |
||||
{ |
||||
$eval = $this->get_evaluation(); |
||||
|
||||
// course/platform admin can go to the view_results page |
||||
if (api_is_allowed_to_create_course()) |
||||
return 'gradebook_view_result.php?selecteval=' . $eval->get_id(); |
||||
// students can go to the statistics page (if custom display enabled) |
||||
elseif (ScoreDisplay :: instance()->is_custom()) |
||||
return 'gradebook_statistics.php?selecteval=' . $eval->get_id(); |
||||
else |
||||
return null; |
||||
} |
||||
|
||||
|
||||
public function get_name() |
||||
{ |
||||
$eval = $this->get_evaluation(); |
||||
return $eval->get_name(); |
||||
} |
||||
|
||||
public function get_description() |
||||
{ |
||||
$eval = $this->get_evaluation(); |
||||
return $eval->get_description(); |
||||
} |
||||
|
||||
public function get_max() |
||||
{ |
||||
$eval = $this->get_evaluation(); |
||||
return $eval->get_max(); |
||||
} |
||||
|
||||
public function is_valid_link() |
||||
{ |
||||
$eval = $this->get_evaluation(); |
||||
return (isset($eval)); |
||||
} |
||||
|
||||
|
||||
public function needs_name_and_description() |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
public function needs_max() |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
public function needs_results() |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
|
||||
public function add_linked_data() |
||||
{ |
||||
if ($this->is_valid_link()) |
||||
{ |
||||
$this->evaluation->add(); |
||||
$this->set_ref_id($this->evaluation->get_id()); |
||||
} |
||||
} |
||||
|
||||
public function save_linked_data() |
||||
{ |
||||
if ($this->is_valid_link()) |
||||
$this->evaluation->save(); |
||||
} |
||||
|
||||
public function delete_linked_data() |
||||
{ |
||||
if ($this->is_valid_link()) |
||||
$this->evaluation->delete_with_results(); |
||||
} |
||||
|
||||
|
||||
public function set_name ($name) |
||||
{ |
||||
if ($this->is_valid_link()) |
||||
$this->evaluation->set_name($name); |
||||
} |
||||
|
||||
public function set_description ($description) |
||||
{ |
||||
if ($this->is_valid_link()) |
||||
$this->evaluation->set_description($description); |
||||
} |
||||
|
||||
public function set_max ($max) |
||||
{ |
||||
if ($this->is_valid_link()) |
||||
$this->evaluation->set_max($max); |
||||
} |
||||
|
||||
|
||||
// Functions overriding non-trivial implementations from AbstractLink |
||||
|
||||
public function set_date ($date) |
||||
{ |
||||
$this->link_date = $date; |
||||
if ($this->is_valid_link()) |
||||
$this->evaluation->set_date($date); |
||||
} |
||||
|
||||
public function set_weight ($weight) |
||||
{ |
||||
$this->weight = $weight; |
||||
if ($this->is_valid_link()) |
||||
$this->evaluation->set_weight($weight); |
||||
} |
||||
|
||||
public function set_visible ($visible) |
||||
{ |
||||
$this->visible = $visible; |
||||
if ($this->is_valid_link()) |
||||
$this->evaluation->set_visible($visible); |
||||
} |
||||
|
||||
|
||||
|
||||
// INTERNAL FUNCTIONS |
||||
|
||||
/** |
||||
* Lazy load function to get the linked evaluation |
||||
*/ |
||||
protected function get_evaluation () |
||||
{ |
||||
if (!isset($this->evaluation)) |
||||
{ |
||||
if (isset($this->ref_id)) |
||||
{ |
||||
$evalarray = Evaluation::load($this->get_ref_id()); |
||||
$this->evaluation = $evalarray[0]; |
||||
} |
||||
else |
||||
{ |
||||
$eval = new Evaluation(); |
||||
$eval->set_category_id(-1); |
||||
$eval->set_date(time()); // these values will be changed |
||||
$eval->set_weight(0); // when the link setter |
||||
$eval->set_visible(0); // is called |
||||
$eval->set_id(-1); // a 'real' id will be set when eval is added to db |
||||
$eval->set_user_id($this->get_user_id()); |
||||
$eval->set_course_code($this->get_course_code()); |
||||
$this->evaluation = $eval; |
||||
$this->set_ref_id($eval->get_id()); |
||||
|
||||
} |
||||
} |
||||
return $this->evaluation; |
||||
} |
||||
|
||||
|
||||
} |
||||
?> |
@ -0,0 +1,595 @@ |
||||
<?php |
||||
|
||||
|
||||
/** |
||||
* Defines a gradebook Evaluation object |
||||
* @author Bert Steppé, Stijn Konings |
||||
* @package dokeos.gradebook |
||||
*/ |
||||
class Evaluation implements GradebookItem |
||||
{ |
||||
|
||||
// PROPERTIES |
||||
|
||||
private $id; |
||||
private $name; |
||||
private $description; |
||||
private $user_id; |
||||
private $course_code; |
||||
private $category; |
||||
private $eval_date; |
||||
private $weight; |
||||
private $eval_max; |
||||
private $visible; |
||||
|
||||
// CONSTRUCTORS |
||||
|
||||
function Evaluation() |
||||
{ |
||||
} |
||||
|
||||
// GETTERS AND SETTERS |
||||
|
||||
public function get_id() |
||||
{ |
||||
return $this->id; |
||||
} |
||||
|
||||
public function get_name() |
||||
{ |
||||
return $this->name; |
||||
} |
||||
|
||||
public function get_description() |
||||
{ |
||||
return $this->description; |
||||
} |
||||
|
||||
public function get_user_id() |
||||
{ |
||||
return $this->user_id; |
||||
} |
||||
|
||||
public function get_course_code() |
||||
{ |
||||
return $this->course_code; |
||||
} |
||||
|
||||
public function get_category_id() |
||||
{ |
||||
return $this->category; |
||||
} |
||||
|
||||
public function get_date() |
||||
{ |
||||
return $this->eval_date; |
||||
} |
||||
|
||||
public function get_weight() |
||||
{ |
||||
return $this->weight; |
||||
} |
||||
|
||||
public function get_max() |
||||
{ |
||||
return $this->eval_max; |
||||
} |
||||
|
||||
public function is_visible() |
||||
{ |
||||
return $this->visible; |
||||
} |
||||
|
||||
public function set_id ($id) |
||||
{ |
||||
$this->id = $id; |
||||
} |
||||
|
||||
public function set_name ($name) |
||||
{ |
||||
$this->name = $name; |
||||
} |
||||
|
||||
public function set_description ($description) |
||||
{ |
||||
$this->description = $description; |
||||
} |
||||
|
||||
public function set_user_id ($user_id) |
||||
{ |
||||
$this->user_id = $user_id; |
||||
} |
||||
|
||||
public function set_course_code ($course_code) |
||||
{ |
||||
$this->course_code = $course_code; |
||||
} |
||||
|
||||
public function set_category_id ($category_id) |
||||
{ |
||||
$this->category = $category_id; |
||||
} |
||||
|
||||
public function set_date ($date) |
||||
{ |
||||
$this->eval_date = $date; |
||||
} |
||||
|
||||
public function set_weight ($weight) |
||||
{ |
||||
$this->weight = $weight; |
||||
} |
||||
|
||||
public function set_max ($max) |
||||
{ |
||||
$this->eval_max = $max; |
||||
} |
||||
|
||||
public function set_visible ($visible) |
||||
{ |
||||
$this->visible = $visible; |
||||
} |
||||
|
||||
|
||||
// CRUD FUNCTIONS |
||||
|
||||
/** |
||||
* Retrieve evaluations and return them as an array of Evaluation objects |
||||
* @param $id evaluation id |
||||
* @param $user_id user id (evaluation owner) |
||||
* @param $course_code course code |
||||
* @param $category_id parent category |
||||
* @param $visible visible |
||||
*/ |
||||
public function load ($id = null, $user_id = null, $course_code = null, $category_id = null, $visible = null) |
||||
{ |
||||
$tbl_grade_evaluations = Database :: get_gradebook_table(TABLE_GRADEBOOK_EVALUATION); |
||||
$sql='SELECT id,name,description,user_id,course_code,category_id,date,weight,max,visible FROM '.$tbl_grade_evaluations; |
||||
$paramcount = 0; |
||||
if (isset ($id)) |
||||
{ |
||||
$sql.= ' WHERE id = '.$id; |
||||
$paramcount ++; |
||||
} |
||||
if (isset ($user_id)) |
||||
{ |
||||
if ($paramcount != 0) $sql .= ' AND'; |
||||
else $sql .= ' WHERE'; |
||||
$sql .= ' user_id = '.$user_id; |
||||
$paramcount ++; |
||||
} |
||||
if (isset ($course_code)) |
||||
{ |
||||
if ($paramcount != 0) $sql .= ' AND'; |
||||
else $sql .= ' WHERE'; |
||||
$sql .= " course_code = '".$course_code."'"; |
||||
$paramcount ++; |
||||
} |
||||
if (isset ($category_id)) |
||||
{ |
||||
if ($paramcount != 0) $sql .= ' AND'; |
||||
else $sql .= ' WHERE'; |
||||
$sql .= ' category_id = '.$category_id; |
||||
$paramcount ++; |
||||
} |
||||
if (isset ($visible)) |
||||
{ |
||||
if ($paramcount != 0) $sql .= ' AND'; |
||||
else $sql .= ' WHERE'; |
||||
$sql .= ' visible = '.$visible; |
||||
$paramcount ++; |
||||
} |
||||
|
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
$alleval = Evaluation::create_evaluation_objects_from_mysql_result($result); |
||||
return $alleval; |
||||
} |
||||
|
||||
private function create_evaluation_objects_from_mysql_result($result) |
||||
{ |
||||
$alleval=array(); |
||||
while ($data=mysql_fetch_array($result)) |
||||
{ |
||||
$eval= new Evaluation(); |
||||
$eval->set_id($data['id']); |
||||
$eval->set_name($data['name']); |
||||
$eval->set_description($data['description']); |
||||
$eval->set_user_id($data['user_id']); |
||||
$eval->set_course_code($data['course_code']); |
||||
$eval->set_category_id($data['category_id']); |
||||
$eval->set_date($data['date']); |
||||
$eval->set_weight($data['weight']); |
||||
$eval->set_max($data['max']); |
||||
$eval->set_visible($data['visible']); |
||||
$alleval[]=$eval; |
||||
} |
||||
return $alleval; |
||||
} |
||||
|
||||
/** |
||||
* Insert this evaluation into the database |
||||
*/ |
||||
public function add() |
||||
{ |
||||
if (isset($this->name) && isset($this->user_id) && isset($this->weight) && isset ($this->eval_max) && isset($this->visible)) |
||||
{ |
||||
$tbl_grade_evaluations = Database :: get_gradebook_table(TABLE_GRADEBOOK_EVALUATION); |
||||
|
||||
$sql = 'INSERT INTO '.$tbl_grade_evaluations |
||||
.' (name,user_id,weight,max,visible'; |
||||
if (isset($this->description)) $sql .= ',description'; |
||||
if (isset($this->course_code)) $sql .= ',course_code'; |
||||
if (isset($this->category)) $sql .= ',category_id'; |
||||
if (isset($this->eval_date)) $sql .= ',date'; |
||||
$sql .= ") VALUES ('".mysql_real_escape_string($this->get_name())."'" |
||||
.','.$this->get_user_id() |
||||
.','.$this->get_weight() |
||||
.','.$this->get_max() |
||||
.','.$this->is_visible(); |
||||
if (isset($this->description)) $sql .= ",'".mysql_real_escape_string($this->get_description())."'"; |
||||
if (isset($this->course_code)) $sql .= ",'".$this->get_course_code()."'"; |
||||
if (isset($this->category)) $sql .= ','.$this->get_category_id(); |
||||
if (isset($this->eval_date)) $sql .= ','.$this->get_date(); |
||||
$sql .= ")"; |
||||
|
||||
api_sql_query($sql, __FILE__, __LINE__); |
||||
$this->set_id(mysql_insert_id()); |
||||
} |
||||
else |
||||
die('Error in Evaluation add: required field empty'); |
||||
} |
||||
|
||||
/** |
||||
* Update the properties of this evaluation in the database |
||||
*/ |
||||
public function save() |
||||
{ |
||||
$tbl_grade_evaluations = Database :: get_gradebook_table(TABLE_GRADEBOOK_EVALUATION); |
||||
$sql = 'UPDATE '.$tbl_grade_evaluations |
||||
." SET name = '".mysql_real_escape_string($this->get_name())."'" |
||||
.', description = '; |
||||
if (isset($this->description)) |
||||
$sql .= "'".mysql_real_escape_string($this->get_description())."'"; |
||||
else |
||||
$sql .= 'null'; |
||||
|
||||
$sql .= ', user_id = '.$this->get_user_id() |
||||
.', course_code = '; |
||||
if (isset($this->course_code)) |
||||
$sql .= "'".$this->get_course_code()."'"; |
||||
else |
||||
$sql .= 'null'; |
||||
|
||||
$sql .= ', category_id = '; |
||||
if (isset($this->category)) |
||||
$sql .= $this->get_category_id(); |
||||
else |
||||
$sql .= 'null'; |
||||
|
||||
$sql .= ', date = '; |
||||
if (isset($this->eval_date)) |
||||
$sql .= $this->get_date(); |
||||
else |
||||
$sql .= 'null'; |
||||
|
||||
$sql .= ', weight = '.$this->get_weight() |
||||
.', max = '.$this->get_max() |
||||
.', visible = '.$this->is_visible() |
||||
.' WHERE id = '.$this->id; |
||||
api_sql_query($sql, __FILE__, __LINE__); |
||||
} |
||||
|
||||
/** |
||||
* Delete this evaluation from the database |
||||
*/ |
||||
public function delete() |
||||
{ |
||||
$tbl_grade_evaluations = Database :: get_gradebook_table(TABLE_GRADEBOOK_EVALUATION); |
||||
$sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.$this->id; |
||||
api_sql_query($sql, __FILE__, __LINE__); |
||||
} |
||||
|
||||
// OTHER FUNCTIONS |
||||
|
||||
/** |
||||
* Check if an evaluation name (with the same parent category) already exists |
||||
* @param $name name to check (if not given, the name property of this object will be checked) |
||||
* @param $parent parent category |
||||
*/ |
||||
public function does_name_exist($name, $parent) |
||||
{ |
||||
if (!isset ($name)) |
||||
{ |
||||
$name = $this->name; |
||||
$parent = $this->category; |
||||
} |
||||
$tbl_grade_evaluations = Database :: get_gradebook_table(TABLE_GRADEBOOK_EVALUATION); |
||||
$sql = 'SELECT count(id) AS number' |
||||
.' FROM '.$tbl_grade_evaluations |
||||
." WHERE name = '".$name."'"; |
||||
|
||||
if (api_is_allowed_to_create_course()) // && !api_is_platform_admin()) |
||||
{ |
||||
$parent = Category::load($parent); |
||||
$code = $parent[0]->get_course_code(); |
||||
if (isset($code) && $code != '0') |
||||
{ |
||||
$main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); |
||||
$sql .= ' AND user_id IN (' |
||||
.' SELECT user_id FROM '.$main_course_user_table |
||||
." WHERE course_code = '".$code."'" |
||||
.' AND status = '.COURSEMANAGER |
||||
.')'; |
||||
} |
||||
else |
||||
$sql .= ' AND user_id = '.api_get_user_id(); |
||||
} |
||||
else |
||||
$sql .= ' AND user_id = '.api_get_user_id(); |
||||
|
||||
if (!isset ($parent)) |
||||
$sql.= ' AND category_id is null'; |
||||
else |
||||
$sql.= ' AND category_id = '.$parent; |
||||
|
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
$number=mysql_fetch_row($result); |
||||
return ($number[0] != 0); |
||||
} |
||||
|
||||
/** |
||||
* Are there any results for this evaluation yet ? |
||||
* The 'max' property should not be changed then. |
||||
*/ |
||||
public function has_results() |
||||
{ |
||||
$tbl_grade_results = Database :: get_gradebook_table(TABLE_GRADEBOOK_RESULT); |
||||
$sql='SELECT count(id) AS number FROM '.$tbl_grade_results |
||||
.' WHERE evaluation_id = '.$this->id; |
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
$number=mysql_fetch_row($result); |
||||
|
||||
return ($number[0] != 0); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Does this evaluation have any results for a student ? |
||||
*/ |
||||
/* - not used anywhere (yet ?) |
||||
public function has_results_for_student($stud_id) |
||||
{ |
||||
$tbl_grade_results = Database :: get_gradebook_table(TABLE_GRADEBOOK_RESULT); |
||||
$sql="SELECT count(id) AS number FROM ".$tbl_grade_results |
||||
." WHERE evaluation_id = ".$this->id." AND user_id = ".$stud_id; |
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
$number=mysql_fetch_row($result); |
||||
return ($number[0] != 0); |
||||
} |
||||
*/ |
||||
|
||||
|
||||
/** |
||||
* Delete all results for this evaluation |
||||
*/ |
||||
public function delete_results() |
||||
{ |
||||
$tbl_grade_results = Database :: get_gradebook_table(TABLE_GRADEBOOK_RESULT); |
||||
$sql = 'DELETE FROM '.$tbl_grade_results.' WHERE evaluation_id = '.$this->id; |
||||
api_sql_query($sql, __FILE__, __LINE__); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Delete this evaluation and all underlying results. |
||||
*/ |
||||
public function delete_with_results() |
||||
{ |
||||
$this->delete_results(); |
||||
$this->delete(); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Check if the given score is possible for this evaluation |
||||
*/ |
||||
public function is_valid_score ($score) |
||||
{ |
||||
return (is_numeric($score) && $score >= 0 && $score <= $this->eval_max); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Calculate the score of this evaluation |
||||
* @param $stud_id student id (default: all students who have results for this eval - then the average is returned) |
||||
* @return array (score, max) if student is given |
||||
* array (sum of scores, number of scores) otherwise |
||||
* or null if no scores available |
||||
*/ |
||||
public function calc_score ($stud_id = null) |
||||
{ |
||||
$results = Result::load(null,$stud_id,$this->id); |
||||
|
||||
$rescount = 0; |
||||
$sum = 0; |
||||
foreach ($results as $res) |
||||
{ |
||||
$score = $res->get_score(); |
||||
if ((!empty ($score)) || ($score == '0')) |
||||
{ |
||||
$rescount++; |
||||
$sum += ($score / $this->get_max()); |
||||
} |
||||
} |
||||
|
||||
if ($rescount == 0) |
||||
return null; |
||||
else if (isset($stud_id)) |
||||
return array ($score, $this->get_max()); |
||||
else |
||||
return array ($sum, $rescount); |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* Generate an array of possible categories where this evaluation can be moved to. |
||||
* Notice: its own parent will be included in the list: it's up to the frontend |
||||
* to disable this element. |
||||
* @return array 2-dimensional array - every element contains 3 subelements (id, name, level) |
||||
*/ |
||||
public function get_target_categories() |
||||
{ |
||||
// - course independent evaluation |
||||
// -> movable to root or other course independent categories |
||||
// - evaluation inside a course |
||||
// -> movable to root, independent categories or categories inside the course |
||||
|
||||
$user = (api_is_platform_admin() ? null : api_get_user_id()); |
||||
$targets = array(); |
||||
$level = 0; |
||||
|
||||
$root = array(0, get_lang('RootCat'), $level); |
||||
$targets[] = $root; |
||||
|
||||
if (isset($this->course_code) && !empty($this->course_code)) |
||||
{ |
||||
$crscats = Category::load(null,null,$this->course_code,0); |
||||
foreach ($crscats as $cat) |
||||
{ |
||||
$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
||||
$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
||||
} |
||||
} |
||||
|
||||
$indcats = Category::load(null,$user,0,0); |
||||
foreach ($indcats as $cat) |
||||
{ |
||||
$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
||||
$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
||||
} |
||||
|
||||
return $targets; |
||||
} |
||||
|
||||
/** |
||||
* Internal function used by get_target_categories() |
||||
*/ |
||||
private function add_target_subcategories($targets, $level, $catid) |
||||
{ |
||||
$subcats = Category::load(null,null,null,$catid); |
||||
foreach ($subcats as $cat) |
||||
{ |
||||
$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
||||
$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
||||
} |
||||
return $targets; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Move this evaluation to the given category. |
||||
* If this evaluation moves from inside a course to outside, |
||||
* its course code is also changed. |
||||
*/ |
||||
public function move_to_cat ($cat) |
||||
{ |
||||
$this->set_category_id($cat->get_id()); |
||||
if ($this->get_course_code() != $cat->get_course_code()) |
||||
{ |
||||
$this->set_course_code($cat->get_course_code()); |
||||
} |
||||
$this->save(); |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* Retrieve evaluations where a student has results for |
||||
* and return them as an array of Evaluation objects |
||||
* @param $cat_id parent category (use 'null' to retrieve them in all categories) |
||||
* @param $stud_id student id |
||||
*/ |
||||
public function get_evaluations_with_result_for_student ($cat_id = null, $stud_id) |
||||
{ |
||||
$tbl_grade_evaluations = Database :: get_gradebook_table(TABLE_GRADEBOOK_EVALUATION); |
||||
$tbl_grade_results = Database :: get_gradebook_table(TABLE_GRADEBOOK_RESULT); |
||||
|
||||
$sql = 'SELECT * FROM '.$tbl_grade_evaluations |
||||
.' WHERE id IN' |
||||
.'(SELECT evaluation_id FROM '.$tbl_grade_results |
||||
.' WHERE user_id = '.$stud_id.' AND score IS NOT NULL)'; |
||||
if (!api_is_allowed_to_create_course()) |
||||
$sql .= ' AND visible = 1'; |
||||
if (isset($cat_id)) |
||||
$sql .= ' AND category_id = '.$cat_id; |
||||
else |
||||
$sql .= ' AND category_id >= 0'; |
||||
|
||||
|
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
$alleval = Evaluation::create_evaluation_objects_from_mysql_result($result); |
||||
|
||||
return $alleval; |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* Get a list of students that do not have a result record for this evaluation |
||||
*/ |
||||
public function get_not_subscribed_students ($first_letter_user = '') |
||||
{ |
||||
$tbl_user = Database :: get_main_table(TABLE_MAIN_USER); |
||||
$tbl_grade_results = Database :: get_gradebook_table(TABLE_GRADEBOOK_RESULT); |
||||
|
||||
$sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user |
||||
." WHERE lastname LIKE '".$first_letter_user."%'" |
||||
.' AND status = '.STUDENT |
||||
.' AND user_id NOT IN' |
||||
.' (SELECT user_id FROM '.$tbl_grade_results |
||||
.' WHERE evaluation_id = '.$this->id |
||||
.' )' |
||||
.' ORDER BY lastname'; |
||||
|
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
$db_users = api_store_result($result); |
||||
return $db_users; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Find evaluations by name |
||||
* @param string $name_mask search string |
||||
* @return array evaluation objects matching the search criterium |
||||
* @todo can be written more efficiently using a new (but very complex) sql query |
||||
*/ |
||||
public function find_evaluations ($name_mask,$selectcat) |
||||
{ |
||||
$rootcat = Category::load($selectcat); |
||||
$evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true); |
||||
$foundevals = array(); |
||||
foreach ($evals as $eval) |
||||
{ |
||||
if (!(strpos(strtolower($eval->get_name()), strtolower($name_mask)) === false)) |
||||
$foundevals[] = $eval; |
||||
} |
||||
return $foundevals; |
||||
} |
||||
|
||||
|
||||
|
||||
// Other methods implementing GradebookItem |
||||
|
||||
public function get_item_type() |
||||
{ |
||||
return 'E'; |
||||
} |
||||
|
||||
public function get_icon_name() |
||||
{ |
||||
return $this->has_results() ? 'evalnotempty' : 'evalempty'; |
||||
} |
||||
|
||||
} |
||||
?> |
@ -0,0 +1,236 @@ |
||||
<?php |
||||
|
||||
|
||||
/** |
||||
* Defines a gradebook ExerciseLink object. |
||||
* @author Bert Steppé |
||||
* @package dokeos.gradebook |
||||
*/ |
||||
class ExerciseLink extends AbstractLink |
||||
{ |
||||
|
||||
|
||||
// INTERNAL VARIABLES |
||||
|
||||
private $course_info = null; |
||||
private $exercise_table = null; |
||||
private $exercise_data = null; |
||||
|
||||
|
||||
// CONSTRUCTORS |
||||
|
||||
function ExerciseLink() |
||||
{ |
||||
$this->set_type(LINK_EXERCISE); |
||||
} |
||||
|
||||
|
||||
// FUNCTIONS IMPLEMENTING ABSTRACTLINK |
||||
|
||||
/** |
||||
* Generate an array of exercises that a teacher hasn't created a link for. |
||||
* @return array 2-dimensional array - every element contains 2 subelements (id, name) |
||||
*/ |
||||
public function get_not_created_links() |
||||
{ |
||||
if (empty($this->course_code)) |
||||
die('Error in get_not_created_links() : course code not set'); |
||||
|
||||
$tbl_grade_links = Database :: get_gradebook_table(TABLE_GRADEBOOK_LINK); |
||||
|
||||
$sql = 'SELECT id,title from '.$this->get_exercise_table() |
||||
.' WHERE id NOT IN' |
||||
.' (SELECT ref_id FROM '.$tbl_grade_links |
||||
.' WHERE type = '.LINK_EXERCISE |
||||
." AND course_code = '".$this->get_course_code()."'" |
||||
.')'; |
||||
|
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
|
||||
$cats=array(); |
||||
while ($data=mysql_fetch_array($result)) |
||||
{ |
||||
$cats[] = array ($data['id'], $data['title']); |
||||
} |
||||
return $cats; |
||||
} |
||||
|
||||
/** |
||||
* Has anyone done this exercise yet ? |
||||
*/ |
||||
public function has_results() |
||||
{ |
||||
$tbl_stats = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); |
||||
$sql = 'SELECT count(exe_id) AS number FROM '.$tbl_stats |
||||
." WHERE exe_cours_id = '".$this->get_course_code()."'" |
||||
.' AND exe_exo_id = '.$this->get_ref_id(); |
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
$number=mysql_fetch_row($result); |
||||
return ($number[0] != 0); |
||||
} |
||||
|
||||
/** |
||||
* Get the score of this exercise. Only the first attempts are taken into account. |
||||
* @param $stud_id student id (default: all students who have results - then the average is returned) |
||||
* @return array (score, max) if student is given |
||||
* array (sum of scores, number of scores) otherwise |
||||
* or null if no scores available |
||||
*/ |
||||
public function calc_score($stud_id = null) |
||||
{ |
||||
$tbl_stats = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); |
||||
$sql = 'SELECT * FROM '.$tbl_stats |
||||
." WHERE exe_cours_id = '".$this->get_course_code()."'" |
||||
.' AND exe_exo_id = '.$this->get_ref_id(); |
||||
|
||||
if (isset($stud_id)) |
||||
$sql .= ' AND exe_user_id = '.$stud_id; |
||||
|
||||
// order by id, that way the student's first attempt is accessed first |
||||
$sql .= ' ORDER BY exe_id'; |
||||
|
||||
$scores = api_sql_query($sql, __FILE__, __LINE__); |
||||
|
||||
// for 1 student |
||||
if (isset($stud_id)) |
||||
{ |
||||
if ($data=mysql_fetch_array($scores)) |
||||
return array ($data['exe_result'], $data['exe_weighting']); |
||||
else |
||||
return null; |
||||
} |
||||
|
||||
// all students -> get average |
||||
else |
||||
{ |
||||
$students=array(); // user list, needed to make sure we only |
||||
// take first attempts into account |
||||
$rescount = 0; |
||||
$sum = 0; |
||||
|
||||
while ($data=mysql_fetch_array($scores)) |
||||
{ |
||||
if (!(array_key_exists($data['exe_user_id'],$students))) |
||||
{ |
||||
if ($data['exe_weighting'] != 0) |
||||
{ |
||||
$students[$data['exe_user_id']] = $data['exe_result']; |
||||
$rescount++; |
||||
$sum += ($data['exe_result'] / $data['exe_weighting']); |
||||
} |
||||
} |
||||
} |
||||
|
||||
if ($rescount == 0) |
||||
return null; |
||||
else |
||||
return array ($sum , $rescount); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Get URL where to go to if the user clicks on the link. |
||||
* First we go to exercise_jump.php and then to the result page. |
||||
* Check this php file for more info. |
||||
*/ |
||||
public function get_link() |
||||
{ |
||||
$url = api_get_path(WEB_PATH) |
||||
.'main/gradebook/exercise_jump.php?cid='.$this->get_course_code(); |
||||
if (!api_is_allowed_to_create_course() |
||||
&& $this->calc_score(api_get_user_id()) == null) |
||||
$url .= '&doexercise='.$this->get_ref_id(); |
||||
|
||||
return $url; |
||||
} |
||||
|
||||
/** |
||||
* Get name to display: same as exercise title |
||||
*/ |
||||
public function get_name() |
||||
{ |
||||
$data = $this->get_exercise_data(); |
||||
return $data['title']; |
||||
} |
||||
|
||||
/** |
||||
* Get description to display: same as exercise description |
||||
*/ |
||||
public function get_description() |
||||
{ |
||||
$data = $this->get_exercise_data(); |
||||
return $data['description']; |
||||
} |
||||
|
||||
/** |
||||
* Check if this still links to an exercise |
||||
*/ |
||||
public function is_valid_link() |
||||
{ |
||||
$sql = 'SELECT count(id) from '.$this->get_exercise_table() |
||||
.' WHERE id = '.$this->get_ref_id(); |
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
$number=mysql_fetch_row($result); |
||||
return ($number[0] != 0); |
||||
} |
||||
|
||||
public function get_type_name() |
||||
{ |
||||
return get_lang('DokeosExercises'); |
||||
} |
||||
|
||||
public function needs_name_and_description() |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
public function needs_max() |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
public function needs_results() |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
public function is_allowed_to_change_name() |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
|
||||
// INTERNAL FUNCTIONS |
||||
|
||||
/** |
||||
* Lazy load function to get the database table of the exercise |
||||
*/ |
||||
private function get_exercise_table () |
||||
{ |
||||
if (!isset($this->exercise_table)) |
||||
{ |
||||
$course_info = Database :: get_course_info($this->get_course_code()); |
||||
$database_name = $course_info['db_name']; |
||||
$this->exercise_table = Database :: get_course_table(TABLE_QUIZ_TEST, $database_name); |
||||
} |
||||
return $this->exercise_table; |
||||
} |
||||
|
||||
/** |
||||
* Lazy load function to get the database contents of this exercise |
||||
*/ |
||||
private function get_exercise_data() |
||||
{ |
||||
if (!isset($this->exercise_data)) |
||||
{ |
||||
$sql = 'SELECT * from '.$this->get_exercise_table() |
||||
.' WHERE id = '.$this->get_ref_id(); |
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
$this->exercise_data=mysql_fetch_array($result); |
||||
} |
||||
return $this->exercise_data; |
||||
} |
||||
|
||||
|
||||
} |
||||
?> |
@ -0,0 +1,26 @@ |
||||
<?php |
||||
|
||||
|
||||
/** |
||||
* Interface for all displayable items in the gradebook. |
||||
* @author Bert Steppé |
||||
*/ |
||||
interface GradebookItem |
||||
{ |
||||
|
||||
public function get_item_type(); |
||||
|
||||
public function get_id(); |
||||
public function get_name(); |
||||
public function get_description(); |
||||
public function get_course_code(); |
||||
public function get_weight(); |
||||
public function get_date(); |
||||
public function is_visible(); |
||||
|
||||
public function get_icon_name(); |
||||
|
||||
public function calc_score($stud_id = null); |
||||
|
||||
} |
||||
?> |
@ -0,0 +1,7 @@ |
||||
<html> |
||||
<head> |
||||
<meta http-equiv="refresh" content="0; url=../../gradebook.php"> |
||||
</head> |
||||
<body> |
||||
</body> |
||||
</html> |
@ -0,0 +1,95 @@ |
||||
<?php |
||||
|
||||
// To add your new link type here: |
||||
// - define a unique type id |
||||
// - add include |
||||
// - change create() and get_all_types() |
||||
|
||||
|
||||
// Please do not change existing values, they are used in the database ! |
||||
define('LINK_EXERCISE',1); |
||||
define('LINK_DROPBOX',2); |
||||
define('LINK_STUDENTPUBLICATION',3); |
||||
|
||||
|
||||
|
||||
include_once('abstractlink.class.php'); |
||||
include_once('exerciselink.class.php'); |
||||
include_once('evallink.class.php'); |
||||
include_once('dropboxlink.class.php'); |
||||
include_once('studentpublicationlink.class.php'); |
||||
|
||||
|
||||
/** |
||||
* Factory for link objects |
||||
* @author Bert Steppé |
||||
* @package dokeos.gradebook |
||||
*/ |
||||
class LinkFactory |
||||
{ |
||||
|
||||
/** |
||||
* Retrieve links and return them as an array of extensions of AbstractLink. |
||||
* @param $id link id |
||||
* @param $type link type |
||||
* @param $ref_id reference id |
||||
* @param $user_id user id (link owner) |
||||
* @param $course_code course code |
||||
* @param $category_id parent category |
||||
* @param $visible visible |
||||
*/ |
||||
public function load ($id = null, $type = null, $ref_id = null, $user_id = null, $course_code = null, $category_id = null, $visible = null) |
||||
{ |
||||
return AbstractLink::load($id, $type, $ref_id, $user_id, $course_code, $category_id, $visible); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Get the link object referring to an evaluation |
||||
*/ |
||||
public function get_evaluation_link ($eval_id) |
||||
{ |
||||
$links = AbstractLink :: load(null, null, $eval_id); |
||||
foreach ($links as $link) |
||||
{ |
||||
if (is_a($link, 'EvalLink')) |
||||
return $link; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Find links by name |
||||
* @param string $name_mask search string |
||||
* @return array link objects matching the search criterium |
||||
*/ |
||||
public function find_links ($name_mask,$selectcat) |
||||
{ |
||||
return AbstractLink::find_links($name_mask,$selectcat); |
||||
} |
||||
|
||||
/** |
||||
* Static method to create specific link objects |
||||
* @param $type link type |
||||
*/ |
||||
public function create ($type) |
||||
{ |
||||
if ($type == LINK_EXERCISE ) return new ExerciseLink(); |
||||
elseif ($type == LINK_DROPBOX ) return new DropboxLink(); |
||||
elseif ($type == LINK_STUDENTPUBLICATION ) return new StudentPublicationLink(); |
||||
else return null; |
||||
} |
||||
|
||||
/** |
||||
* Return an array of all known link types |
||||
*/ |
||||
public function get_all_types () |
||||
{ |
||||
return array (LINK_EXERCISE, |
||||
LINK_DROPBOX, |
||||
LINK_STUDENTPUBLICATION); |
||||
} |
||||
|
||||
} |
||||
?> |
@ -0,0 +1,185 @@ |
||||
<?php |
||||
|
||||
|
||||
/** |
||||
* Defines a gradebook Result object |
||||
* @author Bert Steppé, Stijn Konings |
||||
* @package dokeos.gradebook |
||||
*/ |
||||
class Result |
||||
{ |
||||
|
||||
// PROPERTIES |
||||
|
||||
private $id; |
||||
private $user_id; |
||||
private $evaluation; |
||||
private $creation_date; |
||||
private $score; |
||||
|
||||
// CONSTRUCTORS |
||||
|
||||
function Result() |
||||
{ |
||||
$this->creation_date = time(); |
||||
} |
||||
|
||||
// GETTERS AND SETTERS |
||||
|
||||
public function get_id() |
||||
{ |
||||
return $this->id; |
||||
} |
||||
|
||||
public function get_user_id() |
||||
{ |
||||
return $this->user_id; |
||||
} |
||||
|
||||
public function get_evaluation_id() |
||||
{ |
||||
return $this->evaluation; |
||||
} |
||||
|
||||
public function get_date() |
||||
{ |
||||
return $this->creation_date; |
||||
} |
||||
|
||||
public function get_score() |
||||
{ |
||||
return $this->score; |
||||
} |
||||
|
||||
public function set_id ($id) |
||||
{ |
||||
$this->id = $id; |
||||
} |
||||
|
||||
public function set_user_id ($user_id) |
||||
{ |
||||
$this->user_id = $user_id; |
||||
} |
||||
|
||||
public function set_evaluation_id ($evaluation_id) |
||||
{ |
||||
$this->evaluation = $evaluation_id; |
||||
} |
||||
|
||||
public function set_date ($creation_date) |
||||
{ |
||||
$this->creation_date = $creation_date; |
||||
} |
||||
|
||||
public function set_score ($score) |
||||
{ |
||||
$this->score = $score; |
||||
} |
||||
|
||||
// CRUD FUNCTIONS |
||||
|
||||
/** |
||||
* Retrieve results and return them as an array of Result objects |
||||
* @param $id result id |
||||
* @param $user_id user id (student) |
||||
* @param $evaluation_id evaluation where this is a result for |
||||
*/ |
||||
public function load ($id = null, $user_id = null, $evaluation_id = null) |
||||
{ |
||||
$tbl_grade_results = Database :: get_gradebook_table(TABLE_GRADEBOOK_RESULT); |
||||
$sql='SELECT id,user_id,evaluation_id,date,score FROM '.$tbl_grade_results; |
||||
$paramcount = 0; |
||||
if (!empty ($id)) |
||||
{ |
||||
$sql.= ' WHERE id = '.$id; |
||||
$paramcount ++; |
||||
} |
||||
if (!empty ($user_id)) |
||||
{ |
||||
if ($paramcount != 0) $sql .= ' AND'; |
||||
else $sql .= ' WHERE'; |
||||
$sql .= ' user_id = '.$user_id; |
||||
$paramcount ++; |
||||
} |
||||
if (!empty ($evaluation_id)) |
||||
{ |
||||
if ($paramcount != 0) $sql .= ' AND'; |
||||
else $sql .= ' WHERE'; |
||||
$sql .= ' evaluation_id = '.$evaluation_id; |
||||
$paramcount ++; |
||||
} |
||||
|
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
$allres=array(); |
||||
while ($data=mysql_fetch_array($result)) |
||||
{ |
||||
$res= new Result(); |
||||
$res->set_id($data['id']); |
||||
$res->set_user_id($data['user_id']); |
||||
$res->set_evaluation_id($data['evaluation_id']); |
||||
$res->set_date($data['date']); |
||||
$res->set_score($data['score']); |
||||
$allres[]=$res; |
||||
} |
||||
return $allres; |
||||
} |
||||
|
||||
/** |
||||
* Insert this result into the database |
||||
*/ |
||||
public function add() |
||||
{ |
||||
if (isset($this->user_id) && isset($this->evaluation) && isset($this->creation_date) ) |
||||
{ |
||||
$tbl_grade_results = Database :: get_gradebook_table(TABLE_GRADEBOOK_RESULT); |
||||
$sql = 'INSERT INTO '.$tbl_grade_results |
||||
.' (user_id, evaluation_id, |
||||
date'; |
||||
if (isset($this->score)) $sql .= ',score'; |
||||
|
||||
$sql .= ') VALUES |
||||
('.$this->get_user_id().', '.$this->get_evaluation_id() |
||||
.', '.$this->get_date(); |
||||
if (isset($this->score)) $sql .= ', '.$this->get_score(); |
||||
$sql .= ')'; |
||||
|
||||
api_sql_query($sql, __FILE__, __LINE__); |
||||
} |
||||
else |
||||
die('Error in Result add: required field empty'); |
||||
} |
||||
|
||||
/** |
||||
* Update the properties of this result in the database |
||||
*/ |
||||
public function save() |
||||
{ |
||||
$tbl_grade_results = Database :: get_gradebook_table(TABLE_GRADEBOOK_RESULT); |
||||
$sql = 'UPDATE '.$tbl_grade_results |
||||
.' SET user_id = '.$this->get_user_id() |
||||
.', evaluation_id = '.$this->get_evaluation_id() |
||||
.', score = '; |
||||
|
||||
if (isset($this->score)) |
||||
$sql .= $this->get_score(); |
||||
else |
||||
$sql .= 'null'; |
||||
|
||||
$sql .= ' WHERE id = '.$this->id; |
||||
// no need to update creation date |
||||
api_sql_query($sql, __FILE__, __LINE__); |
||||
} |
||||
|
||||
/** |
||||
* Delete this result from the database |
||||
*/ |
||||
public function delete() |
||||
{ |
||||
$tbl_grade_results = Database :: get_gradebook_table(TABLE_GRADEBOOK_RESULT); |
||||
$sql = 'DELETE FROM '.$tbl_grade_results.' WHERE id = '.$this->id; |
||||
api_sql_query($sql, __FILE__, __LINE__); |
||||
} |
||||
|
||||
|
||||
} |
||||
?> |
@ -0,0 +1,106 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Gradebook link to student publication item |
||||
* @author Bert Steppé |
||||
* @package dokeos.gradebook |
||||
*/ |
||||
class StudentPublicationLink extends EvalLink |
||||
{ |
||||
|
||||
// INTERNAL VARIABLES |
||||
|
||||
private $studpub_table = null; |
||||
private $itemprop_table = null; |
||||
|
||||
|
||||
// CONSTRUCTORS |
||||
|
||||
function StudentPublicationLink() |
||||
{ |
||||
$this->set_type(LINK_STUDENTPUBLICATION); |
||||
} |
||||
|
||||
|
||||
// FUNCTIONS IMPLEMENTING ABSTRACTLINK |
||||
|
||||
public function get_view_url ($stud_id) |
||||
{ |
||||
// find a file uploaded by the given student, |
||||
// with the same title as the evaluation name |
||||
|
||||
$eval = $this->get_evaluation(); |
||||
|
||||
$sql = 'SELECT pub.url' |
||||
.' FROM '.$this->get_itemprop_table().' prop, ' |
||||
.$this->get_studpub_table().' pub' |
||||
." WHERE prop.tool = 'work'" |
||||
.' AND prop.insert_user_id = '.$stud_id |
||||
.' AND prop.ref = pub.id' |
||||
." AND pub.title = '".mysql_real_escape_string($eval->get_name())."'"; |
||||
|
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
if ($fileurl = mysql_fetch_row($result)) |
||||
{ |
||||
$course_info = Database :: get_course_info($this->get_course_code()); |
||||
|
||||
$url = api_get_path(WEB_PATH) |
||||
.'main/gradebook/open_document.php?file=' |
||||
.$course_info['directory'] |
||||
.'/' |
||||
.$fileurl[0]; |
||||
|
||||
return $url; |
||||
} |
||||
else |
||||
return null; |
||||
|
||||
} |
||||
|
||||
|
||||
public function get_type_name() |
||||
{ |
||||
return get_lang('DokeosStudentPublications'); |
||||
} |
||||
|
||||
|
||||
public function is_allowed_to_change_name() |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
|
||||
|
||||
// INTERNAL FUNCTIONS |
||||
|
||||
/** |
||||
* Lazy load function to get the database table of the student publications |
||||
*/ |
||||
private function get_studpub_table () |
||||
{ |
||||
if (!isset($this->studpub_table)) |
||||
{ |
||||
$course_info = Database :: get_course_info($this->get_course_code()); |
||||
$database_name = $course_info['db_name']; |
||||
$this->studpub_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION, $database_name); |
||||
} |
||||
return $this->studpub_table; |
||||
} |
||||
|
||||
/** |
||||
* Lazy load function to get the database table of the item properties |
||||
*/ |
||||
private function get_itemprop_table () |
||||
{ |
||||
if (!isset($this->itemprop_table)) |
||||
{ |
||||
$course_info = Database :: get_course_info($this->get_course_code()); |
||||
$database_name = $course_info['db_name']; |
||||
$this->itemprop_table = Database :: get_course_table(TABLE_ITEM_PROPERTY, $database_name); |
||||
} |
||||
return $this->itemprop_table; |
||||
} |
||||
|
||||
|
||||
} |
||||
?> |
@ -0,0 +1,156 @@ |
||||
<?php |
||||
|
||||
include_once ('../../../inc/global.inc.php'); |
||||
include_once ('../be.inc.php'); |
||||
require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'); |
||||
|
||||
/** |
||||
* Extends formvalidator with add&edit forms |
||||
* @author Stijn Konings |
||||
* @package dokeos.gradebook |
||||
*/ |
||||
|
||||
class CatForm extends FormValidator { |
||||
|
||||
const TYPE_ADD = 1; |
||||
const TYPE_EDIT = 2; |
||||
const TYPE_MOVE = 3; |
||||
private $category_object; |
||||
|
||||
/** |
||||
* Builds a form containing form items based on a given parameter |
||||
* @param int form_type 1=add, 2=edit,3=move,4=browse |
||||
* @param obj cat_obj the category object |
||||
* @param string form name |
||||
* @param method method |
||||
*/ |
||||
function CatForm($form_type, $category_object,$form_name,$method = 'post',$action=null) |
||||
{ |
||||
parent :: __construct($form_name, $method, $action); |
||||
$this->form_type = $form_type; |
||||
if (isset ($category_object)) |
||||
{ |
||||
$this->category_object = $category_object; |
||||
} |
||||
if ($this->form_type == self :: TYPE_EDIT) |
||||
{ |
||||
$this->build_editing_form(); |
||||
} |
||||
elseif ($this->form_type == self :: TYPE_ADD) |
||||
{ |
||||
$this->build_add_form(); |
||||
} |
||||
elseif ($this->form_type == self :: TYPE_MOVE) |
||||
{ |
||||
$this->build_move_form(); |
||||
} |
||||
$this->setDefaults(); |
||||
} |
||||
|
||||
/** |
||||
* This function will build a move form that will allow the user to move a category to |
||||
* a another |
||||
*/ |
||||
protected function build_move_form() |
||||
{ |
||||
$renderer =& $this->defaultRenderer(); |
||||
$renderer->setElementTemplate('<span>{element}</span> '); |
||||
$this->addElement('static',null,null,'"'.$this->category_object->get_name().'" '); |
||||
$this->addElement('static',null,null,get_lang('MoveTo'). ' : '); |
||||
$select = $this->addElement('select','move_cat',null,null); |
||||
foreach ($this->category_object->get_target_categories() as $cat) |
||||
{ |
||||
for ($i=0;$i<$cat[2];$i++) |
||||
{ |
||||
$line .= '--'; |
||||
} |
||||
if ($cat[0] != $this->category_object->get_parent_id()) |
||||
$select->addoption($line.' '.$cat[1],$cat[0]); |
||||
else |
||||
$select->addoption($line.' '.$cat[1],$cat[0],'disabled'); |
||||
$line = ''; |
||||
} |
||||
$this->addElement('submit', null, get_lang('Ok')); |
||||
} |
||||
/** |
||||
* This function builds an 'add category form, if parent id is 0, it will only |
||||
* show courses |
||||
*/ |
||||
protected function build_add_form() |
||||
{ |
||||
//check if we are a root category |
||||
//if so, you can only choose between courses |
||||
if ($this->category_object->get_parent_id() == '0') |
||||
{ |
||||
$select = $this->addElement('select','select_course',array(get_lang('PickACourse'),'test'), null); |
||||
$coursecat = Category :: get_not_created_course_categories(api_get_user_id()); |
||||
if (count($coursecat)==0) |
||||
$select->addoption(get_lang('CourseIndependent'),'COURSEINDEPENDENT','disabled'); |
||||
else |
||||
$select->addoption(get_lang('CourseIndependent'),'COURSEINDEPENDENT'); |
||||
//only return courses that are not yet created by the teacher |
||||
|
||||
foreach($coursecat as $row) |
||||
{ |
||||
$select->addoption($row[1],$row[0]); |
||||
} |
||||
$this->setDefaults(array( |
||||
'hid_user_id' => $this->category_object->get_user_id(), |
||||
'hid_parent_id' => $this->category_object->get_parent_id() |
||||
)); |
||||
} |
||||
else |
||||
{ |
||||
$this->setDefaults(array( |
||||
'hid_user_id' => $this->category_object->get_user_id(), |
||||
'hid_parent_id' => $this->category_object->get_parent_id() |
||||
)); |
||||
$this->addElement('hidden','course_code', $this->category_object->get_course_code()); |
||||
} |
||||
$this->build_basic_form(); |
||||
} |
||||
|
||||
/** |
||||
* Builds an form to edit a category |
||||
*/ |
||||
protected function build_editing_form() |
||||
{ |
||||
$this->setDefaults(array( |
||||
'name' => $this->category_object->get_name(), |
||||
'description' => $this->category_object->get_description(), |
||||
'hid_user_id' => $this->category_object->get_user_id(), |
||||
'hid_parent_id' => $this->category_object->get_parent_id(), |
||||
'weight' => $this->category_object->get_weight(), |
||||
'visible' => $this->category_object->is_visible() |
||||
)); |
||||
$this->addElement('hidden','hid_id', $this->category_object->get_id()); |
||||
$this->addElement('hidden','course_code', $this->category_object->get_course_code()); |
||||
$this->build_basic_form(); |
||||
} |
||||
|
||||
private function build_basic_form() |
||||
{ |
||||
$this->addElement('hidden', 'zero', 0); |
||||
$this->add_textfield('name', get_lang('CategoryName'),true,array('size'=>'54','maxlength'=>'50')); |
||||
$this->add_textfield('weight', get_lang('Weight'),true,array('size'=>'4','maxlength'=>'4')); |
||||
$this->addElement('hidden','hid_user_id'); |
||||
$this->addElement('hidden','hid_parent_id'); |
||||
$this->addElement('textarea', 'description', get_lang('Description'),array('rows'=>'3','cols' => '34')); |
||||
$this->addElement('checkbox', 'visible',get_lang('Visible')); |
||||
$this->addElement('submit', null, get_lang('Ok')); |
||||
$this->addRule('weight',get_lang('OnlyNumbers'),'numeric'); |
||||
$this->addRule('weight',get_lang('NoDecimals'),'nopunctuation'); |
||||
$this->addRule(array ('weight', 'zero'), get_lang('NegativeValue'), 'compare', '>='); |
||||
} |
||||
|
||||
function display() |
||||
{ |
||||
parent :: display(); |
||||
} |
||||
|
||||
function setDefaults($defaults = array ()) |
||||
{ |
||||
parent :: setDefaults($defaults); |
||||
} |
||||
} |
||||
?> |
@ -0,0 +1,97 @@ |
||||
<?php |
||||
include_once ('../../../inc/global.inc.php'); |
||||
include_once ('../be.inc.php'); |
||||
include_once ('../gradebook_functions.inc.php'); |
||||
include_once (api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php'); |
||||
require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php'); |
||||
|
||||
/** |
||||
* Extends formvalidator with import and export forms |
||||
* @author Stijn Konings |
||||
* @package dokeos.gradebook |
||||
*/ |
||||
class DataForm extends FormValidator { |
||||
|
||||
const TYPE_IMPORT = 1; |
||||
const TYPE_EXPORT = 2; |
||||
const TYPE_EXPORT_PDF = 3; |
||||
|
||||
|
||||
/** |
||||
* Builds a form containing form items based on a given parameter |
||||
* @param int form_type 1=import, 2=export |
||||
* @param obj cat_obj the category object |
||||
* @param obj res_obj the result object |
||||
* @param string form name |
||||
* @param method |
||||
* @param action |
||||
*/ |
||||
function DataForm($form_type, $form_name, $method = 'post', $action = null,$target) { |
||||
parent :: __construct($form_name, $method, $action,$target); |
||||
$this->form_type = $form_type; |
||||
if ($this->form_type == self :: TYPE_IMPORT) { |
||||
$this->build_import_form(); |
||||
} |
||||
elseif ($this->form_type == self :: TYPE_EXPORT) { |
||||
$this->build_export_form(); |
||||
} |
||||
elseif ($this->form_type == self :: TYPE_EXPORT_PDF) { |
||||
$this->build_pdf_export_form(); |
||||
} |
||||
$this->setDefaults(); |
||||
} |
||||
|
||||
|
||||
protected function build_pdf_export_form() { |
||||
$renderer =& $this->defaultRenderer(); |
||||
$renderer->setElementTemplate('<span>{element}</span> '); |
||||
$this->addElement('static','label','',get_lang('ChooseOrientation')); |
||||
$this->addElement('radio', 'orientation', null, get_lang('Portrait'), 'portrait'); |
||||
$this->addElement('radio', 'orientation', null, get_lang('Landscape'), 'landscape'); |
||||
$this->addElement('submit', 'submit', get_lang('Ok')); |
||||
$this->setDefaults(array ( |
||||
'orientation' => 'portrait' |
||||
)); |
||||
} |
||||
|
||||
|
||||
protected function build_export_form() { |
||||
$this->addElement('header','label',get_lang('ChooseFormat')); |
||||
$this->addElement('radio', 'file_type', get_lang('OutputFileType'), 'CSV (Comma-Separated Values)', 'csv'); |
||||
$this->addElement('radio', 'file_type', null, 'XML (Extensible Markup Language)', 'xml'); |
||||
$this->addElement('radio', 'file_type', null, 'PDF (Portable Document Format)', 'pdf'); |
||||
$this->addElement('submit', 'submit', get_lang('Ok')); |
||||
$this->setDefaults(array ( |
||||
'file_type' => 'csv' |
||||
)); |
||||
} |
||||
|
||||
protected function build_import_form() { |
||||
$this->addElement('hidden', 'formSent'); |
||||
$this->addElement('header','label',get_lang('ImportFileLocation')); |
||||
$this->addElement('file', 'import_file',get_lang('Location')); |
||||
$allowed_file_types = array ( |
||||
'xml', |
||||
'csv' |
||||
); |
||||
$this->addRule('file', get_lang('InvalidExtension') . ' (' . implode(',', $allowed_file_types) . ')', 'filetype', $allowed_file_types); |
||||
$this->addElement('radio', 'file_type', get_lang('FileType'), 'CSV (<a href="docs/example_csv.html" target="_blank">' . get_lang('ExampleCSVFile') . '</a>)', 'csv'); |
||||
$this->addElement('radio', 'file_type', null, 'XML (<a href="docs/example_xml.html" target="_blank">' . get_lang('ExampleXMLFile') . '</a>)', 'xml'); |
||||
$this->addElement('checkbox','overwrite', null,get_lang('OverwriteScores')); |
||||
$this->addElement('checkbox','ignoreerrors',null,get_lang('IgnoreErrors')); |
||||
$this->addElement('submit', 'submit', get_lang('Ok')); |
||||
$this->setDefaults(array( |
||||
'formSent' => '1', |
||||
'file_type' => 'csv' |
||||
)); |
||||
} |
||||
|
||||
function display() { |
||||
parent :: display(); |
||||
} |
||||
|
||||
function setDefaults($defaults = array ()) { |
||||
parent :: setDefaults($defaults); |
||||
} |
||||
} |
||||
?> |
@ -0,0 +1,246 @@ |
||||
<?php |
||||
/* |
||||
* Created on 25-apr-07 |
||||
* |
||||
* @author Stijn Konings |
||||
* |
||||
*/ |
||||
class DisplayGradebook |
||||
{ |
||||
/** |
||||
* Displays the header for the result page containing the navigation tree and links |
||||
* @param $evalobj |
||||
* @param $selectcat |
||||
* @param $shownavbar 1=show navigation bar |
||||
* @param $forpdf only output for pdf file |
||||
*/ |
||||
function display_header_result($evalobj, $selectcat, $shownavbar) |
||||
{ |
||||
if ($shownavbar == '1') |
||||
{ |
||||
$header= '<table border=0 cellpadding=5><tr><td>'; |
||||
$header .= '<a href=gradebook.php?selectcat=' . $selectcat . '><img src=../img/lp_leftarrow.gif alt=' . get_lang('BackToOverview') . ' align=absmiddle/> ' . get_lang('BackToOverview') . '</a></td>'; |
||||
if ($evalobj->get_course_code() == null) |
||||
{ |
||||
$header .= '<td><a href=gradebook_add_user.php?selecteval=' . $evalobj->get_id() . '><img src=../img/add_user_big.gif alt=' . get_lang('AddStudent') . ' align=absmiddle/> ' . get_lang('AddStudent') . '</a></td>'; |
||||
} |
||||
elseif (!$evalobj->has_results()) |
||||
{ |
||||
$header .= '<td><a href=gradebook_add_result.php?selectcat=' . $selectcat . '&selecteval=' . $evalobj->get_id() . '><img src=../img/filenew.gif alt=' . get_lang('AddResult') . ' align=absmiddle/> ' . get_lang('AddResult') . '</a></td>'; |
||||
} |
||||
$header .= '<td><a href=' . api_get_self() . '?&selecteval=' . $evalobj->get_id() . '&import=><img src="../img/calendar_down.gif" border="0" alt="" />' . ' ' . get_lang('ImportResult') . '</a></td>'; |
||||
if ($evalobj->has_results()) |
||||
{ |
||||
$header .= '<td><a href=' . api_get_self() . '?&selecteval=' . $evalobj->get_id() . '&export=><img src="../img/calendar_up.gif" border="0" alt="" />' . ' ' . get_lang('ExportResult') . '</a></td>'; |
||||
$header .= '<td><a href=gradebook_edit_result.php?selecteval=' . $evalobj->get_id() .'><img src=../img/works.gif alt=' . get_lang('EditResult') . ' align=absmiddle/> ' . get_lang('EditResult') . '</a></td>'; |
||||
$header .= '<td><a href=' . api_get_self() . '?&selecteval=' . $evalobj->get_id() . '&deleteall= onclick="return confirmationall();"><img src="../img/delete.gif" border="0" alt="" />' . ' ' . get_lang('DeleteResult') . '</a></td>'; |
||||
} |
||||
$header .= '<td><a href=' . api_get_self() . '?print=&selecteval=' . $evalobj->get_id() . ' target="_blank"><img src=../img/file_oo_writer.gif alt=' . get_lang('Print') . '/> ' . get_lang('Print') . '</a>'; |
||||
$header .= '</td></tr></table>'; |
||||
} |
||||
if ($evalobj->is_visible() == '1') |
||||
{ |
||||
$visible= get_lang('Yes'); |
||||
} else |
||||
{ |
||||
$visible= get_lang('No'); |
||||
} |
||||
|
||||
$scoredisplay = ScoreDisplay :: instance(); |
||||
if (($evalobj->has_results())) // TODO this check needed ? |
||||
{ |
||||
|
||||
$score= $evalobj->calc_score(); |
||||
if ($score != null) |
||||
$average= get_lang('Average') . ' :<b> ' .$scoredisplay->display_score($score,SCORE_AVERAGE) . '</b>'; |
||||
} |
||||
if (!$evalobj->get_description() == '') |
||||
{ |
||||
$description= get_lang('Description') . ' :<b> ' . $evalobj->get_description() . '</b><br>'; |
||||
} |
||||
if ($evalobj->get_course_code() == null) |
||||
$course= get_lang('CourseIndependent'); |
||||
else |
||||
$course= get_course_name_from_code($evalobj->get_course_code()); |
||||
$evalinfo= '<table width=100% border=0><tr><td>'; |
||||
$evalinfo .= get_lang('EvaluationName') . ' :<b> ' . $evalobj->get_name() . ' </b>(' . date('j/n/Y g:i', $evalobj->get_date()) . ')<br>' . get_lang('Course') . ' :<b> ' . $course . '</b><br>' . get_lang('Weight') . ' :<b> ' . $evalobj->get_weight() . '</b><br>' . get_lang('Max') . ' :<b> ' . $evalobj->get_max() . '</b><br>' . $description . get_lang('Visible') . ' :<b> ' . $visible . '</b><br>' . $average; |
||||
if (!$evalobj->has_results()) |
||||
$evalinfo .= '<br><i>' . get_lang('NoResultsInEvaluation') . '</i>'; |
||||
elseif ($scoredisplay->is_custom() && api_get_self() != '/dokeos/main/gradebook/gradebook_statistics.php') |
||||
$evalinfo .= '<br><br><a href="gradebook_statistics.php?selecteval='.$_GET['selecteval'].'"> '. get_lang('ViewStatistics') . '</a>'; |
||||
$evalinfo .= '</td><td align=right><img src="../img/default_courses_img/tutorial.gif"></img></td></table>'; |
||||
Display :: display_normal_message($evalinfo,false); |
||||
echo $header; |
||||
|
||||
} |
||||
/** |
||||
* Displays the header for the flatview page containing filters |
||||
* @param $catobj |
||||
* @param $showeval |
||||
* @param $showlink |
||||
*/ |
||||
function display_header_flatview($catobj, $showeval, $showlink,$simple_search_form) |
||||
{ |
||||
$header= '<table border=0 cellpadding=5>'; |
||||
$header .= '<td style="vertical-align: top;"><a href=gradebook.php?selectcat=' . $_GET['selectcat'] . '><< ' . get_lang('BackToOverview') . '</a></td>'; |
||||
$header .= '<td style="vertical-align: top;">' . get_lang('FilterCategory') . '</td><td style="vertical-align: top;"><form name=selector><select name=selectcat onchange="document.selector.submit()">'; |
||||
$cats= Category :: load(); |
||||
$tree= $cats[0]->get_tree(); |
||||
unset ($cats); |
||||
foreach ($tree as $cat) |
||||
{ |
||||
for ($i= 0; $i < $cat[2]; $i++) |
||||
{ |
||||
$line .= '—'; |
||||
} |
||||
if ($_GET['selectcat'] == $cat[0]) |
||||
{ |
||||
$header .= '<option selected value=' . $cat[0] . '>' . $line . ' ' . $cat[1] . '</option>'; |
||||
} else |
||||
{ |
||||
$header .= '<option value=' . $cat[0] . '>' . $line . ' ' . $cat[1] . '</option>'; |
||||
} |
||||
$line= ''; |
||||
} |
||||
$header .= '</td></select></form>'; |
||||
if (!$catobj->get_id() == '0') |
||||
$header .= '<td style="vertical-align: top;"><a href=' . api_get_self() . '?selectcat=' . $catobj->get_parent_id() . '><img src="../img/folder_up.gif" border="0" alt="'.get_lang('Up').'" /></a></td>'; |
||||
$header .= '<td style="vertical-align: top;">'.$simple_search_form->toHtml().'</td>'; |
||||
$header .= '<td style="vertical-align: top;"><a href="' . api_get_self() . '?exportpdf=&offset='.$_GET['offset'].'&search=' . $_GET['search'].'&selectcat=' . $catobj->get_id() . '"><img src=../img/calendar_up.gif alt=' . get_lang('ExportPDF') . '/> ' . get_lang('ExportPDF') . '</a>'; |
||||
$header .= '<td style="vertical-align: top;"><a href="' . api_get_self() . '?print=&selectcat=' . $catobj->get_id() . '" target="_blank"><img src=../img/file_oo_writer.gif alt=' . get_lang('Print') . '/> ' . get_lang('Print') . '</a>'; |
||||
$header .= '</td></tr></table>'; |
||||
if (!$catobj->get_id() == '0') |
||||
{ |
||||
$header .= '<table border=0 cellpadding=5><tr><td><form name=itemfilter method=post action=' . api_get_self() . '?selectcat=' . $catobj->get_id() . '><input type="checkbox" name=showeval onclick="document.itemfilter.submit()" ' . (($showeval == '1') ? 'checked' : '') . '>Show Evaluations '; |
||||
$header .= '<input type="checkbox" name=showlink onclick="document.itemfilter.submit()" ' . (($showlink == '1') ? 'checked' : '') . '>Show Links</form></td></tr></table>'; |
||||
} |
||||
if (isset ($_GET['search'])) |
||||
$header .= '<b>'.get_lang('SearchResults').' :</b>'; |
||||
echo $header; |
||||
} |
||||
/** |
||||
* Displays the header for the gradebook containing the navigation tree and links |
||||
* @param category_object $currentcat |
||||
* @param int $showtree '1' will show the browse tree and naviation buttons |
||||
* @param boolean $is_course_admin |
||||
* @param boolean $is_platform_admin |
||||
*/ |
||||
function display_header_gradebook($catobj, $showtree, $selectcat, $is_course_admin, $is_platform_admin,$simple_search_form) |
||||
{ |
||||
//student |
||||
if (!$is_course_admin) |
||||
{ |
||||
$user= get_user_info_from_id(api_get_user_id()); |
||||
$catcourse= Category :: load($catobj->get_id()); |
||||
$scoredisplay = ScoreDisplay :: instance(); |
||||
$scorecourse = $catcourse[0]->calc_score(api_get_user_id()); |
||||
$scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse,SCORE_AVERAGE) : get_lang('NoResultsAvailable')); |
||||
$cattotal = Category :: load(0); |
||||
$scoretotal= $cattotal[0]->calc_score(api_get_user_id()); |
||||
$scoretotal_display = (isset($scoretotal) ? $scoredisplay->display_score($scoretotal,SCORE_PERCENT) : get_lang('NoResultsAvailable')); |
||||
$scoreinfo = get_lang('StatsStudent') . ' :<b> '.$user['lastname'].' '.$user['firstname'].'</b><br>'; |
||||
if ((!$catobj->get_id() == '0') && (!isset ($_GET['studentoverview'])) && (!isset ($_GET['search']))) |
||||
$scoreinfo.= '<br>'.get_lang('TotalForThisCategory') . ' : <b>' . $scorecourse_display . '</b>'; |
||||
$scoreinfo.= '<br>'.get_lang('Total') . ' : <b>' . $scoretotal_display . '</b>'; |
||||
Display :: display_normal_message($scoreinfo,false); |
||||
} |
||||
// show navigation tree and buttons? |
||||
$header .= '<table border=0 cellpadding=5>'; |
||||
if (($showtree == '1') || (isset ($_GET['studentoverview']))) |
||||
{ |
||||
|
||||
$header .= '<tr><td style="vertical-align: top;">' . get_lang('CurrentCategory') . '</td><td style="vertical-align: top;"><form name=selector><select name=selectcat onchange="document.selector.submit()">'; |
||||
$cats= Category :: load(); |
||||
$tree= $cats[0]->get_tree(); |
||||
unset ($cats); |
||||
foreach ($tree as $cat) |
||||
{ |
||||
for ($i= 0; $i < $cat[2]; $i++) |
||||
{ |
||||
$line .= '—'; |
||||
} |
||||
if ($_GET['selectcat'] == $cat[0]) |
||||
{ |
||||
$header .= '<option selected value=' . $cat[0] . '>' . $line . ' ' . $cat[1] . '</option>'; |
||||
} else |
||||
{ |
||||
$header .= '<option value=' . $cat[0] . '>' . $line . ' ' . $cat[1] . '</option>'; |
||||
} |
||||
$line= ''; |
||||
} |
||||
$header .= '</select></form></td>'; |
||||
if (!$selectcat == '0') |
||||
{ |
||||
$header .= '<td style="vertical-align: top;"><a href=' . api_get_self() . '?selectcat=' . $catobj->get_parent_id() . '><img src="../img/folder_up.gif" border="0" alt="" /></a></td>'; |
||||
} |
||||
$header .= '<td style="vertical-align: top;">'.$simple_search_form->toHtml().'</td>'; |
||||
if ($is_course_admin) |
||||
{ |
||||
$header .= '<td style="vertical-align: top;"><a href=gradebook_flatview.php?selectcat=' . $catobj->get_id() . '><img src=../img/stats_access.gif alt=' . get_lang('FlatView') . '/> ' . get_lang('FlatView') . '</a>'; |
||||
if ($is_platform_admin) |
||||
$header .= '<td style="vertical-align: top;"><a href="gradebook_scoring_system.php?selectcat=' . $catobj->get_id() .'"><img src=../img/acces_tool.gif alt=' . get_lang('ScoreEdit') . '/> ' . get_lang('ScoreEdit') . '</a>'; |
||||
} |
||||
elseif (!(isset ($_GET['studentoverview']))) |
||||
{ |
||||
$header .= '<td style="vertical-align: top;"><a href="'.api_get_self().'?studentoverview=&selectcat=' . $catobj->get_id() . '"><img src=../img/stats_access.gif alt=' . get_lang('FlatView') . '/> ' . get_lang('FlatView') . '</a>'; |
||||
} |
||||
else |
||||
{ |
||||
$header .= '<td style="vertical-align: top;"><a href="'.api_get_self().'?studentoverview=&exportpdf=&selectcat=' . $catobj->get_id() . '" target="_blank"><img src=../img/calendar_up.gif alt=' . get_lang('ExportPDF') . '/> ' . get_lang('ExportPDF') . '</a>'; |
||||
} |
||||
$header .= '</td></tr>'; |
||||
} |
||||
$header.='</table>'; |
||||
|
||||
// for course admin & platform admin add item buttons are added to the header |
||||
$header .= '<table border=0 cellpadding=0><tr><td>'; |
||||
if (($is_course_admin) && (!isset ($_GET['search']))) |
||||
{ |
||||
if ($selectcat == '0') |
||||
{ |
||||
$header .= '<a href=gradebook_add_cat.php?selectcat=0><img src=../img/folder_new.gif alt=' . get_lang('NewCategory') . '/> ' . get_lang('NewCategory') . '</a></td>'; |
||||
$header .= '<td><a href=gradebook_add_eval.php><img src=../img/filenew.gif alt=' . get_lang('NewEvaluation') . '/> ' . get_lang('NewEvaluation') . '</a>'; |
||||
} else |
||||
{ |
||||
$header .= '<a href=gradebook_add_cat.php?selectcat=' . $catobj->get_id() . '><img src=../img/folder_new.gif alt=' . get_lang('NewSubCategory') . ' align=absmiddle/> ' . get_lang('NewSubCategory') . '</a></td>'; |
||||
$header .= '<td><a href=gradebook_add_eval.php?selectcat=' . $catobj->get_id() . '><img src=../img/filenew.gif alt=' . get_lang('NewEvaluation') . ' align=absmiddle/> ' . get_lang('NewEvaluation') . '</a>'; |
||||
$cats= Category :: load($selectcat); |
||||
if ($cats[0]->get_course_code() != null) |
||||
$header .= '<td><a href=gradebook_add_link.php?&selectcat=' . $catobj->get_id() . '><img src=../img/link_blank.gif alt=' . get_lang('MakeLink') . ' align=absmiddle/> ' . get_lang('MakeLink') . '</a>'; |
||||
} |
||||
} |
||||
elseif (isset ($_GET['search'])) |
||||
{ |
||||
$header .= '<b>'.get_lang('SearchResults').' :</b>'; |
||||
} |
||||
|
||||
$header .= '</td></tr></table>'; |
||||
echo $header; |
||||
} |
||||
|
||||
function display_header_user($userid) |
||||
{ |
||||
$user= get_user_info_from_id($userid); |
||||
$image= $user['picture_uri']; |
||||
$image_file= ($image != '' ? api_get_path(WEB_CODE_PATH) . "upload/users/$image" : api_get_path(WEB_CODE_PATH) . 'img/unknown.jpg'); |
||||
$image_size= @ getimagesize($image_file); |
||||
$img_attributes= 'src="' . $image_file . '?rand=' . time() . '" ' . 'alt="' . $user['lastname'] . ' ' . $user['firstname'] . '" '; |
||||
if ($image_size[0] > 200) //limit display width to 200px |
||||
$img_attributes .= 'width="200" '; |
||||
$cattotal= Category :: load(0); |
||||
$info = '<table width="100%" border=0 cellpadding=5><tr><td width="80%">'; |
||||
$info.= get_lang('Name') . ' : <b>' . $user['lastname'] . ' ' . $user['firstname'] . '</b> ( <a href="user_info.php?userid=' . $userid . '&selecteval=' . $_GET['selecteval'] . '">' . get_lang('MoreInfo') . '...</a> )<br>'; |
||||
$info.= get_lang('Email') . ' : <b><a href="mailto:' . $user['email'] . '">' . $user['email'] . '</a></b><br><br>'; |
||||
$scoredisplay = ScoreDisplay :: instance(); |
||||
$score_stud= $cattotal[0]->calc_score($userid); |
||||
$score_stud_display = (isset($score_stud) ? $scoredisplay->display_score($score_stud,SCORE_PERCENT) : get_lang('NoResultsAvailable') ); |
||||
$score_avg= $cattotal[0]->calc_score(); |
||||
$score_avg_display = (isset($score_avg) ? $scoredisplay->display_score($score_avg,SCORE_AVERAGE) : get_lang('NoResultsAvailable') ); |
||||
$info.= get_lang('TotalUser') . ' : <b>' . $score_stud_display . '</b><br>'; |
||||
$info.= get_lang('AverageTotal') . ' : <b>' . $score_avg_display . '</b>'; |
||||
$info.= '</td><td>'; |
||||
$info.= '<img ' . $img_attributes . '/></td></tr></table>'; |
||||
echo Display :: display_normal_message($info,false); |
||||
} |
||||
} |
||||
?> |
@ -0,0 +1,400 @@ |
||||
<?php |
||||
include_once ('../../../inc/global.inc.php'); |
||||
include_once ('../be.inc.php'); |
||||
include_once ('../gradebook_functions.inc.php'); |
||||
include_once (api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php'); |
||||
require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php'); |
||||
/** |
||||
* Extends formvalidator with add&edit forms for evaluations |
||||
* @author Stijn Konings |
||||
* @package dokeos.gradebook |
||||
*/ |
||||
class EvalForm extends FormValidator |
||||
{ |
||||
const TYPE_ADD= 1; |
||||
const TYPE_EDIT= 2; |
||||
const TYPE_MOVE= 3; |
||||
const TYPE_RESULT_ADD= 4; |
||||
const TYPE_RESULT_EDIT= 5; |
||||
const TYPE_ALL_RESULTS_EDIT= 6; |
||||
const TYPE_ADD_USERS_TO_EVAL= 7; |
||||
|
||||
private $evaluation_object; |
||||
private $result_object; |
||||
private $extra; |
||||
|
||||
/** |
||||
* Builds a form containing form items based on a given parameter |
||||
* @param int form_type 1=add, 2=edit,3=move,4=result_add |
||||
* @param obj cat_obj the category object |
||||
* @param obj res_obj the result object |
||||
* @param string form name |
||||
* @param method |
||||
* @param action |
||||
*/ |
||||
function EvalForm($form_type, $evaluation_object, $result_object, $form_name, $method= 'post', $action= null, $extra1 = null, $extra2 = null) |
||||
{ |
||||
parent :: __construct($form_name, $method, $action); |
||||
|
||||
if (isset ($evaluation_object)) |
||||
$this->evaluation_object= $evaluation_object; |
||||
if (isset ($result_object)) |
||||
$this->result_object= $result_object; |
||||
if (isset ($extra1)) |
||||
$this->extra = $extra1; |
||||
|
||||
|
||||
if ($form_type == self :: TYPE_EDIT) |
||||
{ |
||||
$this->build_editing_form(); |
||||
} |
||||
elseif ($form_type == self :: TYPE_ADD) |
||||
{ |
||||
$this->build_add_form(); |
||||
} |
||||
elseif ($form_type == self :: TYPE_MOVE) |
||||
{ |
||||
$this->build_move_form(); |
||||
} |
||||
elseif ($form_type == self :: TYPE_RESULT_ADD) |
||||
{ |
||||
$this->build_result_add_form(); |
||||
} |
||||
elseif ($form_type == self :: TYPE_RESULT_EDIT) |
||||
{ |
||||
$this->build_result_edit_form(); |
||||
} |
||||
elseif ($form_type == self :: TYPE_ALL_RESULTS_EDIT) |
||||
{ |
||||
$this->build_all_results_edit_form(); |
||||
} |
||||
elseif ($form_type == self :: TYPE_ADD_USERS_TO_EVAL) |
||||
{ |
||||
$this->build_add_user_to_eval(); |
||||
} |
||||
$this->setDefaults(); |
||||
} |
||||
/** |
||||
* This form will build a form to add users to an evaluation |
||||
*/ |
||||
protected function build_add_user_to_eval() |
||||
{ |
||||
//$this->addElement('hidden', 'formSent'); |
||||
$this->addElement('header','label',get_lang('ChooseUser')); |
||||
$select= $this->addElement('select', 'firstLetterUser', get_lang('FirstLetter'), null, array( |
||||
'onchange'=> 'document.add_users_to_evaluation.submit()' |
||||
)); |
||||
|
||||
$result = ''; |
||||
$select->addOption('',''); |
||||
for ($i = 65; $i <= 90; $i ++) |
||||
{ |
||||
$letter = chr($i); |
||||
if (isset($this->extra) && $this->extra == $letter) |
||||
$select->addOption($letter,$letter,'selected'); |
||||
else |
||||
$select->addOption($letter,$letter); |
||||
} |
||||
|
||||
$select= $this->addElement('select', 'add_users', null, null, array ( |
||||
'multiple' => 'multiple', |
||||
'size' => '15', |
||||
'style' => 'width:250px' |
||||
)); |
||||
foreach ($this->evaluation_object->get_not_subscribed_students() as $user) |
||||
{ |
||||
if ( (!isset($this->extra)) || empty($this->extra) || strtoupper(substr($user[1],0,1)) == $this->extra ) |
||||
$select->addoption($user[1] . ' ' . $user[2] . ' (' . $user[3] . ')', $user[0]); |
||||
} |
||||
$this->addElement('submit', 'submit_button', get_lang('AddUserToEval')); |
||||
// $this->setDefaults(array ( |
||||
// 'formSent' => '1' |
||||
// )); |
||||
|
||||
} |
||||
/** |
||||
* This function builds a form to edit all results in an evaluation |
||||
*/ |
||||
protected function build_all_results_edit_form() |
||||
{ |
||||
//extra field for check on maxvalue |
||||
$this->addElement('hidden', 'maxvalue', $this->evaluation_object->get_max()); |
||||
$this->addElement('hidden', 'minvalue', 0); |
||||
$this->addElement('header','h1','<b>'.get_lang('EditResult').'</b>'); |
||||
$renderer = $this->defaultRenderer(); |
||||
$elementTemplateTwoLabel = '<div class="row"> |
||||
<div class="label"> |
||||
<!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label} |
||||
</div> |
||||
<div class="formw"> |
||||
<!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error --> {element} / '.$this->evaluation_object->get_max().' |
||||
</div> |
||||
</div>'; |
||||
|
||||
$results_and_users = array(); |
||||
foreach ($this->result_object as $result) |
||||
{ |
||||
$user= get_user_info_from_id($result->get_user_id()); |
||||
$results_and_users[] = array ('result' => $result, 'user' => $user); |
||||
} |
||||
|
||||
usort($results_and_users, array ('EvalForm', 'sort_by_user')); |
||||
|
||||
|
||||
$defaults= array (); |
||||
foreach ($results_and_users as $result_and_user) |
||||
{ |
||||
$user = $result_and_user['user']; |
||||
$result = $result_and_user['result']; |
||||
|
||||
$renderer =& $this->defaultRenderer(); |
||||
$this->add_textfield('score[' . $result->get_id() . ']', |
||||
$this->build_stud_label($user['user_id'], $user['lastname'], $user['firstname']), |
||||
false, |
||||
array ('size' => 4, |
||||
'maxlength' => 4)); |
||||
|
||||
$this->addRule('score[' . $result->get_id() . ']', get_lang('OnlyNumbers'), 'numeric'); |
||||
$this->addRule(array ( |
||||
'score[' . $result->get_id() . ']', 'maxvalue'), get_lang('OverMax'), 'compare', '<='); |
||||
$this->addRule(array ( |
||||
'score[' . $result->get_id() . ']', 'minvalue'), get_lang('UnderMin'), 'compare', '>='); |
||||
$defaults['score[' . $result->get_id() . ']']= $result->get_score(); |
||||
$renderer->setElementTemplate($elementTemplateTwoLabel,'score[' . $result->get_id() . ']'); |
||||
} |
||||
$this->setDefaults($defaults); |
||||
$this->addElement('submit', null, get_lang('Ok')); |
||||
} |
||||
/** |
||||
* This function builds a form to move an item to another category |
||||
* |
||||
*/ |
||||
protected function build_move_form() |
||||
{ |
||||
$renderer =& $this->defaultRenderer(); |
||||
$renderer->setElementTemplate('<span>{element}</span> '); |
||||
$this->addElement('static', null, null, '"'.$this->evaluation_object->get_name().'" '); |
||||
$this->addElement('static', null, null, get_lang('MoveTo').' : '); |
||||
$select= $this->addElement('select', 'move_cat', null, null); |
||||
foreach ($this->evaluation_object->get_target_categories() as $cat) |
||||
{ |
||||
for ($i= 0; $i < $cat[2]; $i++) |
||||
{ |
||||
$line .= '—'; |
||||
} |
||||
$select->addoption($line . ' ' . $cat[1], $cat[0]); |
||||
$line= ''; |
||||
} |
||||
$this->addElement('submit', null, get_lang('Ok')); |
||||
} |
||||
/** |
||||
* Builds a result form containing inputs for all students with a given course_code |
||||
*/ |
||||
protected function build_result_add_form() |
||||
{ |
||||
$tblusers= get_users_in_course($this->evaluation_object->get_course_code()); |
||||
$nr_users= 0; |
||||
//extra field for check on maxvalue |
||||
$this->addElement('hidden', 'maxvalue', $this->evaluation_object->get_max()); |
||||
$this->addElement('hidden', 'minvalue', 0); |
||||
$this->addElement('header','h1','<b>'.get_lang('AddResult').'</b>'); |
||||
|
||||
$renderer = $this->defaultRenderer(); |
||||
$elementTemplateTwoLabel = '<div class="row"> |
||||
<div class="label"> |
||||
<!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label} |
||||
</div> |
||||
<div class="formw"> |
||||
<!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error --> {element} / '.$this->evaluation_object->get_max().' |
||||
</div> |
||||
</div>'; |
||||
foreach ($tblusers as $user) |
||||
{ |
||||
$this->add_textfield('score[' . $user[0] . ']', |
||||
$this->build_stud_label($user[0], $user[1], $user[2]), |
||||
false, |
||||
array ('size' => 4, |
||||
'maxlength' => 4)); |
||||
|
||||
$this->addRule('score[' . $user[0] . ']', get_lang('OnlyNumbers'), 'numeric'); |
||||
$this->addRule(array ( |
||||
'score[' . $user[0] . ']', |
||||
'maxvalue' |
||||
), get_lang('OverMax'), 'compare', '<='); |
||||
$this->addRule(array ( |
||||
'score[' . $user[0] . ']', |
||||
'minvalue' |
||||
), get_lang('UnderMin'), 'compare', '>='); |
||||
|
||||
$renderer->setElementTemplate($elementTemplateTwoLabel,'score[' . $user[0] . ']'); |
||||
$nr_users++; |
||||
} |
||||
$this->addElement('hidden', 'nr_users', $nr_users); |
||||
$this->addElement('hidden', 'evaluation_id', $this->result_object->get_evaluation_id()); |
||||
$this->addElement('submit', null, get_lang('Ok')); |
||||
} |
||||
/** |
||||
* Builds a form to edit a result |
||||
*/ |
||||
protected function build_result_edit_form() |
||||
{ |
||||
$this->setDefaults(array ( |
||||
'score' => $this->result_object->get_score(), |
||||
'maximum' => $this->evaluation_object->get_max() |
||||
)); |
||||
$userinfo= api_get_user_info($this->result_object->get_user_id()); |
||||
$renderer =& $this->defaultRenderer(); |
||||
$renderer->setElementTemplate('<span>{element}</span> '); |
||||
$this->addElement('static', null, null,$userinfo['lastName'] . ' ' . $userinfo['firstName']); |
||||
$this->add_textfield('score', get_lang('Result'), false, array ( |
||||
'size' => '4', |
||||
'maxlength' => '4' |
||||
)); |
||||
$this->addElement('static', null, null,'/'); |
||||
|
||||
$this->add_textfield('maximum', null, false, array ( |
||||
'size' => '4', |
||||
'maxlength' => '4', |
||||
'disabled' => 'disabled' |
||||
)); |
||||
$this->addElement('submit', null, get_lang('Edit')); |
||||
$this->addElement('hidden', 'minvalue', 0); |
||||
$this->addElement('hidden', 'hid_user_id', $this->result_object->get_user_id()); |
||||
$this->addElement('hidden', 'maxvalue', $this->evaluation_object->get_max()); |
||||
$this->addRule('score', get_lang('OnlyNumbers'), 'numeric',null,'client'); |
||||
$this->addRule(array ( |
||||
'score', |
||||
'maxvalue' |
||||
), get_lang('OverMax'), 'compare', '<=','client'); |
||||
$this->addRule(array ( |
||||
'score', |
||||
'minvalue' |
||||
), get_lang('UnderMin'), 'compare', '>=','client'); |
||||
} |
||||
/** |
||||
* Builds a form to add an evaluation |
||||
*/ |
||||
protected function build_add_form() |
||||
{ |
||||
$this->setDefaults(array ( |
||||
'hid_user_id' => $this->evaluation_object->get_user_id(), 'hid_category_id' => $this->evaluation_object->get_category_id(), 'hid_course_code' => $this->evaluation_object->get_course_code(), 'date' => time())); |
||||
$this->build_basic_form(0); |
||||
if ($this->evaluation_object->get_course_code() == null) |
||||
{ |
||||
$this->addElement('checkbox', 'adduser', get_lang('AddUserToEval')); |
||||
} else |
||||
{ |
||||
$this->addElement('checkbox', 'addresult', get_lang('AddResult')); |
||||
} |
||||
$this->addElement('submit', null, get_lang('Add')); |
||||
} |
||||
/** |
||||
* Builds a form to edit an evaluation |
||||
*/ |
||||
protected function build_editing_form() |
||||
{ |
||||
$this->setDefaults(array ( |
||||
'hid_id' => $this->evaluation_object->get_id(), 'name' => $this->evaluation_object->get_name(), 'description' => $this->evaluation_object->get_description(), 'hid_user_id' => $this->evaluation_object->get_user_id(), 'hid_course_code' => $this->evaluation_object->get_course_code(), 'hid_category_id' => $this->evaluation_object->get_category_id(), 'date' => $this->evaluation_object->get_date(), 'weight' => $this->evaluation_object->get_weight(), 'max' => $this->evaluation_object->get_max(), 'visible' => $this->evaluation_object->is_visible())); |
||||
$this->addElement('hidden', 'hid_id', $this->id); |
||||
$this->build_basic_form(1); |
||||
$this->addElement('submit', null, get_lang('Edit')); |
||||
} |
||||
/** |
||||
* Builds a basic form that is used in add and edit |
||||
*/ |
||||
private function build_basic_form($edit= 0) |
||||
{ |
||||
$this->addElement('hidden', 'zero', 0); |
||||
$this->addElement('hidden', 'hid_user_id'); |
||||
$this->addElement('hidden', 'hid_category_id'); |
||||
$this->addElement('hidden', 'hid_course_code'); |
||||
$this->add_textfield('name', get_lang('EvaluationName'), true, array ( |
||||
'size' => '54', |
||||
'maxlength' => '50' |
||||
)); |
||||
$this->add_textfield('weight', get_lang('Weight'), true, array ( |
||||
'size' => '4', |
||||
'maxlength' => '4' |
||||
)); |
||||
if ($edit) |
||||
{ |
||||
if (!$this->evaluation_object->has_results()) |
||||
{ |
||||
$this->add_textfield('max', get_lang('Max'), true, array ( |
||||
'size' => '4', |
||||
'maxlength' => '4' |
||||
)); |
||||
} |
||||
else |
||||
{ |
||||
$this->add_textfield('max', get_lang('Max'), false, array ( |
||||
'size' => '4', |
||||
'maxlength' => '4', |
||||
'disabled' => 'disabled' |
||||
)); |
||||
$this->addElement('static','label','','<small>'.get_lang('NoMaxChange').'</small>'); |
||||
} |
||||
} else |
||||
{ |
||||
$this->add_textfield('max', get_lang('Max'), true, array ( |
||||
'size' => '4', |
||||
'maxlength' => '4' |
||||
)); |
||||
} |
||||
$this->add_datepicker('date', get_lang('DateEval')); |
||||
$this->addElement('textarea', 'description', get_lang('Description'), array ( |
||||
'rows' => '3', |
||||
'cols' => '34' |
||||
)); |
||||
$this->addElement('checkbox', 'visible', get_lang('Visible')); |
||||
$this->addRule('weight', get_lang('OnlyNumbers'), 'numeric'); |
||||
$this->addRule(array ('weight', 'zero'), get_lang('NegativeValue'), 'compare', '>='); |
||||
$this->addRule('max', get_lang('OnlyNumbers'), 'numeric'); |
||||
$this->addRule(array ('max', 'zero'), get_lang('NegativeValue'), 'compare', '>='); |
||||
} |
||||
function display() |
||||
{ |
||||
parent :: display(); |
||||
} |
||||
function setDefaults($defaults= array ()) |
||||
{ |
||||
parent :: setDefaults($defaults); |
||||
} |
||||
|
||||
|
||||
private function build_stud_label ($id, $lastname, $firstname) |
||||
{ |
||||
$opendocurl_start = ''; |
||||
$opendocurl_end = ''; |
||||
|
||||
// evaluation's origin is a link |
||||
if ($this->evaluation_object->get_category_id() < 0) |
||||
{ |
||||
$link = LinkFactory :: get_evaluation_link ($this->evaluation_object->get_id()); |
||||
|
||||
//var_dump($stud); |
||||
|
||||
$doc_url = $link->get_view_url($id); |
||||
if ($doc_url != null) |
||||
{ |
||||
$opendocurl_start .= '<a href="'. $doc_url . '" target="_blank">'; |
||||
$opendocurl_end = '</a>'; |
||||
} |
||||
} |
||||
|
||||
return $opendocurl_start . $lastname . ' ' . $firstname . $opendocurl_end; |
||||
} |
||||
|
||||
function sort_by_user ($item1, $item2) |
||||
{ |
||||
$user1 = $item1['user']; |
||||
$user2 = $item2['user']; |
||||
if ($user1['lastname'] == $user2['lastname']) |
||||
return 0; |
||||
else |
||||
return ($user1['lastname'] < $user2['lastname'] ? -1 : 1); |
||||
} |
||||
|
||||
|
||||
} |
||||
?> |
@ -0,0 +1,100 @@ |
||||
<?php |
||||
|
||||
|
||||
function print_table($data_array,$header_names,$view,$coursename) |
||||
{ |
||||
$printdata= '<!DOCTYPE html |
||||
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
||||
<head> |
||||
<title>'.get_lang('Print').'</title> |
||||
|
||||
<style type="text/css"> |
||||
body { |
||||
font-size: 12px; |
||||
color: #000; |
||||
margin: 10px; |
||||
padding: 0; |
||||
} |
||||
|
||||
a:link {text-decoration: none; font-weight : bold; color : black;} |
||||
a:visited {text-decoration: none; font-weight : bold; color : black;} |
||||
a:active {text-decoration: none; font-weight : bold; color : black;} |
||||
|
||||
.data_table{ |
||||
border-collapse: collapse; |
||||
width: 100%; |
||||
padding: 5px; |
||||
border: 1px; |
||||
} |
||||
.data_table th{ |
||||
padding: 5px; |
||||
vertical-align: top; |
||||
border-top: 1px solid black; |
||||
border-bottom: 1px solid black; |
||||
border-right: 1px solid black; |
||||
border-left: 1px solid black; |
||||
} |
||||
.data_table tr.row_odd{ |
||||
background-color: #fafafa; |
||||
} |
||||
.data_table tr.row_even{ |
||||
background-color: #fff; |
||||
} |
||||
.data_table td{ |
||||
padding: 5px; |
||||
vertical-align: top; |
||||
border-bottom: 1px solid black; |
||||
border-right: 1px solid black; |
||||
border-left: 1px solid black; |
||||
} |
||||
</style> |
||||
</head> |
||||
<body><div id="main">'; |
||||
|
||||
$printdata .= '<h2>'.$view.' : '.$coursename.'</h2>'; |
||||
$printdata .= '<h3>'.get_lang('Date').' : '.date('j/n/Y g:i').'</h3>'; |
||||
$printdata .= '<table border=1 width=90% cellspacing=1 cellpadding=1>'; |
||||
foreach ($header_names as $header) |
||||
{ |
||||
$printdata .= '<th>'.$header.'</th>'; |
||||
|
||||
} |
||||
foreach ($data_array as $data) |
||||
{ |
||||
$printdata .= '<tr>'; |
||||
foreach ($data as $rowdata) |
||||
{ |
||||
$printdata .= '<td>'.$rowdata.'</td>'; |
||||
} |
||||
$printdata .= '</tr>'; |
||||
|
||||
} |
||||
$printdata .= '</table></div></body></html>'; |
||||
return $printdata; |
||||
} |
||||
|
||||
function export_pdf($pdf,$newarray,$header_names,$format) |
||||
{ |
||||
$pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Helvetica-Bold.afm'); |
||||
$pdf->ezSetCmMargins(0,0,0,0); |
||||
$pdf->ezSetY(($format=='portrait')?'820':'570'); |
||||
$pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Helvetica.afm'); |
||||
$pdf->ezText(get_lang('FlatView').' ('. date('j/n/Y g:i') .')',12,array('justification'=>'center')); |
||||
if ($format=='portrait') |
||||
{ |
||||
$pdf->line(40,790,540,790); |
||||
$pdf->line(40,40,540,40); |
||||
} |
||||
else |
||||
{ |
||||
$pdf->line(40,540,790,540); |
||||
$pdf->line(40,40,790,40); |
||||
} |
||||
$pdf->ezSetY(($format=='portrait')?'750':'520'); |
||||
$pdf->ezTable($newarray,$header_names,'',array('showHeadings'=>1,'shaded'=>1,'showLines'=>1,'rowGap'=>3,'width'=>(($format=='portrait')?'500':'750'))); |
||||
$pdf->ezStream(); |
||||
|
||||
} |
||||
?> |
@ -0,0 +1,228 @@ |
||||
<?php |
||||
|
||||
include_once ('../../../inc/global.inc.php'); |
||||
include_once ('../be.inc.php'); |
||||
|
||||
/** |
||||
* Table to display categories, evaluations and links |
||||
* @author Stijn Konings |
||||
* @author Bert Steppé (refactored, optimised) |
||||
*/ |
||||
class GradebookTable extends SortableTable |
||||
{ |
||||
|
||||
private $currentcat; |
||||
private $datagen; |
||||
|
||||
|
||||
/** |
||||
* Constructor |
||||
*/ |
||||
function GradebookTable ($currentcat, $cats = array(), $evals = array(), $links = array(), $addparams = null) |
||||
{ |
||||
parent :: SortableTable ('gradebooklist', null, null, (api_is_allowed_to_create_course()?1:0)); |
||||
|
||||
$this->currentcat = $currentcat; |
||||
|
||||
$this->datagen = new GradebookDataGenerator($cats, $evals, $links); |
||||
|
||||
if (isset($addparams)) |
||||
$this->set_additional_parameters($addparams); |
||||
|
||||
$column= 0; |
||||
if (api_is_allowed_to_create_course()) |
||||
$this->set_header($column++, '', false); |
||||
$this->set_header($column++, get_lang('Type')); |
||||
$this->set_header($column++, get_lang('Name')); |
||||
$this->set_header($column++, get_lang('Description')); |
||||
$this->set_header($column++, get_lang('Weight')); |
||||
$this->set_header($column++, get_lang('Date')); |
||||
//admins get an edit column |
||||
if (api_is_allowed_to_create_course()) |
||||
{ |
||||
$this->set_header($column++, get_lang('Modify'), false); |
||||
//actions on multiple selected documents |
||||
$this->set_form_actions(array ( |
||||
'delete' => get_lang('DeleteSelected'), |
||||
'setvisible' => get_lang('SetVisible'), |
||||
'setinvisible' => get_lang('SetInVisible'))); |
||||
} |
||||
//students get a result column |
||||
else |
||||
{ |
||||
$this->set_header($column++, get_lang('Results'), false); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Function used by SortableTable to get total number of items in the table |
||||
*/ |
||||
function get_total_number_of_items() |
||||
{ |
||||
return $this->datagen->get_total_items_count(); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Function used by SortableTable to generate the data to display |
||||
*/ |
||||
function get_table_data($from = 1) |
||||
{ |
||||
|
||||
// determine sorting type |
||||
$col_adjust = (api_is_allowed_to_create_course() ? 1 : 0); |
||||
switch ($this->column) |
||||
{ |
||||
// Type |
||||
case (0 + $col_adjust) : |
||||
$sorting = GradebookDataGenerator :: GDG_SORT_TYPE; |
||||
break; |
||||
case (1 + $col_adjust) : |
||||
$sorting = GradebookDataGenerator :: GDG_SORT_NAME; |
||||
break; |
||||
case (2 + $col_adjust) : |
||||
$sorting = GradebookDataGenerator :: GDG_SORT_DESCRIPTION; |
||||
break; |
||||
case (3 + $col_adjust) : |
||||
$sorting = GradebookDataGenerator :: GDG_SORT_WEIGHT; |
||||
break; |
||||
case (4 + $col_adjust) : |
||||
$sorting = GradebookDataGenerator :: GDG_SORT_DATE; |
||||
break; |
||||
} |
||||
if ($this->direction == 'DESC') |
||||
$sorting |= GradebookDataGenerator :: GDG_SORT_DESC; |
||||
else |
||||
$sorting |= GradebookDataGenerator :: GDG_SORT_ASC; |
||||
|
||||
|
||||
|
||||
$data_array = $this->datagen->get_data($sorting, $from, $this->per_page); |
||||
|
||||
|
||||
// generate the data to display |
||||
$sortable_data = array(); |
||||
foreach ($data_array as $data) |
||||
{ |
||||
$row = array (); |
||||
|
||||
$item = $data[0]; |
||||
|
||||
//if the item is invisible, wrap it in a span with class invisible |
||||
$invisibility_span_open = (api_is_allowed_to_create_course() && $item->is_visible() == '0') ? '<span class="invisible">' : ''; |
||||
$invisibility_span_close = (api_is_allowed_to_create_course() && $item->is_visible() == '0') ? '</span>' : ''; |
||||
|
||||
if (api_is_allowed_to_create_course()) |
||||
$row[] = $this->build_id_column ($item); |
||||
|
||||
$row[] = $this->build_type_column ($item); |
||||
$row[] = $invisibility_span_open . $this->build_name_link ($item) . $invisibility_span_close; |
||||
$row[] = $invisibility_span_open . $data[2] . $invisibility_span_close; |
||||
$row[] = $invisibility_span_open . $data[3] . $invisibility_span_close; |
||||
$row[] = $invisibility_span_open . $data[4] . $invisibility_span_close; |
||||
|
||||
//admins get an edit column |
||||
if (api_is_allowed_to_create_course()) |
||||
$row[] = $this->build_edit_column ($item); |
||||
|
||||
//students get the results column |
||||
else |
||||
$row[] = $data[5]; |
||||
|
||||
$sortable_data[] = $row; |
||||
} |
||||
|
||||
return $sortable_data; |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Other functions |
||||
|
||||
private function build_id_column ($item) |
||||
{ |
||||
switch ($item->get_item_type()) |
||||
{ |
||||
// category |
||||
case 'C' : |
||||
return 'CATE' . $item->get_id(); |
||||
// evaluation |
||||
case 'E' : |
||||
return 'EVAL' . $item->get_id(); |
||||
// link |
||||
case 'L' : |
||||
return 'LINK' . $item->get_id(); |
||||
} |
||||
} |
||||
|
||||
private function build_type_column ($item) |
||||
{ |
||||
return build_type_icon_tag($item->get_icon_name()); |
||||
} |
||||
|
||||
private function build_name_link ($item) |
||||
{ |
||||
switch ($item->get_item_type()) |
||||
{ |
||||
// category |
||||
case 'C' : |
||||
return ' <a href="gradebook.php?selectcat=' . $item->get_id() . '">' |
||||
. $item->get_name() |
||||
. '</a>' |
||||
. ($item->is_course() ? ' [' . $item->get_course_code() . ']' : ''); |
||||
// evaluation |
||||
case 'E' : |
||||
|
||||
// course/platform admin can go to the view_results page |
||||
if (api_is_allowed_to_create_course()) |
||||
return ' ' |
||||
. '<a href="gradebook_view_result.php?selecteval=' . $item->get_id() . '">' |
||||
. $item->get_name() |
||||
. '</a>'; |
||||
// students can go to the statistics page (if custom display enabled) |
||||
elseif (ScoreDisplay :: instance()->is_custom()) |
||||
return ' ' |
||||
. '<a href="gradebook_statistics.php?selecteval=' . $item->get_id() . '">' |
||||
. $item->get_name() |
||||
. '</a>'; |
||||
else |
||||
return $item->get_name(); |
||||
|
||||
// link |
||||
case 'L' : |
||||
$url = $item->get_link(); |
||||
if (isset($url)) |
||||
$text = ' <a href="' . $item->get_link() . '">' |
||||
. $item->get_name() |
||||
. '</a>'; |
||||
else |
||||
$text = $item->get_name(); |
||||
$text .= ' [' . $item->get_type_name() . ']'; |
||||
return $text; |
||||
} |
||||
} |
||||
|
||||
|
||||
private function build_edit_column ($item) |
||||
{ |
||||
switch ($item->get_item_type()) |
||||
{ |
||||
// category |
||||
case 'C' : |
||||
return build_edit_icons_cat($item, $this->currentcat->get_id()); |
||||
// evaluation |
||||
case 'E' : |
||||
return build_edit_icons_eval($item, $this->currentcat->get_id()); |
||||
// link |
||||
case 'L' : |
||||
return build_edit_icons_link($item, $this->currentcat->get_id()); |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
} |
||||
?> |
@ -0,0 +1,7 @@ |
||||
<html> |
||||
<head> |
||||
<meta http-equiv="refresh" content="0; url=../../gradebook.php"> |
||||
</head> |
||||
<body> |
||||
</body> |
||||
</html> |
@ -0,0 +1,129 @@ |
||||
<?php |
||||
include_once ('../../../inc/global.inc.php'); |
||||
include_once ('../be.inc.php'); |
||||
include_once ('../gradebook_functions.inc.php'); |
||||
include_once (api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php'); |
||||
require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php'); |
||||
|
||||
/** |
||||
* Form used to add or edit links |
||||
* @author Stijn Konings |
||||
* @author Bert Steppé |
||||
*/ |
||||
class LinkAddEditForm extends FormValidator |
||||
{ |
||||
|
||||
const TYPE_ADD = 1; |
||||
const TYPE_EDIT = 2; |
||||
|
||||
/** |
||||
* Constructor |
||||
* To add link, define category_object and link_type |
||||
* To edit link, define link_object |
||||
*/ |
||||
function LinkAddEditForm($form_type, $category_object, $link_type, $link_object, $form_name, $action = null) |
||||
{ |
||||
parent :: __construct($form_name, 'post', $action); |
||||
|
||||
// set or create link object |
||||
if (isset ($link_object)) |
||||
$link = $link_object; |
||||
elseif (isset ($link_type) && isset ($category_object)) |
||||
{ |
||||
$link = LinkFactory :: create ($link_type); |
||||
$link->set_course_code($category_object->get_course_code()); |
||||
} |
||||
else |
||||
die ('LinkAddEditForm error: define link_type/category_object or link_object'); |
||||
|
||||
$defaults = array(); |
||||
$this->addElement('hidden', 'zero', 0); |
||||
|
||||
// ELEMENT: name |
||||
if ($form_type == self :: TYPE_ADD || $link->is_allowed_to_change_name()) |
||||
{ |
||||
if ($link->needs_name_and_description()) |
||||
{ |
||||
$this->add_textfield('name', |
||||
get_lang('Name'), |
||||
true, |
||||
array('size'=>'40', |
||||
'maxlength'=>'40')); |
||||
} |
||||
else |
||||
{ |
||||
$select = $this->addElement('select', |
||||
'select_link', |
||||
get_lang('ChooseExercise')); |
||||
foreach ($link->get_not_created_links() as $newlink) |
||||
$select->addoption($newlink[1],$newlink[0]); |
||||
} |
||||
} |
||||
else |
||||
$this->addElement('static', |
||||
'label', |
||||
get_lang('Name'), |
||||
$link->get_name().' ['.$link->get_type_name().']'); |
||||
|
||||
|
||||
// ELEMENT: weight |
||||
$this->add_textfield('weight', get_lang('Weight'),true,array('size'=>'4','maxlength'=>'4')); |
||||
$this->addRule('weight',get_lang('OnlyNumbers'),'numeric'); |
||||
$this->addRule(array ('weight', 'zero'), get_lang('NegativeValue'), 'compare', '>='); |
||||
if ($form_type == self :: TYPE_EDIT) |
||||
$defaults['weight'] = $link->get_weight(); |
||||
|
||||
// ELEMENT: max |
||||
if ($link->needs_max()) |
||||
{ |
||||
if ($form_type == self :: TYPE_EDIT && $link->has_results()) |
||||
$this->add_textfield('max', get_lang('Max'), false, array ('size' => '4','maxlength' => '4', 'disabled' => 'disabled')); |
||||
else |
||||
{ |
||||
$this->add_textfield('max', get_lang('Max'), true, array ('size' => '4','maxlength' => '4')); |
||||
$this->addRule('max', get_lang('OnlyNumbers'), 'numeric'); |
||||
$this->addRule(array ('max', 'zero'), get_lang('NegativeValue'), 'compare', '>='); |
||||
} |
||||
if ($form_type == self :: TYPE_EDIT) |
||||
$defaults['max'] = $link->get_max(); |
||||
} |
||||
|
||||
// ELEMENT: date |
||||
$this->add_datepicker('date',get_lang('Date')); |
||||
$defaults['date'] = ($form_type == self :: TYPE_EDIT ? $link->get_date() : time()); |
||||
|
||||
|
||||
// ELEMENT: description |
||||
if ($link->needs_name_and_description()) |
||||
{ |
||||
$this->addElement('textarea', 'description', get_lang('Description'), array ('rows' => '3','cols' => '34')); |
||||
if ($form_type == self :: TYPE_EDIT) |
||||
$defaults['description'] = $link->get_description(); |
||||
} |
||||
|
||||
// ELEMENT: visible |
||||
$visible = ($form_type == self :: TYPE_EDIT && $link->is_visible()) ? '1' : '0'; |
||||
$this->addElement('checkbox', 'visible',get_lang('Visible'),null,$visible); |
||||
if ($form_type == self :: TYPE_EDIT) |
||||
$defaults['visible'] = $link->is_visible(); |
||||
|
||||
// ELEMENT: add results |
||||
if ($form_type == self :: TYPE_ADD && $link->needs_results()) |
||||
$this->addElement('checkbox', 'addresult', get_lang('AddResult')); |
||||
|
||||
|
||||
// submit button |
||||
if ($form_type == self :: TYPE_ADD) |
||||
$this->addElement('submit', null, get_lang('Add')); |
||||
else |
||||
$this->addElement('submit', null, get_lang('Edit')); |
||||
|
||||
|
||||
// set default values |
||||
$this->setDefaults($defaults); |
||||
|
||||
} |
||||
|
||||
|
||||
} |
||||
?> |
@ -0,0 +1,104 @@ |
||||
<?php |
||||
include_once ('../../../inc/global.inc.php'); |
||||
include_once ('../be.inc.php'); |
||||
include_once ('../gradebook_functions.inc.php'); |
||||
include_once (api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php'); |
||||
require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php'); |
||||
|
||||
/** |
||||
* Forms related to links |
||||
* @author Stijn Konings |
||||
* @author Bert Steppé (made more generic) |
||||
* @package dokeos.gradebook |
||||
*/ |
||||
class LinkForm extends FormValidator |
||||
{ |
||||
|
||||
const TYPE_CREATE = 1; |
||||
const TYPE_MOVE = 2; |
||||
|
||||
private $category_object; |
||||
private $link_object; |
||||
private $extra; |
||||
|
||||
/** |
||||
* Builds a form containing form items based on a given parameter |
||||
* @param int form_type 1=choose link |
||||
* @param obj cat_obj the category object |
||||
* @param string form name |
||||
* @param method |
||||
* @param action |
||||
*/ |
||||
function LinkForm($form_type, $category_object,$link_object, $form_name, $method = 'post', $action = null, $extra = null) |
||||
{ |
||||
parent :: __construct($form_name, $method, $action); |
||||
|
||||
if (isset ($category_object)) |
||||
$this->category_object = $category_object; |
||||
if (isset ($link_object)) |
||||
$this->link_object = $link_object; |
||||
if (isset ($extra)) |
||||
$this->extra = $extra; |
||||
|
||||
if ($form_type == self :: TYPE_CREATE) |
||||
$this->build_create(); |
||||
elseif ($form_type == self :: TYPE_MOVE) |
||||
$this->build_move(); |
||||
|
||||
//$this->setDefaults(); |
||||
} |
||||
|
||||
protected function build_move() |
||||
{ |
||||
$renderer =& $this->defaultRenderer(); |
||||
$renderer->setElementTemplate('<span>{element}</span> '); |
||||
$this->addElement('static',null,null,'"'.$this->link_object->get_name().'" '); |
||||
$this->addElement('static',null,null,get_lang('MoveTo').' : '); |
||||
$select = $this->addElement('select','move_cat',null,null); |
||||
foreach ($this->link_object->get_target_categories() as $cat) |
||||
{ |
||||
for ($i=0;$i<$cat[2];$i++) |
||||
{ |
||||
$line .= '—'; |
||||
} |
||||
$select->addoption($line.' '.$cat[1],$cat[0]); |
||||
$line = ''; |
||||
} |
||||
$this->addElement('submit', null, get_lang('Ok')); |
||||
} |
||||
|
||||
protected function build_create() |
||||
{ |
||||
|
||||
$select = $this->addElement('select', |
||||
'select_link', |
||||
get_lang('ChooseLink'), |
||||
null, |
||||
array('onchange' => 'document.create_link.submit()')); |
||||
|
||||
$linktypes = LinkFactory :: get_all_types(); |
||||
|
||||
$select->addoption('['.get_lang('ChooseLink').']', 0); |
||||
|
||||
foreach ($linktypes as $linktype) |
||||
{ |
||||
$link = LinkFactory :: create ($linktype); |
||||
$link->set_course_code($this->category_object->get_course_code()); |
||||
// disable this element if the link works with a dropdownlist |
||||
// and if there are no links left |
||||
if (!$link->needs_name_and_description() |
||||
&& count($link->get_not_created_links()) == '0') |
||||
$select->addoption($link->get_type_name(), $linktype, 'disabled'); |
||||
else |
||||
$select->addoption($link->get_type_name(), $linktype); |
||||
} |
||||
|
||||
if (isset($this->extra)) |
||||
{ |
||||
$this->setDefaults(array('select_link' => $this->extra)); |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
?> |
@ -0,0 +1,127 @@ |
||||
<?php |
||||
include_once ('../../../inc/global.inc.php'); |
||||
include_once ('../gradebook_functions.inc.php'); |
||||
include_once (api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php'); |
||||
require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php'); |
||||
/** |
||||
* Form for the score display dialog |
||||
* @author Stijn Konings |
||||
* @author Bert Steppé |
||||
* @package dokeos.gradebook |
||||
*/ |
||||
class ScoreDisplayForm extends FormValidator |
||||
{ |
||||
function ScoreDisplayForm($form_name, $action= null) |
||||
{ |
||||
parent :: __construct($form_name, 'post', $action); |
||||
$displayscore= ScoreDisplay :: instance(); |
||||
$customdisplays= $displayscore->get_custom_score_display_settings(); |
||||
$nr_items =(count($customdisplays)!='0')?count($customdisplays):'1'; |
||||
$this->setDefaults(array ( |
||||
'enablescorecolor' => $displayscore->is_coloring_enabled(), |
||||
'scorecolpercent' => $displayscore->get_color_split_value(), |
||||
'enablescore' => $displayscore->is_custom(), |
||||
'includeupperlimit' => $displayscore->is_upperlimit_included() |
||||
)); |
||||
$this->addElement('hidden', 'maxvalue', '100'); |
||||
$this->addElement('hidden', 'minvalue', '0'); |
||||
$counter= 1; |
||||
|
||||
//setting the default values |
||||
|
||||
foreach ($customdisplays as $customdisplay) |
||||
{ |
||||
$this->setDefaults(array ( |
||||
'endscore[' . $counter . ']' => $customdisplay['score'], |
||||
'displaytext[' . $counter . ']' => $customdisplay['display'] |
||||
)); |
||||
$counter++; |
||||
} |
||||
$scorecol= array (); |
||||
|
||||
//settings for the colored score |
||||
|
||||
$this->addElement('header', 'h1', '<b>' . get_lang('ScoreColor') . '</b>'); |
||||
$renderer = $this->defaultRenderer(); |
||||
$elementTemplateColor = '<div class="row"> |
||||
<div class="label"> |
||||
<!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label} |
||||
</div> |
||||
<div class="formw"> |
||||
<!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error --> '.get_lang('Below').'      {element} % '.get_lang('WillColorRed').' |
||||
</div> |
||||
</div>'; |
||||
|
||||
$this->AddElement('checkbox', 'enablescorecolor', null, get_lang('EnableScoreColor'), null); |
||||
$this->AddElement('text', 'scorecolpercent', null, array ( |
||||
'size' => 5, |
||||
'maxlength' => 5 |
||||
)); |
||||
$renderer->setElementTemplate($elementTemplateColor,'scorecolpercent'); |
||||
$this->addRule('scorecolpercent', get_lang('OnlyNumbers'), 'numeric'); |
||||
$this->addRule(array('scorecolpercent','maxvalue'), get_lang('Over100'), 'compare', '<='); |
||||
$this->addRule(array('scorecolpercent','minvalue'), get_lang('UnderMin'), 'compare', '>'); |
||||
|
||||
//settings for the scoring system |
||||
|
||||
$this->addElement('header', 'h2', '<b>' . get_lang('ScoringSystem') . '</b>'); |
||||
$this->addElement('checkbox', 'enablescore', null, get_lang('EnableScoringSystem'), null); |
||||
|
||||
if ($displayscore->is_custom()) |
||||
{ |
||||
$this->addElement('checkbox', 'includeupperlimit', null, get_lang('IncludeUpperLimit'), null); |
||||
$this->addElement('static', null, null, '<small>' . get_lang('ScoreInfo') . '</small>'); |
||||
$scorenull[]= & $this->CreateElement('static', null, null, get_lang('Between')); |
||||
$this->setDefaults(array ( |
||||
'beginscore' => '0' |
||||
)); |
||||
$scorenull[]= & $this->CreateElement('text', 'beginscore', null, array ( |
||||
'size' => 5, |
||||
'maxlength' => 5, |
||||
'disabled' => 'disabled' |
||||
)); |
||||
$scorenull[]= & $this->CreateElement('static', null, null, ' %'); |
||||
$this->addGroup($scorenull, '', '', ' '); |
||||
for ($counter= 1; $counter <= 20; $counter++) |
||||
{ |
||||
|
||||
$renderer =& $this->defaultRenderer(); |
||||
$elementTemplateTwoLabel = |
||||
'<div id=' . $counter . ' style="display: '.(($counter<=$nr_items)?'inline':'none').';" class="row"> |
||||
<p><!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label} |
||||
<div class="formw"><!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error --> <b>'.get_lang('And').'</b>          {element} % ='; |
||||
|
||||
$elementTemplateTwoLabel2 = |
||||
'<!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error --> {element} |
||||
<a href="javascript:minItem(' . ($counter) . ')"><img style="display: '.(($counter>=$nr_items && $counter!=1)?'inline':'none').';" id="min-' . $counter . '" src="../img/gradebook_remove.gif"></img></a> |
||||
<a href="javascript:plusItem(' . ($counter+1) . ')"><img style="display: '.(($counter>=$nr_items)?'inline':'none').';" id="plus-' . ($counter+1) . '" src=../img/gradebook_add.gif></img></a> |
||||
</div></p></div>'; |
||||
|
||||
$scorebetw= array (); |
||||
$this->AddElement('text', 'endscore[' . $counter . ']', null, array ( |
||||
'size' => 5, |
||||
'maxlength' => 5, |
||||
'id' => 'txta-'.$counter |
||||
)); |
||||
$this->AddElement('text', 'displaytext[' . $counter . ']', null,array ( |
||||
'size' => 40, |
||||
'maxlength' => 40, |
||||
'id' => 'txtb-'.$counter |
||||
)); |
||||
$renderer->setElementTemplate($elementTemplateTwoLabel,'endscore[' . $counter . ']'); |
||||
$renderer->setElementTemplate($elementTemplateTwoLabel2,'displaytext[' . $counter . ']'); |
||||
$this->addRule('endscore[' . $counter . ']', get_lang('OnlyNumbers'), 'numeric'); |
||||
$this->addRule(array ('endscore[' . $counter . ']', 'maxvalue'), get_lang('Over100'), 'compare', '<='); |
||||
$this->addRule(array ('endscore[' . $counter . ']', 'minvalue'), get_lang('UnderMin'), 'compare', '>'); |
||||
} |
||||
} |
||||
$this->setDefaults(array ( |
||||
'enablescore' => $displayscore->is_custom(), 'includeupperlimit' => $displayscore->is_upperlimit_included())); |
||||
$this->addElement('submit', 'submit', get_lang('Ok')); |
||||
} |
||||
function validate() |
||||
{ |
||||
return parent :: validate(); |
||||
} |
||||
} |
||||
?> |
@ -0,0 +1,80 @@ |
||||
<?php |
||||
include_once ('../../../inc/global.inc.php'); |
||||
include_once ('../be.inc.php'); |
||||
include_once ('../gradebook_functions.inc.php'); |
||||
include_once (api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php'); |
||||
require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php'); |
||||
/** |
||||
* Extends formvalidator with import and export forms |
||||
* @author Stijn Konings |
||||
* @package dokeos.gradebook |
||||
*/ |
||||
class UserForm extends FormValidator |
||||
{ |
||||
const TYPE_USER_INFO= 1; |
||||
const TYPE_SIMPLE_SEARCH = 3; |
||||
/** |
||||
* Builds a form containing form items based on a given parameter |
||||
* @param int form_type 1 = user_info |
||||
* @param user array |
||||
* @param string form name |
||||
* @param method |
||||
* @param action |
||||
*/ |
||||
function UserForm($form_type, $user, $form_name, $method= 'post', $action= null) |
||||
{ |
||||
parent :: __construct($form_name, $method, $action); |
||||
$this->form_type= $form_type; |
||||
if (isset ($user)) |
||||
{ |
||||
$this->user_info= $user; |
||||
} |
||||
if (isset ($result_object)) |
||||
{ |
||||
$this->result_object= $result_object; |
||||
} |
||||
if ($this->form_type == self :: TYPE_USER_INFO) |
||||
{ |
||||
$this->build_user_info_form(); |
||||
} |
||||
elseif ($this->form_type == self :: TYPE_SIMPLE_SEARCH) |
||||
{ |
||||
$this->build_simple_search(); |
||||
} |
||||
$this->setDefaults(); |
||||
} |
||||
|
||||
protected function build_simple_search() |
||||
{ |
||||
if (isset($_GET['search']) && (!empty($_GET['search']))) |
||||
{ |
||||
$this->setDefaults(array( |
||||
'keyword' => $_GET['search'] |
||||
)); |
||||
} |
||||
$renderer =& $this->defaultRenderer(); |
||||
$renderer->setElementTemplate('<span>{element}</span> '); |
||||
$this->addElement('text','keyword',''); |
||||
$this->addElement('submit','submit',get_lang('Search')); |
||||
} |
||||
|
||||
protected function build_user_info_form() |
||||
{ |
||||
$this->addElement('static', 'fname', get_lang('FirstName'), $this->user_info['firstname']); |
||||
$this->addElement('static', 'lname', get_lang('LastName'), $this->user_info['lastname']); |
||||
$this->addElement('static', 'uname', get_lang('UserName'), $this->user_info['username']); |
||||
$this->addElement('static', 'email', get_lang('Email'), '<a href="mailto:' . $this->user_info['email'] . '">' . $this->user_info['email'] . '</a>'); |
||||
$this->addElement('static', 'ofcode', get_lang('OfficialCode'), $this->user_info['official_code']); |
||||
$this->addElement('static', 'phone', get_lang('Phone'), $this->user_info['phone']); |
||||
$this->addElement('submit', null, get_lang('Back')); |
||||
} |
||||
function display() |
||||
{ |
||||
parent :: display(); |
||||
} |
||||
function setDefaults($defaults= array ()) |
||||
{ |
||||
parent :: setDefaults($defaults); |
||||
} |
||||
} |
||||
?> |
@ -0,0 +1,151 @@ |
||||
<?php |
||||
|
||||
include_once ('../../../inc/global.inc.php'); |
||||
include_once ('../be.inc.php'); |
||||
|
||||
/** |
||||
* Table to display flat view of a student's evaluations and links |
||||
* @author Stijn Konings |
||||
* @author Bert Steppé (refactored, optimised, use of caching, datagenerator class) |
||||
*/ |
||||
class UserTable extends SortableTable |
||||
{ |
||||
|
||||
private $userid; |
||||
private $datagen; |
||||
|
||||
|
||||
/** |
||||
* Constructor |
||||
*/ |
||||
function UserTable ($userid, $evals = array(), $links = array(), $addparams = null) |
||||
{ |
||||
parent :: SortableTable ('userlist', null, null, 0); |
||||
|
||||
$this->userid = $userid; |
||||
|
||||
$this->datagen = new UserDataGenerator($userid, $evals, $links); |
||||
|
||||
if (isset($addparams)) |
||||
$this->set_additional_parameters($addparams); |
||||
|
||||
$column = 0; |
||||
$this->set_header($column++, get_lang('Type')); |
||||
$this->set_header($column++, get_lang('Evaluation')); |
||||
$this->set_header($column++, get_lang('Course')); |
||||
$this->set_header($column++, get_lang('Category')); |
||||
$this->set_header($column++, get_lang('EvaluationAverage')); |
||||
$this->set_header($column++, get_lang('Result')); |
||||
|
||||
$scoredisplay = ScoreDisplay :: instance(); |
||||
if ($scoredisplay->is_custom()) |
||||
$this->set_header($column++, get_lang('Display')); |
||||
|
||||
} |
||||
|
||||
|
||||
/** |
||||
* Function used by SortableTable to get total number of items in the table |
||||
*/ |
||||
function get_total_number_of_items() |
||||
{ |
||||
return $this->datagen->get_total_items_count(); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Function used by SortableTable to generate the data to display |
||||
*/ |
||||
function get_table_data($from = 1) |
||||
{ |
||||
|
||||
$scoredisplay = ScoreDisplay :: instance(); |
||||
|
||||
// determine sorting type |
||||
switch ($this->column) |
||||
{ |
||||
// Type |
||||
case 0: |
||||
$sorting = UserDataGenerator :: UDG_SORT_TYPE; |
||||
break; |
||||
case 1: |
||||
$sorting = UserDataGenerator :: UDG_SORT_NAME; |
||||
break; |
||||
case 2: |
||||
$sorting = UserDataGenerator :: UDG_SORT_COURSE; |
||||
break; |
||||
case 3: |
||||
$sorting = UserDataGenerator :: UDG_SORT_CATEGORY; |
||||
break; |
||||
case 4: |
||||
$sorting = UserDataGenerator :: UDG_SORT_AVERAGE; |
||||
break; |
||||
case 5: |
||||
$sorting = UserDataGenerator :: UDG_SORT_SCORE; |
||||
break; |
||||
case 6: |
||||
$sorting = UserDataGenerator :: UDG_SORT_MASK; |
||||
break; |
||||
} |
||||
if ($this->direction == 'DESC') |
||||
$sorting |= UserDataGenerator :: UDG_SORT_DESC; |
||||
else |
||||
$sorting |= UserDataGenerator :: UDG_SORT_ASC; |
||||
|
||||
|
||||
$data_array = $this->datagen->get_data($sorting, $from, $this->per_page); |
||||
|
||||
|
||||
// generate the data to display |
||||
$sortable_data = array(); |
||||
foreach ($data_array as $data) |
||||
{ |
||||
$row = array (); |
||||
$row[] = $this->build_type_column ($data[0]); |
||||
$row[] = $this->build_name_link ($data[0]); |
||||
$row[] = $data[2]; |
||||
$row[] = $data[3]; |
||||
$row[] = $data[4]; |
||||
$row[] = $data[5]; |
||||
if ($scoredisplay->is_custom()) |
||||
$row[] = $data[6]; |
||||
$sortable_data[] = $row; |
||||
} |
||||
|
||||
return $sortable_data; |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Other functions |
||||
|
||||
private function build_type_column ($item) |
||||
{ |
||||
return build_type_icon_tag($item->get_icon_name()); |
||||
} |
||||
|
||||
private function build_name_link ($item) |
||||
{ |
||||
switch ($item->get_item_type()) |
||||
{ |
||||
// evaluation |
||||
case 'E' : |
||||
return ' ' |
||||
. '<a href="gradebook_view_result.php?selecteval=' . $item->get_id() . '">' |
||||
. $item->get_name() |
||||
. '</a>'; |
||||
// link |
||||
case 'L' : |
||||
return ' <a href="' . $item->get_link() . '">' |
||||
. $item->get_name() |
||||
. '</a>' |
||||
. ' [' . $item->get_type_name() . ']'; |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
} |
||||
?> |
@ -0,0 +1,171 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Class to select, sort and transform object data into array data, |
||||
* used for the teacher's flat view |
||||
* @author Bert Steppé |
||||
*/ |
||||
class FlatViewDataGenerator |
||||
{ |
||||
|
||||
// Sorting types constants |
||||
const FVDG_SORT_LASTNAME = 1; |
||||
const FVDG_SORT_FIRSTNAME = 2; |
||||
const FVDG_SORT_ASC = 4; |
||||
const FVDG_SORT_DESC = 8; |
||||
|
||||
private $users; |
||||
private $evals; |
||||
private $links; |
||||
private $evals_links; |
||||
|
||||
/** |
||||
* Constructor |
||||
*/ |
||||
public function FlatViewDataGenerator ($users= array (), $evals= array (), $links= array ()) |
||||
{ |
||||
$this->users = (isset($users) ? $users : array()); |
||||
$this->evals = (isset($evals) ? $evals : array()); |
||||
$this->links = (isset($links) ? $links : array()); |
||||
$this->evals_links = array_merge($this->evals, $this->links); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Get total number of users (rows) |
||||
*/ |
||||
public function get_total_users_count() |
||||
{ |
||||
return count($this->users); |
||||
} |
||||
|
||||
/** |
||||
* Get total number of evaluations/links (columns) (the 2 users columns not included) |
||||
*/ |
||||
public function get_total_items_count() |
||||
{ |
||||
return count($this->evals_links); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Get array containing column header names (incl user columns) |
||||
*/ |
||||
public function get_header_names ($items_start = 0, $items_count = null) |
||||
{ |
||||
$headers = array(); |
||||
$headers[] = get_lang('LastName'); |
||||
$headers[] = get_lang('FirstName'); |
||||
|
||||
if (!isset($items_count)) |
||||
$items_count = count($this->evals_links) - $items_start; |
||||
|
||||
for ($count=0; |
||||
($count < $items_count ) && ($items_start + $count < count($this->evals_links)); |
||||
$count++) |
||||
{ |
||||
$item = $this->evals_links [$count + $items_start]; |
||||
$headers[] = $item->get_name(); |
||||
} |
||||
|
||||
return $headers; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Get actual array data |
||||
* @return array 2-dimensional array - each array contains the elements: |
||||
* 0: user id |
||||
* 1: user lastname |
||||
* 2: user firstname |
||||
* 3+: evaluation/link scores |
||||
*/ |
||||
public function get_data ($users_sorting = 0, |
||||
$users_start = 0, $users_count = null, |
||||
$items_start = 0, $items_count = null, |
||||
$ignore_score_color = false) |
||||
{ |
||||
|
||||
// do some checks on users/items counts, redefine if invalid values |
||||
if (!isset($users_count)) |
||||
$users_count = count ($this->users) - $users_start; |
||||
if ($users_count < 0) |
||||
$users_count = 0; |
||||
if (!isset($items_count)) |
||||
$items_count = count ($this->evals) + count ($this->links) - $items_start; |
||||
if ($items_count < 0) |
||||
$items_count = 0; |
||||
|
||||
// copy users to a new array that we will sort |
||||
// TODO - needed ? |
||||
$usertable = array (); |
||||
foreach ($this->users as $user) |
||||
$usertable[] = $user; |
||||
|
||||
// sort users array |
||||
if ($users_sorting & self :: FVDG_SORT_LASTNAME) |
||||
usort($usertable, array ('FlatViewDataGenerator','sort_by_last_name')); |
||||
elseif ($users_sorting & self :: FVDG_SORT_FIRSTNAME) |
||||
usort($usertable, array ('FlatViewDataGenerator','sort_by_first_name')); |
||||
if ($users_sorting & self :: FVDG_SORT_DESC) |
||||
$usertable = array_reverse($usertable); |
||||
|
||||
// select the requested users |
||||
$selected_users = array_slice($usertable, $users_start, $users_count); |
||||
|
||||
|
||||
// generate actual data array |
||||
|
||||
$scoredisplay = ScoreDisplay :: instance(); |
||||
|
||||
$data= array (); |
||||
$displaytype = SCORE_DIV; |
||||
if ($ignore_score_color) |
||||
$displaytype |= SCORE_IGNORE_SPLIT; |
||||
|
||||
foreach ($selected_users as $user) |
||||
{ |
||||
$row = array (); |
||||
$row[] = $user[0]; // user id |
||||
$row[] = $user[1]; // last name |
||||
$row[] = $user[2]; // first name |
||||
|
||||
for ($count=0; |
||||
($count < $items_count ) && ($items_start + $count < count($this->evals_links)); |
||||
$count++) |
||||
{ |
||||
$item = $this->evals_links [$count + $items_start]; |
||||
$score = $item->calc_score($user[0]); |
||||
$row[] = $scoredisplay->display_score($score,$displaytype); |
||||
} |
||||
unset($score); |
||||
$data[] = $row; |
||||
} |
||||
|
||||
return $data; |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
// Sort functions - used internally |
||||
|
||||
function sort_by_last_name($item1, $item2) |
||||
{ |
||||
if (strtolower($item1[1]) == strtolower($item2[1])) |
||||
return 0; |
||||
else |
||||
return (strtolower($item1[1]) < strtolower($item2[1]) ? -1 : 1); |
||||
} |
||||
|
||||
function sort_by_first_name($item1, $item2) |
||||
{ |
||||
if (strtolower($item1[2]) == strtolower($item2[2])) |
||||
return $this->sort_by_last_name($item1, $item2); |
||||
else |
||||
return (strtolower($item1[2]) < strtolower($item2[2]) ? -1 : 1); |
||||
} |
||||
|
||||
} |
||||
?> |
@ -0,0 +1,201 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Class to select, sort and transform object data into array data, |
||||
* used for the general gradebook view |
||||
* @author Bert Steppé |
||||
*/ |
||||
class GradebookDataGenerator |
||||
{ |
||||
|
||||
// Sorting types constants |
||||
const GDG_SORT_TYPE = 1; |
||||
const GDG_SORT_NAME = 2; |
||||
const GDG_SORT_DESCRIPTION = 4; |
||||
const GDG_SORT_WEIGHT = 8; |
||||
const GDG_SORT_DATE = 16; |
||||
|
||||
const GDG_SORT_ASC = 32; |
||||
const GDG_SORT_DESC = 64; |
||||
|
||||
|
||||
private $items; |
||||
|
||||
|
||||
function GradebookDataGenerator($cats = array(), $evals = array(), $links = array()) |
||||
{ |
||||
$allcats = (isset($cats) ? $cats : array()); |
||||
$allevals = (isset($evals) ? $evals : array()); |
||||
$alllinks = (isset($links) ? $links : array()); |
||||
|
||||
// merge categories, evaluations and links |
||||
$this->items = array_merge($allcats, $allevals, $alllinks); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Get total number of items (rows) |
||||
*/ |
||||
public function get_total_items_count() |
||||
{ |
||||
return count($this->items); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
/** |
||||
* Get actual array data |
||||
* @return array 2-dimensional array - each array contains the elements: |
||||
* 0: cat/eval/link object |
||||
* 1: item name |
||||
* 2: description |
||||
* 3: weight |
||||
* 4: date |
||||
* 5: student's score (if student logged in) |
||||
*/ |
||||
public function get_data ($sorting = 0, $start = 0, $count = null, $ignore_score_color = false) |
||||
{ |
||||
|
||||
// do some checks on count, redefine if invalid value |
||||
if (!isset($count)) |
||||
$count = count ($this->items) - $start; |
||||
if ($count < 0) |
||||
$count = 0; |
||||
|
||||
$allitems = $this->items; |
||||
|
||||
// sort array |
||||
if ($sorting & self :: GDG_SORT_TYPE) |
||||
usort($allitems, array('GradebookDataGenerator', 'sort_by_type')); |
||||
elseif ($sorting & self :: GDG_SORT_NAME) |
||||
usort($allitems, array('GradebookDataGenerator', 'sort_by_name')); |
||||
elseif ($sorting & self :: GDG_SORT_DESCRIPTION) |
||||
usort($allitems, array('GradebookDataGenerator', 'sort_by_description')); |
||||
elseif ($sorting & self :: GDG_SORT_WEIGHT) |
||||
usort($allitems, array('GradebookDataGenerator', 'sort_by_weight')); |
||||
elseif ($sorting & self :: GDG_SORT_DATE) |
||||
usort($allitems, array('GradebookDataGenerator', 'sort_by_date')); |
||||
|
||||
if ($sorting & self :: GDG_SORT_DESC) |
||||
$allitems = array_reverse($allitems); |
||||
|
||||
|
||||
// get selected items |
||||
$visibleitems = array_slice($allitems, $start, $count); |
||||
|
||||
|
||||
// generate the data to display |
||||
$data = array(); |
||||
foreach ($visibleitems as $item) |
||||
{ |
||||
$row = array (); |
||||
$row[] = $item; |
||||
$row[] = $item->get_name(); |
||||
$row[] = $item->get_description(); |
||||
$row[] = $item->get_weight(); |
||||
$row[] = $this->build_date_column ($item); |
||||
if (!api_is_allowed_to_create_course()) |
||||
$row[] = $this->build_result_column ($item, $ignore_score_color); |
||||
$data[] = $row; |
||||
} |
||||
|
||||
return $data; |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Sort functions |
||||
// Make sure to only use functions as defined in the GradebookItem interface ! |
||||
|
||||
function sort_by_name($item1, $item2) |
||||
{ |
||||
if (strtolower($item1->get_name()) == strtolower($item2->get_name())) |
||||
return 0; |
||||
else |
||||
return (strtolower($item1->get_name()) < strtolower($item2->get_name()) ? -1 : 1); |
||||
} |
||||
|
||||
function sort_by_type($item1, $item2) |
||||
{ |
||||
if ($item1->get_item_type() == $item2->get_item_type()) |
||||
return $this->sort_by_name($item1,$item2); |
||||
else |
||||
return ($item1->get_item_type() < $item2->get_item_type() ? -1 : 1); |
||||
} |
||||
|
||||
function sort_by_description($item1, $item2) |
||||
{ |
||||
if (strtolower($item1->get_description()) == strtolower($item2->get_description())) |
||||
return $this->sort_by_name($item1,$item2); |
||||
else |
||||
return (strtolower($item1->get_description()) < strtolower($item2->get_description()) ? -1 : 1); |
||||
} |
||||
|
||||
function sort_by_weight($item1, $item2) |
||||
{ |
||||
if ($item1->get_weight() == $item2->get_weight()) |
||||
return $this->sort_by_name($item1,$item2); |
||||
else |
||||
return ($item1->get_weight() < $item2->get_weight() ? -1 : 1); |
||||
} |
||||
|
||||
function sort_by_date($item1, $item2) |
||||
{ |
||||
if ($item1->get_date() == $item2->get_date()) |
||||
return $this->sort_by_name($item1,$item2); |
||||
else |
||||
return ($item1->get_date() < $item2->get_date() ? -1 : 1); |
||||
} |
||||
|
||||
|
||||
// Other functions |
||||
|
||||
|
||||
private function build_result_column ($item, $ignore_score_color) |
||||
{ |
||||
$scoredisplay = ScoreDisplay :: instance(); |
||||
$score = $item->calc_score(api_get_user_id()); |
||||
|
||||
switch ($item->get_item_type()) |
||||
{ |
||||
// category |
||||
case 'C' : |
||||
if ($score != null) |
||||
{ |
||||
$displaytype = SCORE_PERCENT; |
||||
if ($ignore_score_color) |
||||
$displaytype |= SCORE_IGNORE_SPLIT; |
||||
return get_lang('Total') . ' : ' |
||||
. $scoredisplay->display_score($score,$displaytype); |
||||
} |
||||
else |
||||
return ''; |
||||
|
||||
// evaluation and link |
||||
case 'E' : |
||||
case 'L' : |
||||
$displaytype = SCORE_DIV_PERCENT; |
||||
if ($ignore_score_color) |
||||
$displaytype |= SCORE_IGNORE_SPLIT; |
||||
return $scoredisplay->display_score($score,$displaytype); |
||||
} |
||||
} |
||||
|
||||
private function build_date_column ($item) |
||||
{ |
||||
$date = $item->get_date(); |
||||
if (!isset($date) || empty($date)) |
||||
return ''; |
||||
else |
||||
return date("j/n/Y g:i", $date); |
||||
} |
||||
|
||||
|
||||
} |
||||
?> |
@ -0,0 +1,121 @@ |
||||
<?php |
||||
/* |
||||
* These are functions used in gradebook |
||||
* |
||||
* @author Stijn Konings <konings.stijn@skynet.be>, Hogeschool Ghent |
||||
* @version april 2007 |
||||
*/ |
||||
include_once ('gradebook_functions_users.inc.php'); |
||||
|
||||
|
||||
function block_students() |
||||
{ |
||||
if (!api_is_allowed_to_create_course()) |
||||
{ |
||||
include (api_get_path(INCLUDE_PATH)."header.inc.php"); |
||||
api_not_allowed(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Returns the info header for the user result page |
||||
* @param $userid |
||||
*/ |
||||
|
||||
/** |
||||
* Returns the course name from a given code |
||||
* @param string $code |
||||
*/ |
||||
function get_course_name_from_code($code) |
||||
{ |
||||
$tbl_main_categories= Database :: get_main_table(TABLE_MAIN_COURSE); |
||||
$sql= 'SELECT title,code FROM ' . $tbl_main_categories . 'WHERE code = "' . $code . '"'; |
||||
$result= mysql_query($sql); |
||||
if ($col= mysql_fetch_array($result)) |
||||
{ |
||||
return $col[title]; |
||||
} |
||||
} |
||||
/** |
||||
* Builds an img tag for a gradebook item |
||||
* @param string $type value returned by a gradebookitem's get_icon_name() |
||||
*/ |
||||
function build_type_icon_tag($kind) |
||||
{ |
||||
return '<img src="' . get_icon_file_name ($kind) . '" border="0" hspace="5" align="middle" alt="" />'; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Returns the icon filename for a gradebook item |
||||
* @param string $type value returned by a gradebookitem's get_icon_name() |
||||
*/ |
||||
function get_icon_file_name ($type) |
||||
{ |
||||
if ($type == 'cat') |
||||
return api_get_path(WEB_CODE_PATH) . 'img/folder_document.gif'; |
||||
elseif ($type == 'evalempty') |
||||
return api_get_path(WEB_CODE_PATH) . 'img/empty.gif'; |
||||
elseif ($type == 'evalnotempty') |
||||
return api_get_path(WEB_CODE_PATH) . 'img/gradebook_eval_not_empty.gif'; |
||||
elseif ($type == 'link') |
||||
return api_get_path(WEB_CODE_PATH) . 'img/link_blank.gif'; |
||||
else |
||||
return null; |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* Builds the course or platform admin icons to edit a category |
||||
* @param object $cat category object |
||||
* @param int $selectcat id of selected category |
||||
*/ |
||||
function build_edit_icons_cat($cat, $selectcat) |
||||
{ |
||||
$visibility_icon= ($cat->is_visible() == 0) ? 'invisible' : 'visible'; |
||||
$visibility_command= ($cat->is_visible() == 0) ? 'set_visible' : 'set_invisible'; |
||||
$modify_icons= '<a href="gradebook_edit_cat.php?editcat=' . $cat->get_id() . '"><img src="../img/edit.gif" border="0" title="' . get_lang('Modify') . '" alt="" /></a>'; |
||||
$modify_icons .= ' <a href="' . api_get_self() . '?deletecat=' . $cat->get_id() . '&selectcat=' . $selectcat . '" onclick="return confirmation();"><img src="../img/delete.gif" border="0" title="' . get_lang('DeleteAll') . '" alt="" /></a>'; |
||||
//no move ability for root categories |
||||
if ($cat->is_movable()) |
||||
{ |
||||
$modify_icons .= ' <a href="' . api_get_self() . '?movecat=' . $cat->get_id() . '&selectcat=' . $selectcat . '"><img src="../img/deplacer_fichier.gif" border="0" title="' . get_lang('Move') . '" alt="" /></a>'; |
||||
} else |
||||
{ |
||||
$modify_icons .= ' <img src="../img/deplacer_fichier_gray.gif" border="0" title="' . get_lang('Move') . '" alt="" />'; |
||||
} |
||||
$modify_icons .= ' <a href="' . api_get_self() . '?visiblecat=' . $cat->get_id() . '&' . $visibility_command . '=&selectcat=' . $selectcat . '"><img src="../img/' . $visibility_icon . '.gif" border="0" title="' . get_lang('Visible') . '" alt="" /></a>'; |
||||
return $modify_icons; |
||||
} |
||||
/** |
||||
* Builds the course or platform admin icons to edit an evaluation |
||||
* @param object $eval evaluation object |
||||
* @param int $selectcat id of selected category |
||||
*/ |
||||
function build_edit_icons_eval($eval, $selectcat) |
||||
{ |
||||
$visibility_icon= ($eval->is_visible() == 0) ? 'invisible' : 'visible'; |
||||
$visibility_command= ($eval->is_visible() == 0) ? 'set_visible' : 'set_invisible'; |
||||
$modify_icons= '<a href="gradebook_edit_eval.php?editeval=' . $eval->get_id() . '"><img src="../img/edit.gif" border="0" title="' . get_lang('Modify') . '" alt="" /></a>'; |
||||
$modify_icons .= ' <a href="' . api_get_self() . '?deleteeval=' . $eval->get_id() . '&selectcat=' . $selectcat . '" onclick="return confirmation();"><img src="../img/delete.gif" border="0" title="' . get_lang('Delete') . '" alt="" /></a>'; |
||||
$modify_icons .= ' <a href="' . api_get_self() . '?moveeval=' . $eval->get_id() . '&selectcat=' . $selectcat . '"><img src="../img/deplacer_fichier.gif" border="0" title="' . get_lang('Move') . '" alt="" /></a>'; |
||||
$modify_icons .= ' <a href="' . api_get_self() . '?visibleeval=' . $eval->get_id() . '&' . $visibility_command . '=&selectcat=' . $selectcat . '"><img src="../img/' . $visibility_icon . '.gif" border="0" title="' . get_lang('Visible') . '" alt="" /></a>'; |
||||
return $modify_icons; |
||||
} |
||||
/** |
||||
* Builds the course or platform admin icons to edit a link |
||||
* @param object $linkobject |
||||
* @param int $selectcat id of selected category |
||||
*/ |
||||
function build_edit_icons_link($link, $selectcat) |
||||
{ |
||||
$visibility_icon= ($link->is_visible() == 0) ? 'invisible' : 'visible'; |
||||
$visibility_command= ($link->is_visible() == 0) ? 'set_visible' : 'set_invisible'; |
||||
$modify_icons= '<a href="gradebook_edit_link.php?editlink=' . $link->get_id() . '"><img src="../img/edit.gif" border="0" title="' . get_lang('Modify') . '" alt="" /></a>'; |
||||
$modify_icons .= ' <a href="' . api_get_self() . '?deletelink=' . $link->get_id() . '&selectcat=' . $selectcat . '" onclick="return confirmation();"><img src="../img/delete.gif" border="0" title="' . get_lang('Delete') . '" alt="" /></a>'; |
||||
$modify_icons .= ' <a href="' . api_get_self() . '?movelink=' . $link->get_id() . '&selectcat=' . $selectcat . '"><img src="../img/deplacer_fichier.gif" border="0" title="' . get_lang('Move') . '" alt="" /></a>'; |
||||
$modify_icons .= ' <a href="' . api_get_self() . '?visiblelink=' . $link->get_id() . '&' . $visibility_command . '=&selectcat=' . $selectcat . '"><img src="../img/' . $visibility_icon . '.gif" border="0" title="' . get_lang('Visible') . '" alt="" /></a>'; |
||||
return $modify_icons; |
||||
} |
||||
?> |
@ -0,0 +1,141 @@ |
||||
<?php |
||||
|
||||
/* |
||||
* Various user related functions |
||||
*/ |
||||
|
||||
|
||||
/** |
||||
* returns users within a course given by param |
||||
* @param $course_id |
||||
*/ |
||||
function get_users_in_course($course_id) |
||||
{ |
||||
$tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); |
||||
$tbl_user = Database :: get_main_table(TABLE_MAIN_USER); |
||||
|
||||
$sql = 'SELECT user.user_id,lastname,firstname' |
||||
.' FROM '.$tbl_course_user.' as course_rel_user, '.$tbl_user.' as user' |
||||
.' WHERE course_rel_user.user_id=user.user_id' |
||||
.' AND course_rel_user.status='.STUDENT |
||||
." AND course_rel_user.course_code='".$course_id."'" |
||||
.' ORDER BY lastname ASC'; |
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
return get_user_array_from_mysql_result($result); |
||||
} |
||||
|
||||
|
||||
function get_user_array_from_mysql_result($result) |
||||
{ |
||||
$a_students = array(); |
||||
while ($user = mysql_fetch_array($result)) |
||||
{ |
||||
if (!array_key_exists($user['user_id'],$a_students)) |
||||
{ |
||||
$a_current_student = array (); |
||||
$a_current_student[] = $user['user_id']; |
||||
$a_current_student[] = $user['lastname']; |
||||
$a_current_student[] = $user['firstname']; |
||||
$a_students['STUD'.$user['user_id']] = $a_current_student; |
||||
} |
||||
} |
||||
//var_dump($a_students); |
||||
return $a_students; |
||||
} |
||||
|
||||
function get_all_users ($evals = array(), $links = array()) |
||||
{ |
||||
$coursecodes = array(); |
||||
$users = array(); |
||||
|
||||
foreach ($evals as $eval) |
||||
{ |
||||
$coursecode = $eval->get_course_code(); |
||||
// evaluation in course |
||||
if (isset($coursecode) && !empty($coursecode)) |
||||
{ |
||||
if (!array_key_exists($coursecode,$coursecodes)) |
||||
{ |
||||
$coursecodes[$coursecode] = '1'; |
||||
$users = array_merge($users, get_users_in_course($coursecode)); |
||||
} |
||||
} |
||||
// course independent evaluation |
||||
else |
||||
{ |
||||
$tbl_user = Database :: get_main_table(TABLE_MAIN_USER); |
||||
$tbl_res = Database :: get_gradebook_table(TABLE_GRADEBOOK_RESULT); |
||||
|
||||
$sql = 'SELECT user.user_id,lastname,firstname' |
||||
.' FROM '.$tbl_res.' as res, '.$tbl_user.' as user' |
||||
.' WHERE res.evaluation_id = '.$eval->get_id() |
||||
.' AND res.user_id = user.user_id'; |
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
$users = array_merge($users,get_user_array_from_mysql_result($result)); |
||||
} |
||||
} |
||||
|
||||
foreach ($links as $link) |
||||
{ |
||||
// links are always in a course |
||||
$coursecode = $link->get_course_code(); |
||||
if (!array_key_exists($coursecode,$coursecodes)) |
||||
{ |
||||
$coursecodes[$coursecode] = '1'; |
||||
$users = array_merge($users, get_users_in_course($coursecode)); |
||||
} |
||||
} |
||||
|
||||
unset ($coursecodes); |
||||
|
||||
return $users; |
||||
|
||||
} |
||||
|
||||
|
||||
/** |
||||
* Search students matching a given last name and/or first name |
||||
* @author Bert Steppé |
||||
*/ |
||||
function find_students($mask= '') |
||||
{ |
||||
// students shouldn't be here // don't search if mask empty |
||||
if (!api_is_allowed_to_create_course() || empty ($mask)) |
||||
return null; |
||||
|
||||
$tbl_user= Database :: get_main_table(TABLE_MAIN_USER); |
||||
$tbl_cru= Database :: get_main_table(TABLE_MAIN_COURSE_USER); |
||||
$sql= 'SELECT DISTINCT user.user_id, user.lastname, user.firstname, user.email' . ' FROM ' . $tbl_user . ' user'; |
||||
if (!api_is_platform_admin()) |
||||
$sql .= ', ' . $tbl_cru . ' cru'; |
||||
$sql .= ' WHERE user.status = ' . STUDENT; |
||||
$sql .= ' AND (user.lastname LIKE '."'%" . $mask . "%'"; |
||||
$sql .= ' OR user.firstname LIKE '."'%" . $mask . "%')"; |
||||
|
||||
if (!api_is_platform_admin()) |
||||
$sql .= ' AND user.user_id = cru.user_id' . ' AND cru.course_code in' . ' (SELECT course_code' . ' FROM ' . $tbl_cru . ' WHERE user_id = ' . api_get_user_id() . ' AND status = ' . COURSEMANAGER . ')'; |
||||
$sql .= ' ORDER BY lastname'; |
||||
$result= api_sql_query($sql, __FILE__, __LINE__); |
||||
$db_users= api_store_result($result); |
||||
return $db_users; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Get user information from a given id |
||||
* @param int $userid The userid |
||||
* @return array All user information as an associative array |
||||
*/ |
||||
function get_user_info_from_id($userid) |
||||
{ |
||||
$user_table= Database :: get_main_table(TABLE_MAIN_USER); |
||||
$sql= 'SELECT * FROM ' . $user_table . ' WHERE user_id=' . $userid; |
||||
//var_dump( $sql); |
||||
$res= api_sql_query($sql, __FILE__, __LINE__); |
||||
$user= mysql_fetch_array($res, MYSQL_ASSOC); |
||||
return $user; |
||||
} |
||||
|
||||
|
||||
|
||||
?> |
@ -0,0 +1,7 @@ |
||||
<html> |
||||
<head> |
||||
<meta http-equiv="refresh" content="0; url=../gradebook.php"> |
||||
</head> |
||||
<body> |
||||
</body> |
||||
</html> |
@ -0,0 +1,160 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Class to select, sort and transform object data into array data, |
||||
* used for the teacher's evaluation results view |
||||
* @author Bert Steppé |
||||
*/ |
||||
class ResultsDataGenerator |
||||
{ |
||||
|
||||
// Sorting types constants |
||||
const RDG_SORT_LASTNAME = 1; |
||||
const RDG_SORT_FIRSTNAME = 2; |
||||
const RDG_SORT_SCORE = 4; |
||||
const RDG_SORT_MASK = 8; |
||||
|
||||
const RDG_SORT_ASC = 16; |
||||
const RDG_SORT_DESC = 32; |
||||
|
||||
|
||||
private $evaluation; |
||||
private $results; |
||||
private $is_course_ind; |
||||
private $include_edit; |
||||
|
||||
|
||||
/** |
||||
* Constructor |
||||
*/ |
||||
function ResultsDataGenerator ( $evaluation, |
||||
$results = array(), |
||||
$include_edit = false) |
||||
{ |
||||
$this->evaluation = $evaluation; |
||||
$this->results = (isset($results) ? $results : array()); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Get total number of results (rows) |
||||
*/ |
||||
public function get_total_results_count() |
||||
{ |
||||
return count($this->results); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Get actual array data |
||||
* @return array 2-dimensional array - each array contains the elements: |
||||
* 0 ['id'] : user id |
||||
* 1 ['result_id'] : result id |
||||
* 2 ['lastname'] : user lastname |
||||
* 3 ['firstname'] : user firstname |
||||
* 4 ['score'] : student's score |
||||
* 5 ['display'] : custom score display (only if custom scoring enabled) |
||||
*/ |
||||
public function get_data ($sorting = 0, $start = 0, $count = null, $ignore_score_color = false) |
||||
{ |
||||
|
||||
// do some checks on count, redefine if invalid value |
||||
if (!isset($count)) |
||||
$count = count ($this->results) - $start; |
||||
if ($count < 0) |
||||
$count = 0; |
||||
|
||||
$scoredisplay = ScoreDisplay :: instance(); |
||||
|
||||
// generate actual data array |
||||
$table = array(); |
||||
foreach($this->results as $result) |
||||
{ |
||||
$user = array(); |
||||
$info = get_user_info_from_id($result->get_user_id()); |
||||
$user['id'] = $result->get_user_id(); |
||||
$user['result_id'] = $result->get_id(); |
||||
$user['lastname'] = $info['lastname']; |
||||
$user['firstname'] = $info['firstname']; |
||||
$user['score'] = $this->get_score_display($result->get_score(),true, $ignore_score_color); |
||||
if ($scoredisplay->is_custom()) |
||||
$user['display'] = $this->get_score_display($result->get_score(),false, $ignore_score_color);; |
||||
$table[] = $user; |
||||
} |
||||
|
||||
|
||||
// sort array |
||||
if ($sorting & self :: RDG_SORT_LASTNAME) |
||||
usort($table, array('ResultsDataGenerator', 'sort_by_last_name')); |
||||
elseif ($sorting & self :: RDG_SORT_FIRSTNAME) |
||||
usort($table, array('ResultsDataGenerator', 'sort_by_first_name')); |
||||
elseif ($sorting & self :: RDG_SORT_SCORE) |
||||
usort($table, array('ResultsDataGenerator', 'sort_by_score')); |
||||
elseif ($sorting & self :: RDG_SORT_MASK) |
||||
usort($table, array('ResultsDataGenerator', 'sort_by_mask')); |
||||
if ($sorting & self :: RDG_SORT_DESC) |
||||
$table = array_reverse($table); |
||||
|
||||
|
||||
return array_slice($table, $start, $count); |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
private function get_score_display ($score, $realscore, $ignore_score_color) |
||||
{ |
||||
if ($score != null) |
||||
{ |
||||
$display_type = SCORE_DIV_PERCENT; |
||||
if ($ignore_score_color) |
||||
$display_type |= SCORE_IGNORE_SPLIT; |
||||
$scoredisplay = ScoreDisplay :: instance(); |
||||
return $scoredisplay->display_score |
||||
(array($score,$this->evaluation->get_max()), |
||||
$display_type, |
||||
$realscore ? SCORE_ONLY_DEFAULT : SCORE_ONLY_CUSTOM); |
||||
} |
||||
else |
||||
return ''; |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Sort functions - used internally |
||||
|
||||
function sort_by_last_name($item1, $item2) |
||||
{ |
||||
if (strtolower($item1['lastname']) == strtolower($item2['lastname'])) |
||||
return 0; |
||||
else |
||||
return (strtolower($item1['lastname']) < strtolower($item2['lastname']) ? -1 : 1); |
||||
} |
||||
|
||||
function sort_by_first_name($item1, $item2) |
||||
{ |
||||
if (strtolower($item1['firstname']) == strtolower($item2['firstname'])) |
||||
return 0; |
||||
else |
||||
return (strtolower($item1['firstname']) < strtolower($item2['firstname']) ? -1 : 1); |
||||
} |
||||
|
||||
function sort_by_score($item1, $item2) |
||||
{ |
||||
if ($item1['score'] == $item2['score']) |
||||
return 0; |
||||
else |
||||
return ($item1['score'] < $item2['score'] ? -1 : 1); |
||||
} |
||||
|
||||
function sort_by_mask ($item1, $item2) |
||||
{ |
||||
$score1 = (isset($item1['score']) ? array($item1['score'],$this->evaluation->get_max()) : null); |
||||
$score2 = (isset($item2['score']) ? array($item2['score'],$this->evaluation->get_max()) : null); |
||||
return ScoreDisplay :: compare_scores_by_custom_display($score1, $score2); |
||||
} |
||||
|
||||
} |
||||
?> |
@ -0,0 +1,428 @@ |
||||
<?php |
||||
|
||||
|
||||
// Score display types constants |
||||
define('SCORE_DIV',1); |
||||
define('SCORE_PERCENT',2); |
||||
define('SCORE_DIV_PERCENT',3); |
||||
define('SCORE_AVERAGE',4); |
||||
|
||||
define('SCORE_IGNORE_SPLIT', 8); |
||||
|
||||
define('SCORE_BOTH',1); |
||||
define('SCORE_ONLY_DEFAULT',2); |
||||
define('SCORE_ONLY_CUSTOM',3); |
||||
|
||||
|
||||
/** |
||||
* Class to display scores according to the settings made by the platform admin. |
||||
* This class works as a singleton: call instance() to retrieve an object. |
||||
* @author Bert Steppé |
||||
* @package dokeos.gradebook |
||||
*/ |
||||
class ScoreDisplay |
||||
{ |
||||
|
||||
// Singleton stuff |
||||
|
||||
/** |
||||
* Get the instance of this class |
||||
*/ |
||||
public static function instance() |
||||
{ |
||||
static $instance; |
||||
if (!isset ($instance)) |
||||
$instance = new ScoreDisplay(); |
||||
return $instance; |
||||
} |
||||
|
||||
|
||||
// Static methods |
||||
|
||||
/** |
||||
* Compare the custom display of 2 scores, can be useful in sorting |
||||
*/ |
||||
public static function compare_scores_by_custom_display ($score1, $score2) |
||||
{ |
||||
if (!isset($score1)) |
||||
return (isset($score2) ? 1 : 0); |
||||
elseif (!isset($score2)) |
||||
return -1; |
||||
else |
||||
{ |
||||
$scoredisplay = ScoreDisplay :: instance(); |
||||
$custom1 = $scoredisplay->display_custom($score1); |
||||
$custom2 = $scoredisplay->display_custom($score2); |
||||
if ($custom1 == $custom2) |
||||
return 0; |
||||
else |
||||
return (($score1[0]/$score1[1]) < ($score2[0]/$score2[1]) ? -1 : 1); |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
// As object |
||||
|
||||
private $coloring_enabled; |
||||
private $color_split_value; |
||||
|
||||
private $custom_enabled; |
||||
private $upperlimit_included; |
||||
private $custom_display; |
||||
private $custom_display_conv; |
||||
|
||||
/** |
||||
* Protected constructor - call instance() to instantiate |
||||
*/ |
||||
protected function ScoreDisplay() |
||||
{ |
||||
$this->coloring_enabled = $this->load_bool_setting('score_display_coloring',0); |
||||
if ($this->coloring_enabled) |
||||
$this->color_split_value = $this->load_int_setting('score_display_colorsplit',50); |
||||
|
||||
$this->custom_enabled = $this->load_bool_setting('score_display_custom', 0); |
||||
if ($this->custom_enabled) |
||||
{ |
||||
$this->upperlimit_included = $this->load_bool_setting('score_display_upperlimit', 0); |
||||
$this->custom_display = $this->get_custom_displays(); |
||||
$this->custom_display_conv = $this->convert_displays($this->custom_display); |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* Is coloring enabled ? |
||||
*/ |
||||
public function is_coloring_enabled () |
||||
{ |
||||
return $this->coloring_enabled; |
||||
} |
||||
|
||||
/** |
||||
* Is custom score display enabled ? |
||||
*/ |
||||
public function is_custom () |
||||
{ |
||||
return $this->custom_enabled; |
||||
} |
||||
|
||||
/** |
||||
* Is upperlimit included ? |
||||
*/ |
||||
public function is_upperlimit_included () |
||||
{ |
||||
return $this->upperlimit_included; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Update the 'coloring' setting |
||||
* @param boolean $coloring coloring enabled or disabled |
||||
*/ |
||||
public function set_coloring_enabled ($coloring) |
||||
{ |
||||
$this->coloring_enabled = $coloring; |
||||
$this->save_bool_setting ('score_display_coloring', $coloring); |
||||
} |
||||
|
||||
/** |
||||
* Update the 'colorsplit' setting |
||||
* @param int $colorsplit color split value, in percent |
||||
*/ |
||||
public function set_color_split_value ($colorsplit) |
||||
{ |
||||
$this->color_split_value = $colorsplit; |
||||
$this->save_int_setting ('score_display_colorsplit', $colorsplit); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Update the 'custom' setting |
||||
* @param boolean $custom custom enabled or disabled |
||||
*/ |
||||
public function set_custom ($custom) |
||||
{ |
||||
$this->custom_enabled = $custom; |
||||
$this->save_bool_setting ('score_display_custom', $custom); |
||||
} |
||||
|
||||
/** |
||||
* Update the 'upperlimit' setting |
||||
* @param boolean $upperlimit_included true if upper limit must be included, false otherwise |
||||
*/ |
||||
public function set_upperlimit_included ($upperlimit_included) |
||||
{ |
||||
$this->upperlimit_incl = $upperlimit_included; |
||||
$this->save_bool_setting ('score_display_upperlimit', $upperlimit_included); |
||||
} |
||||
|
||||
/** |
||||
* If custom score display is enabled, this will return the current settings. |
||||
* See also update_custom_score_display_settings |
||||
* @return array current settings (or null if feature not enabled) |
||||
*/ |
||||
public function get_custom_score_display_settings() |
||||
{ |
||||
return $this->custom_display; |
||||
} |
||||
|
||||
/** |
||||
* If coloring is enabled, scores below this value will be displayed in red. |
||||
* @return int color split value, in percent (or null if feature not enabled) |
||||
*/ |
||||
public function get_color_split_value() |
||||
{ |
||||
return $this->color_split_value; |
||||
} |
||||
|
||||
/** |
||||
* Update custom score display settings |
||||
* @param array $displays 2-dimensional array - every subarray must have keys (score, display) |
||||
*/ |
||||
public function update_custom_score_display_settings ($displays) |
||||
{ |
||||
$this->custom_display = $displays; |
||||
$this->custom_display_conv = $this->convert_displays($this->custom_display); |
||||
|
||||
// remove previous settings |
||||
$tbl_display = Database :: get_gradebook_table(TABLE_GRADEBOOK_SCORE_DISPLAY); |
||||
$sql = 'TRUNCATE TABLE '.$tbl_display; |
||||
api_sql_query($sql, __FILE__, __LINE__); |
||||
|
||||
// add new settings |
||||
$sql = 'INSERT INTO '.$tbl_display.' (id, score, display) VALUES '; |
||||
$count = 0; |
||||
foreach ($displays as $display) |
||||
{ |
||||
if ($count > 0) |
||||
$sql .= ','; |
||||
$sql .= "(NULL, '".$display['score']."', '".$display['display']."')"; |
||||
$count++; |
||||
} |
||||
|
||||
api_sql_query($sql, __FILE__, __LINE__); |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* Display a score according to the current settings |
||||
* @param array $score score data structure, as returned by the calc_score functions |
||||
* @param int $type one of the following constants: SCORE_DIV, SCORE_PERCENT, SCORE_DIV_PERCENT, SCORE_AVERAGE |
||||
* (ignored for student's view if custom score display is enabled) |
||||
* @param int $what one of the following constants: SCORE_BOTH, SCORE_ONLY_DEFAULT, SCORE_ONLY_CUSTOM (default: SCORE_BOTH) |
||||
* (only taken into account if custom score display is enabled and for course/platform admin) |
||||
*/ |
||||
public function display_score($score,$type,$what = SCORE_BOTH) |
||||
{ |
||||
$type2 = $type & 7; // removes the 'SCORE_IGNORE_SPLIT' bit |
||||
$split_enabled = ($type2 == $type); |
||||
|
||||
if (!isset($score)) |
||||
return ''; |
||||
|
||||
elseif ($this->custom_enabled && isset($this->custom_display_conv)) |
||||
{ |
||||
// students only see the custom display |
||||
if (!api_is_allowed_to_create_course()) |
||||
$display = $this->display_custom($score); |
||||
|
||||
// course/platform admins |
||||
elseif ($what == SCORE_ONLY_DEFAULT) |
||||
$display = $this->display_default ($score, $type2); |
||||
elseif ($what == SCORE_ONLY_CUSTOM) |
||||
$display = $this->display_custom ($score); |
||||
else |
||||
$display = $this->display_default ($score, $type2) |
||||
.' ('.$this->display_custom ($score).')'; |
||||
} |
||||
|
||||
// if no custom display set, use default display |
||||
else |
||||
$display = $this->display_default ($score, $type2); |
||||
|
||||
return (($split_enabled ? $this->get_color_display_start_tag($score) : '') |
||||
. $display |
||||
. ($split_enabled ? $this->get_color_display_end_tag($score) : '')); |
||||
} |
||||
|
||||
|
||||
|
||||
// Internal functions |
||||
|
||||
private function display_default ($score, $type) |
||||
{ |
||||
switch ($type) |
||||
{ |
||||
case SCORE_DIV : // X / Y |
||||
return $this->display_as_div($score); |
||||
|
||||
case SCORE_PERCENT : // XX % |
||||
return $this->display_as_percent($score); |
||||
|
||||
case SCORE_DIV_PERCENT : // X / Y (XX %) |
||||
return $this->display_as_div($score) |
||||
. ' (' . $this->display_as_percent($score) . ')'; |
||||
|
||||
case SCORE_AVERAGE : // XX % |
||||
return $this->display_as_percent($score); |
||||
} |
||||
} |
||||
|
||||
private function display_as_percent ($score) |
||||
{ |
||||
return round(($score[0] / $score[1]) * 100) . ' %'; |
||||
} |
||||
|
||||
private function display_as_div ($score) |
||||
{ |
||||
return $score[0] . ' / ' . $score[1]; |
||||
} |
||||
|
||||
private function display_custom ($score) |
||||
{ |
||||
$scaledscore = $score[0] / $score[1]; |
||||
if ($this->upperlimit_included) |
||||
{ |
||||
foreach ($this->custom_display_conv as $displayitem) |
||||
{ |
||||
if ($scaledscore <= $displayitem['score']) |
||||
return $displayitem['display']; |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
foreach ($this->custom_display_conv as $displayitem) |
||||
{ |
||||
if ($scaledscore < $displayitem['score'] || $displayitem['score'] == 1) |
||||
return $displayitem['display']; |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
private function load_bool_setting ($property, $default = 0) |
||||
{ |
||||
$value = $this->load_int_setting($property, $default); |
||||
return ($value == '1' ? true : false); |
||||
} |
||||
|
||||
private function load_int_setting ($property, $default = 0) |
||||
{ |
||||
$tbl_setting = Database :: get_gradebook_table(TABLE_GRADEBOOK_SETTING); |
||||
|
||||
$sql = 'SELECT value FROM '.$tbl_setting |
||||
.' WHERE property = "'.$property.'"'; |
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
|
||||
if ($data = mysql_fetch_row($result)) |
||||
return $data[0]; |
||||
else |
||||
{ |
||||
// if not present, add default setting into table... |
||||
$sql = 'INSERT INTO '.$tbl_setting |
||||
.' (property, value)' |
||||
.' VALUES ("'.$property.'", '.$default.')'; |
||||
api_sql_query($sql, __FILE__, __LINE__); |
||||
// ...and return default value |
||||
return $default; |
||||
} |
||||
} |
||||
|
||||
|
||||
private function save_bool_setting ($property, $value) |
||||
{ |
||||
$this->save_int_setting ($property, ($value ? '1' : '0') ); |
||||
} |
||||
|
||||
private function save_int_setting ($property, $value) |
||||
{ |
||||
$tbl_setting = Database :: get_gradebook_table(TABLE_GRADEBOOK_SETTING); |
||||
$sql = 'UPDATE '.$tbl_setting |
||||
.' SET value = '.$value |
||||
.' WHERE property = "'.$property.'"'; |
||||
api_sql_query($sql, __FILE__, __LINE__); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Get current custom score display settings |
||||
* @return array 2-dimensional array - every element contains 3 subelements (id, score, display) |
||||
*/ |
||||
private function get_custom_displays() |
||||
{ |
||||
$tbl_display = Database :: get_gradebook_table(TABLE_GRADEBOOK_SCORE_DISPLAY); |
||||
$sql = 'SELECT * FROM '.$tbl_display.' ORDER BY score'; |
||||
//echo $sql; |
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
return api_store_result($result); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Convert display settings to internally used values |
||||
*/ |
||||
private function convert_displays($custom_display) |
||||
{ |
||||
if (isset($custom_display)) |
||||
{ |
||||
// get highest score entry, and copy each element to a new array |
||||
$converted = array(); |
||||
$highest = 0; |
||||
foreach ($custom_display as $element) |
||||
{ |
||||
if ($element['score'] > $highest) |
||||
$highest = $element['score']; |
||||
$converted[] = $element; |
||||
} |
||||
|
||||
// sort the new array (ascending) |
||||
usort($converted, array('ScoreDisplay', 'sort_display')); |
||||
|
||||
// adjust each score in such a way that |
||||
// each score is scaled between 0 and 1 |
||||
// the highest score in this array will be equal to 1 |
||||
$converted2 = array(); |
||||
foreach ($converted as $element) |
||||
{ |
||||
$newelement = array(); |
||||
$newelement['score'] = $element['score'] / $highest; |
||||
$newelement['display'] = $element['display']; |
||||
$converted2[] = $newelement; |
||||
} |
||||
|
||||
return $converted2; |
||||
} |
||||
else |
||||
return null; |
||||
} |
||||
|
||||
private function sort_display ($item1, $item2) |
||||
{ |
||||
if ($item1['score'] == $item2['score']) |
||||
return 0; |
||||
else |
||||
return ($item1['score'] < $item2['score'] ? -1 : 1); |
||||
} |
||||
|
||||
|
||||
private function get_color_display_start_tag($score) |
||||
{ |
||||
if ($this->coloring_enabled && ($score[0]/$score[1]) < ($this->color_split_value / 100)) |
||||
return '<font color="red">'; |
||||
else |
||||
return ''; |
||||
} |
||||
|
||||
private function get_color_display_end_tag($score) |
||||
{ |
||||
if ($this->coloring_enabled && ($score[0]/$score[1]) < ($this->color_split_value / 100)) |
||||
return '</font>'; |
||||
else |
||||
return ''; |
||||
} |
||||
|
||||
} |
||||
?> |
@ -0,0 +1,350 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Class to select, sort and transform object data into array data, |
||||
* used for a student's general view |
||||
* @author Bert Steppé |
||||
*/ |
||||
class UserDataGenerator |
||||
{ |
||||
|
||||
// Sorting types constants |
||||
const UDG_SORT_TYPE = 1; |
||||
const UDG_SORT_NAME = 2; |
||||
const UDG_SORT_COURSE = 4; |
||||
const UDG_SORT_CATEGORY = 8; |
||||
const UDG_SORT_AVERAGE = 16; |
||||
const UDG_SORT_SCORE = 32; |
||||
const UDG_SORT_MASK = 64; |
||||
|
||||
const UDG_SORT_ASC = 128; |
||||
const UDG_SORT_DESC = 256; |
||||
|
||||
|
||||
private $items; |
||||
private $userid; |
||||
|
||||
private $coursecodecache; |
||||
private $categorycache; |
||||
private $scorecache; |
||||
private $avgcache; |
||||
|
||||
|
||||
function UserDataGenerator($userid, $evals = array(), $links = array()) |
||||
{ |
||||
$this->userid = $userid; |
||||
|
||||
$evals_filtered = array(); |
||||
foreach ($evals as $eval) |
||||
{ |
||||
$toadd = true; |
||||
$coursecode = $eval->get_course_code(); |
||||
if (isset($coursecode)) |
||||
{ |
||||
$result = Result :: load (null, $userid, $eval->get_id()); |
||||
if (count($result) == 0) |
||||
$toadd = false; |
||||
} |
||||
if ($toadd) |
||||
$evals_filtered[] = $eval; |
||||
} |
||||
|
||||
$this->items = array_merge ($evals_filtered, $links); |
||||
|
||||
|
||||
$this->coursecodecache = array(); |
||||
$this->categorycache = array(); |
||||
$this->scorecache = null; |
||||
$this->avgcache = null; |
||||
|
||||
} |
||||
|
||||
|
||||
/** |
||||
* Get total number of items (rows) |
||||
*/ |
||||
public function get_total_items_count() |
||||
{ |
||||
return count($this->items); |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* Get actual array data |
||||
* @return array 2-dimensional array - each array contains the elements: |
||||
* 0: eval/link object |
||||
* 1: item name |
||||
* 2: course name |
||||
* 3: category name |
||||
* 4: average score |
||||
* 5: student's score |
||||
* 6: student's score as custom display (only if custom scoring enabled) |
||||
*/ |
||||
public function get_data ($sorting = 0, $start = 0, $count = null, $ignore_score_color = false) |
||||
{ |
||||
|
||||
// do some checks on count, redefine if invalid value |
||||
if (!isset($count)) |
||||
$count = count ($this->items) - $start; |
||||
if ($count < 0) |
||||
$count = 0; |
||||
|
||||
$allitems = $this->items; |
||||
|
||||
// sort users array |
||||
if ($sorting & self :: UDG_SORT_TYPE) |
||||
usort($allitems, array('UserDataGenerator', 'sort_by_type')); |
||||
elseif ($sorting & self :: UDG_SORT_NAME) |
||||
usort($allitems, array('UserDataGenerator', 'sort_by_name')); |
||||
elseif ($sorting & self :: UDG_SORT_COURSE) |
||||
usort($allitems, array('UserDataGenerator', 'sort_by_course')); |
||||
elseif ($sorting & self :: UDG_SORT_CATEGORY) |
||||
usort($allitems, array('UserDataGenerator', 'sort_by_category')); |
||||
elseif ($sorting & self :: UDG_SORT_AVERAGE) |
||||
{ |
||||
// if user sorts on average scores, first calculate them and cache them |
||||
foreach ($allitems as $item) |
||||
$this->avgcache[$item->get_item_type() . $item->get_id()] |
||||
= $item->calc_score(); |
||||
usort($allitems, array('UserDataGenerator', 'sort_by_average')); |
||||
} |
||||
elseif ($sorting & self :: UDG_SORT_SCORE) |
||||
{ |
||||
// if user sorts on student's scores, first calculate them and cache them |
||||
foreach ($allitems as $item) |
||||
$this->scorecache[$item->get_item_type() . $item->get_id()] |
||||
= $item->calc_score($this->userid); |
||||
usort($allitems, array('UserDataGenerator', 'sort_by_score')); |
||||
} |
||||
elseif ($sorting & self :: UDG_SORT_MASK) |
||||
{ |
||||
// if user sorts on student's masks, first calculate scores and cache them |
||||
foreach ($allitems as $item) |
||||
$this->scorecache[$item->get_item_type() . $item->get_id()] |
||||
= $item->calc_score($this->userid); |
||||
usort($allitems, array('UserDataGenerator', 'sort_by_mask')); |
||||
} |
||||
|
||||
if ($sorting & self :: UDG_SORT_DESC) |
||||
$allitems = array_reverse($allitems); |
||||
|
||||
// select the items we have to display |
||||
$visibleitems = array_slice($allitems, $start, $count); |
||||
|
||||
|
||||
// fill score cache if not done yet |
||||
if (!isset ($this->scorecache)) |
||||
{ |
||||
foreach ($visibleitems as $item) |
||||
$this->scorecache[$item->get_item_type() . $item->get_id()] |
||||
= $item->calc_score($this->userid); |
||||
} |
||||
|
||||
|
||||
// generate the data to display |
||||
$scoredisplay = ScoreDisplay :: instance(); |
||||
$data = array(); |
||||
foreach ($visibleitems as $item) |
||||
{ |
||||
$row = array (); |
||||
$row[] = $item; |
||||
$row[] = $item->get_name(); |
||||
$row[] = $this->build_course_name ($item); |
||||
$row[] = $this->build_category_name ($item); |
||||
$row[] = $this->build_average_column ($item, $ignore_score_color); |
||||
$row[] = $this->build_result_column ($item, $ignore_score_color); |
||||
if ($scoredisplay->is_custom()) |
||||
$row[] = $this->build_mask_column ($item, $ignore_score_color); |
||||
$data[] = $row; |
||||
} |
||||
|
||||
return $data; |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Sort functions |
||||
// Make sure to only use functions as defined in the GradebookItem interface ! |
||||
|
||||
function sort_by_type($item1, $item2) |
||||
{ |
||||
if ($item1->get_item_type() == $item2->get_item_type()) |
||||
return $this->sort_by_name($item1,$item2); |
||||
else |
||||
return ($item1->get_item_type() < $item2->get_item_type() ? -1 : 1); |
||||
} |
||||
|
||||
function sort_by_course($item1, $item2) |
||||
{ |
||||
$name1 = strtolower($this->get_course_name_from_code_cached($item1->get_course_code())); |
||||
$name2 = strtolower($this->get_course_name_from_code_cached($item2->get_course_code())); |
||||
if ($name1 == $name2) |
||||
return 0; |
||||
else |
||||
return ($name1 < $name2 ? -1 : 1); |
||||
} |
||||
|
||||
function sort_by_category($item1, $item2) |
||||
{ |
||||
$cat1 = $this->get_category_cached($item1->get_category_id()); |
||||
$cat2 = $this->get_category_cached($item2->get_category_id()); |
||||
|
||||
$name1 = strtolower($this->get_category_name_to_display($cat1)); |
||||
$name2 = strtolower($this->get_category_name_to_display($cat2)); |
||||
if ($name1 == $name2) |
||||
return 0; |
||||
else |
||||
return ($name1 < $name2 ? -1 : 1); |
||||
} |
||||
|
||||
|
||||
function sort_by_name($item1, $item2) |
||||
{ |
||||
if (strtolower($item1->get_name()) == strtolower($item2->get_name())) |
||||
return 0; |
||||
else |
||||
return (strtolower($item1->get_name()) < strtolower($item2->get_name()) ? -1 : 1); |
||||
} |
||||
|
||||
|
||||
function sort_by_average($item1, $item2) |
||||
{ |
||||
$score1 = $this->avgcache[$item1->get_item_type() . $item1->get_id()]; |
||||
$score2 = $this->avgcache[$item2->get_item_type() . $item2->get_id()]; |
||||
return $this->compare_scores($score1, $score2); |
||||
} |
||||
|
||||
function sort_by_score($item1, $item2) |
||||
{ |
||||
$score1 = $this->scorecache[$item1->get_item_type() . $item1->get_id()]; |
||||
$score2 = $this->scorecache[$item2->get_item_type() . $item2->get_id()]; |
||||
return $this->compare_scores($score1, $score2); |
||||
} |
||||
|
||||
function sort_by_mask($item1, $item2) |
||||
{ |
||||
$score1 = $this->scorecache[$item1->get_item_type() . $item1->get_id()]; |
||||
$score2 = $this->scorecache[$item2->get_item_type() . $item2->get_id()]; |
||||
return ScoreDisplay :: compare_scores_by_custom_display($score1, $score2); |
||||
} |
||||
|
||||
function compare_scores ($score1, $score2) |
||||
{ |
||||
if (!isset($score1)) |
||||
return (isset($score2) ? 1 : 0); |
||||
elseif (!isset($score2)) |
||||
return -1; |
||||
elseif (($score1[0]/$score1[1]) == ($score2[0]/$score2[1])) |
||||
return 0; |
||||
else |
||||
return (($score1[0]/$score1[1]) < ($score2[0]/$score2[1]) ? -1 : 1); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Other functions |
||||
|
||||
|
||||
private function build_course_name ($item) |
||||
{ |
||||
return $this->get_course_name_from_code_cached($item->get_course_code()); |
||||
} |
||||
|
||||
private function build_category_name ($item) |
||||
{ |
||||
$cat = $this->get_category_cached($item->get_category_id()); |
||||
return $this->get_category_name_to_display($cat); |
||||
} |
||||
|
||||
|
||||
private function build_average_column ($item, $ignore_score_color) |
||||
{ |
||||
if (isset($this->avgcache)) |
||||
$avgscore = $this->avgcache[$item->get_item_type() . $item->get_id()]; |
||||
else |
||||
$avgscore = $item->calc_score(); |
||||
$scoredisplay = ScoreDisplay :: instance(); |
||||
$displaytype = SCORE_AVERAGE; |
||||
if ($ignore_score_color) |
||||
$displaytype |= SCORE_IGNORE_SPLIT; |
||||
return $scoredisplay->display_score($avgscore, $displaytype); |
||||
} |
||||
|
||||
|
||||
private function build_result_column ($item, $ignore_score_color) |
||||
{ |
||||
$studscore = $this->scorecache[$item->get_item_type() . $item->get_id()]; |
||||
$scoredisplay = ScoreDisplay :: instance(); |
||||
$displaytype = SCORE_DIV_PERCENT; |
||||
if ($ignore_score_color) |
||||
$displaytype |= SCORE_IGNORE_SPLIT; |
||||
return $scoredisplay->display_score($studscore, $displaytype, SCORE_ONLY_DEFAULT); |
||||
} |
||||
|
||||
private function build_mask_column ($item, $ignore_score_color) |
||||
{ |
||||
$studscore = $this->scorecache[$item->get_item_type() . $item->get_id()]; |
||||
$scoredisplay = ScoreDisplay :: instance(); |
||||
$displaytype = SCORE_DIV_PERCENT; |
||||
if ($ignore_score_color) |
||||
$displaytype |= SCORE_IGNORE_SPLIT; |
||||
return $scoredisplay->display_score($studscore, $displaytype, SCORE_ONLY_CUSTOM); |
||||
} |
||||
|
||||
|
||||
private function get_course_name_from_code_cached ($coursecode) |
||||
{ |
||||
if (isset ($this->coursecodecache) |
||||
&& isset ($this->coursecodecache[$coursecode])) |
||||
return $this->coursecodecache[$coursecode]; |
||||
else |
||||
{ |
||||
$name = get_course_name_from_code($coursecode); |
||||
$this->coursecodecache[$coursecode] = $name; |
||||
return $name; |
||||
} |
||||
} |
||||
|
||||
private function get_category_cached ($category_id) |
||||
{ |
||||
if (isset ($this->categorycache) |
||||
&& isset ($this->categorycache[$category_id])) |
||||
return $this->categorycache[$category_id]; |
||||
else |
||||
{ |
||||
$cat = Category::load($category_id); |
||||
if (isset($cat)) |
||||
{ |
||||
$this->categorycache[$category_id] = $cat[0]; |
||||
return $cat[0]; |
||||
} |
||||
else |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
private function get_category_name_to_display ($cat) |
||||
{ |
||||
if (isset($cat)) |
||||
{ |
||||
if ($cat->get_parent_id() == '0' || $cat->get_parent_id() == null) |
||||
return ''; |
||||
else |
||||
return $cat->get_name(); |
||||
} |
||||
else |
||||
return ''; |
||||
|
||||
} |
||||
|
||||
|
||||
} |
||||
?> |
@ -0,0 +1,11 @@ |
||||
<?php |
||||
|
||||
include ('../inc/global.inc.php'); |
||||
include ('../inc/lib/document.lib.php'); |
||||
api_block_anonymous_users(); |
||||
|
||||
|
||||
DocumentManager :: file_send_for_download(api_get_path(SYS_COURSE_PATH).$_GET['file']); |
||||
|
||||
|
||||
?> |
@ -0,0 +1,39 @@ |
||||
body { |
||||
font-family: arial, verdana, helvetica, sans-serif; |
||||
font-size: 12px; |
||||
color: #000; |
||||
margin: 10px; |
||||
padding: 0; |
||||
} |
||||
|
||||
a:link {text-decoration: none; font-weight : bold; color : black;} |
||||
a:visited {text-decoration: none; font-weight : bold; color : black;} |
||||
a:active {text-decoration: none; font-weight : bold; color : black;} |
||||
|
||||
.data_table{ |
||||
border-collapse: collapse; |
||||
width: 100%; |
||||
padding: 5px; |
||||
border: 1px; |
||||
} |
||||
.data_table th{ |
||||
padding: 5px; |
||||
vertical-align: top; |
||||
border-top: 1px solid black; |
||||
border-bottom: 1px solid black; |
||||
border-right: 1px solid black; |
||||
border-left: 1px solid black; |
||||
} |
||||
.data_table tr.row_odd{ |
||||
background-color: #fafafa; |
||||
} |
||||
.data_table tr.row_even{ |
||||
background-color: #fff; |
||||
} |
||||
.data_table td{ |
||||
padding: 5px; |
||||
vertical-align: top; |
||||
border-bottom: 1px solid black; |
||||
border-right: 1px solid black; |
||||
border-left: 1px solid black; |
||||
} |
@ -0,0 +1,67 @@ |
||||
<?php |
||||
// test |
||||
|
||||
// $Id: gradebook_view_result.php 479 2007-04-12 11:50:58Z stijn $ |
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2006 Dokeos S.A. |
||||
Copyright (c) 2006 Ghent University (UGent) |
||||
Copyright (c) various contributors |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
as published by the Free Software Foundation; either version 2 |
||||
of the License, or (at your option) any later version. |
||||
|
||||
See the GNU General Public License for more details. |
||||
|
||||
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium |
||||
Mail: info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
$language_file = 'gradebook'; |
||||
$cidReset = true; |
||||
include_once ('../inc/global.inc.php'); |
||||
include_once ('lib/be.inc.php'); |
||||
include_once ('lib/gradebook_functions.inc.php'); |
||||
include_once ('lib/fe/userform.class.php'); |
||||
include_once (api_get_path(LIBRARY_PATH) . 'fileManage.lib.php'); |
||||
include_once (api_get_path(LIBRARY_PATH) . 'export.lib.inc.php'); |
||||
include_once (api_get_path(LIBRARY_PATH) . 'import.lib.php'); |
||||
api_block_anonymous_users(); |
||||
block_students(); |
||||
|
||||
$user = get_user_info_from_id($_GET['userid']); |
||||
$form = new UserForm(UserForm :: TYPE_USER_INFO, $user, 'user_info_form', null, api_get_self() . '?userid=' . $_GET['userid'] . '&selecteval=' . $_GET['selecteval']); |
||||
if ($form->validate()) { |
||||
|
||||
header('Location: user_stats.php?selecteval=' . $_GET['selecteval'].'&userid=' . $_GET['userid']); |
||||
exit; |
||||
|
||||
} |
||||
|
||||
$interbreadcrumb[] = array ( |
||||
'url' => 'gradebook.php', |
||||
'name' => get_lang('Gradebook' |
||||
)); |
||||
Display :: display_header(get_lang('UserInfo')); |
||||
$image = $user['picture_uri']; |
||||
$image_file = ($image != '' ? api_get_path(WEB_CODE_PATH)."upload/users/$image" : api_get_path(WEB_CODE_PATH).'img/unknown.jpg'); |
||||
$image_size = @getimagesize($image_file); |
||||
|
||||
$img_attributes = 'src="'.$image_file.'?rand='.time().'" ' |
||||
.'alt="'.$user_data['lastname'].' '.$user_data['firstname'].'" ' |
||||
.'style="float:'.($text_dir == 'rtl' ? 'left' : 'right').'; padding:5px;" '; |
||||
|
||||
if ($image_size[0] > 300) //limit display width to 300px |
||||
$img_attributes .= 'width="300" '; |
||||
|
||||
echo '<img '.$img_attributes.'/>'; |
||||
$form->display(); |
||||
Display :: display_footer(); |
||||
?> |
@ -0,0 +1,120 @@ |
||||
<?php |
||||
// $Id: gradebook_view_result.php 479 2007-04-12 11:50:58Z stijn $ |
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2006 Dokeos S.A. |
||||
Copyright (c) 2006 Ghent University (UGent) |
||||
Copyright (c) various contributors |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
as published by the Free Software Foundation; either version 2 |
||||
of the License, or (at your option) any later version. |
||||
|
||||
See the GNU General Public License for more details. |
||||
|
||||
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium |
||||
Mail: info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
$language_file= 'gradebook'; |
||||
$cidReset= true; |
||||
include_once ('../inc/global.inc.php'); |
||||
include_once ('lib/be.inc.php'); |
||||
include_once ('lib/gradebook_functions.inc.php'); |
||||
include_once ('lib/fe/userform.class.php'); |
||||
include_once ('lib/user_data_generator.class.php'); |
||||
include_once ('lib/fe/usertable.class.php'); |
||||
include_once ('lib/fe/displaygradebook.php'); |
||||
include_once ('lib/scoredisplay.class.php'); |
||||
include_once (api_get_path(LIBRARY_PATH).'ezpdf/class.ezpdf.php'); |
||||
api_block_anonymous_users(); |
||||
block_students(); |
||||
$interbreadcrumb[]= array ( |
||||
'url' => 'gradebook.php', |
||||
'name' => get_lang('Gradebook' |
||||
)); |
||||
$category= Category :: load(0); |
||||
$allevals= $category[0]->get_evaluations($_GET['userid'], true); |
||||
$alllinks= $category[0]->get_links($_GET['userid'], true); |
||||
if ($_GET['selectcat'] != null) |
||||
$addparams= array ( |
||||
'userid' => $_GET['userid'], |
||||
'selectcat' => $_GET['selectcat'] |
||||
); |
||||
else |
||||
$addparams= array ( |
||||
'userid' => $_GET['userid'], |
||||
'selecteval' => $_GET['selecteval'] |
||||
); |
||||
$user_table= new UserTable($_GET['userid'], $allevals, $alllinks, $addparams); |
||||
if (isset ($_GET['exportpdf'])) |
||||
{ |
||||
$pdf= new Cezpdf(); |
||||
$pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Helvetica.afm'); |
||||
$pdf->ezSetMargins(30, 30, 50, 30); |
||||
$pdf->ezSetY(800); |
||||
$datagen= new UserDataGenerator($_GET['userid'], $allevals,$alllinks); |
||||
$data_array= $datagen->get_data(UserDataGenerator :: UDG_SORT_NAME, 0, null, true); |
||||
$newarray= array (); |
||||
$displayscore= Scoredisplay :: instance(); |
||||
$newitem= array (); |
||||
foreach ($data_array as $data) |
||||
{ |
||||
$newarray[] = array_slice($data, 1); |
||||
} |
||||
$pdf->ezSetY(810); |
||||
$userinfo = get_user_info_from_id($_GET['userid']); |
||||
$pdf->ezText(get_lang('Results').' : '.$userinfo['lastname']. ' '. $userinfo['firstname'].' ('. date('j/n/Y g:i') .')',12,array('justification'=>'center')); |
||||
$pdf->line(50,790,550,790); |
||||
$pdf->line(50,40,550,40); |
||||
|
||||
$pdf->ezSetY(750); |
||||
if ($displayscore->is_custom()) |
||||
$header_names= array ( |
||||
get_lang('Evaluation' |
||||
), get_lang('Course'), get_lang('Category'), get_lang('EvaluationAverage'),get_lang('Result'),get_lang('Display')); |
||||
else |
||||
$header_names= array ( |
||||
get_lang('Evaluation' |
||||
), get_lang('Course'), get_lang('Category'), get_lang('EvaluationAverage'),get_lang('Result')); |
||||
$pdf->ezTable($newarray, $header_names, '', array ( |
||||
'showHeadings' => 1, |
||||
'shaded' => 1, |
||||
'showLines' => 1, |
||||
'rowGap' => 3, |
||||
'width' => 500 |
||||
)); |
||||
$pdf->ezStream(); |
||||
exit; |
||||
} |
||||
if (isset ($_GET['selectcat'])) |
||||
{ |
||||
$interbreadcrumb[]= array ( |
||||
'url' => 'gradebook_flatview.php?selecteval=' . $_GET['selectcat'], |
||||
'name' => get_lang('FlatView' |
||||
)); |
||||
$backto= '<a href=gradebook_flatview.php?selectcat=' . $_GET['selectcat'] . '><img src=../img/lp_leftarrow.gif alt=' . get_lang('BackToOverview') . ' align=absmiddle/> ' . get_lang('BackToOverview') . '</a>  '; |
||||
|
||||
} |
||||
if (isset ($_GET['selecteval'])) |
||||
{ |
||||
$interbreadcrumb[]= array ( |
||||
'url' => 'gradebook_view_result.php?selecteval=' . $_GET['selecteval'], |
||||
'name' => get_lang('ViewResult' |
||||
)); |
||||
$backto= '<a href=gradebook_view_result.php?selecteval=' . $_GET['selecteval'] . '><img src=../img/lp_leftarrow.gif alt=' . get_lang('BackToEvaluation') . ' align=absmiddle/> ' . get_lang('BackToEvaluation') . '</a>  '; |
||||
} |
||||
$backto .= '<a href="' . api_get_self() . '?exportpdf=&userid='.$_GET['userid'].'&selectcat=' . $category[0]->get_id() . '" target="_blank"><img src=../img/calendar_up.gif alt=' . get_lang('ExportPDF') . '/> ' . get_lang('ExportPDF') . '</a>'; |
||||
|
||||
Display :: display_header(get_lang('ResultsPerUser')); |
||||
DisplayGradebook :: display_header_user($_GET['userid']); |
||||
echo $backto; |
||||
$user_table->display(); |
||||
Display :: display_footer(); |
||||
?> |
Loading…
Reference in new issue