Add prerequisite_min_score/prerequisite_max_score db changes see BT#5776

1.10.x
Julio Montoya 10 years ago
parent a57b60d384
commit 856b15afa2
  1. 5
      main/inc/lib/add_course.lib.inc.php
  2. 2
      main/install/db_main.sql
  3. 4
      main/install/migrate-db-1.9.0-1.10.0-pre.sql
  4. 94
      main/newscorm/learnpath.class.php
  5. 101
      main/newscorm/learnpathItem.class.php

@ -1435,9 +1435,10 @@ class AddCourse
"terms TEXT NULL," . // contains the indexing tags (search engine)
"search_did INT NULL," . // contains the internal search-engine id of this element
"audio VARCHAR(250),
prerequisite_min_score float,
prerequisite_max_score float,
PRIMARY KEY (c_id, id)
)" . $charset_clause; // contains the audio file that goes with the learning path step
)" . $charset_clause; // contains the audio file that goes with the learning path step
Database::query($sql);

@ -884,7 +884,7 @@ VALUES
('tool_visible_by_default_at_creation','quiz','checkbox','Tools','true','ToolVisibleByDefaultAtCreationTitle','ToolVisibleByDefaultAtCreationComment',NULL,'Quiz', 1),
('tool_visible_by_default_at_creation','gradebook','checkbox','Tools','true','ToolVisibleByDefaultAtCreationTitle','ToolVisibleByDefaultAtCreationComment',NULL,'Gradebook', 1),
('prevent_session_admins_to_manage_all_users', NULL, 'radio', 'Session', 'false', 'PreventSessionAdminsToManageAllUsersTitle', 'PreventSessionAdminsToManageAllUsersComment', NULL, NULL, 1),
('chamilo_database_version', NULL, 'textfield',NULL, '1.10.0.15','DatabaseVersion','', NULL, NULL, 0);
('chamilo_database_version', NULL, 'textfield',NULL, '1.10.0.16','DatabaseVersion','', NULL, NULL, 0);
UNLOCK TABLES;
/*!40000 ALTER TABLE settings_current ENABLE KEYS */;

@ -82,9 +82,11 @@ INSERT INTO settings_options (variable, value, display_text) VALUES ('show_gloss
INSERT INTO settings_options (variable, value, display_text) VALUES ('show_glossary_in_extra_tools', 'exercise_and_lp', 'ExerciseAndLearningPath');
-- Do not move this query
UPDATE settings_current SET selected_value = '1.10.0.15' WHERE variable = 'chamilo_database_version';
UPDATE settings_current SET selected_value = '1.10.0.16' WHERE variable = 'chamilo_database_version';
-- xxCOURSExx
ALTER TABLE c_survey ADD visible_results INT UNSIGNED DEFAULT 0;
ALTER TABLE c_lp_item ADD COLUMN prerequisite_min_score float;
ALTER TABLE c_lp_item ADD COLUMN prerequisite_max_score float;

@ -1460,26 +1460,32 @@ class learnpath
$max_score = 100;
}
if ($mastery_score > $max_score) {
/*if ($mastery_score > $max_score) {
$max_score = $mastery_score;
}
}*/
if (!is_numeric($prerequisite_id)) {
$prerequisite_id = 'NULL';
}
$sql = " UPDATE " . $tbl_lp_item . "
SET prerequisite = " . $prerequisite_id . "
WHERE c_id = ".$course_id." AND id = " . $id;
$mastery_score = floatval($mastery_score);
$max_score = floatval($max_score);
$sql = " UPDATE $tbl_lp_item
SET
prerequisite = $prerequisite_id ,
prerequisite_min_score = $mastery_score ,
prerequisite_max_score = $max_score
WHERE c_id = $course_id AND id = $id";
Database::query($sql);
if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
// Will this be enough to ensure unicity?
$sql = " UPDATE $tbl_lp_item
/*$sql = " UPDATE $tbl_lp_item
SET mastery_score = $mastery_score
WHERE c_id = $course_id AND ref = '$prerequisite_id'";
Database::query($sql);
Database::query($sql);*/
}
// TODO: Update the item object (can be ignored for now because refreshed).
return true;
@ -5284,10 +5290,12 @@ class learnpath
* @param int $depth
* @param array $tmp
*/
public function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array ()) {
public function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array ())
{
if ($this->debug > 1) {
error_log('New LP - In learnpath::create_tree_array())', 0);
}
if (is_array($array)) {
for ($i = 0; $i < count($array); $i++) {
if ($array[$i]['parent_item_id'] == $parent) {
@ -5298,6 +5306,10 @@ class learnpath
$preq = (empty($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
$audio = isset($array[$i]['audio']) ? $array[$i]['audio'] : null;
$path = isset($array[$i]['path']) ? $array[$i]['path'] : null;
$prerequisiteMinScore = isset($array[$i]['prerequisite_min_score']) ? $array[$i]['prerequisite_min_score'] : null;
$prerequisiteMaxScore = isset($array[$i]['prerequisite_max_score']) ? $array[$i]['prerequisite_max_score'] : null;
$this->arrMenu[] = array(
'id' => $array[$i]['id'],
'item_type' => $array[$i]['item_type'],
@ -5313,7 +5325,9 @@ class learnpath
'display_order' => $array[$i]['display_order'],
'prerequisite' => $preq,
'depth' => $depth,
'audio' => $audio
'audio' => $audio,
'prerequisite_min_score' => $prerequisiteMinScore,
'prerequisite_max_score' => $prerequisiteMaxScore
);
$this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
@ -5431,7 +5445,9 @@ class learnpath
'mastery_score' => $row['mastery_score'],
'prerequisite' => $row['prerequisite'],
'display_order' => $row['display_order'],
'audio' => $row['audio']
'audio' => $row['audio'],
'prerequisite_max_score' => $row['prerequisite_max_score'],
'prerequisite_min_score' => $row['prerequisite_min_score']
);
}
@ -8242,7 +8258,7 @@ class learnpath
WHERE c_id = $course_id AND id = " . $item_id;
$result = Database::query($sql);
$row = Database::fetch_array($result);
$preq_id = $row['prerequisite'];
$prerequisiteId = $row['prerequisite'];
$return = '<legend>';
$return .= get_lang('AddEditPrerequisites');
$return .= '</legend>';
@ -8264,8 +8280,15 @@ class learnpath
$sql = "SELECT * FROM $tbl_lp_item
WHERE c_id = $course_id AND lp_id = " . $this->lp_id;
$result = Database::query($sql);
$arrLP = array ();
$arrLP = array();
$selectedMinScore = array();
$selectedMaxScore = array();
while ($row = Database :: fetch_array($result)) {
if ($row['id'] == $item_id) {
$selectedMinScore[$row['prerequisite']] = $row['prerequisite_min_score'];
$selectedMaxScore[$row['prerequisite']] = $row['prerequisite_max_score'];
}
$arrLP[] = array(
'id' => $row['id'],
'item_type' => $row['item_type'],
@ -8280,12 +8303,10 @@ class learnpath
'mastery_score' => $row['mastery_score'],
'prerequisite' => $row['prerequisite'],
'next_item_id' => $row['next_item_id'],
'display_order' => $row['display_order']
'display_order' => $row['display_order'],
'prerequisite_min_score' => $row['prerequisite_min_score'],
'prerequisite_max_score' => $row['prerequisite_max_score'],
);
if ($row['ref'] == $preq_id) {
$preq_mastery = $row['mastery_score'];
$preq_max = $row['max_score'];
}
}
$this->tree_array($arrLP);
@ -8293,14 +8314,20 @@ class learnpath
unset($this->arrMenu);
for ($i = 0; $i < count($arrLP); $i++) {
if ($arrLP[$i]['id'] == $item_id) {
$item = $arrLP[$i];
if ($item['id'] == $item_id) {
break;
}
$selectedMaxScoreValue = isset($selectedMaxScore[$item['id']]) ? $selectedMaxScore[$item['id']] : $item['max_score'];
$selectedMinScoreValue = isset($selectedMinScore[$item['id']]) ? $selectedMinScore[$item['id']]: 0;
$return .= '<tr>';
$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
$return .= '<label for="id' . $arrLP[$i]['id'] . '">';
$return .= '<input' . (($arrLP[$i]['id'] == $preq_id) ? ' checked="checked" ' : '') . (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter') ? ' disabled="disabled" ' : ' ') . 'id="id' . $arrLP[$i]['id'] . '" name="prerequisites" style="margin-left:' . $arrLP[$i]['depth'] * 10 . 'px; margin-right:10px;" type="radio" value="' . $arrLP[$i]['id'] . '" />';
$icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
$return .= '<td class="radio"' . (($item['item_type'] != TOOL_QUIZ && $item['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
$return .= '<label for="id' . $item['id'] . '">';
$return .= '<input' . (($item['id'] == $prerequisiteId) ? ' checked="checked" ' : '') . (($item['item_type'] == 'dokeos_module' || $item['item_type'] == 'dokeos_chapter') ? ' disabled="disabled" ' : ' ') . 'id="id' . $item['id'] . '" name="prerequisites" style="margin-left:' . $item['depth'] * 10 . 'px; margin-right:10px;" type="radio" value="' . $item['id'] . '" />';
$icon_name = str_replace(' ', '', $item['item_type']);
if (file_exists('../img/lp_' . $icon_name . '.png')) {
$return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
@ -8311,32 +8338,33 @@ class learnpath
$return .= Display::return_icon('folder_document.gif','',array('style'=>'margin-right:5px;'));
}
}
$return .= $arrLP[$i]['title'] . '</label>';
$return .= $item['title'] . '</label>';
$return .= '</td>';
if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
if ($item['item_type'] == TOOL_QUIZ) {
// lets update max_score Quiz information depending of the Quiz Advanced properties
$tmp_obj_lp_item = new LpItem($course_id, $arrLP[$i]['id']);
$tmp_obj_lp_item = new LpItem($course_id, $item['id']);
$tmp_obj_exercice = new Exercise();
$tmp_obj_exercice->read($tmp_obj_lp_item->path);
$tmp_obj_lp_item->max_score = $tmp_obj_exercice->get_max_score();
$tmp_obj_lp_item->update_in_bdd();
$arrLP[$i]['max_score'] = $tmp_obj_lp_item->max_score;
$item['max_score'] = $tmp_obj_lp_item->max_score;
$return .= '<td class="exercise">';
$return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
$return .= '<input size="4" maxlength="3" name="min_' . $item['id'] . '" type="number" min="0" step="any" max="'.$item['max_score'].'" value="' . $selectedMinScoreValue. '" />';
$return .= '</td>';
$return .= '<td class="exercise">';
$return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
$return .= '<input size="4" maxlength="3" name="max_' . $item['id'] . '" type="number" min="0" step="any" max="'.$item['max_score'].'" value="' . $selectedMaxScoreValue . '" />';
$return .= '</td>';
}
if ($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES) {
if ($item['item_type'] == TOOL_HOTPOTATOES) {
$return .= '<td class="exercise">';
$return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
$return .= '<center><input size="4" maxlength="3" name="min_' . $item['id'] . '" type="number" min="0" step="any" max="'.$item['max_score'].'" value="' . $selectedMinScoreValue . '" /></center>';
$return .= '</td>';
$return .= '<td class="exercise"">';
$return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
$return .= '<center><input size="4" maxlength="3" name="max_' . $item['id'] . '" type="number" min="0" step="any" max="'.$item['max_score'].'" value="'.$selectedMaxScoreValue . '" /></center>';
$return .= '</td>';
}
$return .= '</tr>';
@ -8366,7 +8394,7 @@ class learnpath
$sql = "SELECT * FROM $tbl_lp WHERE c_id = $course_id AND id = $lp_id ";
$result = Database::query($sql);
$row = Database :: fetch_array($result);
$preq_id = $row['prerequisite'];
$prerequisiteId = $row['prerequisite'];
$session_id = api_get_session_id();
$session_condition = api_get_session_condition($session_id);
$sql = "SELECT * FROM $tbl_lp
@ -8381,7 +8409,7 @@ class learnpath
if ($row['id'] == $lp_id) {
continue;
}
$return .= '<option value="'.$row['id'].'" '.(($row['id']==$preq_id)?' selected ' : '').'>'.$row['name'].'</option>';
$return .= '<option value="'.$row['id'].'" '.(($row['id']==$prerequisiteId)?' selected ' : '').'>'.$row['name'].'</option>';
}
}
$return .= '</select>';

@ -11,6 +11,8 @@
*/
class learnpathItem
{
const debug = 0; // Logging parameter.
public $attempt_id; // Also called "objectives" SCORM-wise.
public $audio; // The path to an audio file (stored in document/audio/).
public $children = array(); // Contains the ids of children items.
@ -73,7 +75,8 @@ class learnpathItem
public $view_id;
//var used if absolute session time mode is used
private $last_scorm_session_time = 0;
const debug = 0; // Logging parameter.
private $prerequisiteMaxScore;
private $prerequisiteMinScore;
/**
* Prepares the learning path item for later launch.
@ -140,6 +143,8 @@ class learnpathItem
$this->display_order = $row['display_order'];
$this->prereq_string = $row['prerequisite'];
$this->max_time_allowed = $row['max_time_allowed'];
$this->setPrerequisiteMaxScore($row['prerequisite_max_score']);
$this->setPrerequisiteMinScore($row['prerequisite_min_score']);
if (isset($row['launch_data'])) {
$this->launch_data = $row['launch_data'];
@ -2504,9 +2509,8 @@ class learnpathItem
}
}
// For one attempt LPs.
// For one and first attempt.
if ($this->prevent_reinit == 1) {
// 2. If is completed we check the results in the DB of the quiz.
if ($returnstatus) {
//AND origin_lp_item_id = '.$user_id.'
@ -2522,13 +2526,26 @@ class learnpathItem
LIMIT 0, 1';
$rs_quiz = Database::query($sql);
if ($quiz = Database :: fetch_array($rs_quiz)) {
if ($quiz['exe_result'] >= $items[$refs_list[$prereqs_string]]->get_mastery_score()) {
$returnstatus = true;
$minScore = $items[$refs_list[$this->get_id()]]->getPrerequisiteMinScore();
$maxScore = $items[$refs_list[$this->get_id()]]->getPrerequisiteMaxScore();
if (isset($minScore) && isset($minScore)) {
// Taking min/max prerequisites values see BT#5776
//var_dump($quiz['exe_result'], $minScore, $maxScore);exit;
if ($quiz['exe_result'] >= $minScore && $quiz['exe_result'] <= $maxScore) {
$returnstatus = true;
} else {
$this->prereq_alert = get_lang('LearnpathPrereqNotCompleted');
$returnstatus = false;
}
} else {
$this->prereq_alert = get_lang(
'LearnpathPrereqNotCompleted'
);
$returnstatus = false;
// Classic way
if ($quiz['exe_result'] >= $items[$refs_list[$prereqs_string]]->get_mastery_score()) {
$returnstatus = true;
} else {
$this->prereq_alert = get_lang('LearnpathPrereqNotCompleted');
$returnstatus = false;
}
}
} else {
$this->prereq_alert = get_lang(
@ -2538,7 +2555,7 @@ class learnpathItem
}
}
} else {
// 3. for multiple attempts we check that there are minimun 1 item completed.
// 3. for multiple attempts we check that there are minimum 1 item completed.
// Checking in the database.
$sql = 'SELECT exe_result, exe_weighting
@ -2548,19 +2565,34 @@ class learnpathItem
exe_user_id = ' . $user_id . ' AND
orig_lp_id = ' . $this->lp_id . ' AND
orig_lp_item_id = ' . $prereqs_string . ' ';
//error_log('results 2:'.$items[$refs_list[$prereqs_string]]->path. ':'.$user_id);
$rs_quiz = Database::query($sql);
if (Database::num_rows($rs_quiz) > 0) {
while ($quiz = Database :: fetch_array($rs_quiz)) {
if ($quiz['exe_result'] >= $items[$refs_list[$prereqs_string]]->get_mastery_score()) {
$returnstatus = true;
break;
$minScore = $items[$refs_list[$this->get_id()]]->getPrerequisiteMinScore();
$maxScore = $items[$refs_list[$this->get_id()]]->getPrerequisiteMaxScore();
if (isset($minScore) && isset($minScore)) {
// Taking min/max prerequisites values see BT#5776
if ($quiz['exe_result'] >= $minScore && $quiz['exe_result'] <= $maxScore) {
$returnstatus = true;
break;
} else {
$this->prereq_alert = get_lang('LearnpathPrereqNotCompleted');
$returnstatus = false;
}
} else {
$this->prereq_alert = get_lang(
'LearnpathPrereqNotCompleted'
);
$returnstatus = false;
if ($quiz['exe_result'] >= $items[$refs_list[$prereqs_string]]->get_mastery_score()) {
$returnstatus = true;
break;
} else {
$this->prereq_alert = get_lang(
'LearnpathPrereqNotCompleted'
);
$returnstatus = false;
}
}
}
} else {
@ -2591,7 +2623,6 @@ class learnpathItem
}
}
//$returnstatus = true;
if ($returnstatus && $this->prevent_reinit == 1) {
// I would prefer check in the database.
$lp_item_view = Database::get_course_table(
@ -4329,4 +4360,36 @@ class learnpathItem
return $myLessonStatus;
}
}
/**
* @return float
*/
public function getPrerequisiteMaxScore()
{
return $this->prerequisiteMaxScore;
}
/**
* @param float $prerequisiteMaxScore
*/
public function setPrerequisiteMaxScore($prerequisiteMaxScore)
{
$this->prerequisiteMaxScore = $prerequisiteMaxScore;
}
/**
* @return float
*/
public function getPrerequisiteMinScore()
{
return $this->prerequisiteMinScore;
}
/**
* @param float $prerequisiteMinScore
*/
public function setPrerequisiteMinScore($prerequisiteMinScore)
{
$this->prerequisiteMinScore = $prerequisiteMinScore;
}
}

Loading…
Cancel
Save