Format code, add docs, remove unused code.

1.10.x
Julio Montoya 10 years ago
parent 111e5681a2
commit 42d12d826c
  1. 399
      main/exercice/TestCategory.php
  2. 56
      main/exercice/multiple_answer.class.php
  3. 30
      main/exercice/multiple_answer_combination.class.php
  4. 30
      main/exercice/multiple_answer_combination_true_false.class.php
  5. 22
      main/exercice/multiple_answer_true_false.class.php
  6. 111
      main/exercice/oral_expression.class.php
  7. 81
      main/exercice/question.class.php
  8. 87
      main/exercice/question_create.php
  9. 13
      main/exercice/question_list_admin.inc.php
  10. 14
      main/exercice/question_pool.php
  11. 3
      main/exercice/savescores.php
  12. 2
      main/exercice/showinframes.php
  13. 7
      main/exercice/stats.php

@ -9,101 +9,105 @@
*/
class TestCategory
{
public $id;
public $name;
public $description;
public $id;
public $name;
public $description;
/**
* Constructor of the class Category
* @author - Hubert Borderiou
* If you give an in_id and no in_name, you get info concerning the category of id=in_id
* otherwise, you've got an category objet avec your in_id, in_name, in_descr
*
* @param int $in_id
* @param string $in_name
* @param string $in_description
* @param int $id
* @param string $name
* @param string $description
*
* @author - Hubert Borderiou
*/
public function __construct($in_id=0, $in_name = '', $in_description="")
public function __construct($id = 0, $name = '', $description = "")
{
if ($in_id != 0 && $in_name == "") {
$tmpobj = new TestCategory();
$tmpobj->getCategory($in_id);
$this->id = $tmpobj->id;
$this->name = $tmpobj->name;
$this->description = $tmpobj->description;
} else {
$this->id = $in_id;
$this->name = $in_name;
$this->description = $in_description;
}
}
if ($id != 0 && $name == "") {
$obj = new TestCategory();
$obj->getCategory($id);
$this->id = $obj->id;
$this->name = $obj->name;
$this->description = $obj->description;
} else {
$this->id = $id;
$this->name = $name;
$this->description = $description;
}
}
/**
* return the TestCategory object with id=in_id
* @param $in_id
* @param int $id
*
* @return TestCategory
*/
public function getCategory($in_id)
public function getCategory($id)
{
$t_cattable = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$in_id = intval($in_id);
$sql = "SELECT * FROM $t_cattable WHERE id = $in_id AND c_id=".api_get_course_int_id();
$res = Database::query($sql);
$numrows = Database::num_rows($res);
if ($numrows > 0) {
$row = Database::fetch_array($res);
$this->id = $row['id'];
$this->name = $row['title'];
$this->description = $row['description'];
}
}
$table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$id = intval($id);
$sql = "SELECT * FROM $table
WHERE id = $id AND c_id=".api_get_course_int_id();
$res = Database::query($sql);
if (Database::num_rows($res)) {
$row = Database::fetch_array($res);
$this->id = $row['id'];
$this->name = $row['title'];
$this->description = $row['description'];
}
}
/**
* add TestCategory in the database if name doesn't already exists
*/
public function addCategoryInBDD()
{
$t_cattable = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$v_name = $this->name;
$v_name = Database::escape_string($v_name);
$v_description = $this->description;
$v_description = Database::escape_string($v_description);
// check if name already exists
$sql = "SELECT count(*) AS nb FROM $t_cattable
WHERE title = '$v_name' AND c_id=".api_get_course_int_id();
$result_verif = Database::query($sql);
$data_verif = Database::fetch_array($result_verif);
// lets add in BDD if not the same name
if ($data_verif['nb'] <= 0) {
$c_id = api_get_course_int_id();
$params = [
'c_id' => $c_id,
'title' => $v_name,
'description' => $v_description,
];
$new_id = Database::insert($t_cattable, $params);
if ($new_id) {
$sql = "UPDATE $t_cattable SET id = iid WHERE iid = $new_id";
Database::query($sql);
// add test_category in item_property table
$course_id = api_get_course_int_id();
$course_info = api_get_course_info_by_id($course_id);
api_item_property_update(
$course_info,
TOOL_TEST_CATEGORY,
$new_id,
'TestCategoryAdded',
api_get_user_id()
);
}
$table = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$v_name = $this->name;
$v_name = Database::escape_string($v_name);
$v_description = $this->description;
$v_description = Database::escape_string($v_description);
// check if name already exists
$sql = "SELECT count(*) AS nb FROM $table
WHERE title = '$v_name' AND c_id=".api_get_course_int_id();
$result_verif = Database::query($sql);
$data_verif = Database::fetch_array($result_verif);
// lets add in BDD if not the same name
if ($data_verif['nb'] <= 0) {
$c_id = api_get_course_int_id();
$params = [
'c_id' => $c_id,
'title' => $v_name,
'description' => $v_description,
];
$new_id = Database::insert($table, $params);
if ($new_id) {
$sql = "UPDATE $table SET id = iid WHERE iid = $new_id";
Database::query($sql);
// add test_category in item_property table
$course_id = api_get_course_int_id();
$course_info = api_get_course_info_by_id($course_id);
api_item_property_update(
$course_info,
TOOL_TEST_CATEGORY,
$new_id,
'TestCategoryAdded',
api_get_user_id()
);
}
return $new_id;
} else {
return $new_id;
} else {
return false;
}
return false;
}
}
/**
@ -112,30 +116,33 @@ class TestCategory
*/
public function removeCategory()
{
$t_cattable = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$table = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$tbl_question_rel_cat = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$v_id = intval($this->id);
$sql = "DELETE FROM $t_cattable WHERE id=$v_id AND c_id=".api_get_course_int_id();
$result = Database::query($sql);
if (Database::affected_rows($result) <= 0) {
return false;
} else {
$course_id = api_get_course_int_id();
$v_id = intval($this->id);
$course_id = api_get_course_int_id();
$sql = "DELETE FROM $table
WHERE id= $v_id AND c_id=".$course_id;
$result = Database::query($sql);
if (Database::affected_rows($result) <= 0) {
return false;
} else {
// remove link between question and category
$sql2 = "DELETE FROM $tbl_question_rel_cat
WHERE category_id=$v_id AND c_id=".$course_id;
WHERE category_id = $v_id AND c_id=".$course_id;
Database::query($sql2);
// item_property update
$course_info = api_get_course_info_by_id($course_id);
api_item_property_update(
$course_info,
TOOL_TEST_CATEGORY,
$this->id,
'TestCategoryDeleted',
api_get_user_id()
);
return true;
}
api_item_property_update(
$course_info,
TOOL_TEST_CATEGORY,
$this->id,
'TestCategoryDeleted',
api_get_user_id()
);
return true;
}
}
/**
@ -143,16 +150,18 @@ class TestCategory
*/
public function modifyCategory()
{
$t_cattable = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$v_id = intval($this->id);
$v_name = Database::escape_string($this->name);
$v_description = Database::escape_string($this->description);
$sql = "UPDATE $t_cattable SET title='$v_name', description='$v_description'
WHERE id = $v_id AND c_id=".api_get_course_int_id();
$result = Database::query($sql);
if (Database::affected_rows($result) <= 0) {
return false;
} else {
$table = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$v_id = intval($this->id);
$v_name = Database::escape_string($this->name);
$v_description = Database::escape_string($this->description);
$sql = "UPDATE $table SET
title = '$v_name',
description = '$v_description'
WHERE id = $v_id AND c_id=".api_get_course_int_id();
$result = Database::query($sql);
if (Database::affected_rows($result) <= 0) {
return false;
} else {
// item_property update
$course_id = api_get_course_int_id();
$course_info = api_get_course_info_by_id($course_id);
@ -163,8 +172,9 @@ class TestCategory
'TestCategoryModified',
api_get_user_id()
);
return true;
}
return true;
}
}
/**
@ -172,9 +182,10 @@ class TestCategory
*/
public function getCategoryQuestionsNumber()
{
$t_reltable = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$in_id = intval($this->id);
$sql = "SELECT count(*) AS nb FROM $t_reltable
$sql = "SELECT count(*) AS nb
FROM $table
WHERE category_id=$in_id AND c_id=".api_get_course_int_id();
$res = Database::query($sql);
$row = Database::fetch_array($res);
@ -198,33 +209,41 @@ class TestCategory
* Otherwise, return an array of all in_field value
* in the database (in_field = id or name or description)
*/
public static function getCategoryListInfo($in_field="", $in_courseid="")
public static function getCategoryListInfo($in_field = "", $courseId = "")
{
if (empty($in_courseid) || $in_courseid=="") {
$in_courseid = api_get_course_int_id();
}
$t_cattable = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$in_field = Database::escape_string($in_field);
$tabres = array();
if ($in_field=="") {
$sql = "SELECT * FROM $t_cattable WHERE c_id=$in_courseid ORDER BY title ASC";
$res = Database::query($sql);
while ($row = Database::fetch_array($res)) {
$tmpcat = new TestCategory($row['id'], $row['title'], $row['description']);
$tabres[] = $tmpcat;
}
} else {
$sql = "SELECT $in_field FROM $t_cattable WHERE c_id=$in_courseid ORDER BY $in_field ASC";
$res = Database::query($sql);
while ($row = Database::fetch_array($res)) {
$tabres[] = $row[$in_field];
}
}
if (empty($courseId) || $courseId=="") {
$courseId = api_get_course_int_id();
}
$table = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$in_field = Database::escape_string($in_field);
$tabres = array();
if ($in_field == "") {
$sql = "SELECT * FROM $table
WHERE c_id=$courseId ORDER BY title ASC";
$res = Database::query($sql);
while ($row = Database::fetch_array($res)) {
$tmpcat = new TestCategory(
$row['id'],
$row['title'],
$row['description']
);
$tabres[] = $tmpcat;
}
} else {
$sql = "SELECT $in_field FROM $table
WHERE c_id = $courseId
ORDER BY $in_field ASC";
$res = Database::query($sql);
while ($row = Database::fetch_array($res)) {
$tabres[] = $row[$in_field];
}
}
return $tabres;
}
/**
* Return the TestCategory id for question with question_id = $in_questionid
* Return the TestCategory id for question with question_id = $questionId
* In this version, a question has only 1 TestCategory.
* Return the TestCategory id, 0 if none
* @param int $questionId
@ -235,12 +254,13 @@ class TestCategory
public static function getCategoryForQuestion($questionId, $courseId ="")
{
$result = 0;
if (empty($courseId) || $courseId=="") {
if (empty($courseId) || $courseId == "") {
$courseId = api_get_course_int_id();
}
}
$table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$questionId = intval($questionId);
$sql = "SELECT category_id FROM $table
$sql = "SELECT category_id
FROM $table
WHERE question_id = $questionId AND c_id = $courseId";
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
@ -254,29 +274,32 @@ class TestCategory
/**
* true if question id has a category
*/
public static function isQuestionHasCategory($in_questionid)
public static function isQuestionHasCategory($questionId)
{
if (TestCategory::getCategoryForQuestion($in_questionid) > 0) {
if (TestCategory::getCategoryForQuestion($questionId) > 0) {
return true;
}
return false;
}
/**
Return the category name for question with question_id = $in_questionid
Return the category name for question with question_id = $questionId
In this version, a question has only 1 category.
Return the category id, "" if none
*/
public static function getCategoryNameForQuestion($in_questionid, $in_courseid="")
{
if (empty($in_courseid) || $in_courseid=="") {
$in_courseid = api_get_course_int_id();
public static function getCategoryNameForQuestion(
$questionId,
$courseId = ""
) {
if (empty($courseId) || $courseId=="") {
$courseId = api_get_course_int_id();
}
$catid = TestCategory::getCategoryForQuestion($in_questionid, $in_courseid);
$catid = TestCategory::getCategoryForQuestion($questionId, $courseId);
$result = ""; // result
$t_cattable = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$catid = intval($catid);
$sql = "SELECT title FROM $t_cattable WHERE id = $catid AND c_id = $in_courseid";
$sql = "SELECT title FROM $table
WHERE id = $catid AND c_id = $courseId";
$res = Database::query($sql);
$data = Database::fetch_array($res);
if (Database::num_rows($res) > 0) {
@ -340,22 +363,26 @@ class TestCategory
/**
* return the number of question of a category id in a test
* input : test_id, category_id
* return : integer
* hubert.borderiou 07-04-2011
* @param int $exerciseId
* @param int $categoryId
*
* @return integer
*
* @author hubert.borderiou 07-04-2011
*/
public static function getNumberOfQuestionsInCategoryForTest($in_testid, $in_categoryid)
public static function getNumberOfQuestionsInCategoryForTest($exerciseId, $categoryId)
{
$nbCatResult = 0;
$quiz = new Exercise();
$quiz->read($in_testid);
$quiz->read($exerciseId);
$tabQuestionList = $quiz->selectQuestionList();
// the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ? ? ?
for ($i=1; $i <= count($tabQuestionList); $i++) {
if (TestCategory::getCategoryForQuestion($tabQuestionList[$i]) == $in_categoryid) {
if (TestCategory::getCategoryForQuestion($tabQuestionList[$i]) == $categoryId) {
$nbCatResult++;
}
}
return $nbCatResult;
}
@ -365,13 +392,13 @@ class TestCategory
* hubert.borderiou 07-04-2011
* question without categories are not counted
*/
public static function getNumberOfQuestionRandomByCategory($in_testid, $in_nbrandom)
public static function getNumberOfQuestionRandomByCategory($exerciseId, $in_nbrandom)
{
$nbquestionresult = 0;
$tabcatid = TestCategory::getListOfCategoriesIDForTest($in_testid);
$tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId);
for ($i=0; $i < count($tabcatid); $i++) {
if ($tabcatid[$i] > 0) { // 0 = no category for this questio
$nbQuestionInThisCat = TestCategory::getNumberOfQuestionsInCategoryForTest($in_testid, $tabcatid[$i]);
$nbQuestionInThisCat = TestCategory::getNumberOfQuestionsInCategoryForTest($exerciseId, $tabcatid[$i]);
if ($nbQuestionInThisCat > $in_nbrandom) {
$nbquestionresult += $in_nbrandom;
}
@ -386,14 +413,18 @@ class TestCategory
/**
* Return an array (id=>name)
* tabresult[0] = get_lang('NoCategory');
*
* @param int $courseId
*
* @return array
*
*/
public static function getCategoriesIdAndName($in_courseid="")
public static function getCategoriesIdAndName($courseId = "")
{
if (empty($in_courseid) || $in_courseid=="") {
$in_courseid = api_get_course_int_id();
if (empty($courseId)) {
$courseId = api_get_course_int_id();
}
$tabcatobject = TestCategory::getCategoryListInfo("", $in_courseid);
$tabcatobject = TestCategory::getCategoryListInfo("", $courseId);
$tabresult = array("0"=>get_lang('NoCategorySelected'));
for ($i=0; $i < count($tabcatobject); $i++) {
$tabresult[$tabcatobject[$i]->id] = $tabcatobject[$i]->name;
@ -406,16 +437,19 @@ class TestCategory
* tabres[0] = array of question id with category id = 0 (i.e. no category)
* tabres[24] = array of question id with category id = 24
* In this version, a question has 0 or 1 category
*
* @param int $exerciseId
* @return array
*/
public static function getQuestionsByCat($in_exerciseId)
public static function getQuestionsByCat($exerciseId)
{
$TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$in_exerciseId = intval($in_exerciseId);
$exerciseId = intval($exerciseId);
$sql = "SELECT qrc.question_id, qrc.category_id
FROM $TBL_QUESTION_REL_CATEGORY qrc, $TBL_EXERCISE_QUESTION eq
WHERE
exercice_id=$in_exerciseId AND
exercice_id=$exerciseId AND
eq.question_id=qrc.question_id AND
eq.c_id=".api_get_course_int_id()." AND
eq.c_id=qrc.c_id
@ -448,17 +482,18 @@ class TestCategory
/**
* display the category
*/
public static function displayCategoryAndTitle($in_questionID, $in_display_category_name = 1)
public static function displayCategoryAndTitle($questionId, $in_display_category_name = 1)
{
echo self::returnCategoryAndTitle($in_questionID, $in_display_category_name);
echo self::returnCategoryAndTitle($questionId, $in_display_category_name);
}
/**
* @param $in_questionID
* @param int $questionId
* @param int $in_display_category_name
* @return null|string
*/
public static function returnCategoryAndTitle($in_questionID, $in_display_category_name = 1) {
public static function returnCategoryAndTitle($questionId, $in_display_category_name = 1)
{
$is_student = !(api_is_allowed_to_edit(null,true) || api_is_session_admin());
// @todo fix $_SESSION['objExercise']
$objExercise = isset($_SESSION['objExercise']) ? $_SESSION['objExercise'] : null;
@ -466,9 +501,9 @@ class TestCategory
$in_display_category_name = $objExercise->display_category_name;
}
$content = null;
if (TestCategory::getCategoryNameForQuestion($in_questionID) != "" && ($in_display_category_name == 1 || !$is_student)) {
if (TestCategory::getCategoryNameForQuestion($questionId) != "" && ($in_display_category_name == 1 || !$is_student)) {
$content .= '<div class="page-header">';
$content .= '<h4>'.get_lang('Category').": ".TestCategory::getCategoryNameForQuestion($in_questionID).'</h4>';
$content .= '<h4>'.get_lang('Category').": ".TestCategory::getCategoryNameForQuestion($questionId).'</h4>';
$content .= "</div>";
}
return $content;
@ -512,46 +547,20 @@ class TestCategory
return $tabResult;
}
/**
* return total score for test exe_id for all question in the category $in_cat_id for user
* If no question for this category, return ""
*/
public static function getCatScoreForExeidForUserid($in_cat_id, $in_exe_id, $in_user_id)
{
$tbl_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$tbl_question_rel_category = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$in_cat_id = intval($in_cat_id);
$in_exe_id = intval($in_exe_id);
$in_user_id = intval($in_user_id);
$query = "SELECT DISTINCT
marks, exe_id, user_id, ta.question_id, category_id
FROM $tbl_track_attempt ta , $tbl_question_rel_category qrc
WHERE
ta.question_id=qrc.question_id AND
qrc.category_id=$in_cat_id AND
exe_id=$in_exe_id AND user_id=$in_user_id";
$res = Database::query($query);
$totalcatscore = "";
while ($data = Database::fetch_array($res)) {
$totalcatscore += $data['marks'];
}
return $totalcatscore;
}
/**
* return the number max of question in a category
* count the number of questions in all categories, and return the max
* @param int $exerciseId
* @author - hubert borderiou
*/
public static function getNumberMaxQuestionByCat($in_testid)
public static function getNumberMaxQuestionByCat($exerciseId)
{
$res_num_max = 0;
// foreach question
$tabcatid = TestCategory::getListOfCategoriesIDForTest($in_testid);
$tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId);
for ($i=0; $i < count($tabcatid); $i++) {
if ($tabcatid[$i] > 0) { // 0 = no category for this question
$nbQuestionInThisCat = TestCategory::getNumberOfQuestionsInCategoryForTest($in_testid, $tabcatid[$i]);
$nbQuestionInThisCat = TestCategory::getNumberOfQuestionsInCategoryForTest($exerciseId, $tabcatid[$i]);
if ($nbQuestionInThisCat > $res_num_max) {
$res_num_max = $nbQuestionInThisCat;
}
@ -663,14 +672,14 @@ class TestCategory
*/
public static function add_category_for_question_id($in_category_id, $in_question_id, $in_course_c_id)
{
$tbl_reltable = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
// if question doesn't have a category
// @todo change for 1.10 when a question can have several categories
if (TestCategory::getCategoryForQuestion($in_question_id, $in_course_c_id) == 0 &&
$in_question_id > 0 &&
$in_course_c_id > 0
) {
$sql = "INSERT INTO $tbl_reltable
$sql = "INSERT INTO $table
VALUES (".intval($in_course_c_id).", ".intval($in_question_id).", ".intval($in_category_id).")";
Database::query($sql);
}

@ -12,20 +12,20 @@
**/
class MultipleAnswer extends Question
{
static $typePicture = 'mcma.png';
static $explanationLangVar = 'MultipleSelect';
static $typePicture = 'mcma.png';
static $explanationLangVar = 'MultipleSelect';
/**
* Constructor
*/
public function __construct()
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this -> type = MULTIPLE_ANSWER;
$this -> isContent = $this-> getIsContent();
}
parent::__construct();
$this -> type = MULTIPLE_ANSWER;
$this -> isContent = $this-> getIsContent();
}
/**
/**
* function which redifines Question::createAnswersForm
* @param the formvalidator instance
* @param the answers number to display
@ -143,7 +143,7 @@ class MultipleAnswer extends Question
$buttonGroup = [];
global $text, $class;
global $text;
if ($obj_ex->edit_exercise_in_lp == true) {
// setting the save button here and not in the question class.php
$buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true);
@ -171,31 +171,31 @@ class MultipleAnswer extends Question
* @param the formvalidator instance
* @param the answers number to display
*/
function processAnswersCreation($form) {
$questionWeighting = $nbrGoodAnswers = 0;
$objAnswer = new Answer($this->id);
$nb_answers = $form->getSubmitValue('nb_answers');
function processAnswersCreation($form)
{
$questionWeighting = $nbrGoodAnswers = 0;
$objAnswer = new Answer($this->id);
$nb_answers = $form->getSubmitValue('nb_answers');
for($i=1 ; $i <= $nb_answers ; $i++) {
$answer = trim(str_replace(['<p>', '</p>'], '', $form -> getSubmitValue('answer['.$i.']')));
for($i=1 ; $i <= $nb_answers ; $i++) {
$answer = trim(str_replace(['<p>', '</p>'], '', $form -> getSubmitValue('answer['.$i.']')));
$comment = trim(str_replace(['<p>', '</p>'], '', $form -> getSubmitValue('comment['.$i.']')));
$weighting = trim($form -> getSubmitValue('weighting['.$i.']'));
$goodAnswer = trim($form -> getSubmitValue('correct['.$i.']'));
if ($goodAnswer) {
$weighting = abs($weighting);
} else {
$weighting = abs($weighting);
$weighting = -$weighting;
}
if($weighting > 0) {
if ($goodAnswer) {
$weighting = abs($weighting);
} else {
$weighting = abs($weighting);
$weighting = -$weighting;
}
if($weighting > 0) {
$questionWeighting += $weighting;
}
$objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i);
$objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i);
}
// saves the answers into the data base
// saves the answers into the data base
$objAnswer -> save();
// sets the total weighting of the question

@ -13,20 +13,20 @@
**/
class MultipleAnswerCombination extends Question
{
static $typePicture = 'mcmac.png';
static $explanationLangVar = 'MultipleSelectCombination';
static $typePicture = 'mcmac.png';
static $explanationLangVar = 'MultipleSelectCombination';
/**
* Constructor
*/
public function __construct()
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this -> type = MULTIPLE_ANSWER_COMBINATION;
$this -> isContent = $this-> getIsContent();
}
parent::__construct();
$this -> type = MULTIPLE_ANSWER_COMBINATION;
$this -> isContent = $this-> getIsContent();
}
/**
/**
* function which redefines Question::createAnswersForm
* @param FormValidator $form
*/
@ -111,22 +111,22 @@ class MultipleAnswerCombination extends Question
$answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"');
$answer_number->freeze();
$form->addElement('checkbox',
$form->addElement('checkbox',
'correct[' . $i . ']',
null,
null,
'class="checkbox" style="margin-left: 0em;"'
);
$boxes_names[] = 'correct[' . $i . ']';
$boxes_names[] = 'correct[' . $i . ']';
$form->addElement(
$form->addElement(
'html_editor',
'answer[' . $i . ']',
null,
array(),
array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')
);
$form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement(
'html_editor',

@ -12,22 +12,22 @@
**/
class MultipleAnswerCombinationTrueFalse extends MultipleAnswerCombination
{
static $typePicture = 'mcmaco.png';
static $explanationLangVar = 'MultipleAnswerCombinationTrueFalse';
static $typePicture = 'mcmaco.png';
static $explanationLangVar = 'MultipleAnswerCombinationTrueFalse';
var $options;
/**
* Constructor
*/
public function __construct()
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this -> type = MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE;
$this -> isContent = $this-> getIsContent();
$this->options = array(
'1' => get_lang('True'),
'0' => get_lang('False'),
'2' => get_lang('DontKnow'),
);
}
parent::__construct();
$this -> type = MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE;
$this -> isContent = $this-> getIsContent();
$this->options = array(
'1' => get_lang('True'),
'0' => get_lang('False'),
'2' => get_lang('DontKnow'),
);
}
}

@ -11,22 +11,22 @@
*/
class MultipleAnswerTrueFalse extends Question
{
static $typePicture = 'mcmao.png';
static $explanationLangVar = 'MultipleAnswerTrueFalse';
static $typePicture = 'mcmao.png';
static $explanationLangVar = 'MultipleAnswerTrueFalse';
public $options;
/**
* Constructor
*/
public function __construct()
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this->type = MULTIPLE_ANSWER_TRUE_FALSE;
$this->isContent = $this-> getIsContent();
parent::__construct();
$this->type = MULTIPLE_ANSWER_TRUE_FALSE;
$this->isContent = $this-> getIsContent();
$this->options = array(1 => 'True', 2 => 'False', 3 => 'DoubtScore');
}
}
/**
/**
* function which redefines Question::createAnswersForm
* @param FormValidator $form
*/

@ -2,77 +2,78 @@
/* For licensing terms, see /license.txt */
/**
* Class OralExpression
* This class allows to instantiate an object of type FREE_ANSWER,
* extending the class question
* @author Eric Marguin
* Class OralExpression
* This class allows to instantiate an object of type FREE_ANSWER,
* extending the class question
* @author Eric Marguin
*
* @package chamilo.exercise
*/
class OralExpression extends Question
{
static $typePicture = 'audio_question.png';
static $explanationLangVar = 'OralExpression';
static $typePicture = 'audio_question.png';
static $explanationLangVar = 'OralExpression';
/**
* Constructor
*/
public function __construct()
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this -> type = ORAL_EXPRESSION;
$this -> isContent = $this-> getIsContent();
}
parent::__construct();
$this -> type = ORAL_EXPRESSION;
$this -> isContent = $this-> getIsContent();
}
/**
* function which redefine Question::createAnswersForm
* @param FormValidator $form
*/
function createAnswersForm($form)
/**
* function which redefine Question::createAnswersForm
* @param FormValidator $form
*/
function createAnswersForm($form)
{
$form -> addElement('text','weighting', get_lang('Weighting'), array('class' => 'span1'));
global $text, $class;
// setting the save button here and not in the question class.php
$form->addButtonSave($text, 'submitQuestion');
if (!empty($this->id)) {
$form -> setDefaults(array('weighting' => float_format($this->weighting, 1)));
} else {
if ($this -> isContent == 1) {
$form -> setDefaults(array('weighting' => '10'));
}
}
}
$form -> addElement('text','weighting', get_lang('Weighting'), array('class' => 'span1'));
global $text, $class;
// setting the save button here and not in the question class.php
$form->addButtonSave($text, 'submitQuestion');
if (!empty($this->id)) {
$form -> setDefaults(array('weighting' => float_format($this->weighting, 1)));
} else {
if ($this -> isContent == 1) {
$form -> setDefaults(array('weighting' => '10'));
}
}
}
/**
* abstract function which creates the form to create / edit the answers of the question
* @param the FormValidator $form
*/
function processAnswersCreation($form)
/**
* abstract function which creates the form to create / edit the answers of the question
* @param the FormValidator $form
*/
function processAnswersCreation($form)
{
$this->weighting = $form ->getSubmitValue('weighting');
$this->save();
}
$this->weighting = $form ->getSubmitValue('weighting');
$this->save();
}
/**
* @param null $feedback_type
* @param null $counter
* @param null $score
* @return null|string
*/
function return_header($feedback_type = null, $counter = null, $score = null)
/**
* @param null $feedback_type
* @param null $counter
* @param null $score
* @return null|string
*/
function return_header($feedback_type = null, $counter = null, $score = null)
{
$header = parent::return_header($feedback_type, $counter, $score);
$header .= '<table class="'.$this->question_table_class.'">
<tr>
$header = parent::return_header($feedback_type, $counter, $score);
$header .= '<table class="'.$this->question_table_class.'">
<tr>
<th>&nbsp;</th>
</tr>
<tr>
</tr>
<tr>
<th>'.get_lang("Answer").'</th>
</tr>
<tr>
</tr>
<tr>
<th>&nbsp;</th>
</tr>';
</tr>';
return $header;
}
}
}

@ -95,11 +95,12 @@ abstract class Question
/**
* Reads question information from the data base
*
* @author Olivier Brouckaert
* @param int $id - question ID
* @param int $course_id
*
* @return Question
*
* @author Olivier Brouckaert
*/
public static function read($id, $course_id = null)
{
@ -177,7 +178,7 @@ abstract class Question
*
* @author Olivier Brouckaert
*
* @return - integer - question ID
* @return integer - question ID
*/
public function selectId()
{
@ -300,9 +301,9 @@ abstract class Question
/**
* changes the question title
*
* @author Olivier Brouckaert
*
* @param string $title - question title
*
* @author Olivier Brouckaert
*/
public function updateTitle($title)
{
@ -320,9 +321,10 @@ abstract class Question
/**
* changes the question description
*
* @param string $description - question description
*
* @author Olivier Brouckaert
*
* @param string $description - question description
*/
public function updateDescription($description)
{
@ -332,8 +334,9 @@ abstract class Question
/**
* changes the question weighting
*
* @author Olivier Brouckaert
* @param integer $weighting - question weighting
*
* @author Olivier Brouckaert
*/
public function updateWeighting($weighting)
{
@ -341,39 +344,44 @@ abstract class Question
}
/**
* @param array $category
*
* @author Hubert Borderiou 12-10-2011
* @param array of category $in_category
*
*/
public function updateCategory($in_category)
public function updateCategory($category)
{
$this->category = $in_category;
$this->category = $category;
}
/**
* @param int $value
*
* @author Hubert Borderiou 12-10-2011
* @param int $in_positive
*/
public function updateScoreAlwaysPositive($in_positive)
public function updateScoreAlwaysPositive($value)
{
$this->scoreAlwaysPositive = $in_positive;
$this->scoreAlwaysPositive = $value;
}
/**
* @param int $value
*
* @author Hubert Borderiou 12-10-2011
* @param int $in_positive
*/
public function updateUncheckedMayScore($in_positive)
public function updateUncheckedMayScore($value)
{
$this->uncheckedMayScore = $in_positive;
$this->uncheckedMayScore = $value;
}
/**
* Save category of a question
*
* A question can have n categories
* if category is empty, then question has no category then delete the category entry
* A question can have n categories if category is empty,
* then question has no category then delete the category entry
*
* @param array $category_list
*
* @param - int $in_positive
* @author Julio Montoya - Adding multiple cat support
*/
public function saveCategories($category_list)
@ -406,20 +414,21 @@ abstract class Question
}
/**
* @author Hubert Borderiou 12-10-2011
* @param int $in_category
* in this version, a question can only have 1 category
* if category is 0, then question has no category then delete the category entry
* @param int $category
*
* @author Hubert Borderiou 12-10-2011
*/
public function saveCategory($in_category)
public function saveCategory($category)
{
if ($in_category <= 0) {
if ($category <= 0) {
$this->deleteCategory();
} else {
// update or add category for a question
$table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$category_id = intval($in_category);
$category_id = intval($category);
$question_id = intval($this->id);
$sql = "SELECT count(*) AS nb FROM $table
WHERE question_id = $question_id AND c_id=" . api_get_course_int_id();
@ -440,7 +449,6 @@ abstract class Question
/**
* @author hubert borderiou 12-10-2011
* delete any category entry for question id
* @param : none
* delete the category for question
*/
public function deleteCategory()
@ -455,8 +463,9 @@ abstract class Question
/**
* changes the question position
*
* @author Olivier Brouckaert
* @param integer $position - question position
*
* @author Olivier Brouckaert
*/
public function updatePosition($position)
{
@ -466,8 +475,9 @@ abstract class Question
/**
* changes the question level
*
* @author Nicolas Raynaud
* @param integer $level - question level
*
* @author Nicolas Raynaud
*/
public function updateLevel($level)
{
@ -478,8 +488,9 @@ abstract class Question
* changes the answer type. If the user changes the type from "unique answer" to "multiple answers"
* (or conversely) answers are not deleted, otherwise yes
*
* @author Olivier Brouckaert
* @param integer $type - answer type
*
* @author Olivier Brouckaert
*/
public function updateType($type)
{
@ -509,10 +520,13 @@ abstract class Question
/**
* adds a picture to the question
*
* @author Olivier Brouckaert
* @param string $Picture - temporary path of the picture to upload
* @param string $PictureName - Name of the picture
* @param string $picturePath
*
* @return boolean - true if uploaded, otherwise false
*
* @author Olivier Brouckaert
*/
public function uploadPicture($Picture, $PictureName, $picturePath = null)
{
@ -566,10 +580,12 @@ abstract class Question
/**
* Resizes a picture || Warning!: can only be called after uploadPicture,
* or if picture is already available in object.
* @author Toon Keppens
* @param string $Dimension - Resizing happens proportional according to given dimension: height|width|any
* @param integer $Max - Maximum size
*
* @return boolean - true if success, false if failed
*
* @author Toon Keppens
*/
public function resizePicture($Dimension, $Max)
{
@ -671,9 +687,10 @@ abstract class Question
$extension = $picture[sizeof($picture) - 1];
$picture = 'quiz-' . $questionId . '.' . $extension;
$result = @copy($source_path . '/' . $this->picture, $destination_path . '/' . $picture) ? true : false;
//If copy was correct then add to the database
// If copy was correct then add to the database
if ($result) {
$sql = "UPDATE $TBL_QUESTIONS SET picture='" . Database::escape_string($picture) . "'
$sql = "UPDATE $TBL_QUESTIONS SET
picture = '" . Database::escape_string($picture) . "'
WHERE c_id = $course_id AND id='" . intval($questionId) . "'";
Database::query($sql);
@ -1146,7 +1163,7 @@ abstract class Question
c_id = $course_id
AND exercice_id = " . intval($exerciseId) . "
AND question_order > " . $row['question_order'];
$res = Database::query($sql);
Database::query($sql);
}
}

@ -29,7 +29,13 @@ $question_list_options = array();
foreach ($question_list as $key=> $value) {
$question_list_options[$key] = addslashes(get_lang($value[1]));
}
$form->addElement('select', 'question_type_hidden', get_lang('QuestionType'), $question_list_options, array('id' => 'question_type_hidden'));
$form->addElement(
'select',
'question_type_hidden',
get_lang('QuestionType'),
$question_list_options,
array('id' => 'question_type_hidden')
);
//session id
$session_id = api_get_session_id();
@ -38,7 +44,10 @@ $session_id = api_get_session_id();
$tbl_exercises = Database :: get_course_table(TABLE_QUIZ_TEST);
$course_id = api_get_course_int_id();
$sql = "SELECT id,title,type,description, results_disabled FROM $tbl_exercises WHERE c_id = $course_id AND active<>'-1' AND session_id=".$session_id." ORDER BY title ASC";
$sql = "SELECT id,title,type,description, results_disabled
FROM $tbl_exercises
WHERE c_id = $course_id AND active<>'-1' AND session_id=".$session_id."
ORDER BY title ASC";
$result = Database::query($sql);
$exercises['-'] = '-'.get_lang('SelectExercise').'-';
while ($row = Database :: fetch_array($result)) {
@ -66,47 +75,47 @@ $form->registerRule('validquestiontype', 'callback', 'check_question_type');
$form->addRule('question_type_hidden', get_lang('InvalidQuestionType'), 'validquestiontype');
if ($form->validate()) {
$values = $form->exportValues();
$values = $form->exportValues();
$answer_type = $values['question_type_hidden'];
// check feedback_type from current exercise for type of question delineation
$exercise_id = intval($values['exercise']);
$sql = "SELECT feedback_type FROM $tbl_exercises WHERE c_id = $course_id AND id = '$exercise_id'";
$rs_feedback_type = Database::query($sql);
$row_feedback_type = Database::fetch_row($rs_feedback_type);
$feedback_type = $row_feedback_type[0];
// if question type does not belong to self-evaluation (immediate feedback) it'll send an error
if (($answer_type == HOT_SPOT_DELINEATION && $feedback_type != 1) ||
($feedback_type == 1 && ($answer_type != HOT_SPOT_DELINEATION && $answer_type != UNIQUE_ANSWER))) {
header('Location: question_create.php?'.api_get_cidreq().'&error=true');
exit;
}
header('Location: admin.php?exerciseId='.$values['exercise'].'&newQuestion=yes&isContent='.$values['is_content'].'&answerType='.$answer_type);
exit;
} else {
// header
Display::display_header($nameTools);
echo '<div class="actions">';
echo '<a href="exercise.php?show=test">'.Display :: return_icon('back.png', get_lang('BackToExercisesList'),'',ICON_SIZE_MEDIUM).'</a>';
echo '</div>';
// displaying the form
$form->display();
// footer
Display::display_footer();
// check feedback_type from current exercise for type of question delineation
$exercise_id = intval($values['exercise']);
$sql = "SELECT feedback_type FROM $tbl_exercises WHERE c_id = $course_id AND id = '$exercise_id'";
$rs_feedback_type = Database::query($sql);
$row_feedback_type = Database::fetch_row($rs_feedback_type);
$feedback_type = $row_feedback_type[0];
// if question type does not belong to self-evaluation (immediate feedback) it'll send an error
if (($answer_type == HOT_SPOT_DELINEATION && $feedback_type != 1) ||
($feedback_type == 1 && ($answer_type != HOT_SPOT_DELINEATION && $answer_type != UNIQUE_ANSWER))) {
header('Location: question_create.php?'.api_get_cidreq().'&error=true');
exit;
}
header('Location: admin.php?exerciseId='.$values['exercise'].'&newQuestion=yes&isContent='.$values['is_content'].'&answerType='.$answer_type);
exit;
} else {
// header
Display::display_header($nameTools);
echo '<div class="actions">';
echo '<a href="exercise.php?show=test">'.Display :: return_icon('back.png', get_lang('BackToExercisesList'),'',ICON_SIZE_MEDIUM).'</a>';
echo '</div>';
// displaying the form
$form->display();
// footer
Display::display_footer();
}
function check_question_type($parameter) {
$question_list = Question::get_question_type_list();
foreach ($question_list as $key => $value) {
$valid_question_types[] = $key;
}
if (in_array($parameter, $valid_question_types)) {
return true;
} else {
return false;
}
foreach ($question_list as $key => $value) {
$valid_question_types[] = $key;
}
if (in_array($parameter, $valid_question_types)) {
return true;
} else {
return false;
}
}

@ -171,13 +171,8 @@ if (!$inATest) {
$objQuestionTmp = Question::read($id);
$question_class = get_class($objQuestionTmp);
$clone_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&clone_question='.$id.'">'.Display::return_icon('cd.gif',get_lang('Copy'), array(), ICON_SIZE_SMALL).'</a>';
/*$edit_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&type='.$objQuestionTmp->selectType().'&myid=1&editQuestion='.$id.'">'.Display::return_icon('edit.png',get_lang('Modify'), array(), ICON_SIZE_SMALL).'</a>';
if ($objQuestionTmp->type == CALCULATED_ANSWER && $objQuestionTmp->isAnswered()) {
$edit_link = '<a>'.Display::return_icon('edit_na.png',get_lang('Modify'), array(), ICON_SIZE_SMALL).'</a>';
}*/
$clone_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&clone_question='.$id.'">'.
Display::return_icon('cd.gif',get_lang('Copy'), array(), ICON_SIZE_SMALL).'</a>';
$edit_link = ($objQuestionTmp->type == CALCULATED_ANSWER && $objQuestionTmp->isAnswered()) ?
'<a>'.Display::return_icon(
'edit_na.png',
@ -198,8 +193,8 @@ if (!$inATest) {
$delete_link = '<a id="delete_'.$id.'" class="opener" href="'.api_get_self().'?'.api_get_cidreq().'&exerciseId='.$exerciseId.'&deleteQuestion='.$id.'" >'.Display::return_icon('delete.png',get_lang('RemoveFromTest'), array(), ICON_SIZE_SMALL).'</a>';
}
$edit_link = Display::tag('div', $edit_link, array('style'=>'float:left; padding:0px; margin:0px'));
$clone_link = Display::tag('div', $clone_link, array('style'=>'float:left; padding:0px; margin:0px'));
$edit_link = Display::tag('div', $edit_link, array('style'=>'float:left; padding:0px; margin:0px'));
$clone_link = Display::tag('div', $clone_link, array('style'=>'float:left; padding:0px; margin:0px'));
$delete_link = Display::tag('div', $delete_link, array('style'=>'float:left; padding:0px; margin:0px'));
$actions = Display::tag(
'div',

@ -312,12 +312,12 @@ if ($course_id_changed) {
$course_id = $course_info['real_id'];
// Redefining table calls
$TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
$TBL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$TBL_COURSE_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
$TBL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$TBL_COURSE_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
// Get course categories for the selected course
@ -471,7 +471,7 @@ if ($exerciseId > 0) {
$level_where = '';
$from = '';
if (isset($courseCategoryId) && $courseCategoryId > 0) {
$from = " INNER JOIN $TBL_COURSE_REL_CATEGORY crc ON crc.question_id=q.id AND crc.c_id= q.c_id ";
$from = " INNER JOIN $TBL_COURSE_REL_CATEGORY crc ON crc.question_id=q.id AND crc.c_id= q.c_id ";
$level_where .= " AND
crc.c_id = $selected_course AND
crc.category_id = $courseCategoryId";

@ -1,10 +1,9 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Saving the scores.
* @package chamilo.exercise
* @author
* @version $Id: savescores.php 15602 2008-06-18 08:52:24Z pcool $
*/
require_once '../inc/global.inc.php';
$courseInfo = api_get_course_info();

@ -1,10 +1,12 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Code library for HotPotatoes integration.
* @package chamilo.exercise
* @author Istvan Mandak
*/
require_once '../inc/global.inc.php';
require_once api_get_path(SYS_CODE_PATH).'exercice/hotpotatoes.lib.php';
$_course = api_get_course_info();

@ -2,6 +2,7 @@
/* See license terms in /license.txt */
require_once '../inc/global.inc.php';
$this_section = SECTION_COURSES;
$exercise_id = isset($_GET['exerciseId']) && !empty($_GET['exerciseId']) ? intval($_GET['exerciseId']) : 0;
@ -251,7 +252,6 @@ if (!empty($question_list)) {
}
$id++;
}
}
}
@ -281,11 +281,6 @@ $interbreadcrumb[] = array("url" => "exercise.php?gradebook=$gradebook&".api_get
$interbreadcrumb[] = array("url" => "admin.php?exerciseId=$exercise_id&".api_get_cidreq(), "name" => $objExercise->name);
$tpl = new Template(get_lang('ReportByQuestion'));
//$actions = array();
//$actions[]= array(get_lang('Back'), Display::return_icon('back.png', get_lang('Back'), 'exercise_report.php?'.$exercise_id));
//$tpl->set_actions($actions);
$actions = '<a href="exercise_report.php?exerciseId='.intval($_GET['exerciseId']).'&'.api_get_cidreq().'">' .
Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).'</a>';
$actions = Display::div($actions, array('class'=> 'actions'));

Loading…
Cancel
Save