Adding hotpotatoe type in assessments -refs #5994

1.9.x
Yoselyn Castillo 12 years ago
parent ad5b66254e
commit 5045015027
  1. 107
      main/gradebook/lib/be/exerciselink.class.php
  2. 3
      main/gradebook/lib/be/linkfactory.class.php
  3. 1
      main/inc/lib/main_api.lib.php

@ -15,13 +15,20 @@ class ExerciseLink extends AbstractLink
private $course_info = null;
private $exercise_table = null;
private $exercise_data = null;
private $is_hp;
// CONSTRUCTORS
function __construct() {
function __construct($hp=0) {
parent::__construct();
$this->set_type(LINK_EXERCISE);
$this->is_hp = $hp;
if ($this->is_hp == 1) {
$this->set_type(LINK_HOTPOTATOES);
}
}
// FUNCTIONS IMPLEMENTING ABSTRACTLINK
/**
@ -56,6 +63,9 @@ class ExerciseLink extends AbstractLink
* @return array 2-dimensional array - every element contains 2 subelements (id, name)
*/
public function get_all_links() {
$TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
$TBL_ITEM_PROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
$documentPath = api_get_path(SYS_COURSE_PATH).$this->course_code."/document";
if (empty($this->course_code)) {
die('Error in get_not_created_links() : course code not set');
}
@ -68,16 +78,53 @@ class ExerciseLink extends AbstractLink
$sql = 'SELECT id,title from '.$this->get_exercise_table().'
WHERE c_id = '.$this->course_id.' AND active=1 '.$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
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 '".Database :: escape_string($uploadPath)."/%/%' AND ip.visibility='1'";
/* $sql = 'SELECT id,title from '.$this->get_exercise_table().'
WHERE c_id = '.$this->course_id.' AND active=1 AND session_id='.api_get_session_id().'';
*/
$result = Database::query($sql);
*/ require_once api_get_path(SYS_CODE_PATH).'exercice/hotpotatoes.lib.php';
if (!$this->is_hp) {
$result = Database::query($sql);
} else {
$result2 = Database::query($sql2);
}
$cats = array();
while ($data=Database::fetch_array($result)) {
$cats[] = array ($data['id'], $data['title']);
}
if (isset($result)) {
if (mysql_numrows($result) > 0) {
while ($data=Database::fetch_array($result)) {
$cats[] = array ($data['id'], $data['title']);
}
}
}
if (isset($result2)) {
if (mysql_numrows($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'];
$attribute['id'] = $row['id'];
}
if (isset($attribute['path']) && is_array($attribute['path'])) {
$hotpotatoes_exist = true;
while (list($key, $path) = each($attribute['path'])) {
$item = '';
$title = GetQuizName($path, $documentPath);
if ($title == '') {
$title = basename($path);
}
$cats[] = array ($attribute['id'], $title.'(HP)');
}
}
}
}
return $cats;
}
@ -179,7 +226,20 @@ class ExerciseLink extends AbstractLink
* Get name to display: same as exercise title
*/
public function get_name() {
$data = $this->get_exercise_data();
$documentPath = api_get_path(SYS_COURSE_PATH).$this->course_code."/document";
require_once api_get_path(SYS_CODE_PATH).'exercice/hotpotatoes.lib.php';
$data = $this->get_exercise_data();
if ($this->is_hp == 1) {
if (isset($data['path'])) {
$hotpotatoes_exist = true;
$item = '';
$title = GetQuizName($data['path'], $documentPath);
if ($title == '') {
$title = basename($data['path']);
}
return $title;
}
}
return $data['title'];
}
@ -203,7 +263,12 @@ class ExerciseLink extends AbstractLink
}
public function get_type_name() {
return get_lang('Quiz');
if ($this->is_hp == 1) {
return get_lang('Hopotatoe');
} else {
return get_lang('Quiz');
}
}
public function needs_name_and_description() {
@ -229,21 +294,31 @@ class ExerciseLink extends AbstractLink
* Lazy load function to get the database table of the exercise
*/
private function get_exercise_table() {
$this->exercise_table = Database :: get_course_table(TABLE_QUIZ_TEST);
return $this->exercise_table;
$this->exercise_table = Database :: get_course_table(TABLE_QUIZ_TEST);
return $this->exercise_table;
}
/**
* Lazy load function to get the database contents of this exercise
*/
private function get_exercise_data() {
$tbl_exercise = $this->get_exercise_table();
if ($tbl_exercise=='') {
if ($this->is_hp == 1) {
$tbl_exercise = Database :: get_course_table(TABLE_DOCUMENT);
$TBL_ITEM_PROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
} else {
$tbl_exercise = $this->get_exercise_table();
}
if ($tbl_exercise=='') {
return false;
} elseif (!isset($this->exercise_data)) {
$sql = 'SELECT * FROM '.$this->get_exercise_table().'
WHERE c_id = '.$this->course_id.' AND id = '.(int)$this->get_ref_id().' ';
if ($this->is_hp == 1) {
$ref_id = intval($this->get_ref_id());
$sql = "SELECT * FROM $tbl_exercise ex, $TBL_ITEM_PROPERTY ip
WHERE ip.ref = ex.id AND ip.c_id = $this->course_id AND ex.c_id = $this->course_id AND ip.tool = '".TOOL_DOCUMENT."' AND (ex.path LIKE '%htm%')AND (ex.path LIKE '%HotPotatoes_files%') AND ip.visibility = 1";
} else {
$sql = 'SELECT * FROM '.$tbl_exercise.'
WHERE c_id = '.$this->course_id.' AND id = '.(int)$this->get_ref_id().' ';
}
$result = Database::query($sql);
$this->exercise_data=Database::fetch_array($result);
}

@ -76,6 +76,8 @@ class LinkFactory
switch ($type) {
case LINK_EXERCISE:
return new ExerciseLink();
case LINK_HOTPOTATOES:
return new ExerciseLink(1);
case LINK_DROPBOX:
return new DropboxLink();
case LINK_STUDENTPUBLICATION:
@ -99,6 +101,7 @@ class LinkFactory
//LINK_DROPBOX,
return array (LINK_EXERCISE,
//LINK_DROPBOX,
LINK_HOTPOTATOES,
LINK_STUDENTPUBLICATION,
LINK_LEARNPATH,
LINK_FORUM_THREAD,

@ -292,6 +292,7 @@ define('LINK_FORUM_THREAD', 5);
//define('LINK_WORK',6);
define('LINK_ATTENDANCE', 7);
define('LINK_SURVEY', 8);
define('LINK_HOTPOTATOES', 9);
//From display.lib.php

Loading…
Cancel
Save