Update UI when using "course score model" see BT#12898

pull/2990/head
Julio 7 years ago
parent a7ad5865d4
commit 7d5e68d1d7
  1. 1
      main/exercise/exercise_report.php
  2. 46
      main/exercise/exercise_show.php
  3. 4
      main/gradebook/gradebook_flatview.php
  4. 31
      main/gradebook/gradebook_statistics.php
  5. 7
      main/gradebook/gradebook_view_result.php
  6. 14
      main/gradebook/index.php
  7. 37
      main/gradebook/lib/fe/displaygradebook.php
  8. 209
      main/gradebook/lib/fe/evalform.class.php
  9. 23
      main/gradebook/lib/fe/resulttable.class.php
  10. 5
      main/gradebook/lib/fe/usertable.class.php
  11. 56
      main/gradebook/lib/flatview_data_generator.class.php
  12. 14
      main/gradebook/lib/results_data_generator.class.php
  13. 44
      main/gradebook/lib/user_data_generator.class.php
  14. 2
      main/inc/lib/display.lib.php
  15. 109
      main/inc/lib/pear/HTML/QuickForm/select.php
  16. 5
      main/inc/lib/pear/HTML/QuickForm/text.php

@ -212,7 +212,6 @@ if (isset($_REQUEST['comments']) &&
'marks' => $my_marks,
'teacher_comment' => $my_comments,
];
Database::update(
$TBL_TRACK_ATTEMPT,
$params,

@ -811,22 +811,42 @@ foreach ($questionList as $questionId) {
if ($is_allowedToEdit && $isFeedbackAllowed && $action != 'export') {
if (in_array($answerType, [FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION])) {
$marksname = "marksName".$questionId;
$marksname = 'marksName'.$questionId;
$arrmarks[] = $questionId;
echo '<div id="'.$marksname.'" class="hidden">';
// @todo use FormValidator
/*$formMark = new FormValidator("marksform_'.$questionId.'", 'post');
$options = [
1,
2
];
$formMark->addSelect('marks', get_lang('AssignMarks'), $options);
$formMark->display();*/
echo '<form name="marksform_'.$questionId.'" method="post" action="">';
$formMark = new FormValidator('marksform_'.$questionId, 'post');
$formMark->addHeader(get_lang('AssignMarks'));
$select = $formMark->addSelect('marks', get_lang('AssignMarks'), [], ['disable_js' => true]);
$model = ExerciseLib::getCourseScoreModel();
if (empty($model)) {
for ($i = 0; $i <= $questionWeighting; $i++) {
$attributes = [];
if ($questionScore == $i) {
$attributes['selected'] = 'selected';
}
$select->addOption($i, $i, $attributes);
}
} else {
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 ($questionScore == $i) {
$attributes['selected'] = 'selected';
}
$select->addOption($model, $i, $attributes);
}
$select->updateSelectWithSelectedOption($formMark);
}
$formMark->display();
/*echo '<form name="smarksform_'.$questionId.'" method="post" action="">';
echo get_lang('AssignMarks');
echo "&nbsp;<select name='marks' id='select_marks_".$questionId."' class='selectpicker exercise_mark_select'>";
$model = ExerciseLib::getCourseScoreModel();
if (empty($model)) {
for ($i = 0; $i <= $questionWeighting; $i++) {
echo '<option value="'.$i.'" '.(($i == $questionScore) ? "selected='selected'" : '').'>'.$i.'</option>';
@ -839,8 +859,8 @@ foreach ($questionList as $questionId) {
}
}
echo '</select>';
echo '</form><br /></div>';
echo '</form><br /></div>';*/
echo '</div>';
if ($questionScore == -1) {
$questionScore = 0;
echo ExerciseLib::getNotCorrectedYetText();

@ -66,11 +66,9 @@ if (isset($export_flatview_form) && !$file_type == 'pdf') {
)
);
}
$category_id = 0;
if (isset($_GET['selectcat'])) {
$category_id = (int) $_GET['selectcat'];
} else {
$category_id = '';
}
$simple_search_form = new UserForm(

@ -47,7 +47,7 @@ DisplayGradebook::display_header_result(
'statistics'
);
//Bad, Regular, Good - User definitions
// Bad, Regular, Good - User definitions
$displays = $displayScore->get_custom_score_display_settings();
if (!$displayScore->is_custom() || empty($displays)) {
@ -86,21 +86,28 @@ if (!$displayScore->is_custom() || empty($displays)) {
}
// Generate table
$stattable = '<table class="data_table" cellspacing="0" cellpadding="3">';
$stattable .= '<tr><th>'.get_lang('ScoringSystem').'</th>';
$stattable .= '<th>'.get_lang('Percentage').'</th>';
$stattable .= '<th>'.get_lang('CountUsers').'</th></tr>';
$html = '<table class="data_table" cellspacing="0" cellpadding="3">';
$html .= '<tr><th>'.get_lang('ScoringSystem').'</th>';
$html .= '<th>'.get_lang('Percentage').'</th>';
$html .= '<th>'.get_lang('CountUsers').'</th></tr>';
$counter = 0;
$model = ExerciseLib::getCourseScoreModel();
foreach ($keys as $key) {
$bar = ($highest_ratio > 0 ? ($nr_items[$key] / $highest_ratio) * 100 : 0);
$stattable .= '<tr class="row_'.($counter % 2 == 0 ? 'odd' : 'even').'">';
$stattable .= '<td width="150">'.$key.'</td>';
$stattable .= '<td width="550">'.Display::bar_progress($bar).'</td>';
$stattable .= '<td align="right">'.$nr_items[$key].'</td>';
$stattable .= '</tr>';
$html .= '<tr class="row_'.($counter % 2 == 0 ? 'odd' : 'even').'">';
$html .= '<td width="150">'.$key.'</td>';
if (empty($model)) {
$html .= '<td width="550">'.Display::bar_progress($bar).'</td>';
} else {
$html .= '<td width="550">'.ExerciseLib::convertScoreToModel($bar).'</td>';
}
$html .= '<td align="right">'.$nr_items[$key].'</td>';
$html .= '</tr>';
$counter++;
}
$stattable .= '</table>';
echo $stattable;
$html .= '</table>';
echo $html;
}
Display :: display_footer();

@ -166,8 +166,7 @@ if (isset($_GET['action'])) {
}
if (isset($_GET['editres'])) {
$edit_res_xml = Security::remove_XSS($_GET['editres']);
$resultedit = Result::load($edit_res_xml);
$resultedit = Result::load($_GET['editres']);
$edit_res_form = new EvalForm(
EvalForm::TYPE_RESULT_EDIT,
$eval[0],
@ -182,7 +181,7 @@ if (isset($_GET['editres'])) {
$result = new Result();
$resultlog = new Result();
$resultlog->addResultLog($values['hid_user_id'], $select_eval);
$result->set_id($edit_res_xml);
$result->set_id($_GET['editres']);
$result->set_user_id($values['hid_user_id']);
$result->set_evaluation_id($select_eval);
$row_value = isset($values['score']) ? $values['score'] : 0;
@ -349,7 +348,7 @@ if (isset($_GET['export'])) {
];
$locked_status = $eval[0]->get_locked();
$export_result_form = new DataForm(
DataForm :: TYPE_EXPORT,
DataForm::TYPE_EXPORT,
'export_result_form',
null,
api_get_self().'?export=&selecteval='.$select_eval.'&'.api_get_cidreq(),

@ -939,6 +939,8 @@ if (isset($first_time) && $first_time == 1 && api_is_allowed_to_edit(null, true)
$i = 0;
$allcat = [];
$model = ExerciseLib::getCourseScoreModel();
$allowGraph = api_get_configuration_value('gradebook_hide_graph') === false;
$isAllow = api_is_allowed_to_edit(null, true);
/** @var Category $cat */
foreach ($cats as $cat) {
@ -963,9 +965,7 @@ if (isset($first_time) && $first_time == 1 && api_is_allowed_to_edit(null, true)
$certificate
);
if (api_is_allowed_to_edit(null, true) &&
api_get_setting('gradebook_enable_grade_model') === 'true'
) {
if ($isAllow && api_get_setting('gradebook_enable_grade_model') === 'true') {
// Showing the grading system
if (!empty($grade_models[$grade_model_id])) {
echo Display::return_message(
@ -980,8 +980,7 @@ if (isset($first_time) && $first_time == 1 && api_is_allowed_to_edit(null, true)
}
$loadStats = [];
$teacher = api_is_allowed_to_edit(null, true);
if (!$teacher) {
if (!$isAllow) {
if (api_get_setting('gradebook_detailed_admin_view') === 'true') {
$loadStats = [1, 2, 3];
} else {
@ -1004,7 +1003,7 @@ if (isset($first_time) && $first_time == 1 && api_is_allowed_to_edit(null, true)
$loadStats
);
if (api_is_allowed_to_edit()) {
if ($isAllow) {
$gradebookTable->td_attributes = [
4 => 'class="text-center"',
];
@ -1012,9 +1011,8 @@ if (isset($first_time) && $first_time == 1 && api_is_allowed_to_edit(null, true)
$table = $gradebookTable->return_table();
$allowGraph = api_get_configuration_value('gradebook_hide_graph') === false;
$graph = '';
if ($allowGraph) {
if ($allowGraph && empty($model)) {
$graph = $gradebookTable->getGraph();
}

@ -21,7 +21,7 @@ class DisplayGradebook
$header = null;
if (api_is_allowed_to_edit(null, true)) {
$header = '<div class="actions">';
if ($page != 'statistics') {
if ($page !== 'statistics') {
$header .= '<a href="'.Category::getUrl().'selectcat='.$selectcat.'">'.
Display::return_icon('back.png', get_lang('FolderView'), '', ICON_SIZE_MEDIUM)
.'</a>';
@ -62,20 +62,23 @@ class DisplayGradebook
// TODO this check needed ?
$score = $evalobj->calc_score();
if ($score != null) {
$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);
$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);
}
}
}
}
@ -97,7 +100,9 @@ class DisplayGradebook
$evalinfo .= '<h2>'.$evalobj->get_name().'</h2><hr>';
$evalinfo .= $description;
$evalinfo .= get_lang('Course').' :<b> '.$course.'</b><br />';
$evalinfo .= get_lang('QualificationNumeric').' :<b> '.$evalobj->get_max().'</b><br>'.$average;
if (empty($model)) {
$evalinfo .= get_lang('QualificationNumeric').' :<b> '.$evalobj->get_max().'</b><br>'.$average;
}
if (!api_is_allowed_to_edit()) {
$evalinfo .= $student_score;

@ -206,23 +206,13 @@ class EvalForm extends FormValidator
}
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'];
$result = $result_and_user['result'];
$renderer = &$this->defaultRenderer();
$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();
if (api_is_western_name_order()) {
$user_info = '<td align="left" >'.$user['firstname'].'</td>';
@ -240,10 +230,55 @@ class EvalForm extends FormValidator
<!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error -->
</td>
</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>
</tr>';
}
$renderer->setElementTemplate($template, 'score['.$result->get_id().']');
}
$this->setDefaults($defaults);
$this->addButtonSave(get_lang('EditResult'), 'submit');
if (empty($model)) {
$this->setDefaults($defaults);
}
$this->addButtonSave(get_lang('EditResult'));
$renderer->setElementTemplate($template_submit, 'submit');
}
@ -369,39 +404,58 @@ class EvalForm extends FormValidator
*/
protected function build_result_edit_form()
{
$this->setDefaults(
[
'score' => $this->result_object->get_score(),
'maximum' => $this->evaluation_object->get_max(),
]
);
$userInfo = api_get_user_info($this->result_object->get_user_id());
$this->addHeader(get_lang('User').': '.$userInfo['complete_name']);
$this->addFloat(
'score',
[
get_lang('Score'),
null,
'/ '.$this->evaluation_object->get_max(),
],
false,
[
'size' => '4',
'maxlength' => '5',
],
false,
0,
$this->evaluation_object->get_max()
);
$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'), 'submit');
$this->addButtonSave(get_lang('Edit'));
$this->addElement('hidden', 'hid_user_id', $this->result_object->get_user_id());
}
/**
@ -417,7 +471,7 @@ class EvalForm extends FormValidator
'created_at' => api_get_utc_datetime(),
]
);
$this->build_basic_form(0);
$this->build_basic_form();
if ($this->evaluation_object->get_course_code() == null) {
$this->addElement('checkbox', 'adduser', null, get_lang('AddUserToEval'));
} else {
@ -463,16 +517,17 @@ class EvalForm extends FormValidator
/**
* 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']) && $_GET['editeval'] == 1) {
$form_title = get_lang('EditEvaluation');
}
$this->addElement('header', $form_title);
$this->addHeader($form_title);
$this->addElement('hidden', 'hid_user_id');
$this->addElement('hidden', 'hid_course_code');
@ -550,8 +605,51 @@ class EvalForm extends FormValidator
]
);
$model = ExerciseLib::getCourseScoreModel();
if ($edit) {
if (!$this->evaluation_object->has_results()) {
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'),
@ -560,29 +658,28 @@ class EvalForm extends FormValidator
'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'), get_lang('CannotChangeTheMaxNote')],
get_lang('QualificationNumeric'),
false,
[
'maxlength' => '5',
'disabled' => 'disabled',
'class' => $class,
'disabled' => 'disabled'
]
);
$defaults['max'] = $item['max'];
$this->setDefaults($defaults);
}
} else {
$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);
}
$this->addElement('textarea', 'description', get_lang('Description'));

@ -64,7 +64,12 @@ class ResultTable extends SortableTable
$this->set_header($column++, get_lang('LastName'));
$this->set_header($column++, get_lang('FirstName'));
}
$this->set_header($column++, get_lang('Score'));
$model = ExerciseLib::getCourseScoreModel();
if (empty($model)) {
$this->set_header($column++, get_lang('Score'));
}
if ($scoredisplay->is_custom()) {
$this->set_header($column++, get_lang('Display'));
}
@ -123,7 +128,7 @@ class ResultTable extends SortableTable
break;
}
if ($this->direction == 'DESC') {
if ($this->direction === 'DESC') {
$sorting |= ResultsDataGenerator::RDG_SORT_DESC;
} else {
$sorting |= ResultsDataGenerator::RDG_SORT_ASC;
@ -131,6 +136,8 @@ class ResultTable extends SortableTable
$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) {
@ -146,11 +153,13 @@ class ResultTable extends SortableTable
$row[] = $item['firstname'];
}
$row[] = Display::bar_progress(
$item['percentage_score'],
false,
$item['score']
);
if (empty($model)) {
$row[] = Display::bar_progress(
$item['percentage_score'],
false,
$item['score']
);
}
if ($scoredisplay->is_custom()) {
$row[] = $item['display'];

@ -80,7 +80,7 @@ class UserTable extends SortableTable
$sorting = UserDataGenerator::UDG_SORT_MASK;
break;
}
if ($this->direction == 'DESC') {
if ($this->direction === 'DESC') {
$sorting |= UserDataGenerator::UDG_SORT_DESC;
} else {
$sorting |= UserDataGenerator::UDG_SORT_ASC;
@ -89,7 +89,8 @@ class UserTable extends SortableTable
// generate the data to display
$sortable_data = [];
foreach ($data_array as $data) {
if ($data[2] != '') {//filter by course removed
if ($data[2] != '') {
// filter by course removed
$row = [];
$row[] = $this->build_type_column($data[0]);
$row[] = $this->build_name_link($data[0]);

@ -121,16 +121,9 @@ class FlatViewDataGenerator
$this->params['only_subcat'] == $this->category->get_id()
) {
$main_weight = $this->category->get_weight();
$grade_model_id = $this->category->get_grade_model_id();
} else {
$main_cat = Category::load($parent_id, null, null);
$main_weight = $main_cat[0]->get_weight();
$grade_model_id = $main_cat[0]->get_grade_model_id();
}
$use_grade_model = true;
if (empty($grade_model_id) || $grade_model_id == -1) {
$use_grade_model = false;
}
//@todo move these in a function
@ -161,6 +154,7 @@ class FlatViewDataGenerator
// No category was added
$course_code = api_get_course_id();
$session_id = api_get_session_id();
$model = ExerciseLib::getCourseScoreModel();
$allcat = $this->category->get_subcategories(
null,
@ -220,7 +214,11 @@ class FlatViewDataGenerator
/** @var AbstractLink $item */
$item = $this->evals_links[$count + $items_start];
$weight = round(100 * $item->get_weight() / $main_weight, 1);
$headers[] = $item->get_name().' '.$weight.' % ';
$label = $item->get_name().' '.$weight.' % ';
if (!empty($model)) {
$label = $item->get_name();
}
$headers[] = $label;
$evaluationsAdded[] = $item->get_id();
}
}
@ -234,7 +232,11 @@ class FlatViewDataGenerator
!in_array($item->get_id(), $evaluationsAdded)
) {
$weight = round(100 * $item->get_weight() / $main_weight, 1);
$headers[] = $item->get_name().' '.$weight.' % ';
$label = $item->get_name().' '.$weight.' % ';
if (!empty($model)) {
$label = $item->get_name();
}
$headers[] = $label;
}
}
}
@ -375,16 +377,9 @@ class FlatViewDataGenerator
(isset($this->params['only_subcat']) && $this->params['only_subcat'] == $this->category->get_id())
) {
$main_weight = $this->category->get_weight();
$grade_model_id = $this->category->get_grade_model_id();
} else {
$main_cat = Category::load($parent_id, null, null);
$main_weight = $main_cat[0]->get_weight();
$grade_model_id = $main_cat[0]->get_grade_model_id();
}
$use_grade_model = true;
if (empty($grade_model_id) || $grade_model_id == -1) {
$use_grade_model = false;
}
$export_to_pdf = false;
@ -394,6 +389,7 @@ class FlatViewDataGenerator
$course_code = api_get_course_id();
$session_id = api_get_session_id();
$model = ExerciseLib::getCourseScoreModel();
foreach ($selected_users as $user) {
$row = [];
@ -446,10 +442,8 @@ class FlatViewDataGenerator
$row[] = $user[1];
$item_value = 0;
$item_value_total = 0;
$item_total = 0;
$convert_using_the_global_weight = true;
$allcat = $this->category->get_subcategories(
null,
@ -599,22 +593,24 @@ class FlatViewDataGenerator
}
if (!$show_all) {
$displayScore = $scoreDisplay->display_score($total_score);
if (!empty($model)) {
$displayScore = ExerciseLib::show_score($total_score[0], $total_score[1]);
}
if ($export_to_pdf) {
$row['total'] = $scoreDisplay->display_score($total_score);
$row['total'] = $displayScore;
} else {
$row[] = $scoreDisplay->display_score($total_score);
$row[] = $displayScore;
}
} else {
$displayScore = $scoreDisplay->display_score($total_score, $defaultStyle);
if (!empty($model)) {
$displayScore = ExerciseLib::show_score($total_score[0], $total_score[1]);
}
if ($export_to_pdf) {
$row['total'] = $scoreDisplay->display_score(
$total_score,
$defaultStyle
);
$row['total'] = $displayScore;
} else {
$row[] = $scoreDisplay->display_score(
$total_score,
$defaultStyle
);
$row[] = $displayScore;
}
}
unset($score);
@ -734,7 +730,7 @@ class FlatViewDataGenerator
if (isset($score[0]) && isset($score[1])) {
$scoreToShow = ExerciseLib::show_score($score[0], $score[1]);
}
$temp_score = $temp_score.'&nbsp;'.$scoreToShow;
$temp_score = $scoreToShow;
}
if (!isset($this->params['only_total_category']) ||
@ -877,7 +873,6 @@ class FlatViewDataGenerator
$score_final = ($score[0] / $score_denom) * 100;
$row[] = $score_final;
}
//$total_score = array($item_value, $item_total);
$score_final = ($item_value / $item_total) * 100;
$row[] = $score_final;
@ -917,7 +912,6 @@ class FlatViewDataGenerator
$item_total = 0;
$final_score = 0;
$item_value_total = 0;
$convert_using_the_global_weight = true;
$allcat = $this->category->get_subcategories(
null,
$course_code,

@ -98,14 +98,14 @@ class ResultsDataGenerator
$ignore_score_color
);
}
$user['percentage_score'] = intval(
$scoreDisplay->display_score(
[$result->get_score(), $this->evaluation->get_max()],
SCORE_PERCENT,
SCORE_BOTH,
true
)
$user['percentage_score'] = (int) $scoreDisplay->display_score(
[$result->get_score(), $this->evaluation->get_max()],
SCORE_PERCENT,
SCORE_BOTH,
true
);
if ($pdf && $number_decimals == null) {
$user['scoreletter'] = $result->get_score();
}

@ -122,15 +122,13 @@ class UserDataGenerator
} elseif ($sorting & self::UDG_SORT_SCORE) {
// if user sorts on student's scores, first calculate them and cache them
foreach ($allitems as $item) {
$this->scorecache[$item->get_item_type().$item->get_id()]
= $item->calc_score($this->userid);
$this->scorecache[$item->get_item_type().$item->get_id()] = $item->calc_score($this->userid);
}
usort($allitems, ['UserDataGenerator', 'sort_by_score']);
} elseif ($sorting & self::UDG_SORT_MASK) {
// if user sorts on student's masks, first calculate scores and cache them
foreach ($allitems as $item) {
$this->scorecache[$item->get_item_type().$item->get_id()]
= $item->calc_score($this->userid);
$this->scorecache[$item->get_item_type().$item->get_id()] = $item->calc_score($this->userid);
}
usort($allitems, ['UserDataGenerator', 'sort_by_mask']);
}
@ -144,24 +142,42 @@ class UserDataGenerator
// fill score cache if not done yet
if (!isset($this->scorecache)) {
foreach ($visibleitems as $item) {
$this->scorecache[$item->get_item_type().$item->get_id()]
= $item->calc_score($this->userid);
$this->scorecache[$item->get_item_type().$item->get_id()] = $item->calc_score($this->userid);
}
}
// generate the data to display
$scoredisplay = ScoreDisplay::instance();
$data = [];
$model = ExerciseLib::getCourseScoreModel();
foreach ($visibleitems as $item) {
$row = [];
$row[] = $item;
$row[] = $item->get_name();
$row[] = $this->build_course_name($item);
$row[] = $this->build_category_name($item);
$row[] = $this->build_average_column($item, $ignore_score_color);
$row[] = $this->build_result_column($item, $ignore_score_color);
if ($scoredisplay->is_custom()) {
$row[] = $this->build_mask_column($item, $ignore_score_color);
if (!empty($model)) {
if (isset($this->avgcache)) {
$avgscore = $this->avgcache[$item->get_item_type().$item->get_id()];
} else {
$avgscore = $item->calc_score();
}
$row[] = ExerciseLib::show_score($avgscore[0], $avgscore[1]);
$score = $this->scorecache[$item->get_item_type().$item->get_id()];
$displayScore = ExerciseLib::show_score($score[0], $score[1]);
$row[] = $displayScore;
if ($scoredisplay->is_custom()) {
$row[] = $displayScore;
}
} else {
$row[] = $this->build_average_column($item, $ignore_score_color);
$row[] = $this->build_result_column($item, $ignore_score_color);
if ($scoredisplay->is_custom()) {
$row[] = $this->build_mask_column($item, $ignore_score_color);
}
}
$data[] = $row;
}
@ -378,7 +394,7 @@ class UserDataGenerator
}
/**
* @param $coursecode
* @param string $coursecode
*
* @return mixed
*/
@ -397,7 +413,7 @@ class UserDataGenerator
}
/**
* @param $category_id
* @param int $category_id
*/
private function get_category_cached($category_id)
{
@ -430,8 +446,8 @@ class UserDataGenerator
} else {
return $cat->get_name();
}
} else {
return '';
}
return '';
}
}

@ -1967,7 +1967,7 @@ class Display
}
/**
* @param int $percentage
* @param int $percentage int value between 0 and 100
* @param bool $show_percentage
* @param string $extra_info
*

@ -178,10 +178,7 @@ class HTML_QuickForm_select extends HTML_QuickForm_element
function apiVersion()
{
return 2.3;
} //end func apiVersion
// }}}
// {{{ setSelected()
}
/**
* Sets the default values of the select box
@ -194,32 +191,14 @@ class HTML_QuickForm_select extends HTML_QuickForm_element
function setSelected($values)
{
if (is_string($values) && $this->getMultiple()) {
$values = explode("[ ]?,[ ]?", $values);
$values = explode('[ ]?,[ ]?', $values);
}
if (is_array($values)) {
$this->_values = array_values($values);
} else {
$this->_values = array($values);
}
} //end func setSelected
// }}}
// {{{ getSelected()
/**
* Returns an array of the selected values
*
* @since 1.0
* @access public
* @return array of selected values
*/
function getSelected()
{
return $this->_values;
} // end func getSelected
// }}}
// {{{ setName()
}
/**
* Sets the input field name
@ -232,10 +211,7 @@ class HTML_QuickForm_select extends HTML_QuickForm_element
function setName($name)
{
$this->updateAttributes(array('name' => $name));
} //end func setName
// }}}
// {{{ getName()
}
/**
* Returns the element name
@ -247,10 +223,7 @@ class HTML_QuickForm_select extends HTML_QuickForm_element
function getName()
{
return $this->getAttribute('name');
} //end func getName
// }}}
// {{{ getPrivateName()
}
/**
* Returns the element name (possibly with brackets appended)
@ -266,10 +239,7 @@ class HTML_QuickForm_select extends HTML_QuickForm_element
} else {
return $this->getName();
}
} //end func getPrivateName
// }}}
// {{{ setValue()
}
/**
* Sets the value of the form element
@ -282,10 +252,7 @@ class HTML_QuickForm_select extends HTML_QuickForm_element
function setValue($value)
{
$this->setSelected($value);
} // end func setValue
// }}}
// {{{ getValue()
}
/**
* Returns an array of the selected values
@ -297,10 +264,7 @@ class HTML_QuickForm_select extends HTML_QuickForm_element
function getValue()
{
return $this->_values;
} // end func getValue
// }}}
// {{{ setSize()
}
/**
* Sets the select field size, only applies to 'multiple' selects
@ -313,10 +277,7 @@ class HTML_QuickForm_select extends HTML_QuickForm_element
function setSize($size)
{
$this->updateAttributes(array('size' => $size));
} //end func setSize
// }}}
// {{{ getSize()
}
/**
* Returns the select field size
@ -328,11 +289,7 @@ class HTML_QuickForm_select extends HTML_QuickForm_element
function getSize()
{
return $this->getAttribute('size');
} //end func getSize
// }}}
// {{{ setMultiple()
}
/**
* Sets the select mutiple attribute
@ -349,10 +306,7 @@ class HTML_QuickForm_select extends HTML_QuickForm_element
} else {
$this->removeAttribute('multiple');
}
} //end func setMultiple
// }}}
// {{{ getMultiple()
}
/**
* Returns the select mutiple attribute
@ -364,10 +318,7 @@ class HTML_QuickForm_select extends HTML_QuickForm_element
function getMultiple()
{
return (bool)$this->getAttribute('multiple');
} //end func getMultiple
// }}}
// {{{ addOption()
}
/**
* Adds a new OPTION to the SELECT
@ -402,10 +353,9 @@ class HTML_QuickForm_select extends HTML_QuickForm_element
} else {
$this->_options[] = array('text' => $text, 'attr' => $attributes);
}
} // end func addOption
}
/**
/**
* Adds a new OPTION to the SELECT
*
* @param string $text Display text for the OPTION
@ -521,10 +471,7 @@ class HTML_QuickForm_select extends HTML_QuickForm_element
}
}
return $html;
} //end func getFrozenHtml
// }}}
// {{{ exportValue()
}
/**
* We check the options and return only the values that _could_ have been
@ -579,6 +526,24 @@ class HTML_QuickForm_select extends HTML_QuickForm_element
}
}
/**
* @param FormValidator $form
*/
public function updateSelectWithSelectedOption(FormValidator $form)
{
$id = $this->getAttribute('id');
$form->addHtml('<script>
$(function(){
var optionClass = $("#'.$id.'").find("option:checked").attr("class");
$("#'.$id.'").attr("class", "form-control " + optionClass);
$("#'.$id.'").on("change", function() {
var optionClass = ($(this).find("option:checked").attr("class"));
$(this).attr("class", "form-control " + optionClass);
});
});
</script>');
}
/**
* @param string $layout
*
@ -634,12 +599,4 @@ class HTML_QuickForm_select extends HTML_QuickForm_element
break;
}
}
/**
* Remove all options
*/
public function clearOptions()
{
$this->_options = [];
}
}

@ -53,7 +53,8 @@ class HTML_QuickForm_text extends HTML_QuickForm_input
$attributes = [];
}
if (is_array($attributes) || empty($attributes)) {
$attributes['class'] = 'form-control';
$classFromAttributes = isset($attributes['class']) ? $attributes['class'] : '';
$attributes['class'] = $classFromAttributes.' form-control';
}
$inputSize = isset($attributes['input-size']) ? $attributes['input-size'] : null;
$this->setInputSize($inputSize);
@ -161,8 +162,6 @@ class HTML_QuickForm_text extends HTML_QuickForm_input
{element}
</div>';
}
return $template;
break;
}

Loading…
Cancel
Save