Fix gradebook: if the only tests are HotPotatoes, impossible to select

See #1641
remotes/angel/1.11.x
jmontoyaa 8 years ago
parent 9e592b7901
commit 69489715fa
  1. 41
      main/gradebook/lib/be/exerciselink.class.php
  2. 13
      main/gradebook/lib/fe/linkform.class.php

@ -62,7 +62,7 @@ class ExerciseLink extends AbstractLink
* Generate an array of all exercises available.
* @return array 2-dimensional array - every element contains 2 subelements (id, name)
*/
public function get_all_links()
public function get_all_links($getOnlyHotPotatoes = false)
{
$TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
$TBL_ITEM_PROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
@ -86,25 +86,33 @@ class ExerciseLink extends AbstractLink
$sql = 'SELECT id,title FROM '.$exerciseTable.'
WHERE c_id = '.$this->course_id.' AND active=1 '.$session_condition;
$sqlLp = "SELECT e.id, e.title FROM $exerciseTable e INNER JOIN $lpItemTable i
$sqlLp = "SELECT e.id, e.title
FROM $exerciseTable e
INNER JOIN $lpItemTable i
ON (e.c_id = i.c_id AND e.id = i.path)
WHERE e.c_id = $this->course_id AND active = 0 AND item_type = 'quiz'
WHERE
e.c_id = $this->course_id AND
active = 0 AND
item_type = 'quiz'
$session_condition";
$sql2 = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility, d.id
FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
FROM $TBL_DOCUMENT d
INNER JOIN $TBL_ITEM_PROPERTY ip
ON (d.id = ip.ref AND d.c_id = ip.c_id)
WHERE
d.c_id = $this->course_id AND
ip.c_id = $this->course_id AND
d.id = ip.ref AND
ip.tool = '".TOOL_DOCUMENT."' AND
(d.path LIKE '%htm%')AND (d.path LIKE '%HotPotatoes_files%') AND
(d.path LIKE '%htm%') AND
(d.path LIKE '%HotPotatoes_files%') AND
d.path LIKE '".Database :: escape_string($uploadPath.'/%/%')."' AND
ip.visibility = '1'
";
require_once api_get_path(SYS_CODE_PATH).'exercise/hotpotatoes.lib.php';
$exerciseInLP = array();
if (!$this->is_hp) {
$result = Database::query($sql);
$resultLp = Database::query($sqlLp);
@ -121,13 +129,10 @@ class ExerciseLink extends AbstractLink
}
}
}
$hotPotatoes = [];
if (isset($result2)) {
if (Database::num_rows($result2) > 0) {
while ($row = Database::fetch_array($result2)) {
/*$path = $data['path'];
$fname = GetQuizName($path,$documentPath);
$cats[] = array ($data['id'], $fname);*/
$attribute['path'][] = $row['path'];
$attribute['visibility'][] = $row['visibility'];
$attribute['comment'][] = $row['comment'];
@ -139,11 +144,17 @@ class ExerciseLink extends AbstractLink
if ($title == '') {
$title = basename($path);
}
$cats[] = array($attribute['id'], $title.'(HP)');
$element = array($attribute['id'], $title.'(HP)');
$cats[] = $element;
$hotPotatoes[] = $element;
}
}
}
}
}
if ($getOnlyHotPotatoes) {
return $hotPotatoes;
}
if (!empty($exerciseInLP)) {
@ -461,4 +472,12 @@ class ExerciseLink extends AbstractLink
{
return 'exercise';
}
/**
* @param bool $hp
*/
public function setHp($hp)
{
$this->hp = $hp;
}
}

@ -108,17 +108,24 @@ class LinkForm extends FormValidator
if (!$link->needs_name_and_description() && count($link->get_all_links()) == '0') {
$select->addoption($link->get_type_name(), $linkType, 'disabled');
} else {
if ($link->get_type() == LINK_EXERCISE) {
// Adding exercise
$select->addoption($link->get_type_name(), $linkType);
}
if ($link->get_type() == LINK_EXERCISE) {
// Adding hot potatoes
$linkHot = $this->createLink(LINK_HOTPOTATOES, $courseCode);
$linkHot->setHp(true);
if ($linkHot->get_all_links(true)) {
$select->addoption(
'   '.$linkHot->get_type_name(),
LINK_HOTPOTATOES
);
} else {
$select->addoption($link->get_type_name(), $linkType);
$select->addoption(
'   '.$linkHot->get_type_name(),
LINK_HOTPOTATOES,
'disabled'
);
}
}
}

Loading…
Cancel
Save