Merge pull request #94 from ycastillo/yoselyn.5994

Adding hotpotatoe type in assessments -refs #5994
1.9.x
Yannick Warnier 12 years ago
commit 391cc06316
  1. 4
      main/exercice/hotpotatoes.lib.php
  2. 117
      main/gradebook/lib/be/exerciselink.class.php
  3. 3
      main/gradebook/lib/be/linkfactory.class.php
  4. 1
      main/inc/lib/main_api.lib.php

@ -73,11 +73,11 @@ function GetQuizName($fname, $fpath) {
* Added conditional to the table if is empty.
*/
function GetComment($path, $course_code = '') {
global $dbTable;
$dbTable = Database::get_course_table(TABLE_DOCUMENT);
$course_info = api_get_course_info($course_code);
$path = Database::escape_string($path);
if (!empty($course_info) && !empty($path)) {
$query = "SELECT comment FROM $dbTable WHERE c_id = {$course_info['real_id']} AND path='$path'";
$query = "SELECT comment FROM $dbTable WHERE c_id = {$course_info['real_id']}";
$result = Database::query($query);
while ($row = Database::fetch_array($result)) {
return $row[0];

@ -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,9 +63,12 @@ class ExerciseLink extends AbstractLink
* @return array 2-dimensional array - every element contains 2 subelements (id, name)
*/
public function get_all_links() {
if (empty($this->course_code)) {
die('Error in get_not_created_links() : course code not set');
}
$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');
}
$session_id = api_get_session_id();
if (empty($session_id)) {
$session_condition = api_get_session_condition(0, true);
@ -68,16 +78,55 @@ 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().'
/*
$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 (Database::num_rows($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 +228,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 +265,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 +296,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,

@ -297,6 +297,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