You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
566 lines
18 KiB
566 lines
18 KiB
![]()
16 years ago
|
<?php
|
||
![]()
16 years ago
|
/* For licensing terms, see /license.txt */
|
||
![]()
11 years ago
|
|
||
![]()
16 years ago
|
/**
|
||
![]()
11 years ago
|
* Class ExerciseLink
|
||
![]()
16 years ago
|
* Defines a gradebook ExerciseLink object.
|
||
![]()
8 years ago
|
*
|
||
![]()
16 years ago
|
* @author Bert Steppé
|
||
![]()
8 years ago
|
*
|
||
![]()
16 years ago
|
* @package chamilo.gradebook
|
||
![]()
16 years ago
|
*/
|
||
|
class ExerciseLink extends AbstractLink
|
||
|
{
|
||
![]()
6 years ago
|
private $course_info;
|
||
|
private $exercise_table;
|
||
![]()
7 years ago
|
private $exercise_data = [];
|
||
![]()
12 years ago
|
private $is_hp;
|
||
![]()
16 years ago
|
|
||
![]()
12 years ago
|
/**
|
||
|
* @param int $hp
|
||
|
*/
|
||
|
public function __construct($hp = 0)
|
||
|
{
|
||
![]()
11 years ago
|
parent::__construct();
|
||
|
$this->set_type(LINK_EXERCISE);
|
||
![]()
12 years ago
|
$this->is_hp = $hp;
|
||
|
if ($this->is_hp == 1) {
|
||
|
$this->set_type(LINK_HOTPOTATOES);
|
||
|
}
|
||
![]()
16 years ago
|
}
|
||
|
|
||
![]()
11 years ago
|
/**
|
||
|
* Generate an array of all exercises available.
|
||
![]()
8 years ago
|
*
|
||
![]()
7 years ago
|
* @param bool $getOnlyHotPotatoes
|
||
|
*
|
||
![]()
11 years ago
|
* @return array 2-dimensional array - every element contains 2 subelements (id, name)
|
||
|
*/
|
||
![]()
9 years ago
|
public function get_all_links($getOnlyHotPotatoes = false)
|
||
![]()
12 years ago
|
{
|
||
![]()
7 years ago
|
$tableItemProperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
|
||
![]()
11 years ago
|
$exerciseTable = $this->get_exercise_table();
|
||
![]()
9 years ago
|
$lpItemTable = Database::get_course_table(TABLE_LP_ITEM);
|
||
![]()
11 years ago
|
|
||
![]()
6 years ago
|
$documentPath = api_get_path(SYS_COURSE_PATH).$this->course_code.'/document';
|
||
![]()
12 years ago
|
if (empty($this->course_code)) {
|
||
![]()
7 years ago
|
return [];
|
||
![]()
12 years ago
|
}
|
||
![]()
6 years ago
|
$sessionId = $this->get_session_id();
|
||
![]()
7 years ago
|
if (empty($sessionId)) {
|
||
![]()
14 years ago
|
$session_condition = api_get_session_condition(0, true);
|
||
|
} else {
|
||
![]()
7 years ago
|
$session_condition = api_get_session_condition($sessionId, true, true);
|
||
![]()
12 years ago
|
}
|
||
|
|
||
|
// @todo
|
||
|
$uploadPath = null;
|
||
|
|
||
![]()
6 years ago
|
$sql = 'SELECT iid, title FROM '.$exerciseTable.'
|
||
![]()
12 years ago
|
WHERE c_id = '.$this->course_id.' AND active=1 '.$session_condition;
|
||
![]()
12 years ago
|
|
||
![]()
6 years ago
|
$sqlLp = "SELECT e.iid, e.title
|
||
![]()
9 years ago
|
FROM $exerciseTable e
|
||
|
INNER JOIN $lpItemTable i
|
||
![]()
11 years ago
|
ON (e.c_id = i.c_id AND e.id = i.path)
|
||
![]()
9 years ago
|
WHERE
|
||
|
e.c_id = $this->course_id AND
|
||
|
active = 0 AND
|
||
|
item_type = 'quiz'
|
||
![]()
11 years ago
|
$session_condition";
|
||
|
|
||
![]()
6 years ago
|
$exerciseInLP = [];
|
||
![]()
6 years ago
|
$result = Database::query($sql);
|
||
|
$resultLp = Database::query($sqlLp);
|
||
|
$exerciseInLP = Database::store_result($resultLp);
|
||
|
|
||
![]()
8 years ago
|
$cats = [];
|
||
![]()
12 years ago
|
if (isset($result)) {
|
||
![]()
12 years ago
|
if (Database::num_rows($result) > 0) {
|
||
![]()
9 years ago
|
while ($data = Database::fetch_array($result)) {
|
||
![]()
6 years ago
|
$cats[] = [$data['iid'], $data['title']];
|
||
![]()
12 years ago
|
}
|
||
![]()
12 years ago
|
}
|
||
|
}
|
||
![]()
9 years ago
|
|
||
![]()
11 years ago
|
if (!empty($exerciseInLP)) {
|
||
|
foreach ($exerciseInLP as $exercise) {
|
||
![]()
8 years ago
|
$cats[] = [
|
||
![]()
6 years ago
|
$exercise['iid'],
|
||
![]()
6 years ago
|
$exercise['title'].' ('.get_lang('Learning path').')',
|
||
![]()
8 years ago
|
];
|
||
![]()
11 years ago
|
}
|
||
|
}
|
||
|
|
||
![]()
11 years ago
|
return $cats;
|
||
![]()
16 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Has anyone done this exercise yet ?
|
||
|
*/
|
||
![]()
12 years ago
|
public function has_results()
|
||
|
{
|
||
![]()
11 years ago
|
$tbl_stats = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
|
||
![]()
6 years ago
|
$sessionId = $this->get_session_id();
|
||
![]()
11 years ago
|
$course_id = api_get_course_int_id($this->get_course_code());
|
||
![]()
9 years ago
|
$sql = "SELECT count(exe_id) AS number
|
||
|
FROM $tbl_stats
|
||
![]()
11 years ago
|
WHERE
|
||
![]()
7 years ago
|
session_id = $sessionId AND
|
||
![]()
11 years ago
|
c_id = $course_id AND
|
||
![]()
7 years ago
|
exe_exo_id = ".$this->get_ref_id();
|
||
![]()
11 years ago
|
$result = Database::query($sql);
|
||
![]()
9 years ago
|
$number = Database::fetch_row($result);
|
||
![]()
9 years ago
|
|
||
![]()
8 years ago
|
return $number[0] != 0;
|
||
![]()
16 years ago
|
}
|
||
|
|
||
|
/**
|
||
![]()
12 years ago
|
* Get the score of this exercise. Only the first attempts are taken into account.
|
||
![]()
8 years ago
|
*
|
||
![]()
7 years ago
|
* @param int $stud_id student id (default: all students who have results -
|
||
|
* then the average is returned)
|
||
|
* @param string $type
|
||
![]()
8 years ago
|
*
|
||
|
* @return array (score, max) if student is given
|
||
|
* array (sum of scores, number of scores) otherwise
|
||
|
* or null if no scores available
|
||
![]()
12 years ago
|
*/
|
||
![]()
11 years ago
|
public function calc_score($stud_id = null, $type = null)
|
||
![]()
12 years ago
|
{
|
||
![]()
7 years ago
|
$allowStats = api_get_configuration_value('allow_gradebook_stats');
|
||
|
|
||
|
if ($allowStats) {
|
||
|
$link = $this->entity;
|
||
|
if (!empty($link)) {
|
||
|
$weight = $link->getScoreWeight();
|
||
|
|
||
|
switch ($type) {
|
||
|
case 'best':
|
||
|
$bestResult = $link->getBestScore();
|
||
|
$result = [$bestResult, $weight];
|
||
|
|
||
|
return $result;
|
||
|
break;
|
||
|
case 'average':
|
||
|
$count = count($this->getStudentList());
|
||
|
if (empty($count)) {
|
||
|
$result = [0, $weight];
|
||
|
|
||
|
return $result;
|
||
|
}
|
||
|
$sumResult = array_sum($link->getUserScoreList());
|
||
|
$result = [$sumResult / $count, $weight];
|
||
|
|
||
|
return $result;
|
||
|
break;
|
||
|
case 'ranking':
|
||
![]()
6 years ago
|
return [null, null];
|
||
![]()
7 years ago
|
break;
|
||
|
default:
|
||
|
if (!empty($stud_id)) {
|
||
|
$scoreList = $link->getUserScoreList();
|
||
|
$result = [0, $weight];
|
||
|
if (isset($scoreList[$stud_id])) {
|
||
|
$result = [$scoreList[$stud_id], $weight];
|
||
|
}
|
||
|
|
||
|
return $result;
|
||
|
} else {
|
||
|
$studentCount = count($this->getStudentList());
|
||
|
$sumResult = array_sum($link->getUserScoreList());
|
||
|
$result = [$sumResult, $studentCount];
|
||
|
}
|
||
|
|
||
|
return $result;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
![]()
11 years ago
|
$tblStats = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
|
||
![]()
11 years ago
|
$tblHp = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
|
||
![]()
12 years ago
|
$tblDoc = Database::get_course_table(TABLE_DOCUMENT);
|
||
![]()
12 years ago
|
|
||
|
/* the following query should be similar (in conditions) to the one used
|
||
![]()
9 years ago
|
in exercise/exercise.php, look for note-query-exe-results marker*/
|
||
![]()
7 years ago
|
$sessionId = $this->get_session_id();
|
||
![]()
11 years ago
|
$courseId = $this->getCourseId();
|
||
![]()
7 years ago
|
$exerciseData = $this->get_exercise_data();
|
||
![]()
7 years ago
|
|
||
![]()
6 years ago
|
$exerciseId = isset($exerciseData['id']) ? (int) $exerciseData['id'] : 0;
|
||
![]()
7 years ago
|
$stud_id = (int) $stud_id;
|
||
![]()
7 years ago
|
|
||
|
if (empty($exerciseId)) {
|
||
|
return null;
|
||
|
}
|
||
![]()
7 years ago
|
|
||
|
$key = 'exercise_link_id:'.
|
||
|
$this->get_id().
|
||
|
'exerciseId:'.$exerciseId.'student:'.$stud_id.'session:'.$sessionId.'courseId:'.$courseId.'type:'.$type;
|
||
|
|
||
|
$useCache = api_get_configuration_value('gradebook_use_apcu_cache');
|
||
|
$cacheAvailable = api_get_configuration_value('apc') && $useCache;
|
||
|
$cacheDriver = null;
|
||
|
if ($cacheAvailable) {
|
||
|
$cacheDriver = new \Doctrine\Common\Cache\ApcuCache();
|
||
|
if ($cacheDriver->contains($key)) {
|
||
|
return $cacheDriver->fetch($key);
|
||
|
}
|
||
|
}
|
||
|
|
||
![]()
9 years ago
|
$exercise = new Exercise($courseId);
|
||
![]()
6 years ago
|
$exercise->read($exerciseId);
|
||
![]()
7 years ago
|
|
||
![]()
12 years ago
|
if (!$this->is_hp) {
|
||
![]()
9 years ago
|
if ($exercise->exercise_was_added_in_lp == false) {
|
||
|
$sql = "SELECT * FROM $tblStats
|
||
|
WHERE
|
||
![]()
7 years ago
|
exe_exo_id = $exerciseId AND
|
||
![]()
9 years ago
|
orig_lp_id = 0 AND
|
||
|
orig_lp_item_id = 0 AND
|
||
|
status <> 'incomplete' AND
|
||
![]()
7 years ago
|
session_id = $sessionId AND
|
||
![]()
9 years ago
|
c_id = $courseId
|
||
|
";
|
||
|
} else {
|
||
|
$lpId = null;
|
||
|
if (!empty($exercise->lpList)) {
|
||
|
// Taking only the first LP
|
||
|
$lpId = current($exercise->lpList);
|
||
|
$lpId = $lpId['lp_id'];
|
||
|
}
|
||
![]()
11 years ago
|
|
||
![]()
9 years ago
|
$sql = "SELECT *
|
||
|
FROM $tblStats
|
||
|
WHERE
|
||
![]()
7 years ago
|
exe_exo_id = $exerciseId AND
|
||
![]()
9 years ago
|
orig_lp_id = $lpId AND
|
||
|
status <> 'incomplete' AND
|
||
![]()
7 years ago
|
session_id = $sessionId AND
|
||
![]()
9 years ago
|
c_id = $courseId ";
|
||
|
}
|
||
![]()
16 years ago
|
|
||
![]()
10 years ago
|
if (!empty($stud_id) && $type != 'ranking') {
|
||
|
$sql .= " AND exe_user_id = $stud_id ";
|
||
![]()
12 years ago
|
}
|
||
|
$sql .= ' ORDER BY exe_id DESC';
|
||
|
} else {
|
||
![]()
9 years ago
|
$sql = "SELECT * FROM $tblHp hp
|
||
|
INNER JOIN $tblDoc doc
|
||
|
ON (hp.exe_name = doc.path AND doc.c_id = hp.c_id)
|
||
![]()
11 years ago
|
WHERE
|
||
![]()
9 years ago
|
hp.c_id = $courseId AND
|
||
![]()
6 years ago
|
doc.id = $exerciseId";
|
||
![]()
9 years ago
|
|
||
|
if (!empty($stud_id)) {
|
||
|
$sql .= " AND hp.exe_user_id = $stud_id ";
|
||
|
}
|
||
![]()
12 years ago
|
}
|
||
![]()
12 years ago
|
|
||
![]()
15 years ago
|
$scores = Database::query($sql);
|
||
![]()
12 years ago
|
|
||
![]()
10 years ago
|
if (isset($stud_id) && empty($type)) {
|
||
![]()
12 years ago
|
// for 1 student
|
||
![]()
12 years ago
|
if ($data = Database::fetch_array($scores)) {
|
||
![]()
6 years ago
|
$attempts = Database::query($sql);
|
||
|
$counter = 0;
|
||
|
while ($attempt = Database::fetch_array($attempts)) {
|
||
|
$counter++;
|
||
|
}
|
||
|
$result = [$data['score'], $data['max_score'], $data['exe_date'], $counter];
|
||
![]()
7 years ago
|
if ($cacheAvailable) {
|
||
|
$cacheDriver->save($key, $result);
|
||
|
}
|
||
|
|
||
|
return $result;
|
||
![]()
12 years ago
|
} else {
|
||
![]()
7 years ago
|
if ($cacheAvailable) {
|
||
|
$cacheDriver->save($key, null);
|
||
|
}
|
||
|
|
||
![]()
15 years ago
|
return null;
|
||
![]()
11 years ago
|
}
|
||
![]()
12 years ago
|
} else {
|
||
|
// all students -> get average
|
||
![]()
11 years ago
|
// normal way of getting the info
|
||
![]()
8 years ago
|
$students = []; // user list, needed to make sure we only
|
||
![]()
11 years ago
|
// take first attempts into account
|
||
![]()
12 years ago
|
$student_count = 0;
|
||
|
$sum = 0;
|
||
![]()
11 years ago
|
$bestResult = 0;
|
||
|
$weight = 0;
|
||
|
$sumResult = 0;
|
||
![]()
11 years ago
|
|
||
![]()
7 years ago
|
$studentList = $this->getStudentList();
|
||
|
$studentIdList = [];
|
||
|
if (!empty($studentList)) {
|
||
|
$studentIdList = array_column($studentList, 'user_id');
|
||
|
}
|
||
|
|
||
![]()
12 years ago
|
while ($data = Database::fetch_array($scores, 'ASSOC')) {
|
||
![]()
7 years ago
|
// Only take into account users in the current student list.
|
||
|
if (!empty($studentIdList)) {
|
||
|
if (!in_array($data['exe_user_id'], $studentIdList)) {
|
||
|
continue;
|
||
|
}
|
||
|
}
|
||
|
|
||
![]()
11 years ago
|
if (!isset($students[$data['exe_user_id']])) {
|
||
![]()
7 years ago
|
if ($data['max_score'] != 0) {
|
||
|
$students[$data['exe_user_id']] = $data['score'];
|
||
![]()
12 years ago
|
$student_count++;
|
||
![]()
6 years ago
|
if ($data['score'] > $bestResult) {
|
||
|
$bestResult = $data['score'];
|
||
![]()
11 years ago
|
}
|
||
![]()
7 years ago
|
$sum += $data['score'] / $data['max_score'];
|
||
![]()
6 years ago
|
$sumResult += $data['score'];
|
||
![]()
7 years ago
|
$weight = $data['max_score'];
|
||
![]()
12 years ago
|
}
|
||
|
}
|
||
|
}
|
||
![]()
11 years ago
|
|
||
![]()
12 years ago
|
if ($student_count == 0) {
|
||
![]()
7 years ago
|
if ($cacheAvailable) {
|
||
|
$cacheDriver->save($key, null);
|
||
|
}
|
||
|
|
||
![]()
12 years ago
|
return null;
|
||
|
} else {
|
||
![]()
11 years ago
|
switch ($type) {
|
||
|
case 'best':
|
||
![]()
7 years ago
|
$result = [$bestResult, $weight];
|
||
|
if ($cacheAvailable) {
|
||
|
$cacheDriver->save($key, $result);
|
||
|
}
|
||
|
|
||
|
return $result;
|
||
![]()
11 years ago
|
break;
|
||
|
case 'average':
|
||
![]()
10 years ago
|
$count = count($this->getStudentList());
|
||
![]()
10 years ago
|
if (empty($count)) {
|
||
![]()
7 years ago
|
$result = [0, $weight];
|
||
|
if ($cacheAvailable) {
|
||
|
$cacheDriver->save($key, $result);
|
||
![]()
7 years ago
|
}
|
||
![]()
7 years ago
|
|
||
|
return $result;
|
||
|
}
|
||
|
|
||
|
$result = [$sumResult / $count, $weight];
|
||
|
|
||
|
if ($cacheAvailable) {
|
||
|
$cacheDriver->save($key, $result);
|
||
![]()
10 years ago
|
}
|
||
![]()
8 years ago
|
|
||
![]()
7 years ago
|
return $result;
|
||
![]()
11 years ago
|
break;
|
||
|
case 'ranking':
|
||
![]()
7 years ago
|
$ranking = AbstractLink::getCurrentUserRanking($stud_id, $students);
|
||
|
if ($cacheAvailable) {
|
||
|
$cacheDriver->save($key, $ranking);
|
||
|
}
|
||
|
|
||
|
return $ranking;
|
||
![]()
11 years ago
|
break;
|
||
|
default:
|
||
![]()
7 years ago
|
$result = [$sum, $student_count];
|
||
|
if ($cacheAvailable) {
|
||
|
$cacheDriver->save($key, $result);
|
||
|
}
|
||
|
|
||
|
return $result;
|
||
![]()
11 years ago
|
break;
|
||
![]()
11 years ago
|
}
|
||
![]()
12 years ago
|
}
|
||
|
}
|
||
![]()
16 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Get URL where to go to if the user clicks on the link.
|
||
|
* First we go to exercise_jump.php and then to the result page.
|
||
|
* Check this php file for more info.
|
||
|
*/
|
||
![]()
12 years ago
|
public function get_link()
|
||
![]()
12 years ago
|
{
|
||
![]()
6 years ago
|
$sessionId = $this->get_session_id();
|
||
![]()
9 years ago
|
$data = $this->get_exercise_data();
|
||
![]()
7 years ago
|
$exerciseId = $data['id'];
|
||
![]()
9 years ago
|
$path = isset($data['path']) ? $data['path'] : '';
|
||
![]()
9 years ago
|
|
||
![]()
7 years ago
|
$url = api_get_path(WEB_CODE_PATH).'gradebook/exercise_jump.php?'
|
||
|
.http_build_query(
|
||
|
[
|
||
|
'path' => $path,
|
||
|
'session_id' => $sessionId,
|
||
|
'cidReq' => $this->get_course_code(),
|
||
|
'gradebook' => 'view',
|
||
|
'exerciseId' => $exerciseId,
|
||
|
'type' => $this->get_type(),
|
||
|
]
|
||
|
);
|
||
![]()
10 years ago
|
|
||
![]()
12 years ago
|
return $url;
|
||
|
}
|
||
![]()
16 years ago
|
|
||
|
/**
|
||
![]()
8 years ago
|
* Get name to display: same as exercise title.
|
||
![]()
16 years ago
|
*/
|
||
![]()
12 years ago
|
public function get_name()
|
||
|
{
|
||
|
$data = $this->get_exercise_data();
|
||
![]()
7 years ago
|
|
||
![]()
11 years ago
|
return $data['title'];
|
||
![]()
16 years ago
|
}
|
||
|
|
||
|
/**
|
||
![]()
8 years ago
|
* Get description to display: same as exercise description.
|
||
![]()
16 years ago
|
*/
|
||
![]()
12 years ago
|
public function get_description()
|
||
|
{
|
||
![]()
11 years ago
|
$data = $this->get_exercise_data();
|
||
![]()
12 years ago
|
|
||
![]()
11 years ago
|
return isset($data['description']) ? $data['description'] : null;
|
||
![]()
16 years ago
|
}
|
||
|
|
||
|
/**
|
||
![]()
8 years ago
|
* Check if this still links to an exercise.
|
||
![]()
16 years ago
|
*/
|
||
![]()
12 years ago
|
public function is_valid_link()
|
||
|
{
|
||
![]()
7 years ago
|
$exerciseData = $this->get_exercise_data();
|
||
![]()
10 years ago
|
|
||
![]()
7 years ago
|
return !empty($exerciseData);
|
||
![]()
16 years ago
|
}
|
||
|
|
||
![]()
12 years ago
|
/**
|
||
![]()
9 years ago
|
* @return string
|
||
![]()
12 years ago
|
*/
|
||
|
public function get_type_name()
|
||
|
{
|
||
![]()
12 years ago
|
if ($this->is_hp == 1) {
|
||
![]()
9 years ago
|
return 'HotPotatoes';
|
||
![]()
12 years ago
|
}
|
||
![]()
6 years ago
|
|
||
![]()
6 years ago
|
return get_lang('Tests');
|
||
![]()
16 years ago
|
}
|
||
|
|
||
![]()
11 years ago
|
public function needs_name_and_description()
|
||
![]()
12 years ago
|
{
|
||
![]()
11 years ago
|
return false;
|
||
|
}
|
||
![]()
16 years ago
|
|
||
![]()
11 years ago
|
public function needs_max()
|
||
![]()
12 years ago
|
{
|
||
![]()
11 years ago
|
return false;
|
||
|
}
|
||
![]()
16 years ago
|
|
||
![]()
11 years ago
|
public function needs_results()
|
||
![]()
12 years ago
|
{
|
||
![]()
11 years ago
|
return false;
|
||
|
}
|
||
![]()
16 years ago
|
|
||
![]()
8 years ago
|
public function is_allowed_to_change_name()
|
||
|
{
|
||
![]()
11 years ago
|
return false;
|
||
|
}
|
||
![]()
16 years ago
|
|
||
|
/**
|
||
![]()
8 years ago
|
* @return string
|
||
|
*/
|
||
|
public function get_icon_name()
|
||
|
{
|
||
|
return 'exercise';
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param bool $hp
|
||
|
*/
|
||
|
public function setHp($hp)
|
||
|
{
|
||
|
$this->hp = $hp;
|
||
|
}
|
||
|
|
||
![]()
7 years ago
|
public function getBestScore()
|
||
|
{
|
||
|
return $this->getStats('best');
|
||
|
}
|
||
|
|
||
|
public function getStats($type)
|
||
|
{
|
||
|
switch ($type) {
|
||
|
case 'best':
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
![]()
16 years ago
|
/**
|
||
![]()
8 years ago
|
* Lazy load function to get the database contents of this exercise.
|
||
![]()
16 years ago
|
*/
|
||
![]()
6 years ago
|
public function get_exercise_data()
|
||
![]()
12 years ago
|
{
|
||
![]()
7 years ago
|
$tableItemProperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
|
||
![]()
12 years ago
|
if ($this->is_hp == 1) {
|
||
![]()
7 years ago
|
$table = Database::get_course_table(TABLE_DOCUMENT);
|
||
![]()
12 years ago
|
} else {
|
||
![]()
6 years ago
|
$table = Database::get_course_table(TABLE_QUIZ_TEST);
|
||
![]()
12 years ago
|
}
|
||
![]()
11 years ago
|
|
||
![]()
7 years ago
|
$exerciseId = $this->get_ref_id();
|
||
![]()
11 years ago
|
|
||
![]()
6 years ago
|
if (empty($this->exercise_data)) {
|
||
![]()
12 years ago
|
if ($this->is_hp == 1) {
|
||
![]()
7 years ago
|
$sql = "SELECT * FROM $table ex
|
||
![]()
6 years ago
|
INNER JOIN $tableItemProperty ip
|
||
|
ON (ip.ref = ex.id AND ip.c_id = ex.c_id)
|
||
|
WHERE
|
||
|
ip.c_id = $this->course_id AND
|
||
|
ex.c_id = $this->course_id AND
|
||
|
ip.ref = $exerciseId AND
|
||
|
ip.tool = '".TOOL_DOCUMENT."' AND
|
||
|
ex.path LIKE '%htm%' AND
|
||
|
ex.path LIKE '%HotPotatoes_files%' AND
|
||
|
ip.visibility = 1";
|
||
![]()
7 years ago
|
$result = Database::query($sql);
|
||
|
$this->exercise_data = Database::fetch_array($result);
|
||
![]()
12 years ago
|
} else {
|
||
![]()
7 years ago
|
// Try with iid
|
||
|
$sql = 'SELECT * FROM '.$table.'
|
||
![]()
6 years ago
|
WHERE
|
||
|
c_id = '.$this->course_id.' AND
|
||
|
iid = '.$exerciseId;
|
||
![]()
7 years ago
|
$result = Database::query($sql);
|
||
|
$rows = Database::num_rows($result);
|
||
|
|
||
|
if (!empty($rows)) {
|
||
|
$this->exercise_data = Database::fetch_array($result);
|
||
|
} else {
|
||
![]()
7 years ago
|
// Try wit id
|
||
![]()
7 years ago
|
$sql = 'SELECT * FROM '.$table.'
|
||
![]()
6 years ago
|
WHERE
|
||
|
c_id = '.$this->course_id.' AND
|
||
|
id = '.$exerciseId;
|
||
![]()
7 years ago
|
$result = Database::query($sql);
|
||
|
$this->exercise_data = Database::fetch_array($result);
|
||
|
}
|
||
![]()
12 years ago
|
}
|
||
![]()
11 years ago
|
}
|
||
![]()
11 years ago
|
|
||
![]()
6 years ago
|
if (empty($this->exercise_data)) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
![]()
11 years ago
|
return $this->exercise_data;
|
||
![]()
16 years ago
|
}
|
||
![]()
6 years ago
|
|
||
|
/**
|
||
|
* 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;
|
||
|
}
|
||
![]()
12 years ago
|
}
|