This commit is contained in:
Xes
2025-08-14 22:37:50 +02:00
parent fb6d5d5926
commit 3641e93527
9156 changed files with 1813532 additions and 0 deletions

View File

@@ -0,0 +1,478 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Class CatForm.
*
* @author Stijn Konings
*/
class CatForm extends FormValidator
{
public const TYPE_ADD = 1;
public const TYPE_EDIT = 2;
public const TYPE_MOVE = 3;
public const TYPE_SELECT_COURSE = 4;
/** @var Category */
private $category_object;
/**
* CatForm constructor.
* Builds a form containing form items based on a given parameter.
*
* @param string $form_type 1=add, 2=edit,3=move,4=browse
* @param string $category_object
* @param string $form_name
* @param string $method
* @param null $action
*/
public function __construct(
$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;
}
switch ($this->form_type) {
case self::TYPE_EDIT:
$this->build_editing_form();
break;
case self::TYPE_ADD:
$this->build_add_form();
break;
case self::TYPE_MOVE:
$this->build_move_form();
break;
case self::TYPE_SELECT_COURSE:
$this->build_select_course_form();
break;
}
$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->setCustomElementTemplate('<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);
$line = 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 ('0' == $this->category_object->get_parent_id()) {
$this->setDefaults(
[
'select_course' => $this->category_object->get_course_code(),
'hid_user_id' => $this->category_object->get_user_id(),
'hid_parent_id' => $this->category_object->get_parent_id(),
]
);
} else {
$this->setDefaults(
[
'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()
{
$skills = $this->category_object->getSkillsForSelect();
$course_code = api_get_course_id();
$session_id = api_get_session_id();
$test_cats = Category::load(
null,
null,
$course_code,
null,
null,
$session_id,
false
);
$links = null;
if (isset($test_cats[0])) {
$links = $test_cats[0]->get_links();
}
$grade_model_id = $this->category_object->get_grade_model_id();
if (empty($links)) {
$grade_model_id = 0;
}
$category_name = $this->category_object->get_name();
// The main course category:
if (isset($this->category_object) && 0 == $this->category_object->get_parent_id()) {
if (empty($category_name)) {
$category_name = $course_code;
}
}
$this->setDefaults(
[
'name' => $category_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(),
'grade_model_id' => $grade_model_id,
'skills' => $skills,
'weight' => $this->category_object->get_weight(),
'visible' => $this->category_object->is_visible(),
'certif_min_score' => $this->category_object->getCertificateMinScore(),
'generate_certificates' => $this->category_object->getGenerateCertificates(),
'is_requirement' => $this->category_object->getIsRequirement(),
]
);
$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();
}
/**
* This function builds an 'select course' form in the add category process,
* if parent id is 0, it will only show courses.
*/
protected function build_select_course_form()
{
$select = $this->addElement(
'select',
'select_course',
[get_lang('PickACourse'), 'test'],
null
);
$courses = Category::get_all_courses(api_get_user_id());
//only return courses that are not yet created by the teacher
foreach ($courses as $row) {
$select->addOption($row[1], $row[0]);
}
$this->setDefaults([
'hid_user_id' => $this->category_object->get_user_id(),
'hid_parent_id' => $this->category_object->get_parent_id(),
]);
$this->addElement('hidden', 'hid_user_id');
$this->addElement('hidden', 'hid_parent_id');
$this->addElement('submit', null, get_lang('Ok'));
}
private function build_basic_form()
{
$this->addText(
'name',
get_lang('CategoryName'),
true,
['maxlength' => '50']
);
$this->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
if (isset($this->category_object) &&
$this->category_object->get_parent_id() == 0
) {
// we can't change the root category
$this->freeze('name');
}
$global_weight = api_get_setting('gradebook_default_weight');
$value = 100;
if (isset($global_weight)) {
$value = $global_weight;
}
$this->addFloat(
'weight',
[
get_lang('TotalWeight'),
get_lang('TotalSumOfWeights'),
],
true,
['value' => $value, 'maxlength' => '5']
);
$skillsDefaults = [];
$allowSkillEdit = api_is_platform_admin() || api_is_drh();
if (api_get_configuration_value('skills_teachers_can_assign_skills')) {
$allowSkillEdit = $allowSkillEdit || api_is_allowed_to_edit();
}
if ($allowSkillEdit) {
if (Skill::isToolAvailable()) {
$skillSelect = $this->addElement(
'select_ajax',
'skills',
[
get_lang('Skills'),
get_lang('SkillsAchievedWhenAchievingThisGradebook'),
],
null,
[
'id' => 'skills',
'multiple' => 'multiple',
'url' => api_get_path(WEB_AJAX_PATH).'skill.ajax.php?a=search_skills',
]
);
// The magic should be here
$skills = $this->category_object->get_skills();
foreach ($skills as $skill) {
$skillsDefaults[] = $skill['id'];
$skillSelect->addOption($skill['name'], $skill['id']);
}
}
}
$defaultCertification = 0;
if (!empty($this->category_object)) {
$defaultCertification = $this->category_object->getCertificateMinScore();
}
if (isset($this->category_object) &&
0 == $this->category_object->get_parent_id()
) {
$model = ExerciseLib::getCourseScoreModel();
if (empty($model)) {
$this->addText(
'certif_min_score',
get_lang('CertificateMinScore'),
true,
['maxlength' => '5']
);
if (true === api_get_configuration_value('gradebook_enable_subcategory_skills_independant_assignement')) {
// It allows the acquisition of competencies independently in the subcategories
$allowSkillsBySubCategory = $this->addCheckBox(
'allow_skills_by_subcategory',
[
null,
get_lang('ItAllowsTheAcquisitionOfSkillsBySubCategories'),
],
get_lang('AllowsSkillsBySubCategories')
);
$allowSkillsBySubCategory->setChecked($this->category_object->getAllowSkillBySubCategory());
}
} else {
$questionWeighting = $value;
$defaultCertification = api_number_format($this->category_object->getCertificateMinScore(), 2);
$select = $this->addSelect(
'certif_min_score',
get_lang('CertificateMinScore'),
[],
['disable_js' => true]
);
foreach ($model['score_list'] as $item) {
$i = api_number_format($item['score_to_qualify'] / 100 * $questionWeighting, 2);
$model = ExerciseLib::getModelStyle($item, $i);
$attributes = ['class' => $item['css_class']];
if ($defaultCertification == $i) {
$attributes['selected'] = 'selected';
}
$select->addOption($model, $i, $attributes);
}
$select->updateSelectWithSelectedOption($this);
}
$this->addRule(
'certif_min_score',
get_lang('OnlyNumbers'),
'numeric'
);
$this->addRule(
'certif_min_score',
get_lang('NegativeValue'),
'compare',
'>=',
'server',
false,
false,
0
);
} else {
// It enables minimun score to get the skills independant assigment
if (true === api_get_configuration_value('gradebook_enable_subcategory_skills_independant_assignement')) {
$allowSkillsBySubCategory = $this->category_object->getAllowSkillBySubCategory($this->category_object->get_parent_id());
if ($allowSkillsBySubCategory) {
$this->addText(
'certif_min_score',
get_lang('SkillMinScore'),
true,
['maxlength' => '5']
);
$this->addRule(
'certif_min_score',
get_lang('OnlyNumbers'),
'numeric'
);
$this->addRule(
'certif_min_score',
get_lang('NegativeValue'),
'compare',
'>=',
'server',
false,
false,
0
);
}
}
$this->addElement('checkbox', 'visible', null, get_lang('Visible'));
}
$this->addElement('hidden', 'hid_user_id');
$this->addElement('hidden', 'hid_parent_id');
$this->addElement(
'textarea',
'description',
get_lang('Description')
);
if (isset($this->category_object) &&
$this->category_object->get_parent_id() == 0 &&
(api_is_platform_admin() || api_get_setting('teachers_can_change_grade_model_settings') == 'true')
) {
// Getting grade models
$obj = new GradeModel();
$obj->fill_grade_model_select_in_form(
$this,
'grade_model_id',
$this->category_object->get_grade_model_id()
);
// Freeze or not
$course_code = api_get_course_id();
$session_id = api_get_session_id();
$test_cats = Category::load(
null,
null,
$course_code,
null,
null,
$session_id,
false
);
$links = null;
if (!empty($test_cats[0])) {
$links = $test_cats[0]->get_links();
}
if (count($test_cats) > 1 || !empty($links)) {
if ('true' == api_get_setting('gradebook_enable_grade_model')) {
$this->freeze('grade_model_id');
}
}
$generateCertificatesParams = [];
if ($this->category_object->getGenerateCertificates()) {
$generateCertificatesParams['checked'] = 'checked';
}
$this->addElement(
'checkbox',
'generate_certificates',
null,
get_lang('GenerateCertificates'),
$generateCertificatesParams
);
}
//if (!empty($session_id)) {
$isRequirementCheckbox = $this->addCheckBox(
'is_requirement',
[
null,
get_lang('ConsiderThisGradebookAsRequirementForASessionSequence'),
],
get_lang('IsRequirement')
);
//}
if ($this->category_object->getIsRequirement()) {
$isRequirementCheckbox->setChecked(true);
}
$documentId = $this->category_object->getDocumentId();
if (!empty($documentId)) {
$documentData = DocumentManager::get_document_data_by_id($documentId, api_get_course_id());
if (!empty($documentData)) {
$this->addLabel(get_lang('Certificate'), $documentData['title']);
}
}
if ($this->form_type == self::TYPE_ADD) {
$this->addButtonCreate(get_lang('AddCategory'));
} else {
$this->addElement('hidden', 'editcat', intval($_GET['editcat']));
$this->addButtonUpdate(get_lang('EditCategory'));
}
$setting = api_get_setting('tool_visible_by_default_at_creation');
$visibility_default = 1;
if (isset($setting['gradebook']) && $setting['gradebook'] == 'false') {
$visibility_default = 0;
}
$this->setDefaults(
[
'visible' => $visibility_default,
'skills' => $skillsDefaults,
'certif_min_score' => (string) $defaultCertification,
]
);
}
}

View File

@@ -0,0 +1,126 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Extends FormValidator with import and export forms.
*
* @author Stijn Konings
*/
class DataForm extends FormValidator
{
public const TYPE_IMPORT = 1;
public const TYPE_EXPORT = 2;
public 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
*/
public function __construct(
$form_type,
$form_name,
$method = 'post',
$action = null,
$target = '',
$locked_status
) {
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) {
if ($locked_status == 0) {
$this->build_export_form_option(false);
} else {
$this->build_export_form();
}
} elseif ($this->form_type == self::TYPE_EXPORT_PDF) {
$this->build_pdf_export_form();
}
$this->setDefaults();
}
public function display()
{
parent::display();
}
public function setDefaults($defaults = [], $filter = null)
{
parent::setDefaults($defaults, $filter);
}
protected function build_pdf_export_form()
{
$renderer = &$this->defaultRenderer();
$renderer->setCustomElementTemplate('<span>{element}</span>');
$this->addElement('header', get_lang('ChooseOrientation'));
$this->addElement('radio', 'orientation', null, get_lang('Portrait'), 'portrait');
$this->addElement('radio', 'orientation', null, get_lang('Landscape'), 'landscape');
$this->addButtonExport(get_lang('Export'));
$this->setDefaults([
'orientation' => 'portrait',
]);
}
protected function build_export_form()
{
$this->addElement('header', 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->addButtonExport(get_lang('Export'));
$this->setDefaults([
'file_type' => 'csv',
]);
}
protected function build_export_form_option($show_pdf = true)
{
$this->addElement('header', 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',
Display::return_icon('info3.gif', get_lang('ToExportMustLockEvaluation')),
'PDF (Portable Document Format)',
'pdf',
['disabled']
);
$this->addButtonExport(get_lang('Export'));
$this->setDefaults([
'file_type' => 'csv',
]);
}
protected function build_import_form()
{
$this->addElement('hidden', 'formSent');
$this->addElement('header', get_lang('ImportFileLocation'));
$this->addElement('file', 'import_file', get_lang('Location'));
$this->addElement(
'radio',
'file_type',
get_lang('FileType'),
'CSV (<a href="docs/example_csv.html" target="_blank" download>'
.get_lang('ExampleCSVFile')
.'</a>)',
'csv'
);
//$this->addElement('radio', 'file_type', null, 'XML (<a href="docs/example_xml.html" target="_blank" download>'.get_lang('ExampleXMLFile').'</a>)', 'xml');
$this->addElement('checkbox', 'overwrite', null, get_lang('OverwriteScores'));
$this->addElement('checkbox', 'ignoreerrors', null, get_lang('IgnoreErrors'));
$this->addButtonImport(get_lang('Ok'));
$this->setDefaults([
'formSent' => '1',
'file_type' => 'csv',
]);
}
}

View File

@@ -0,0 +1,734 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Class DisplayGradebook.
*/
class DisplayGradebook
{
/**
* Displays the header for the result page containing the navigation tree and links.
*
* @param Evaluation $evalobj
* @param int $selectcat
* @param string $page
*/
public static function display_header_result($evalobj, $selectcat, $page)
{
$header = null;
if (api_is_allowed_to_edit(null, true)) {
$header = '<div class="actions">';
if ('statistics' !== $page) {
$header .= '<a href="'.Category::getUrl().'selectcat='.$selectcat.'">'
.Display::return_icon('back.png', get_lang('FolderView'), [], ICON_SIZE_MEDIUM)
.'</a>';
if (($evalobj->get_course_code() != null) && !$evalobj->has_results()) {
$header .= '<a href="gradebook_add_result.php?'.api_get_cidreq().'&selectcat='.$selectcat.'&selecteval='.$evalobj->get_id().'">'
.Display::return_icon('evaluation_rate.png', get_lang('AddResult'), '', ICON_SIZE_MEDIUM)
.'</a>';
}
if (api_is_platform_admin() || $evalobj->is_locked() == false) {
$header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&selecteval='.$evalobj->get_id().'&import=">'
.Display::return_icon('import_evaluation.png', get_lang('ImportResult'), [], ICON_SIZE_MEDIUM)
.'</a>';
}
if ($evalobj->has_results()) {
$header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&selecteval='.$evalobj->get_id().'&export=">'
.Display::return_icon('export_evaluation.png', get_lang('ExportResult'), [], ICON_SIZE_MEDIUM)
.'</a>';
if (api_is_platform_admin() || !$evalobj->is_locked()) {
$header .= '<a href="gradebook_edit_result.php?'.api_get_cidreq().'&selecteval='.$evalobj->get_id().'">'
.Display::return_icon('edit.png', get_lang('EditResult'), [], ICON_SIZE_MEDIUM)
.'</a>';
$header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&selecteval='.$evalobj->get_id().'&deleteall=" onclick="return confirmationall();">'
.Display::return_icon('delete.png', get_lang('DeleteResult'), [], ICON_SIZE_MEDIUM).'</a>';
}
}
$header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&print=&selecteval='.$evalobj->get_id().'" target="_blank">'
.Display::return_icon('printer.png', get_lang('Print'), [], ICON_SIZE_MEDIUM).'</a>';
} else {
$header .= '<a href="gradebook_view_result.php?'.api_get_cidreq().'&selecteval='.Security::remove_XSS($_GET['selecteval']).'"> '
.Display::return_icon('back.png', get_lang('FolderView'), [], ICON_SIZE_MEDIUM).'</a>';
}
$header .= '</div>';
}
$scoredisplay = ScoreDisplay::instance();
$student_score = '';
$average = '';
if ($evalobj->has_results()) {
// TODO this check needed ?
$score = $evalobj->calc_score();
if (null != $score) {
$model = ExerciseLib::getCourseScoreModel();
if (empty($model)) {
$average = get_lang('Average').' :<b> '.$scoredisplay->display_score($score, SCORE_AVERAGE).'</b>';
$student_score = $evalobj->calc_score(api_get_user_id());
$student_score = Display::tag(
'h3',
get_lang('Score').': '.$scoredisplay->display_score($student_score, SCORE_DIV_PERCENT)
);
$allowMultipleAttempts = api_get_configuration_value('gradebook_multiple_evaluation_attempts');
if ($allowMultipleAttempts) {
$results = Result::load(null, api_get_user_id(), $evalobj->get_id());
if (!empty($results)) {
/** @var Result $resultData */
foreach ($results as $resultData) {
$student_score .= ResultTable::getResultAttemptTable($resultData);
}
}
}
}
}
}
$description = '';
if ('' == !$evalobj->get_description()) {
$description = get_lang('Description').' :<b> '.Security::remove_XSS($evalobj->get_description()).'</b><br>';
}
if ($evalobj->get_course_code() == null) {
$course = get_lang('CourseIndependent');
} else {
$course = CourseManager::getCourseNameFromCode($evalobj->get_course_code());
}
$evalinfo = '<table width="100%" border="0"><tr><td>';
$evalinfo .= '<h2>'.Security::remove_XSS($evalobj->get_name()).'</h2><hr>';
$evalinfo .= $description;
$evalinfo .= get_lang('Course').' :<b> '.$course.'</b><br />';
if (empty($model)) {
$evalinfo .= get_lang('QualificationNumeric').' :<b> '.$evalobj->get_max().'</b><br>'.$average;
}
if (!api_is_allowed_to_edit()) {
$evalinfo .= $student_score;
}
if (!$evalobj->has_results()) {
$evalinfo .= '<br /><i>'.get_lang('NoResultsInEvaluation').'</i>';
}
if ($page != 'statistics') {
if (api_is_allowed_to_edit(null, true)) {
$evalinfo .= '<br /><a href="gradebook_statistics.php?'.api_get_cidreq().'&selecteval='.Security::remove_XSS($_GET['selecteval']).'"> '
.Display::return_icon(
'statistics.png',
get_lang('ViewStatistics'),
[],
ICON_SIZE_MEDIUM
).'</a>';
}
}
$evalinfo .= '</td><td>'
.Display::return_icon(
'tutorial.gif',
'',
['style' => 'float:right; position:relative;']
)
.'</td></table>';
echo $evalinfo;
echo $header;
}
/**
* Displays the header for the flatview page containing filters.
*
* @param $catobj
* @param $showeval
* @param $showlink
*/
public static function display_header_reduce_flatview($catobj, $showeval, $showlink, $simple_search_form)
{
$header = '<div class="actions">';
if ($catobj->get_parent_id() == 0) {
$select_cat = $catobj->get_id();
$url = Category::getUrl();
} else {
$select_cat = $catobj->get_parent_id();
$url = 'gradebook_flatview.php';
}
$header .= '<a href="'.$url.'?'.api_get_cidreq().'&selectcat='.$select_cat.'">'
.Display::return_icon('back.png', get_lang('FolderView'), [], ICON_SIZE_MEDIUM).'</a>';
$pageNum = isset($_GET['flatviewlist_page_nr']) ? (int) $_GET['flatviewlist_page_nr'] : null;
$perPage = isset($_GET['flatviewlist_per_page']) ? (int) $_GET['flatviewlist_per_page'] : null;
$offset = $_GET['offset'] ?? '0';
$exportCsvUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
'export_format' => 'csv',
'export_report' => 'export_report',
'selectcat' => $catobj->get_id(),
]);
$scoreRanking = ScoreDisplay::instance()->get_custom_score_display_settings();
$attributes = [];
if (!empty($scoreRanking)) {
$attributes = ['class' => 'export_opener'];
}
$header .= Display::url(
Display::return_icon(
'export_csv.png',
get_lang('ExportAsCSV'),
'',
ICON_SIZE_MEDIUM
),
$exportCsvUrl,
$attributes
);
$exportXlsUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
'export_format' => 'xls',
'export_report' => 'export_report',
'selectcat' => $catobj->get_id(),
]);
$header .= Display::url(
Display::return_icon(
'export_excel.png',
get_lang('ExportAsXLS'),
'',
ICON_SIZE_MEDIUM
),
$exportXlsUrl,
$attributes
);
$exportDocUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
'export_format' => 'doc',
'export_report' => 'export_report',
'selectcat' => $catobj->get_id(),
]);
$header .= Display::url(
Display::return_icon(
'export_doc.png',
get_lang('ExportAsDOC'),
'',
ICON_SIZE_MEDIUM
),
$exportDocUrl,
$attributes
);
$exportPrintUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
'print' => '',
'selectcat' => $catobj->get_id(),
]);
$header .= Display::url(
Display::return_icon(
'printer.png',
get_lang('Print'),
'',
ICON_SIZE_MEDIUM
),
$exportPrintUrl,
['target' => '_blank']
);
$exportPdfUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
'exportpdf' => '',
'selectcat' => $catobj->get_id(),
'offset' => $offset,
'flatviewlist_page_nr' => $pageNum,
'flatviewlist_per_page' => $perPage,
]);
$header .= Display::url(
Display::return_icon(
'pdf.png',
get_lang('ExportToPDF'),
'',
ICON_SIZE_MEDIUM
),
$exportPdfUrl
);
$header .= '</div>';
$dialog = '';
if (!empty($scoreRanking)) {
$dialog = '<div id="dialog-confirm" style="display:none" title="'.get_lang('ConfirmYourChoice').'">';
$form = new FormValidator(
'report',
'post',
null,
null,
['class' => 'form-vertical']
);
$form->addCheckBox(
'only_score',
null,
get_lang('OnlyNumbers')
);
$dialog .= $form->returnForm();
$dialog .= '</div>';
}
echo $header.$dialog;
}
/**
* Displays the header for the gradebook containing the navigation tree and links.
*
* @param Category $catobj
* @param int $showtree '1' will show the browse tree and naviation buttons
* @param $selectcat
* @param bool $is_course_admin
* @param bool $is_platform_admin
* @param bool $simple_search_form
* @param bool $show_add_qualification Whether to show or not the link to add a new qualification
* (we hide it in case of the course-embedded tool where we have only one
* per course or session)
* @param bool $show_add_link Whether to show or not the link to add a new item inside
* the qualification (we hide it in case of the course-embedded tool
* where we have only one qualification per course or session)
* @param array $certificateLinkInfo
*/
public static function header(
$catobj,
$showtree,
$selectcat,
$is_course_admin,
$is_platform_admin,
$simple_search_form,
$show_add_qualification = true,
$show_add_link = true,
$certificateLinkInfo = []
) {
$userId = api_get_user_id();
$courseId = api_get_course_int_id();
$sessionId = api_get_session_id();
if (!$is_course_admin) {
$model = ExerciseLib::getCourseScoreModel();
if (!empty($model)) {
return '';
}
}
// Student.
$status = CourseManager::getUserInCourseStatus($userId, $courseId);
$sessionStatus = 0;
if (!empty($sessionId)) {
$sessionStatus = SessionManager::get_user_status_in_course_session(
$userId,
$courseId,
$sessionId
);
}
$objcat = new Category();
$course_id = CourseManager::get_course_by_category($selectcat);
$message_resource = $objcat->show_message_resource_delete($course_id);
$grade_model_id = $catobj->get_grade_model_id();
$header = null;
if (isset($catobj) && !empty($catobj)) {
$categories = Category::load(
null,
null,
null,
$catobj->get_id(),
null,
$sessionId
);
}
if (!$is_course_admin && ($status != 1 || $sessionStatus == 0) && $selectcat != 0) {
$catcourse = Category::load($catobj->get_id());
/** @var Category $category */
$category = $catcourse[0];
$main_weight = $category->get_weight();
$scoredisplay = ScoreDisplay::instance();
$allevals = $category->get_evaluations($userId, true);
$alllinks = $category->get_links($userId, true);
$allEvalsLinks = array_merge($allevals, $alllinks);
$item_value_total = 0;
$scoreinfo = null;
for ($count = 0; $count < count($allEvalsLinks); $count++) {
$item = $allEvalsLinks[$count];
$score = $item->calc_score($userId);
if (!empty($score)) {
$divide = $score[1] == 0 ? 1 : $score[1];
$item_value = $score[0] / $divide * $item->get_weight();
$item_value_total += $item_value;
}
}
$item_total = $main_weight;
$total_score = [$item_value_total, $item_total];
$scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);
if (!$catobj->get_id() == '0' && !isset($_GET['studentoverview']) && !isset($_GET['search'])) {
$additionalButtons = null;
if (!empty($certificateLinkInfo)) {
$additionalButtons .= '<div class="btn-group pull-right">';
$additionalButtons .= $certificateLinkInfo['certificate_link'] ?? '';
$additionalButtons .= $certificateLinkInfo['badge_link'] ?? '';
$additionalButtons .= '</div>';
}
$scoreinfo .= '<strong>'.sprintf(get_lang('TotalX'), $scorecourse_display.$additionalButtons).'</strong>';
}
echo Display::return_message($scoreinfo, 'normal', false);
}
// show navigation tree and buttons?
if ($showtree == '1' || isset($_GET['studentoverview'])) {
$header = '<div class="actions"><table>';
$header .= '<tr>';
if (!$selectcat == '0') {
$header .= '<td><a href="'.api_get_self().'?selectcat='.$catobj->get_parent_id().'">'
.Display::return_icon(
'back.png',
get_lang('BackTo').' '.get_lang('RootCat'),
[],
ICON_SIZE_MEDIUM
)
.'</a></td>';
}
$header .= '<td>'.get_lang('CurrentCategory').'</td>'
.'<td><form name="selector"><select name="selectcat" onchange="document.selector.submit()">';
$cats = Category::load();
$tree = $cats[0]->get_tree();
unset($cats);
foreach ($tree as $cat) {
$line = str_repeat('&mdash;', $cat[2]);
if (isset($_GET['selectcat']) && $_GET['selectcat'] == $cat[0]) {
$header .= '<option selected value='.$cat[0].'>'.$line.' '.$cat[1].'</option>';
} else {
$header .= '<option value='.$cat[0].'>'.$line.' '.$cat[1].'</option>';
}
}
$header .= '</select></form></td>';
if (!empty($simple_search_form) && $message_resource === false) {
$header .= '<td style="vertical-align: top;">'.$simple_search_form->toHtml().'</td>';
} else {
$header .= '<td></td>';
}
if (!($is_course_admin &&
$message_resource === false &&
isset($_GET['selectcat']) && $_GET['selectcat'] != 0) &&
isset($_GET['studentoverview'])
) {
$header .= '<td style="vertical-align: top;">
<a href="'.api_get_self().'?'.api_get_cidreq().'&studentoverview=&exportpdf=&selectcat='.$catobj->get_id().'" target="_blank">
'.Display::return_icon('pdf.png', get_lang('ExportPDF'), [], ICON_SIZE_MEDIUM).'
'.get_lang('ExportPDF').'</a>';
}
$header .= '</td></tr>';
$header .= '</table></div>';
}
// for course admin & platform admin add item buttons are added to the header
$actionsLeft = '';
$actionsRight = '';
$my_api_cidreq = api_get_cidreq();
$isCoach = api_is_coach(api_get_session_id(), api_get_course_int_id());
$accessToRead = api_is_allowed_to_edit(null, true) || $isCoach;
$accessToEdit = api_is_allowed_to_edit(null, true);
$courseCode = api_get_course_id();
if ($accessToRead) {
$my_category = $catobj->showAllCategoryInfo($catobj->get_id());
if ($selectcat != '0' && $accessToEdit) {
if ($my_api_cidreq == '') {
$my_api_cidreq = 'cidReq='.$my_category['course_code'];
}
if ($show_add_link && !$message_resource) {
$actionsLeft .= '<a href="gradebook_add_eval.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'" >'
.Display::return_icon('new_evaluation.png', get_lang('NewEvaluation'), [], ICON_SIZE_MEDIUM)
.'</a>';
$cats = Category::load($selectcat);
if ($cats[0]->get_course_code() != null && !$message_resource) {
$actionsLeft .= '<a href="gradebook_add_link.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'
.Display::return_icon('new_online_evaluation.png', get_lang('MakeLink'), [], ICON_SIZE_MEDIUM)
.'</a>';
} else {
$actionsLeft .= '<a href="gradebook_add_link_select_course.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'
.Display::return_icon('new_online_evaluation.png', get_lang('MakeLink'), [], ICON_SIZE_MEDIUM)
.'</a>';
}
}
}
if ((empty($grade_model_id) || $grade_model_id == -1) && $accessToEdit) {
$actionsLeft .= '<a href="gradebook_add_cat.php?'.api_get_cidreq().'&selectcat='.$catobj->get_id().'">'
.Display::return_icon(
'new_folder.png',
get_lang('AddGradebook'),
[],
ICON_SIZE_MEDIUM
).'</a></td>';
}
if ($selectcat != '0') {
if (!$message_resource) {
$actionsLeft .= '<a href="gradebook_flatview.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'
.Display::return_icon('statistics.png', get_lang('FlatView'), [], ICON_SIZE_MEDIUM)
.'</a>';
if ($my_category['generate_certificates'] == 1) {
$actionsLeft .= Display::url(
Display::return_icon(
'certificate_list.png',
get_lang('GradebookSeeListOfStudentsCertificates'),
'',
ICON_SIZE_MEDIUM
),
"gradebook_display_certificate.php?$my_api_cidreq&cat_id=".$selectcat
);
}
$actionsLeft .= Display::url(
Display::return_icon(
'user.png',
get_lang('GradebookListOfStudentsReports'),
'',
ICON_SIZE_MEDIUM
),
"gradebook_display_summary.php?$my_api_cidreq&selectcat=".$selectcat
);
$allow = api_get_configuration_value('gradebook_custom_student_report');
if ($allow) {
$actionsLeft .= Display::url(
get_lang('GenerateCustomReport'),
api_get_path(WEB_AJAX_PATH)."gradebook.ajax.php?$my_api_cidreq&a=generate_custom_report",
['class' => 'btn btn-default ajax']
);
}
// Right icons
if ($accessToEdit) {
$actionsRight = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id(
).'&cidReq='.$catobj->get_course_code().'&id_session='.$catobj->get_session_id().'">'
.Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_MEDIUM)
.'</a>';
if (api_get_plugin_setting('customcertificate', 'enable_plugin_customcertificate') === 'true' &&
api_get_course_setting('customcertificate_course_enable') == 1
) {
$actionsRight .= '<a href="'.api_get_path(WEB_PLUGIN_PATH).'customcertificate/src/index.php?'
.$my_api_cidreq.'&origin=gradebook&selectcat='.$catobj->get_id().'">'.
Display::return_icon(
'certificate.png',
get_lang('AttachCertificate'),
[],
ICON_SIZE_MEDIUM
).'</a>';
} else {
$actionsRight .= '<a href="'.api_get_path(WEB_CODE_PATH)
.'document/document.php?curdirpath=/certificates&'.$my_api_cidreq
.'&origin=gradebook&selectcat='.$catobj->get_id().'">'.
Display::return_icon(
'certificate.png',
get_lang('AttachCertificate'),
[],
ICON_SIZE_MEDIUM
).'</a>';
}
if (empty($categories)) {
$actionsRight .= '<a href="gradebook_edit_all.php?id_session='.api_get_session_id()
.'&'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'
.Display::return_icon(
'percentage.png',
get_lang('EditAllWeights'),
[],
ICON_SIZE_MEDIUM
).'</a>';
}
$score_display_custom = api_get_setting('gradebook_score_display_custom');
if (api_get_setting('teachers_can_change_score_settings') == 'true' &&
$score_display_custom['my_display_custom'] == 'true'
) {
$actionsRight .= '<a href="gradebook_scoring_system.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'
.Display::return_icon('ranking.png', get_lang('ScoreEdit'), [], ICON_SIZE_MEDIUM).'</a>';
}
}
}
}
} elseif (isset($_GET['search'])) {
echo $header = '<b>'.get_lang('SearchResults').' :</b>';
}
$isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
api_get_user_id(),
api_get_course_info()
);
if ($isDrhOfCourse) {
$actionsLeft .= '<a href="gradebook_flatview.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'
.Display::return_icon(
'statistics.png',
get_lang('FlatView'),
[],
ICON_SIZE_MEDIUM
)
.'</a>';
}
if ($isCoach || api_is_allowed_to_edit(null, true)) {
echo $toolbar = Display::toolbarAction(
'gradebook-actions',
[$actionsLeft, $actionsRight]
);
}
if ($accessToEdit || api_is_allowed_to_edit(null, true)) {
$weight = intval($catobj->get_weight()) > 0 ? $catobj->get_weight() : 0;
$weight = '<strong>'.get_lang('TotalWeight').' : </strong>'.$weight;
$min_certification = intval($catobj->getCertificateMinScore() > 0) ? $catobj->getCertificateMinScore() : 0;
if (!empty($min_certification)) {
$model = ExerciseLib::getCourseScoreModel();
if (!empty($model)) {
$defaultCertification = api_number_format($min_certification, 2);
$questionWeighting = $catobj->get_weight();
foreach ($model['score_list'] as $item) {
$i = api_number_format($item['score_to_qualify'] / 100 * $questionWeighting, 2);
$model = ExerciseLib::getModelStyle($item, $i);
if ($defaultCertification == $i) {
$min_certification = $model;
break;
}
}
}
}
$min_certification = get_lang('CertificateMinScore').' : '.$min_certification;
$edit_icon = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id().'&cidReq='.$catobj->get_course_code().'&id_session='.$catobj->get_session_id().'">'
.Display::return_icon('edit.png', get_lang('Edit')).'</a>';
$msg = $weight.' - '.$min_certification.$edit_icon;
//@todo show description
$description = (($catobj->get_description() == '' || is_null($catobj->get_description())) ? '' : '<strong>'.get_lang('GradebookDescriptionLog').'</strong>'.': '.$catobj->get_description());
echo Display::return_message($msg, 'normal', false);
if (!empty($description)) {
echo Display::div($description, []);
}
}
}
/**
* @param Category $catobj
* @param $is_course_admin
* @param $is_platform_admin
* @param $simple_search_form
* @param bool $show_add_qualification
* @param bool $show_add_link
*/
public function display_reduce_header_gradebook(
$catobj,
$is_course_admin,
$is_platform_admin,
$simple_search_form,
$show_add_qualification = true,
$show_add_link = true
) {
//student
if (!$is_course_admin) {
$user = api_get_user_info(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['complete_name'].'</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::addFlash(
Display::return_message($scoreinfo, 'normal', false)
);
}
// show navigation tree and buttons?
$header = '<div class="actions">';
if ($is_course_admin) {
$header .= '<a href="gradebook_flatview.php?'.api_get_cidreq().'&selectcat='.$catobj->get_id().'">'
.Display::return_icon('statistics.png', get_lang('FlatView'), [], ICON_SIZE_MEDIUM).'</a>';
$header .= '<a href="gradebook_scoring_system.php?'.api_get_cidreq().'&selectcat='.$catobj->get_id().'">'
.Display::return_icon('settings.png', get_lang('ScoreEdit'), [], ICON_SIZE_MEDIUM).'</a>';
} elseif (!(isset($_GET['studentoverview']))) {
$header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&studentoverview=&selectcat='.$catobj->get_id().'">'
.Display::return_icon('view_list.gif', get_lang('FlatView')).' '.get_lang('FlatView').'</a>';
} else {
$header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&studentoverview=&exportpdf=&selectcat='.$catobj->get_id().'" target="_blank">'
.Display::return_icon('pdf.png', get_lang('ExportPDF'), [], ICON_SIZE_MEDIUM).'</a>';
}
$header .= '</div>';
echo $header;
}
/**
* @param int $userId
* @param int $categoryId
*
* @return string
*/
public static function display_header_user($userId, $categoryId)
{
$user = api_get_user_info($userId);
if (empty($user)) {
return '';
}
$catcourse = Category::load($categoryId);
$scoredisplay = ScoreDisplay::instance();
// generating the total score for a course
$allevals = $catcourse[0]->get_evaluations(
$userId,
true,
api_get_course_id()
);
$alllinks = $catcourse[0]->get_links(
$userId,
true,
api_get_course_id()
);
$evals_links = array_merge($allevals, $alllinks);
$item_value = 0;
$item_total = 0;
for ($count = 0; $count < count($evals_links); $count++) {
$item = $evals_links[$count];
$score = $item->calc_score($userId);
if ($score) {
$my_score_denom = ($score[1] == 0) ? 1 : $score[1];
$item_value += $score[0] / $my_score_denom * $item->get_weight();
}
$item_total += $item->get_weight();
}
$item_value = api_number_format($item_value, 2);
$total_score = [$item_value, $item_total];
$scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);
$info = '<div class="row"><div class="col-md-3">';
$info .= '<div class="thumbnail"><img src="'.$user['avatar'].'" /></div>';
$info .= '</div>';
$info .= '<div class="col-md-6">';
$info .= get_lang('Name').' : '.$user['complete_name_with_message_link'].'<br />';
if (api_get_setting('show_email_addresses') === 'true') {
$info .= get_lang('Email').' : <a href="mailto:'.$user['email'].'">'.$user['email'].'</a><br />';
}
$info .= get_lang('TotalUser').' : <b>'.$scorecourse_display.'</b>';
$info .= '</div>';
$info .= '</div>';
echo $info;
}
}

View File

@@ -0,0 +1,768 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Class EvalForm.
*
* Extends FormValidator with add&edit forms for evaluations
*
* @author Stijn Konings
*/
class EvalForm extends FormValidator
{
public const TYPE_ADD = 1;
public const TYPE_EDIT = 2;
public const TYPE_MOVE = 3;
public const TYPE_RESULT_ADD = 4;
public const TYPE_RESULT_EDIT = 5;
public const TYPE_ALL_RESULTS_EDIT = 6;
public const TYPE_ADD_USERS_TO_EVAL = 7;
protected $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 Evaluation $evaluation_object the category object
* @param obj $result_object the result object
* @param string $form_name
* @param string $method
* @param string $action
*/
public function __construct(
$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;
}
switch ($form_type) {
case self::TYPE_EDIT:
$this->build_editing_form();
break;
case self::TYPE_ADD:
$this->build_add_form();
break;
case self::TYPE_MOVE:
$this->build_editing_form();
break;
case self::TYPE_RESULT_ADD:
$this->build_result_add_form();
break;
case self::TYPE_RESULT_EDIT:
$this->build_result_edit_form();
break;
case self::TYPE_ALL_RESULTS_EDIT:
$this->build_all_results_edit_form();
break;
case self::TYPE_ADD_USERS_TO_EVAL:
$this->build_add_user_to_eval();
break;
}
$this->protect();
$this->setDefaults();
}
public function display()
{
parent::display();
}
public function setDefaults($defaults = [], $filter = null)
{
parent::setDefaults($defaults, $filter);
}
public function sort_by_user($item1, $item2)
{
$user1 = $item1['user'];
$user2 = $item2['user'];
if (api_sort_by_first_name()) {
$result = api_strcmp($user1['firstname'], $user2['firstname']);
if (0 == $result) {
return api_strcmp($user1['lastname'], $user2['lastname']);
}
} else {
$result = api_strcmp($user1['lastname'], $user2['lastname']);
if (0 == $result) {
return api_strcmp($user1['firstname'], $user2['firstname']);
}
}
return $result;
}
/**
* This form will build a form to add users to an evaluation.
*/
protected function build_add_user_to_eval()
{
$this->addElement('header', get_lang('ChooseUser'));
$select = $this->addElement(
'select',
'firstLetterUser',
get_lang('FirstLetter'),
null,
[
'onchange' => 'document.add_users_to_evaluation.submit()',
]
);
$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,
[
'multiple' => 'multiple',
'size' => '15',
'style' => 'width:250px',
]
);
foreach ($this->evaluation_object->get_not_subscribed_students() as $user) {
if ((!isset($this->extra)) || empty($this->extra) || api_strtoupper(api_substr($user[1], 0, 1)) == $this->extra
) {
$select->addOption($user[1].' '.$user[2].' ('.$user[3].')', $user[0]);
}
}
$this->addButtonCreate(get_lang('AddUserToEval'), 'submit_button');
}
/**
* 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('header', get_lang('EditResult'));
$renderer = &$this->defaultRenderer();
// set new form template
$form_template = '<form{attributes}>
<div class="table-responsive">
<table class="table table-hover table-striped data_table" border="0" cellpadding="5" cellspacing="5">{content}</table>
</div>
</form>';
$renderer->setFormTemplate($form_template);
$skillRelItemsEnabled = api_get_configuration_value('allow_skill_rel_items');
$columnSkill = '';
if ($skillRelItemsEnabled) {
$columnSkill = '<th>'.get_lang('Skills').'</th>';
}
if (api_is_western_name_order()) {
$renderer->setHeaderTemplate(
'<tr>
<th>'.get_lang('OfficialCode').'</th>
<th>'.get_lang('UserName').'</th>
<th>'.get_lang('FirstName').'</th>
<th>'.get_lang('LastName').'</th>
<th>'.get_lang('Qualify').'</th>
'.$columnSkill.'
</tr>'
);
} else {
$renderer->setHeaderTemplate(
'<tr>
<th>'.get_lang('OfficialCode').'</th>
<th>'.get_lang('UserName').'</th>
<th>'.get_lang('LastName').'</th>
<th>'.get_lang('FirstName').'</th>
<th>'.get_lang('Qualify').'</th>
'.$columnSkill.'
</tr>'
);
}
$template_submit = '<tr>
<td colspan="4" ></td>
<td>
{element}
<!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error -->
</td>
'.($skillRelItemsEnabled ? '<td></td>' : '').'
</tr>';
$results_and_users = [];
foreach ($this->result_object as $result) {
$user = api_get_user_info($result->get_user_id());
$results_and_users[] = ['result' => $result, 'user' => $user];
}
usort($results_and_users, ['EvalForm', 'sort_by_user']);
$defaults = [];
$model = ExerciseLib::getCourseScoreModel();
foreach ($results_and_users as $result_and_user) {
$user = $result_and_user['user'];
/** @var \Result $result */
$result = $result_and_user['result'];
$renderer = &$this->defaultRenderer();
$columnSkillResult = '';
if ($skillRelItemsEnabled) {
$columnSkillResult = '<td>'.Skill::getAddSkillsToUserBlock(ITEM_TYPE_GRADEBOOK_EVALUATION, $result->get_evaluation_id(), $result->get_user_id(), $result->get_id()).'</td>';
}
if (api_is_western_name_order()) {
$user_info = '<td align="left" >'.$user['firstname'].'</td>';
$user_info .= '<td align="left" >'.$user['lastname'].'</td>';
} else {
$user_info = '<td align="left" >'.$user['lastname'].'</td>';
$user_info .= '<td align="left" >'.$user['firstname'].'</td>';
}
$template = '<tr>
<td align="left" >'.$user['official_code'].'</td>
<td align="left" >'.$user['username'].'</td>
'.$user_info.'
<td align="left">{element} / '.$this->evaluation_object->get_max().'
<!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error -->
</td>
'.$columnSkillResult.'
</tr>';
if (empty($model)) {
$this->addFloat(
'score['.$result->get_id().']',
$this->build_stud_label($user['user_id'], $user['username'], $user['lastname'], $user['firstname']),
false,
[
'maxlength' => 5,
],
false,
0,
$this->evaluation_object->get_max()
);
$defaults['score['.$result->get_id().']'] = $result->get_score();
} else {
$questionWeighting = $this->evaluation_object->get_max();
$select = $this->addSelect(
'score['.$result->get_id().']',
get_lang('Score'),
[],
['disable_js' => true, 'id' => 'score_'.$result->get_id()]
);
foreach ($model['score_list'] as $item) {
$i = api_number_format($item['score_to_qualify'] / 100 * $questionWeighting, 2);
$modelStyle = ExerciseLib::getModelStyle($item, $i);
$attributes = ['class' => $item['css_class']];
if ($result->get_score() == $i) {
$attributes['selected'] = 'selected';
}
$select->addOption($modelStyle, $i, $attributes);
}
$select->updateSelectWithSelectedOption($this);
$template = '<tr>
<td align="left" >'.$user['official_code'].'</td>
<td align="left" >'.$user['username'].'</td>
'.$user_info.'
<td align="left">{element} <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error -->
</td>
'.$columnSkillResult.'
</tr>';
}
$renderer->setElementTemplate($template, 'score['.$result->get_id().']');
}
if (empty($model)) {
$this->setDefaults($defaults);
}
$this->addButtonSave(get_lang('EditResult'));
$renderer->setElementTemplate($template_submit, 'submit');
}
/**
* This function builds a form to move an item to another category.
*/
protected function build_move_form()
{
$renderer = &$this->defaultRenderer();
$renderer->setCustomElementTemplate('<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);
$line = '';
foreach ($this->evaluation_object->get_target_categories() as $cat) {
for ($i = 0; $i < $cat[2]; $i++) {
$line .= '&mdash;';
}
$select->addOption($line.' '.$cat[1], $cat[0]);
$line = '';
}
$this->addButtonSave(get_lang('Ok'), 'submit');
}
/**
* Builds a result form containing inputs for all students with a given course_code.
*/
protected function build_result_add_form()
{
$renderer = &$this->defaultRenderer();
$renderer->setFormTemplate(
'<form{attributes}>
<div class="table-responsive">
<table class="table table-hover table-striped data_table">
{content}
</table>
</div>
</form>'
);
$users = GradebookUtils::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', get_lang('AddResult'));
if (api_is_western_name_order()) {
$renderer->setHeaderTemplate(
'<tr>
<th>'.get_lang('OfficialCode').'</th>
<th>'.get_lang('UserName').'</th>
<th>'.get_lang('FirstName').'</th>
<th>'.get_lang('LastName').'</th>
<th>'.get_lang('Qualify').'</th>
</tr>'
);
} else {
$renderer->setHeaderTemplate(
'<tr>
<th>'.get_lang('OfficialCode').'</th>
<th>'.get_lang('UserName').'</th>
<th>'.get_lang('LastName').'</th>
<th>'.get_lang('FirstName').'</th>
<th>'.get_lang('Qualify').'</th>
</tr>'
);
}
$firstUser = true;
foreach ($users as $user) {
$element_name = 'score['.$user[0].']';
$scoreColumnProperties = ['maxlength' => 5];
if ($firstUser) {
$scoreColumnProperties['autofocus'] = '';
$firstUser = false;
}
//user_id, user.username, lastname, firstname
$this->addFloat(
$element_name,
$this->build_stud_label($user[0], $user[1], $user[2], $user[3]),
false,
$scoreColumnProperties,
false,
0,
$this->evaluation_object->get_max()
);
if (api_is_western_name_order()) {
$user_info = '<td align="left" >'.$user[3].'</td>';
$user_info .= '<td align="left" >'.$user[2].'</td>';
} else {
$user_info = '<td align="left" >'.$user[2].'</td>';
$user_info .= '<td align="left" >'.$user[3].'</td>';
}
$nr_users++;
$template = '<tr>
<td align="left" >'.$user[4].'</td>
<td align="left" >'.$user[1].'</td>
'.$user_info.'
<td align="left">{element} / '.$this->evaluation_object->get_max().'
<!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error -->
</td>
</tr>';
$renderer->setElementTemplate($template, $element_name);
}
$this->addElement('hidden', 'nr_users', $nr_users);
$this->addElement('hidden', 'evaluation_id', $this->result_object->get_evaluation_id());
$this->addButtonSave(get_lang('AddResult'), 'submit');
$template_submit = '<tr>
<td colspan="4" ></td>
<td >
{element}
<!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error -->
</td>
</tr>';
$renderer->setElementTemplate($template_submit, 'submit');
}
/**
* Builds a form to edit a result.
*/
protected function build_result_edit_form()
{
$userInfo = api_get_user_info($this->result_object->get_user_id());
$this->addHeader(get_lang('User').': '.$userInfo['complete_name']);
$model = ExerciseLib::getCourseScoreModel();
if (empty($model)) {
$this->addFloat(
'score',
[
get_lang('Score'),
null,
'/ '.$this->evaluation_object->get_max(),
],
false,
[
'size' => '4',
'maxlength' => '5',
],
false,
0,
$this->evaluation_object->get_max()
);
$this->setDefaults(
[
'score' => $this->result_object->get_score(),
'maximum' => $this->evaluation_object->get_max(),
]
);
} else {
$questionWeighting = $this->evaluation_object->get_max();
$select = $this->addSelect('score', get_lang('Score'), [], ['disable_js' => true]);
foreach ($model['score_list'] as $item) {
$i = api_number_format($item['score_to_qualify'] / 100 * $questionWeighting, 2);
$model = ExerciseLib::getModelStyle($item, $i);
$attributes = ['class' => $item['css_class']];
if ($this->result_object->get_score() == $i) {
$attributes['selected'] = 'selected';
}
$select->addOption($model, $i, $attributes);
}
$select->updateSelectWithSelectedOption($this);
}
$allowMultipleAttempts = api_get_configuration_value('gradebook_multiple_evaluation_attempts');
if ($allowMultipleAttempts) {
$this->addTextarea('comment', get_lang('Comment'));
}
$this->addButtonSave(get_lang('Edit'));
$this->addElement('hidden', 'hid_user_id', $this->result_object->get_user_id());
}
/**
* Builds a form to add an evaluation.
*/
protected function build_add_form()
{
$this->setDefaults([
'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(),
'created_at' => api_get_utc_datetime(),
]);
$this->build_basic_form();
if ($this->evaluation_object->get_course_code() == null) {
$this->addElement('checkbox', 'adduser', null, get_lang('AddUserToEval'));
} else {
$this->addElement('checkbox', 'addresult', null, get_lang('AddResult'));
}
Skill::addSkillsToForm(
$this,
api_get_course_int_id(),
api_get_session_id(),
ITEM_TYPE_GRADEBOOK_EVALUATION
);
$this->addButtonCreate(get_lang('AddAssessment'));
}
/**
* Builds a form to edit an evaluation.
*/
protected function build_editing_form()
{
$parent_cat = Category::load($this->evaluation_object->get_category_id());
//@TODO $weight_mask is replaced?
if ($parent_cat[0]->get_parent_id() == 0) {
$weight_mask = $this->evaluation_object->get_weight();
} else {
$cat = Category::load($parent_cat[0]->get_parent_id());
$global_weight = $cat[0]->get_weight();
$weight_mask = $global_weight * $this->evaluation_object->get_weight() / $parent_cat[0]->get_weight();
}
$weight = $weight_mask = $this->evaluation_object->get_weight();
$evaluationId = $this->evaluation_object->get_id();
$this->addHidden('hid_id', $evaluationId);
$this->setDefaults([
'hid_id' => $evaluationId,
'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(),
'created_at' => api_get_utc_datetime($this->evaluation_object->get_date()),
'weight' => $weight,
'weight_mask' => $weight_mask,
'max' => $this->evaluation_object->get_max(),
'visible' => $this->evaluation_object->is_visible(),
]);
$this->build_basic_form(1);
if (!empty($evaluationId)) {
Skill::addSkillsToForm(
$this,
api_get_course_int_id(),
api_get_session_id(),
ITEM_TYPE_GRADEBOOK_EVALUATION,
$evaluationId
);
}
$this->addButtonSave(get_lang('ModifyEvaluation'));
}
/**
* Builds a basic form that is used in add and edit.
*
* @param int $edit
*/
private function build_basic_form($edit = 0)
{
$form_title = get_lang('NewEvaluation');
if (!empty($_GET['editeval'])) {
$form_title = get_lang('EditEvaluation');
}
$this->addHeader($form_title);
$this->addElement('hidden', 'hid_user_id');
$this->addElement('hidden', 'hid_course_code');
$this->addText(
'name',
get_lang('EvaluationName'),
true,
[
'maxlength' => '50',
'id' => 'evaluation_title',
]
);
$cat_id = $this->evaluation_object->get_category_id();
$session_id = api_get_session_id();
$course_code = api_get_course_id();
$all_categories = Category::load(
null,
null,
$course_code,
null,
null,
$session_id,
false
);
if (1 == count($all_categories)) {
$this->addElement('hidden', 'hid_category_id', $cat_id);
} else {
$select_gradebook = $this->addElement(
'select',
'hid_category_id',
get_lang('SelectGradebook'),
[],
['id' => 'hid_category_id']
);
$this->addRule('hid_category_id', get_lang('ThisFieldIsRequired'), 'nonzero');
$default_weight = 0;
if (!empty($all_categories)) {
foreach ($all_categories as $my_cat) {
if ($my_cat->get_course_code() == api_get_course_id()) {
$grade_model_id = $my_cat->get_grade_model_id();
if (empty($grade_model_id)) {
if ($my_cat->get_parent_id() == 0) {
$default_weight = $my_cat->get_weight();
$select_gradebook->addOption(get_lang('Default'), $my_cat->get_id());
$cats_added[] = $my_cat->get_id();
} else {
$select_gradebook->addOption(Security::remove_XSS($my_cat->get_name()), $my_cat->get_id());
$cats_added[] = $my_cat->get_id();
}
} else {
$select_gradebook->addOption(get_lang('Select'), 0);
}
if ($this->evaluation_object->get_category_id() == $my_cat->get_id()) {
$default_weight = $my_cat->get_weight();
}
}
}
}
}
$this->addFloat(
'weight_mask',
[
get_lang('Weight'),
null,
' [0 .. <span id="max_weight">'.$all_categories[0]->get_weight().'</span>] ',
],
true,
[
'size' => '4',
'maxlength' => '5',
]
);
$model = ExerciseLib::getCourseScoreModel();
if ($edit) {
if (empty($model)) {
if (!$this->evaluation_object->has_results()) {
$this->addText(
'max',
get_lang('QualificationNumeric'),
true,
[
'maxlength' => '5',
]
);
} else {
$this->addText(
'max',
[get_lang('QualificationNumeric'), get_lang('CannotChangeTheMaxNote')],
false,
[
'maxlength' => '5',
'disabled' => 'disabled',
]
);
}
} else {
$class = '';
foreach ($model['score_list'] as $item) {
$class = $item['css_class'];
}
$this->addText(
'max',
get_lang('QualificationNumeric'),
false,
[
'maxlength' => '5',
'class' => $class,
'disabled' => 'disabled',
]
);
$defaults['max'] = $item['max'];
$this->setDefaults($defaults);
}
} else {
if (empty($model)) {
$this->addText(
'max',
get_lang('QualificationNumeric'),
true,
[
'maxlength' => '5',
]
);
$default_max = api_get_setting('gradebook_default_weight');
$defaults['max'] = isset($default_max) ? $default_max : 100;
$this->setDefaults($defaults);
} else {
$class = '';
foreach ($model['score_list'] as $item) {
$class = $item['css_class'];
}
$this->addText(
'max',
get_lang('QualificationNumeric'),
false,
[
'maxlength' => '5',
'class' => $class,
'disabled' => 'disabled',
]
);
$defaults['max'] = $item['max'];
$this->setDefaults($defaults);
}
}
$this->addElement('textarea', 'description', get_lang('Description'));
$this->addRule('hid_category_id', get_lang('ThisFieldIsRequired'), 'required');
$this->addElement('checkbox', 'visible', null, get_lang('Visible'));
$this->addRule('max', get_lang('OnlyNumbers'), 'numeric');
$this->addRule(
'max',
get_lang('NegativeValue'),
'compare',
'>=',
'server',
false,
false,
0
);
$setting = api_get_setting('tool_visible_by_default_at_creation');
$visibility_default = 1;
if (isset($setting['gradebook']) && $setting['gradebook'] == 'false') {
$visibility_default = 0;
}
$this->setDefaults(['visible' => $visibility_default]);
}
/**
* @param $id
* @param $username
* @param $lastname
* @param $firstname
*
* @return string
*/
private function build_stud_label($id, $username, $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());
$doc_url = $link->get_view_url($id);
if (null != $doc_url) {
$opendocurl_start .= '<a href="'.$doc_url.'" target="_blank">';
$opendocurl_end = '</a>';
}
}
return $opendocurl_start.api_get_person_name($firstname, $lastname).' ('.$username.')'.$opendocurl_end;
}
}

View File

@@ -0,0 +1,168 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Script.
*/
/**
* Prints an HTML page with a table containing the gradebook data.
*
* @param array Array containing the data to be printed in the table
* @param array Table headers
* @param string View to print as a title for the table
* @param string Course name to print as title for the table
*
* @return string
*/
function print_table($data_array, $header_names, $view, $coursename)
{
$styleWebPath = api_get_path(WEB_PUBLIC_PATH).'assets/bootstrap/dist/css/bootstrap.min.css';
$printdata = '<!DOCTYPE html>
<html lang="'.api_get_language_isocode().'">
<head>
<title>'.get_lang('Print').'</title>
<meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
'.api_get_css(api_get_cdn_path($styleWebPath), 'screen,print').'
</head>
<body dir="'.api_get_text_direction().'"><div id="main">';
$printdata .= '<h2>'.$view.' : '.$coursename.'</h2>';
$table = new HTML_Table(['class' => 'table table-bordered']);
$table->setHeaders($header_names);
$table->setData($data_array);
$printdata .= $table->toHtml();
$printdata .= '</div></body></html>';
return $printdata;
}
/**
* This function get a content html for export inside a pdf file.
*
* @param array table headers
* @param array table body
* @param array pdf headers
* @param array pdf footers
*/
function export_pdf_with_html($headers_table, $data_table, $headers_pdf, $footers_pdf, $title_pdf)
{
$headers_in_pdf = '<img src="'.api_get_path(WEB_CSS_PATH).api_get_setting('stylesheets').'/images/header-logo.png">';
if (is_array($headers_pdf)) {
// preparing headers pdf
$header = '<br/><br/>
<table width="100%" cellspacing="1" cellpadding="5" border="0" class="strong">
<tr>
<td width="100%" style="text-align: center;" class="title" colspan="4">
<h1>'.$title_pdf.'</h1></td></tr>';
foreach ($headers_pdf as $header_pdf) {
if (!empty($header_pdf[0]) && !empty($header_pdf[1])) {
$header .= '<tr><td><strong>'.$header_pdf[0].'</strong> </td><td>'.$header_pdf[1].'</td></tr>';
}
}
$header .= '</table><br />';
}
// preparing footer pdf
$footer = '<table width="100%" cellspacing="2" cellpadding="10" border="0">';
if (is_array($footers_pdf)) {
$footer .= '<tr>';
foreach ($footers_pdf as $foot_pdf) {
$footer .= '<td width="33%" style="text-align: center;">'.$foot_pdf.'</td>';
}
$footer .= '</tr>';
}
$footer .= '</table>';
$footer .= '<div align="right" style="font-weight: bold;">{PAGENO}/{nb}</div>';
// preparing content pdf
$css = api_get_print_css();
$items_per_page = 30;
$count_pages = ceil(count($data_table) / $items_per_page);
for ($x = 0; $x < $count_pages; $x++) {
$content_table .= '<table width="100%" border="1" style="border-collapse:collapse">';
// header table
$content_table .= '<tr>';
$i = 0;
if (is_array($headers_table)) {
foreach ($headers_table as $head_table) {
if (!empty($head_table[0])) {
$width = (!empty($head_table[1]) ? $head_table[1].'%' : '');
$content_table .= '<th width="'.$width.'">'.$head_table[0].'</th>';
$i++;
}
}
}
$content_table .= '</tr>';
// body table
if (is_array($data_table) && count($data_table) > 0) {
$offset = $x * $items_per_page;
$data_table = array_slice($data_table, $offset, count($data_table));
$i = 1;
$item = $offset + 1;
foreach ($data_table as $data) {
$content_table .= '<tr>';
$content_table .= '<td>'.($item < 10 ? '0'.$item : $item).'</td>';
foreach ($data as $key => $content) {
if (isset($content)) {
$key == 1 ? $align = 'align="left"' : $align = 'align="center"';
$content_table .= '<td '.$align.' style="padding:4px;" >'.$content.'</td>';
}
}
$content_table .= '</tr>';
$i++;
$item++;
if ($i > $items_per_page) {
break;
}
}
} else {
$content_table .= '<tr colspan="'.$i.'"><td>'.get_lang('Empty').'</td></tr>';
}
$content_table .= '</table>';
if ($x < ($count_pages - 1)) {
$content_table .= '<pagebreak />';
}
}
$pdf = new PDF();
$pdf->set_custom_footer($footer);
$pdf->set_custom_header($headers_in_pdf);
$pdf->content_to_pdf($header.$content_table, $css, $title_pdf);
exit;
}
/**
* Exports the data as a table on a PDF page.
*
* @param resource The PDF object (ezpdf class) used to generate the file
* @param array The data array
* @param array Table headers
* @param string Format (portrait or landscape)
*/
function export_pdf($pdf, $newarray, $header_names, $format)
{
$pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
$pdf->ezSetCmMargins(0, 0, 0, 0);
$pdf->ezSetY(($format == 'portrait') ? '820' : '570');
$pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
if ('portrait' == $format) {
$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, '', [
'showHeadings' => 1,
'shaded' => 1,
'showLines' => 1,
'rowGap' => 3,
'width' => (($format == 'portrait') ? '500' : '750'),
]);
$pdf->ezStream();
}

View File

@@ -0,0 +1,517 @@
<?php
/* For licensing terms, see /license.txt */
set_time_limit(0);
use CpChart\Cache as pCache;
use CpChart\Data as pData;
use CpChart\Image as pImage;
/**
* Class FlatViewTable
* Table to display flat view (all evaluations and links for all students).
*
* @author Stijn Konings
* @author Bert Steppé - (refactored, optimised)
* @author Julio Montoya Armas - Gradebook Graphics
*/
class FlatViewTable extends SortableTable
{
public $datagen;
private $selectcat;
private $limit_enabled;
private $offset;
private $mainCourseCategory;
/**
* @param Category $selectcat
* @param array $users
* @param array $evals
* @param array $links
* @param bool $limit_enabled
* @param int $offset
* @param null $addparams
* @param Category $mainCourseCategory
*/
public function __construct(
$selectcat,
$users = [],
$evals = [],
$links = [],
$limit_enabled = false,
$offset = 0,
$addparams = null,
$mainCourseCategory = null
) {
parent::__construct(
'flatviewlist',
null,
null,
api_is_western_name_order() ? 1 : 0
);
$this->selectcat = $selectcat;
$this->datagen = new FlatViewDataGenerator(
$users,
$evals,
$links,
['only_subcat' => $this->selectcat->get_id()],
$mainCourseCategory
);
$this->limit_enabled = $limit_enabled;
$this->offset = $offset;
if (isset($addparams)) {
$this->set_additional_parameters($addparams ?: []);
}
// step 2: generate rows: students
$this->datagen->category = $this->selectcat;
$this->mainCourseCategory = $mainCourseCategory;
}
/**
* @param bool $value
*/
public function setLimitEnabled($value)
{
$this->limit_enabled = (bool) $value;
}
/**
* @return Category
*/
public function getMainCourseCategory()
{
return $this->mainCourseCategory;
}
/**
* Display gradebook graphs.
*/
public function display_graph_by_resource()
{
$headerName = $this->datagen->get_header_names();
$total_users = $this->datagen->get_total_users_count();
$customdisplays = ScoreDisplay::instance()->get_custom_score_display_settings();
if (empty($customdisplays)) {
echo get_lang('ToViewGraphScoreRuleMustBeEnabled');
return '';
}
$user_results = $this->datagen->get_data_to_graph2(false);
if (empty($user_results) || empty($total_users)) {
echo get_lang('NoResults');
return '';
}
// Removing first name
array_shift($headerName);
// Removing last name
array_shift($headerName);
// Removing username
array_shift($headerName);
$pre_result = [];
foreach ($user_results as $result) {
for ($i = 0; $i < count($headerName); $i++) {
if (isset($result[$i + 1])) {
$pre_result[$i + 3][] = $result[$i + 1];
}
}
}
$i = 0;
$resource_list = [];
$pre_result2 = [];
foreach ($pre_result as $key => $res_array) {
rsort($res_array);
$pre_result2[] = $res_array;
}
//@todo when a display custom does not exist the order of the color does not match
//filling all the answer that are not responded with 0
rsort($customdisplays);
if ($total_users > 0) {
foreach ($pre_result2 as $key => $res_array) {
$key_list = [];
foreach ($res_array as $user_result) {
$userResult = isset($user_result[1]) ? $user_result[1] : null;
if (!isset($resource_list[$key][$userResult])) {
$resource_list[$key][$userResult] = 0;
}
$resource_list[$key][$userResult]++;
$key_list[] = $userResult;
}
foreach ($customdisplays as $display) {
if (!in_array($display['display'], $key_list)) {
$resource_list[$key][$display['display']] = 0;
}
}
$i++;
}
}
//fixing $resource_list
$max = 0;
$new_list = [];
foreach ($resource_list as $key => $value) {
$new_value = [];
foreach ($customdisplays as $item) {
if ($value[$item['display']] > $max) {
$max = $value[$item['display']];
}
$new_value[$item['display']] = strip_tags($value[$item['display']]);
}
$new_list[] = $new_value;
}
$resource_list = $new_list;
$i = 1;
// Cache definition
$cachePath = api_get_path(SYS_ARCHIVE_PATH);
foreach ($resource_list as $key => $resource) {
// Reverse array, otherwise we get highest values first
$resource = array_reverse($resource, true);
$dataSet = new pData();
$dataSet->addPoints($resource, 'Serie');
$dataSet->addPoints(array_keys($resource), 'Labels');
$header = $headerName[$i - 1];
if (is_array($header) && isset($header['header'])) {
$header = $header['header'];
}
$header = strip_tags(api_html_entity_decode($header));
$dataSet->setSerieDescription('Labels', $header);
$dataSet->setAbscissa('Labels');
$dataSet->setAbscissaName(get_lang('GradebookSkillsRanking'));
$dataSet->setAxisName(0, get_lang('Students'));
$palette = [
'0' => ['R' => 186, 'G' => 206, 'B' => 151, 'Alpha' => 100],
'1' => ['R' => 210, 'G' => 148, 'B' => 147, 'Alpha' => 100],
'2' => ['R' => 148, 'G' => 170, 'B' => 208, 'Alpha' => 100],
'3' => ['R' => 221, 'G' => 133, 'B' => 61, 'Alpha' => 100],
'4' => ['R' => 65, 'G' => 153, 'B' => 176, 'Alpha' => 100],
'5' => ['R' => 114, 'G' => 88, 'B' => 144, 'Alpha' => 100],
'6' => ['R' => 138, 'G' => 166, 'B' => 78, 'Alpha' => 100],
'7' => ['R' => 171, 'G' => 70, 'B' => 67, 'Alpha' => 100],
'8' => ['R' => 69, 'G' => 115, 'B' => 168, 'Alpha' => 100],
];
$myCache = new pCache(['CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1)]);
$chartHash = $myCache->getHash($dataSet);
if ($myCache->isInCache($chartHash)) {
$imgPath = api_get_path(SYS_ARCHIVE_PATH).$chartHash;
$myCache->saveFromCache($chartHash, $imgPath);
$imgPath = api_get_path(WEB_ARCHIVE_PATH).$chartHash;
} else {
/* Create the pChart object */
$widthSize = 480;
$heightSize = 250;
$myPicture = new pImage($widthSize, $heightSize, $dataSet);
/* Turn of Antialiasing */
$myPicture->Antialias = false;
/* Add a border to the picture */
$myPicture->drawRectangle(
0,
0,
$widthSize - 1,
$heightSize - 1,
[
'R' => 0,
'G' => 0,
'B' => 0,
]
);
/* Set the default font */
$myPicture->setFontProperties(
[
'FontName' => api_get_path(SYS_FONTS_PATH).'opensans/OpenSans-Regular.ttf',
'FontSize' => 10,
]
);
/* Write the chart title */
$myPicture->drawText(
250,
30,
$header,
[
'FontSize' => 12,
'Align' => TEXT_ALIGN_BOTTOMMIDDLE,
]
);
/* Define the chart area */
$myPicture->setGraphArea(50, 40, $widthSize - 20, $heightSize - 50);
/* Draw the scale */
$scaleSettings = [
'GridR' => 200,
'GridG' => 200,
'GridB' => 200,
'DrawSubTicks' => true,
'CycleBackground' => true,
'Mode' => SCALE_MODE_START0,
];
$myPicture->drawScale($scaleSettings);
/* Turn on shadow computing */
$myPicture->setShadow(
true,
[
'X' => 1,
'Y' => 1,
'R' => 0,
'G' => 0,
'B' => 0,
'Alpha' => 10,
]
);
/* Draw the chart */
$myPicture->setShadow(
true,
[
'X' => 1,
'Y' => 1,
'R' => 0,
'G' => 0,
'B' => 0,
'Alpha' => 10,
]
);
$settings = [
'OverrideColors' => $palette,
'Gradient' => false,
'GradientMode' => GRADIENT_SIMPLE,
'DisplayPos' => LABEL_POS_TOP,
'DisplayValues' => true,
'DisplayR' => 0,
'DisplayG' => 0,
'DisplayB' => 0,
'DisplayShadow' => true,
'Surrounding' => 10,
];
$myPicture->drawBarChart($settings);
/* Render the picture (choose the best way) */
$myCache->writeToCache($chartHash, $myPicture);
$imgPath = api_get_path(SYS_ARCHIVE_PATH).$chartHash;
$myCache->saveFromCache($chartHash, $imgPath);
$imgPath = api_get_path(WEB_ARCHIVE_PATH).$chartHash;
}
echo '<img src="'.$imgPath.'" >';
if ($i % 2 == 0 && $i != 0) {
echo '<br /><br />';
} else {
echo '&nbsp;&nbsp;&nbsp;';
}
$i++;
}
}
/**
* Function used by SortableTable to get total number of items in the table.
*/
public function get_total_number_of_items()
{
return $this->datagen->get_total_users_count();
}
/**
* Function used by SortableTable to generate the data to display.
*/
public function get_table_data(
$from = 1,
$per_page = null,
$column = null,
$direction = null,
$sort = null
) {
$is_western_name_order = api_is_western_name_order();
// create page navigation if needed
$totalitems = $this->datagen->get_total_items_count();
if ($this->limit_enabled && $totalitems > GRADEBOOK_ITEM_LIMIT) {
$selectlimit = GRADEBOOK_ITEM_LIMIT;
} else {
$selectlimit = $totalitems;
}
$header = null;
if ($this->limit_enabled && $totalitems > GRADEBOOK_ITEM_LIMIT) {
$header .= '<table
style="width: 100%; text-align: right; margin-left: auto; margin-right: auto;"
border="0" cellpadding="2"><tbody>
<tr>';
// previous X
$header .= '<td style="width:100%;">';
if ($this->offset >= GRADEBOOK_ITEM_LIMIT) {
$header .= '<a
href="'.api_get_self().'?selectcat='.(int) $_GET['selectcat'].'&offset='.(($this->offset) - GRADEBOOK_ITEM_LIMIT)
.(isset($_GET['search']) ? '&search='.Security::remove_XSS($_GET['search']) : '').'">'
.Display::return_icon(
'action_prev.png',
get_lang('PreviousPage'),
[],
ICON_SIZE_MEDIUM
)
.'</a>';
} else {
$header .= Display::return_icon(
'action_prev_na.png',
get_lang('PreviousPage'),
[],
ICON_SIZE_MEDIUM
);
}
$header .= ' ';
// next X
$calcnext = (($this->offset + (2 * GRADEBOOK_ITEM_LIMIT)) > $totalitems) ?
($totalitems - (GRADEBOOK_ITEM_LIMIT + $this->offset)) : GRADEBOOK_ITEM_LIMIT;
if ($calcnext > 0) {
$header .= '<a href="'.api_get_self()
.'?selectcat='.Security::remove_XSS($_GET['selectcat'])
.'&offset='.($this->offset + GRADEBOOK_ITEM_LIMIT)
.(isset($_GET['search']) ? '&search='.Security::remove_XSS($_GET['search']) : '').'">'
.Display::return_icon('action_next.png', get_lang('NextPage'), [], ICON_SIZE_MEDIUM)
.'</a>';
} else {
$header .= Display::return_icon(
'action_next_na.png',
get_lang('NextPage'),
[],
ICON_SIZE_MEDIUM
);
}
$header .= '</td>';
$header .= '</tbody></table>';
echo $header;
}
// retrieve sorting type
if ($is_western_name_order) {
$users_sorting = ($this->column == 0 ? FlatViewDataGenerator::FVDG_SORT_FIRSTNAME : FlatViewDataGenerator::FVDG_SORT_LASTNAME);
} else {
$users_sorting = ($this->column == 0 ? FlatViewDataGenerator::FVDG_SORT_LASTNAME : FlatViewDataGenerator::FVDG_SORT_FIRSTNAME);
}
if ('DESC' === $this->direction) {
$users_sorting |= FlatViewDataGenerator::FVDG_SORT_DESC;
} else {
$users_sorting |= FlatViewDataGenerator::FVDG_SORT_ASC;
}
// step 1: generate columns: evaluations and links
$header_names = $this->datagen->get_header_names($this->offset, $selectlimit);
$userRowSpan = false;
foreach ($header_names as $item) {
if (is_array($item)) {
$userRowSpan = true;
break;
}
}
$thAttributes = '';
if ($userRowSpan) {
$thAttributes = 'rowspan=2';
}
$this->set_header(0, $header_names[0], true, $thAttributes);
$this->set_header(1, $header_names[1], true, $thAttributes);
$column = 2;
$firstHeader = [];
while ($column < count($header_names)) {
$headerData = $header_names[$column];
if (is_array($headerData)) {
$countItems = count($headerData['items']);
$this->set_header(
$column,
$headerData['header'],
false,
'colspan="'.$countItems.'"'
);
if (count($headerData['items']) > 0) {
foreach ($headerData['items'] as $item) {
$firstHeader[] = '<span class="text-center">'.$item.'</span>';
}
} else {
$firstHeader[] = '&mdash;';
}
} else {
$this->set_header($column, $headerData, false, $thAttributes);
}
$column++;
}
$data_array = $this->datagen->get_data(
$users_sorting,
$from,
$this->per_page,
$this->offset,
$selectlimit
);
$table_data = [];
if (!empty($firstHeader)) {
$table_data[] = $firstHeader;
}
$columnOffset = empty($this->datagen->params['show_official_code']) ? 0 : 1;
foreach ($data_array as $user_row) {
$user_id = $user_row[0];
unset($user_row[0]);
$userInfo = api_get_user_info($user_id);
if ($is_western_name_order) {
$user_row[1 + $columnOffset] = $this->build_name_link(
$user_id,
$userInfo['firstname']
);
$user_row[2 + $columnOffset] = $this->build_name_link(
$user_id,
$userInfo['lastname']
);
} else {
$user_row[1 + $columnOffset] = $this->build_name_link(
$user_id,
$userInfo['lastname']
);
$user_row[2 + $columnOffset] = $this->build_name_link(
$user_id,
$userInfo['firstname']
);
}
$user_row = array_values($user_row);
$table_data[] = $user_row;
}
return $table_data;
}
/**
* @param $userId
* @param $name
*
* @return string
*/
private function build_name_link($userId, $name)
{
return '<a
href="user_stats.php?userid='.$userId.'&selectcat='.$this->selectcat->get_id().'&'.api_get_cidreq().'">'.
$name.'</a>';
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
<html>
<head>
<meta http-equiv="refresh" content="0; url=../../gradebook.php">
</head>
<body>
</body>
</html>

View File

@@ -0,0 +1,211 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Form used to add or edit links.
*
* @author Stijn Konings
* @author Bert Steppé
*/
class LinkAddEditForm extends FormValidator
{
public const TYPE_ADD = 1;
public const TYPE_EDIT = 2;
/**
* Constructor
* To add link, define category_object and link_type
* To edit link, define link_object.
*/
public function __construct(
$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(api_get_course_id());
$link->set_session_id(api_get_session_id());
$link->set_category_id($category_object[0]->get_id());
} else {
exit('LinkAddEditForm error: define link_type/category_object or link_object');
}
$defaults = [];
if (!empty($_GET['editlink'])) {
$this->addElement('header', '', get_lang('EditLink'));
}
// ELEMENT: name
if ($form_type == self::TYPE_ADD || $link->is_allowed_to_change_name()) {
if ($link->needs_name_and_description()) {
$this->addText('name', get_lang('Name'), true, ['size' => '40', 'maxlength' => '40']);
} else {
$select = $this->addElement('select', 'select_link', get_lang('ChooseItem'));
foreach ($link->get_all_links() as $newlink) {
$name = strip_tags(Exercise::get_formated_title_variable($newlink[1]));
$select->addOption($name, $newlink[0]);
}
}
} else {
$this->addElement(
'label',
get_lang('Name'),
'<span class="freeze">'.$link->get_name().' ['.$link->get_type_name().']</span>'
);
$this->addElement(
'hidden',
'name_link',
$link->get_name(),
['id' => 'name_link']
);
}
if (1 == count($category_object)) {
$this->addElement('hidden', 'select_gradebook', $category_object[0]->get_id());
} else {
$select_gradebook = $this->addElement(
'select',
'select_gradebook',
get_lang('SelectGradebook'),
[],
['id' => 'hide_category_id']
);
$this->addRule('select_gradebook', get_lang('ThisFieldIsRequired'), 'nonzero');
$default_weight = 0;
if (!empty($category_object)) {
foreach ($category_object as $my_cat) {
if ($my_cat->get_course_code() == api_get_course_id()) {
$grade_model_id = $my_cat->get_grade_model_id();
if (empty($grade_model_id)) {
if (0 == $my_cat->get_parent_id()) {
$default_weight = $my_cat->get_weight();
$select_gradebook->addOption(get_lang('Default'), $my_cat->get_id());
} else {
$select_gradebook->addOption(Security::remove_XSS($my_cat->get_name()), $my_cat->get_id());
}
} else {
$select_gradebook->addOption(get_lang('Select'), 0);
}
if ($link->get_category_id() == $my_cat->get_id()) {
$default_weight = $my_cat->get_weight();
}
}
}
}
}
$this->addFloat(
'weight_mask',
[
get_lang('Weight'),
null,
' [0 .. <span id="max_weight">'.$category_object[0]->get_weight(
).'</span>] ',
],
true,
[
'size' => '4',
'maxlength' => '5',
]
);
$this->addElement('hidden', 'weight');
if (self::TYPE_EDIT == $form_type) {
$parent_cat = Category::load($link->get_category_id());
if (0 == $parent_cat[0]->get_parent_id()) {
$values['weight'] = $link->get_weight();
} else {
$cat = Category::load($parent_cat[0]->get_parent_id());
$values['weight'] = $link->get_weight();
}
$defaults['weight_mask'] = $values['weight'];
$defaults['select_gradebook'] = $link->get_category_id();
}
// ELEMENT: max
if ($link->needs_max()) {
if ($form_type == self::TYPE_EDIT && $link->has_results()) {
$this->addText(
'max',
get_lang('QualificationNumeric'),
false,
[
'size' => '4',
'maxlength' => '5',
'disabled' => 'disabled',
]
);
} else {
$this->addText('max', get_lang('QualificationNumeric'), true, ['size' => '4', 'maxlength' => '5']);
$this->addRule('max', get_lang('OnlyNumbers'), 'numeric');
$this->addRule(
'max',
get_lang('NegativeValue'),
'compare',
'>=',
'server',
false,
false,
0
);
}
if ($form_type == self::TYPE_EDIT) {
$defaults['max'] = $link->get_max();
}
}
// ELEMENT: description
if ($link->needs_name_and_description()) {
$this->addElement(
'textarea',
'description',
get_lang('Description'),
['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', null, get_lang('Visible'), $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->addButtonCreate(get_lang('CreateLink'));
} else {
$this->addButtonUpdate(get_lang('LinkMod'));
}
if ($form_type == self::TYPE_ADD) {
$setting = api_get_setting('tool_visible_by_default_at_creation');
$visibility_default = 1;
if (isset($setting['gradebook']) && $setting['gradebook'] === 'false') {
$visibility_default = 0;
}
$defaults['visible'] = $visibility_default;
}
// set default values
$this->setDefaults($defaults);
}
}

View File

@@ -0,0 +1,158 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Class LinkForm
* Forms related to links.
*
* @author Stijn Konings
* @author Bert Steppé (made more generic)
*/
class LinkForm extends FormValidator
{
public const TYPE_CREATE = 1;
public const TYPE_MOVE = 2;
/** @var Category */
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 Category $category_object the category object
* @param AbstractLink $link_object
* @param string $form_name name
* @param string $method
* @param string $action
*/
public function __construct(
$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;
} else {
if (isset($link_object)) {
$this->link_object = $link_object;
}
}
if (isset($extra)) {
$this->extra = $extra;
}
if (self::TYPE_CREATE == $form_type) {
$this->build_create();
} elseif (self::TYPE_MOVE == $form_type) {
$this->build_move();
}
}
protected function build_move()
{
$renderer = &$this->defaultRenderer();
$renderer->setCustomElementTemplate('<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);
$line = '';
foreach ($this->link_object->get_target_categories() as $cat) {
for ($i = 0; $i < $cat[2]; $i++) {
$line .= '&mdash;';
}
$select->addOption($line.' '.$cat[1], $cat[0]);
$line = '';
}
$this->addElement('submit', null, get_lang('Ok'));
}
/**
* Builds the form.
*/
protected function build_create()
{
$this->addHeader(get_lang('MakeLink'));
$select = $this->addElement(
'select',
'select_link',
get_lang('ChooseLink'),
null,
['onchange' => 'document.create_link.submit()']
);
$select->addOption('['.get_lang('ChooseLink').']', 0);
$courseCode = $this->category_object->get_course_code();
$linkTypes = LinkFactory::get_all_types();
foreach ($linkTypes as $linkType) {
// The hot potatoe link will be added "inside" the exercise option.
if ($linkType == LINK_HOTPOTATOES) {
continue;
}
$link = $this->createLink($linkType, $courseCode);
/* configure the session id within the gradebook evaluation*/
$link->set_session_id(api_get_session_id());
// 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_all_links()) == '0') {
$select->addOption($link->get_type_name(), $linkType, 'disabled');
} else {
$select->addOption($link->get_type_name(), $linkType);
}
if ($link->get_type() == LINK_EXERCISE) {
// Adding hot potatoes
$linkHot = $this->createLink(LINK_HOTPOTATOES, $courseCode);
$linkHot->setHp(true);
if ($linkHot->get_all_links(true)) {
$select->addOption(
'&nbsp;&nbsp;&nbsp;'.$linkHot->get_type_name(),
LINK_HOTPOTATOES
);
} else {
$select->addOption(
'&nbsp;&nbsp;&nbsp;'.$linkHot->get_type_name(),
LINK_HOTPOTATOES,
'disabled'
);
}
}
}
if (isset($this->extra)) {
$this->setDefaults(['select_link' => $this->extra]);
}
}
/**
* @param int $link
* @param string|null $courseCode
*
* @return AttendanceLink|DropboxLink|ExerciseLink|ForumThreadLink|LearnpathLink|StudentPublicationLink|SurveyLink|null
*/
private function createLink($link, $courseCode)
{
$link = LinkFactory::create($link);
if (!empty($courseCode)) {
$link->set_course_code($courseCode);
} elseif (!empty($_GET['course_code'])) {
$link->set_course_code(Database::escape_string($_GET['course_code'], null, false));
}
return $link;
}
}

View File

@@ -0,0 +1,275 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Class ResultTable
* Table to display results for an evaluation.
*
* @author Stijn Konings
* @author Bert Steppé
*/
class ResultTable extends SortableTable
{
private $datagen;
private $evaluation;
private $allresults;
private $iscourse;
/**
* ResultTable constructor.
*
* @param string $evaluation
* @param array $results
* @param string|null $iscourse
* @param array $addparams
* @param bool $forprint
*/
public function __construct(
$evaluation,
$results,
$iscourse,
$addparams = [],
$forprint = false
) {
parent::__construct(
'resultlist',
null,
null,
api_is_western_name_order() ? 1 : 2
);
$this->datagen = new ResultsDataGenerator($evaluation, $results, true);
$this->evaluation = $evaluation;
$this->iscourse = $iscourse;
$this->forprint = $forprint;
if (isset($addparams)) {
$this->set_additional_parameters($addparams);
}
$scoredisplay = ScoreDisplay::instance();
$column = 0;
if ('1' == $this->iscourse) {
$this->set_header($column++, '', false);
$this->set_form_actions([
'delete' => get_lang('Delete'),
]);
}
if (api_is_western_name_order()) {
$this->set_header($column++, get_lang('FirstName'));
$this->set_header($column++, get_lang('LastName'));
} else {
$this->set_header($column++, get_lang('LastName'));
$this->set_header($column++, get_lang('FirstName'));
}
$model = ExerciseLib::getCourseScoreModel();
if (empty($model)) {
$this->set_header($column++, get_lang('Score'));
}
if ($scoredisplay->is_custom()) {
$this->set_header($column++, get_lang('Display'));
}
if (!$this->forprint) {
$this->set_header($column++, get_lang('Modify'), false);
}
}
/**
* Function used by SortableTable to get total number of items in the table.
*/
public function get_total_number_of_items()
{
return $this->datagen->get_total_results_count();
}
/**
* Function used by SortableTable to generate the data to display.
*/
public function get_table_data(
$from = 1,
$per_page = null,
$column = null,
$direction = null,
$sort = null
) {
$isWesternNameOrder = api_is_western_name_order();
$scoredisplay = ScoreDisplay::instance();
// determine sorting type
$col_adjust = $this->iscourse == '1' ? 1 : 0;
switch ($this->column) {
// first name or last name
case 0 + $col_adjust:
if ($isWesternNameOrder) {
$sorting = ResultsDataGenerator::RDG_SORT_FIRSTNAME;
} else {
$sorting = ResultsDataGenerator::RDG_SORT_LASTNAME;
}
break;
// first name or last name
case 1 + $col_adjust:
if ($isWesternNameOrder) {
$sorting = ResultsDataGenerator::RDG_SORT_LASTNAME;
} else {
$sorting = ResultsDataGenerator::RDG_SORT_FIRSTNAME;
}
break;
// Score
case 2 + $col_adjust:
$sorting = ResultsDataGenerator::RDG_SORT_SCORE;
break;
case 3 + $col_adjust:
$sorting = ResultsDataGenerator::RDG_SORT_MASK;
break;
}
if ($this->direction === 'DESC') {
$sorting |= ResultsDataGenerator::RDG_SORT_DESC;
} else {
$sorting |= ResultsDataGenerator::RDG_SORT_ASC;
}
$data_array = $this->datagen->get_data($sorting, $from, $this->per_page);
$model = ExerciseLib::getCourseScoreModel();
// generate the data to display
$sortable_data = [];
foreach ($data_array as $item) {
$row = [];
if ('1' == $this->iscourse) {
$row[] = $item['result_id'];
}
if ($isWesternNameOrder) {
$row[] = $item['firstname'];
$row[] = $item['lastname'];
} else {
$row[] = $item['lastname'];
$row[] = $item['firstname'];
}
if (empty($model)) {
$row[] = Display::bar_progress(
$item['percentage_score'],
false,
$item['score']
);
}
if ($scoredisplay->is_custom()) {
$row[] = $item['display'];
}
if (!$this->forprint) {
$row[] = $this->build_edit_column($item);
}
$sortable_data[] = $row;
}
return $sortable_data;
}
/**
* @param Result $result
* @param string $url
*
* @return string
*/
public static function getResultAttemptTable($result, $url = '')
{
if (empty($result)) {
return '';
}
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT_ATTEMPT);
$sql = "SELECT * FROM $table WHERE result_id = ".$result->get_id().' ORDER BY created_at DESC';
$resultQuery = Database::query($sql);
$list = Database::store_result($resultQuery);
$htmlTable = new HTML_Table(['class' => 'table table-hover table-striped data_table']);
$htmlTable->setHeaderContents(0, 0, get_lang('Score'));
$htmlTable->setHeaderContents(0, 1, get_lang('Comment'));
$htmlTable->setHeaderContents(0, 2, get_lang('CreatedAt'));
if (!empty($url)) {
$htmlTable->setHeaderContents(0, 3, get_lang('Actions'));
}
$row = 1;
foreach ($list as $data) {
$htmlTable->setCellContents($row, 0, $data['score']);
$htmlTable->setCellContents($row, 1, $data['comment']);
$htmlTable->setCellContents($row, 2, Display::dateToStringAgoAndLongDate($data['created_at']));
if (!empty($url)) {
$htmlTable->setCellContents(
$row,
3,
Display::url(
Display::return_icon('delete.png', get_lang('Delete')),
$url.'&action=delete_attempt&result_attempt_id='.$data['id']
)
);
}
$row++;
}
return $htmlTable->toHtml();
}
/**
* @param array $item
*
* @return string
*/
private function build_edit_column($item)
{
$locked_status = $this->evaluation->get_locked();
$allowMultipleAttempts = api_get_configuration_value('gradebook_multiple_evaluation_attempts');
$baseUrl = api_get_self().'?selecteval='.$this->evaluation->get_id().'&'.api_get_cidreq();
$editColumn = '';
if (api_is_allowed_to_edit(null, true) && $locked_status == 0) {
if ($allowMultipleAttempts) {
if (!empty($item['percentage_score'])) {
$editColumn .=
Display::url(
Display::return_icon('add.png', get_lang('AddAttempt'), '', '22'),
$baseUrl.'&action=add_attempt&editres='.$item['result_id']
);
} else {
$editColumn .= '<a href="'.api_get_self().'?editres='.$item['result_id'].'&selecteval='.$this->evaluation->get_id().'&'.api_get_cidreq().'">'.
Display::return_icon('edit.png', get_lang('Modify'), '', '22').'</a>';
}
} else {
$editColumn .= '<a href="'.api_get_self().'?editres='.$item['result_id'].'&selecteval='.$this->evaluation->get_id().'&'.api_get_cidreq().'">'.
Display::return_icon('edit.png', get_lang('Modify'), '', '22').'</a>';
}
$editColumn .= ' <a href="'.api_get_self().'?delete_mark='.$item['result_id'].'&selecteval='.$this->evaluation->get_id().'&'.api_get_cidreq().'">'.
Display::return_icon('delete.png', get_lang('Delete'), '', '22').'</a>';
}
if ($this->evaluation->get_course_code() == null) {
$editColumn .= '&nbsp;<a href="'.api_get_self().'?resultdelete='.$item['result_id'].'&selecteval='.$this->evaluation->get_id().'" onclick="return confirmationuser();">';
$editColumn .= Display::return_icon('delete.png', get_lang('Delete'));
$editColumn .= '</a>';
$editColumn .= '&nbsp;<a href="user_stats.php?userid='.$item['id'].'&selecteval='.$this->evaluation->get_id().'&'.api_get_cidreq().'">';
$editColumn .= Display::return_icon('statistics.gif', get_lang('Statistics'));
$editColumn .= '</a>';
}
// Evaluation's origin is a link
if ($this->evaluation->get_category_id() < 0) {
$link = LinkFactory::get_evaluation_link($this->evaluation->get_id());
$doc_url = $link->get_view_url($item['id']);
if ($doc_url != null) {
$editColumn .= '&nbsp;<a href="'.$doc_url.'" target="_blank">';
$editColumn .= Display::return_icon('link.gif', get_lang('OpenDocument')).'</a>';
}
}
return $editColumn;
}
}

View File

@@ -0,0 +1,160 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Class ScoreDisplayForm
* Form for the score display dialog.
*
* @author Stijn Konings
* @author Bert Steppé
*/
class ScoreDisplayForm extends FormValidator
{
/**
* @param $form_name
* @param null $action
*/
public function __construct($form_name, $action = null)
{
parent::__construct($form_name, 'post', $action);
$displayscore = ScoreDisplay::instance();
$customdisplays = $displayscore->get_custom_score_display_settings();
$nr_items = ('0' != count($customdisplays)) ? count($customdisplays) : '1';
$this->setDefaults(
[
'scorecolpercent' => $displayscore->get_color_split_value(),
]
);
$this->addElement('hidden', 'maxvalue', '100');
$this->addElement('hidden', 'minvalue', '0');
$counter = 1;
// Setting the default values
if (is_array($customdisplays)) {
foreach ($customdisplays as $customdisplay) {
$this->setDefaults(
[
'endscore['.$counter.']' => $customdisplay['score'],
'displaytext['.$counter.']' => $customdisplay['display'],
]
);
$counter++;
}
}
// Settings for the colored score
$this->addElement('header', get_lang('ScoreEdit'));
if ($displayscore->is_coloring_enabled()) {
$this->addElement('html', '<b>'.get_lang('ScoreColor').'</b>');
$this->addElement(
'text',
'scorecolpercent',
[get_lang('Below'), get_lang('WillColorRed'), '%'],
[
'size' => 5,
'maxlength' => 5,
'input-size' => 2,
]
);
if (api_get_setting('teachers_can_change_score_settings') != 'true') {
$this->freeze('scorecolpercent');
}
$this->addRule('scorecolpercent', get_lang('OnlyNumbers'), 'numeric');
$this->addRule(['scorecolpercent', 'maxvalue'], get_lang('Over100'), 'compare', '<=');
$this->addRule(['scorecolpercent', 'minvalue'], get_lang('UnderMin'), 'compare', '>');
}
// Settings for the scoring system
if ($displayscore->is_custom()) {
$this->addElement('html', '<br /><b>'.get_lang('ScoringSystem').'</b>');
$this->addElement('static', null, null, get_lang('ScoreInfo'));
$this->setDefaults([
'beginscore' => '0',
]);
$this->addElement('text', 'beginscore', [get_lang('Between'), null, '%'], [
'size' => 5,
'maxlength' => 5,
'disabled' => 'disabled',
'input-size' => 2,
]);
for ($counter = 1; $counter <= 20; $counter++) {
$renderer = &$this->defaultRenderer();
$elementTemplateTwoLabel =
'<div id='.$counter.' style="display: '.(($counter <= $nr_items) ? 'inline' : 'none').';">
<!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->
<label class="control-label">{label}</label>
<div class="form-group">
<label class="col-sm-2 control-label">
</label>
<div class="col-sm-1">
<!-- BEGIN error --><span class="form_error">{error}</span><br />
<!-- END error -->&nbsp<b>'.get_lang('And').'</b>
</div>
<div class="col-sm-2">
{element}
</div>
<div class="col-sm-1">
=
</div>';
$elementTemplateTwoLabel2 = '
<div class="col-sm-2">
<!-- BEGIN error --><span class="form_error">{error}</span>
<!-- END error -->
{element}
</div>
<div class="col-sm-1">
<a href="javascript:plusItem('.($counter + 1).')">
<img style="display: '.(($counter >= $nr_items) ? 'inline' : 'none').';" id="plus-'.($counter + 1).'" src="'.Display::returnIconPath('add.png').'" alt="'.get_lang('Add').'" title="'.get_lang('Add').'"></a>
<a href="javascript:minItem('.($counter).')">
<img style="display: '.(($counter >= $nr_items && $counter != 1) ? 'inline' : 'none').';" id="min-'.$counter.'" src="'.Display::returnIconPath('delete.png').'" alt="'.get_lang('Delete').'" title="'.get_lang('Delete').'"></a>
</div>
</div>
</div>';
$this->addElement(
'text',
'endscore['.$counter.']',
null,
[
'size' => 5,
'maxlength' => 5,
'id' => 'txta-'.$counter,
'input-size' => 2,
]
);
$this->addElement(
'text',
'displaytext['.$counter.']',
null,
[
'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(['endscore['.$counter.']', 'maxvalue'], get_lang('Over100'), 'compare', '<=');
$this->addRule(['endscore['.$counter.']', 'minvalue'], get_lang('UnderMin'), 'compare', '>');
}
}
if ($displayscore->is_custom()) {
$this->addButtonSave(get_lang('Ok'));
}
}
public function validate()
{
return parent::validate();
}
}

View File

@@ -0,0 +1,85 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Class UserForm
* Extends formvalidator with import and export forms.
*
* @author Stijn Konings
*/
class UserForm extends FormValidator
{
public const TYPE_USER_INFO = 1;
public 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 string $method
* @param string $action
*/
public function __construct($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 (self::TYPE_USER_INFO == $this->form_type) {
$this->build_user_info_form();
} elseif (self::TYPE_SIMPLE_SEARCH == $this->form_type) {
$this->build_simple_search();
}
$this->setDefaults();
}
public function display()
{
parent::display();
}
public function setDefaults($defaults = [], $filter = null)
{
parent::setDefaults($defaults, $filter);
}
protected function build_simple_search()
{
if (isset($_GET['search']) && (!empty($_GET['search']))) {
$this->setDefaults([
'keyword' => Security::remove_XSS($_GET['search']),
]);
}
$renderer = &$this->defaultRenderer();
$renderer->setCustomElementTemplate('<span>{element}</span> ');
$this->addElement('text', 'keyword', '');
$this->addButtonSearch(get_lang('Search'), 'submit');
}
protected function build_user_info_form()
{
if (api_is_western_name_order()) {
$this->addElement('static', 'fname', get_lang('FirstName'), $this->user_info['firstname']);
$this->addElement('static', 'lname', get_lang('LastName'), $this->user_info['lastname']);
} else {
$this->addElement('static', 'lname', get_lang('LastName'), $this->user_info['lastname']);
$this->addElement('static', 'fname', get_lang('FirstName'), $this->user_info['firstname']);
}
$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->addButtonSave(get_lang('Back'), 'submit');
}
}

View File

@@ -0,0 +1,141 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Class UserTable
* 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.
*/
public function __construct($userid, $evals = [], $links = [], $addparams = null)
{
parent::__construct('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.
*/
public function get_total_number_of_items()
{
return $this->datagen->get_total_items_count();
}
/**
* Function used by SortableTable to generate the data to display.
*/
public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = null)
{
$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 ('DESC' === $this->direction) {
$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 = [];
foreach ($data_array as $data) {
if ('' != $data[2]) {
// filter by course removed
$row = [];
$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;
}
/**
* @param $item
*
* @return string
*/
private function build_type_column($item)
{
return GradebookUtils::build_type_icon_tag($item->get_icon_name());
}
/**
* @param $item
*
* @return string
*/
private function build_name_link($item)
{
switch ($item->get_item_type()) {
// evaluation
case 'E':
return '&nbsp;'
.'<a href="gradebook_view_result.php?selecteval='.$item->get_id().'&'.api_get_cidreq().'">'
.$item->get_name()
.'</a>';
// link
case 'L':
return '&nbsp;<a href="'.$item->get_link().'">'
.$item->get_name()
.'</a>'
.'&nbsp;['.$item->get_type_name().']';
}
}
}