From 69489715fa95257abefccb9da896e39a68a75328 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Thu, 9 Feb 2017 09:22:40 +0100 Subject: [PATCH] Fix gradebook: if the only tests are HotPotatoes, impossible to select See #1641 --- main/gradebook/lib/be/exerciselink.class.php | 47 ++++++++++++++------ main/gradebook/lib/fe/linkform.class.php | 19 +++++--- 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/main/gradebook/lib/be/exerciselink.class.php b/main/gradebook/lib/be/exerciselink.class.php index 2d21ae8428..52d8226416 100755 --- a/main/gradebook/lib/be/exerciselink.class.php +++ b/main/gradebook/lib/be/exerciselink.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.c_id = $this->course_id 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' + 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);*/ + while ($row = Database::fetch_array($result2)) { $attribute['path'][] = $row['path']; $attribute['visibility'][] = $row['visibility']; $attribute['comment'][] = $row['comment']; @@ -139,13 +144,19 @@ 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)) { foreach ($exerciseInLP as $exercise) { $cats[] = array( @@ -461,4 +472,12 @@ class ExerciseLink extends AbstractLink { return 'exercise'; } + + /** + * @param bool $hp + */ + public function setHp($hp) + { + $this->hp = $hp; + } } diff --git a/main/gradebook/lib/fe/linkform.class.php b/main/gradebook/lib/fe/linkform.class.php index 1742faf40e..f684e423ea 100755 --- a/main/gradebook/lib/fe/linkform.class.php +++ b/main/gradebook/lib/fe/linkform.class.php @@ -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); - // Adding hot potatoes - $linkHot = $this->createLink(LINK_HOTPOTATOES, $courseCode); + $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' + ); } } }