Minor - format code

remotes/angel/1.11.x
jmontoyaa 8 years ago
parent 7b03362128
commit 8c130aa8e6
  1. 65
      main/exercise/TestCategory.php
  2. 11
      main/exercise/question.class.php

@ -73,7 +73,6 @@ class TestCategory
$new_id = Database::insert($table, $params);
if ($new_id) {
$sql = "UPDATE $table SET id = iid WHERE iid = $new_id";
Database::query($sql);
@ -91,7 +90,6 @@ class TestCategory
return $new_id;
} else {
return false;
}
}
@ -106,7 +104,6 @@ class TestCategory
$tbl_question_rel_cat = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$id = intval($id);
$course_id = api_get_course_int_id();
$category = $this->getCategory($id);
if ($category) {
@ -205,7 +202,8 @@ class TestCategory
$categories = array();
if ($in_field == '') {
$sql = "SELECT id FROM $table
WHERE c_id=$courseId ORDER BY title ASC";
WHERE c_id = $courseId
ORDER BY title ASC";
$res = Database::query($sql);
while ($row = Database::fetch_array($res)) {
$category = new TestCategory();
@ -262,7 +260,6 @@ class TestCategory
public static function isQuestionHasCategory($questionId)
{
if (TestCategory::getCategoryForQuestion($questionId) > 0) {
return true;
}
@ -270,9 +267,11 @@ class TestCategory
}
/**
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
* Return the category name for question with question_id = $questionId
* In this version, a question has only 1 category.
* @param $questionId
* @param int $courseId
* @return string
*/
public static function getCategoryNameForQuestion(
$questionId,
@ -285,7 +284,8 @@ class TestCategory
$result = '';
$table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$categoryId = intval($categoryId);
$sql = "SELECT title FROM $table
$sql = "SELECT title
FROM $table
WHERE id = $categoryId AND c_id = $courseId";
$res = Database::query($sql);
$data = Database::fetch_array($res);
@ -443,9 +443,8 @@ class TestCategory
*/
public static function getNumberOfQuestionRandomByCategory($exerciseId, $in_nbrandom)
{
$nbquestionresult = 0;
$count = 0;
$categories = TestCategory::getListOfCategoriesIDForTest($exerciseId);
foreach ($categories as $category) {
if (empty($category['id'])) {
continue;
@ -454,13 +453,13 @@ class TestCategory
$nbQuestionInThisCat = TestCategory::getNumberOfQuestionsInCategoryForTest($exerciseId, $category['id']);
if ($nbQuestionInThisCat > $in_nbrandom) {
$nbquestionresult += $in_nbrandom;
$count += $in_nbrandom;
} else {
$nbquestionresult += $nbQuestionInThisCat;
$count += $nbQuestionInThisCat;
}
}
return $nbquestionresult;
return $count;
}
/**
@ -674,12 +673,18 @@ class TestCategory
$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
marks,
exe_id,
user_id,
ta.question_id,
category_id
FROM $tbl_track_attempt ta
INNER JOIN $tbl_question_rel_category qrc
ON (ta.question_id=qrc.question_id)
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";
qrc.category_id = $in_cat_id AND
exe_id = $in_exe_id AND
user_id = $in_user_id";
$res = Database::query($query);
$score = '';
while ($data = Database::fetch_array($res)) {
@ -780,7 +785,7 @@ class TestCategory
$sql = "SELECT * FROM $table ORDER BY title ASC";
$res = Database::query($sql);
$array = [];
while ($row = Database::fetch_array($res,'ASSOC')) {
while ($row = Database::fetch_array($res, 'ASSOC')) {
$array[] = $row;
}
@ -852,7 +857,7 @@ class TestCategory
*/
public function getForm(& $form, $action = 'new')
{
switch($action) {
switch ($action) {
case 'new':
$header = get_lang('AddACategory');
$submit = get_lang('AddTestCategory');
@ -908,7 +913,6 @@ class TestCategory
public function returnCategoryForm(Exercise $exercise_obj)
{
$categories = $this->getListOfCategoriesForTest($exercise_obj);
$saved_categories = $exercise_obj->get_categories_in_exercise();
$return = null;
@ -995,7 +999,8 @@ class TestCategory
/**
* Return the id of the test category with title = $in_title
* @param $in_title
* @param string $title
* @param int $courseId
*
* @return int is id of test category
*/
@ -1059,9 +1064,19 @@ class TestCategory
$courseId = intval($courseId);
if (empty($sessionId)) {
$sessionCondition = api_get_session_condition($sessionId, true, false, 'i.session_id');
$sessionCondition = api_get_session_condition(
$sessionId,
true,
false,
'i.session_id'
);
} else {
$sessionCondition = api_get_session_condition($sessionId, true, true, 'i.session_id');
$sessionCondition = api_get_session_condition(
$sessionId,
true,
true,
'i.session_id'
);
}
if (empty($courseId)) {

@ -130,10 +130,8 @@ abstract class Question
// if the question has been found
if ($object = Database::fetch_object($result)) {
$objQuestion = Question::getInstance($object->type);
if (!empty($objQuestion)) {
$objQuestion->id = $id;
$objQuestion->question = $object->question;
$objQuestion->description = $object->description;
@ -425,7 +423,6 @@ abstract class Question
$this->deleteCategory();
} else {
// update or add category for a question
$table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$category_id = intval($category);
$question_id = intval($this->id);
@ -606,10 +603,11 @@ abstract class Question
$current_width = $current_image_size['width'];
$current_height = $current_image_size['height'];
if ($current_width < $Max && $current_height < $Max)
if ($current_width < $Max && $current_height < $Max) {
return true;
elseif ($current_height == "")
} elseif ($current_height == '') {
return false;
}
// Resize according to height.
if ($Dimension == "height") {
@ -810,8 +808,7 @@ abstract class Question
$category = $this->category;
// question already exists
if(!empty($id)) {
if (!empty($id)) {
$params = [
'question' => $question,
'description' => $description,

Loading…
Cancel
Save