Quiz course copy object creation is more easy, adding text_when_finished, pass_percentage parameters see #5744

skala
Julio Montoya 12 years ago
parent 9a84f7676d
commit bb11f0df9f
  1. 24
      main/coursecopy/classes/CourseBuilder.class.php
  2. 104
      main/coursecopy/classes/CourseRecycler.class.php
  3. 16
      main/coursecopy/classes/CourseRestorer.class.php
  4. 17
      main/coursecopy/classes/CourseSelectForm.class.php
  5. 165
      main/coursecopy/classes/Quiz.class.php
  6. 2
      main/coursecopy/classes/Resource.class.php
  7. 2
      main/coursecopy/copy_course.php

@ -443,22 +443,8 @@ class CourseBuilder {
$doc = Database::fetch_object($res); $doc = Database::fetch_object($res);
$obj->sound = $doc->id; $obj->sound = $doc->id;
} }
$quiz = new Quiz( $obj->id, $quiz = new Quiz($obj);
$obj->title,
$obj->description,
$obj->random,
$obj->type,
$obj->active,
$obj->sound,
$obj->max_attempt,
$obj->results_disabled,
$obj->access_condition,
$obj->start_time,
$obj->end_time,
$obj->feedback_type,
$obj->random_answers,
$obj->expired_time,
$obj->session_id);
$sql = 'SELECT * FROM '.$table_rel.' WHERE c_id = '.$course_id.' AND exercice_id = '.$obj->id; $sql = 'SELECT * FROM '.$table_rel.' WHERE c_id = '.$course_id.' AND exercice_id = '.$obj->id;
$db_result2 = Database::query($sql); $db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2)) { while ($obj2 = Database::fetch_object($db_result2)) {
@ -533,7 +519,11 @@ class CourseBuilder {
} }
if ($build_orphan_questions) { if ($build_orphan_questions) {
$this->course->add_resource(new Quiz(-1, get_lang('OrphanQuestions', ''), '', 0, 0, 1, '', 0)); $obj = array(
'id' => -1,
'title' => get_lang('OrphanQuestions', '')
);
$this->course->add_resource(new Quiz((object)$obj));
} }
} }

@ -15,15 +15,15 @@ class CourseRecycler
*/ */
public $course; public $course;
public $type; public $type;
/** /**
* Create a new CourseRecycler * Create a new CourseRecycler
* @param course $course The course-object which contains the items to * @param course $course The course-object which contains the items to
* delete * delete
*/ */
function CourseRecycler($course) { function CourseRecycler($course) {
$this->course = $course; $this->course = $course;
$this->course_info = api_get_course_info($this->course->code); $this->course_info = api_get_course_info($this->course->code);
$this->course_id = $this->course_info['real_id']; $this->course_id = $this->course_info['real_id'];
} }
/** /**
@ -36,7 +36,7 @@ class CourseRecycler
function recycle($type) { function recycle($type) {
if (empty($type)) { return false; } if (empty($type)) { return false; }
$this->type = $type; $this->type = $type;
$table_tool_intro = Database::get_course_table(TABLE_TOOL_INTRO); $table_tool_intro = Database::get_course_table(TABLE_TOOL_INTRO);
$table_linked_resources = Database::get_course_table(TABLE_LINKED_RESOURCES); $table_linked_resources = Database::get_course_table(TABLE_LINKED_RESOURCES);
$table_item_properties = Database::get_course_table(TABLE_ITEM_PROPERTY); $table_item_properties = Database::get_course_table(TABLE_ITEM_PROPERTY);
@ -78,7 +78,7 @@ class CourseRecycler
function recycle_documents() { function recycle_documents() {
if ($this->course->has_resources(RESOURCE_DOCUMENT)) { if ($this->course->has_resources(RESOURCE_DOCUMENT)) {
$table = Database :: get_course_table(TABLE_DOCUMENT); $table = Database :: get_course_table(TABLE_DOCUMENT);
foreach ($this->course->resources[RESOURCE_DOCUMENT] as $id => $document) { foreach ($this->course->resources[RESOURCE_DOCUMENT] as $id => $document) {
rmdirr($this->course->backup_path.'/'.$document->path); rmdirr($this->course->backup_path.'/'.$document->path);
} }
$ids = implode(',', (array_keys($this->course->resources[RESOURCE_DOCUMENT]))); $ids = implode(',', (array_keys($this->course->resources[RESOURCE_DOCUMENT])));
@ -134,12 +134,12 @@ class CourseRecycler
Database::query($sql); Database::query($sql);
} }
} }
/** /**
* Delete forums * Delete forums
*/ */
function recycle_forums() { function recycle_forums() {
$table_category = Database :: get_course_table(TABLE_FORUM_CATEGORY); $table_category = Database :: get_course_table(TABLE_FORUM_CATEGORY);
$table_forum = Database :: get_course_table(TABLE_FORUM); $table_forum = Database :: get_course_table(TABLE_FORUM);
$table_thread = Database :: get_course_table(TABLE_FORUM_THREAD); $table_thread = Database :: get_course_table(TABLE_FORUM_THREAD);
@ -149,9 +149,9 @@ class CourseRecycler
$table_mail_queue = Database::get_course_table(TABLE_FORUM_MAIL_QUEUE); $table_mail_queue = Database::get_course_table(TABLE_FORUM_MAIL_QUEUE);
$table_thread_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY); $table_thread_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY);
$table_thread_qualify_log = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY_LOG); $table_thread_qualify_log = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY_LOG);
if ($this->type == 'full_backup') { if ($this->type == 'full_backup') {
$sql = "DELETE FROM ".$table_category." WHERE c_id = ".$this->course_id; $sql = "DELETE FROM ".$table_category." WHERE c_id = ".$this->course_id;
Database::query($sql); Database::query($sql);
$sql = "DELETE FROM ".$table_forum." WHERE c_id = ".$this->course_id; $sql = "DELETE FROM ".$table_forum." WHERE c_id = ".$this->course_id;
Database::query($sql); Database::query($sql);
@ -166,29 +166,29 @@ class CourseRecycler
$sql = "DELETE FROM ".$table_mail_queue." WHERE c_id = ".$this->course_id; $sql = "DELETE FROM ".$table_mail_queue." WHERE c_id = ".$this->course_id;
Database::query($sql); Database::query($sql);
$sql = "DELETE FROM ".$table_thread_qualify." WHERE c_id = ".$this->course_id; $sql = "DELETE FROM ".$table_thread_qualify." WHERE c_id = ".$this->course_id;
Database::query($sql); Database::query($sql);
$sql = "DELETE FROM ".$table_thread_qualify_log." WHERE c_id = ".$this->course_id; $sql = "DELETE FROM ".$table_thread_qualify_log." WHERE c_id = ".$this->course_id;
Database::query($sql); Database::query($sql);
$sql = "DELETE FROM ".$table_thread_qualify_log." WHERE c_id = ".$this->course_id; $sql = "DELETE FROM ".$table_thread_qualify_log." WHERE c_id = ".$this->course_id;
Database::query($sql); Database::query($sql);
} }
if ($this->course->has_resources(RESOURCE_FORUMCATEGORY)) { if ($this->course->has_resources(RESOURCE_FORUMCATEGORY)) {
$forum_ids = implode(',', (array_keys($this->course->resources[RESOURCE_FORUMCATEGORY]))); $forum_ids = implode(',', (array_keys($this->course->resources[RESOURCE_FORUMCATEGORY])));
$sql = "DELETE FROM ".$table_category." WHERE c_id = ".$this->course_id." AND cat_id IN(".$forum_ids.");"; $sql = "DELETE FROM ".$table_category." WHERE c_id = ".$this->course_id." AND cat_id IN(".$forum_ids.");";
Database::query($sql); Database::query($sql);
} }
if ($this->course->has_resources(RESOURCE_FORUM)) { if ($this->course->has_resources(RESOURCE_FORUM)) {
$forum_ids = implode(',', (array_keys($this->course->resources[RESOURCE_FORUM]))); $forum_ids = implode(',', (array_keys($this->course->resources[RESOURCE_FORUM])));
$sql = "DELETE FROM $table_attachment USING $table_attachment $sql = "DELETE FROM $table_attachment USING $table_attachment
INNER JOIN $table_post INNER JOIN $table_post
WHERE ".$table_post.".c_id = ".$this->course_id." AND WHERE ".$table_post.".c_id = ".$this->course_id." AND
".$table_attachment.".c_id = ".$this->course_id." AND ".$table_attachment.".c_id = ".$this->course_id." AND
".$table_attachment.".post_id = ".$table_post.".post_id". ".$table_attachment.".post_id = ".$table_post.".post_id".
" AND ".$table_post.".forum_id IN(".$forum_ids.");"; " AND ".$table_post.".forum_id IN(".$forum_ids.");";
Database::query($sql); Database::query($sql);
@ -229,9 +229,9 @@ class CourseRecycler
$sql = "DELETE FROM ".$table_forum." WHERE c_id = ".$this->course_id." AND forum_id IN(".$forum_ids.")"; $sql = "DELETE FROM ".$table_forum." WHERE c_id = ".$this->course_id." AND forum_id IN(".$forum_ids.")";
Database::query($sql); Database::query($sql);
} }
} }
/** /**
* Delete forum-categories * Delete forum-categories
* Deletes all forum-categories from current course without forums * Deletes all forum-categories from current course without forums
@ -239,16 +239,16 @@ class CourseRecycler
function recycle_forum_categories() { function recycle_forum_categories() {
$table_forum = Database :: get_course_table(TABLE_FORUM); $table_forum = Database :: get_course_table(TABLE_FORUM);
$table_forumcat = Database :: get_course_table(TABLE_FORUM_CATEGORY); $table_forumcat = Database :: get_course_table(TABLE_FORUM_CATEGORY);
$sql = "SELECT fc.cat_id FROM ".$table_forumcat." fc $sql = "SELECT fc.cat_id FROM ".$table_forumcat." fc
LEFT JOIN ".$table_forum." f ON fc.cat_id=f.forum_category AND fc.c_id = ".$this->course_id." AND f.c_id = ".$this->course_id." LEFT JOIN ".$table_forum." f ON fc.cat_id=f.forum_category AND fc.c_id = ".$this->course_id." AND f.c_id = ".$this->course_id."
WHERE f.forum_id IS NULL"; WHERE f.forum_id IS NULL";
$res = Database::query($sql); $res = Database::query($sql);
while ($obj = Database::fetch_object($res)) { while ($obj = Database::fetch_object($res)) {
$sql = "DELETE FROM ".$table_forumcat." WHERE c_id = ".$this->course_id." AND cat_id = ".$obj->cat_id; $sql = "DELETE FROM ".$table_forumcat." WHERE c_id = ".$this->course_id." AND cat_id = ".$obj->cat_id;
Database::query($sql); Database::query($sql);
} }
} }
/** /**
* Delete link-categories * Delete link-categories
* Deletes all empty link-categories (=without links) from current course * Deletes all empty link-categories (=without links) from current course
@ -256,9 +256,9 @@ class CourseRecycler
function recycle_link_categories() { function recycle_link_categories() {
$link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY); $link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY);
$link_table = Database :: get_course_table(TABLE_LINK); $link_table = Database :: get_course_table(TABLE_LINK);
$sql = "SELECT lc.id FROM ".$link_cat_table." lc $sql = "SELECT lc.id FROM ".$link_cat_table." lc
LEFT JOIN ".$link_table." l LEFT JOIN ".$link_table." l
ON lc.id=l.category_id AND lc.c_id = ".$this->course_id." AND l.c_id = ".$this->course_id." ON lc.id=l.category_id AND lc.c_id = ".$this->course_id." AND l.c_id = ".$this->course_id."
WHERE l.id IS NULL"; WHERE l.id IS NULL";
$res = Database::query($sql); $res = Database::query($sql);
while ($obj = Database::fetch_object($res)) { while ($obj = Database::fetch_object($res)) {
@ -266,7 +266,7 @@ class CourseRecycler
Database::query($sql); Database::query($sql);
} }
} }
/** /**
* Delete events * Delete events
*/ */
@ -299,7 +299,7 @@ class CourseRecycler
Database::query($sql); Database::query($sql);
} }
} }
/** /**
* Recycle quizzes - doesn't remove the questions and their answers, as they might still be used later * Recycle quizzes - doesn't remove the questions and their answers, as they might still be used later
*/ */
@ -319,13 +319,15 @@ class CourseRecycler
// This value is set in CourseBuilder::quiz_build_questions() // This value is set in CourseBuilder::quiz_build_questions()
$delete_orphan_questions = in_array(-1, $ids); $delete_orphan_questions = in_array(-1, $ids);
$ids = implode(',', $ids); $ids = implode(',', $ids);
// Deletion of the tests first. Questions in these tests are if (!empty($ids)) {
// not deleted and become orphan at this point // Deletion of the tests first. Questions in these tests are
$sql = "DELETE FROM ".$table_qui." WHERE c_id = ".$this->course_id." AND id IN(".$ids.")"; // not deleted and become orphan at this point
Database::query($sql); $sql = "DELETE FROM ".$table_qui." WHERE c_id = ".$this->course_id." AND id IN(".$ids.")";
$sql = "DELETE FROM ".$table_rel." WHERE c_id = ".$this->course_id." AND exercice_id IN(".$ids.")"; Database::query($sql);
Database::query($sql); $sql = "DELETE FROM ".$table_rel." WHERE c_id = ".$this->course_id." AND exercice_id IN(".$ids.")";
Database::query($sql);
}
// Identifying again and deletion of the orphan questions, if it was desired. // Identifying again and deletion of the orphan questions, if it was desired.
if ($delete_orphan_questions) { if ($delete_orphan_questions) {
@ -340,7 +342,7 @@ class CourseRecycler
' quizz_questions.c_id = '.$this->course_id.' AND '. ' quizz_questions.c_id = '.$this->course_id.' AND '.
' exercices.c_id = '.$this->course_id.' AND '. ' exercices.c_id = '.$this->course_id.' AND '.
' quizz_questions.exercice_id IS NULL OR '. ' quizz_questions.exercice_id IS NULL OR '.
' exercices.active = -1'; ' exercices.active = -1';
// active = -1 means "deleted" test. // active = -1 means "deleted" test.
$db_result = Database::query($sql); $db_result = Database::query($sql);
if (Database::num_rows($db_result) > 0) { if (Database::num_rows($db_result) > 0) {
@ -367,10 +369,10 @@ class CourseRecycler
// Quizzes previously deleted are, in fact, kept with a status // Quizzes previously deleted are, in fact, kept with a status
// (active field) of "-1". Delete those, now. // (active field) of "-1". Delete those, now.
$sql = "DELETE FROM ".$table_qui." WHERE c_id = ".$this->course_id." AND active = -1"; $sql = "DELETE FROM ".$table_qui." WHERE c_id = ".$this->course_id." AND active = -1";
Database::query($sql); Database::query($sql);
} }
} }
/** /**
* Recycle surveys - removes everything * Recycle surveys - removes everything
*/ */
@ -405,7 +407,7 @@ class CourseRecycler
$table_iv = Database :: get_course_table(TABLE_LP_ITEM_VIEW); $table_iv = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
$table_iv_int = Database::get_course_table(TABLE_LP_IV_INTERACTION); $table_iv_int = Database::get_course_table(TABLE_LP_IV_INTERACTION);
$table_tool = Database::get_course_table(TABLE_TOOL_LIST); $table_tool = Database::get_course_table(TABLE_TOOL_LIST);
foreach($this->course->resources[RESOURCE_LEARNPATH] as $id => $learnpath) { foreach($this->course->resources[RESOURCE_LEARNPATH] as $id => $learnpath) {
// See task #875. // See task #875.
if ($learnpath->lp_type == 2) { if ($learnpath->lp_type == 2) {
@ -469,17 +471,17 @@ class CourseRecycler
$table_thematic = Database :: get_course_table(TABLE_THEMATIC); $table_thematic = Database :: get_course_table(TABLE_THEMATIC);
$table_thematic_advance = Database :: get_course_table(TABLE_THEMATIC_ADVANCE); $table_thematic_advance = Database :: get_course_table(TABLE_THEMATIC_ADVANCE);
$table_thematic_plan = Database :: get_course_table(TABLE_THEMATIC_PLAN); $table_thematic_plan = Database :: get_course_table(TABLE_THEMATIC_PLAN);
$resources = $this->course->resources; $resources = $this->course->resources;
foreach ($resources[RESOURCE_THEMATIC] as $last_id => $thematic) { foreach ($resources[RESOURCE_THEMATIC] as $last_id => $thematic) {
if (is_numeric($last_id)) { if (is_numeric($last_id)) {
foreach($thematic->thematic_advance_list as $thematic_advance) { foreach($thematic->thematic_advance_list as $thematic_advance) {
$cond = array('id = ? AND c_id = ?'=>array($thematic_advance['id'], $this->course_id)); $cond = array('id = ? AND c_id = ?'=>array($thematic_advance['id'], $this->course_id));
api_item_property_update($this->course_info, 'thematic_advance', $thematic_advance['id'],'ThematicAdvanceDeleted', api_get_user_id()); api_item_property_update($this->course_info, 'thematic_advance', $thematic_advance['id'],'ThematicAdvanceDeleted', api_get_user_id());
Database::delete($table_thematic_advance, $cond); Database::delete($table_thematic_advance, $cond);
} }
foreach($thematic->thematic_plan_list as $thematic_plan) { foreach($thematic->thematic_plan_list as $thematic_plan) {
$cond = array('id = ? AND c_id = ?'=>array($thematic_plan['id'], $this->course_id)); $cond = array('id = ? AND c_id = ?'=>array($thematic_plan['id'], $this->course_id));
api_item_property_update($this->course_info, 'thematic_plan', $thematic_advance['id'], 'ThematicPlanDeleted', api_get_user_id()); api_item_property_update($this->course_info, 'thematic_plan', $thematic_advance['id'], 'ThematicPlanDeleted', api_get_user_id());
@ -489,21 +491,21 @@ class CourseRecycler
api_item_property_update($this->course_info, 'thematic', $last_id,'ThematicDeleted', api_get_user_id()); api_item_property_update($this->course_info, 'thematic', $last_id,'ThematicDeleted', api_get_user_id());
Database::delete($table_thematic,$cond); Database::delete($table_thematic,$cond);
} }
} }
} }
} }
/** /**
* Recycle Attendances * Recycle Attendances
*/ */
function recycle_attendance($session_id = 0) { function recycle_attendance($session_id = 0) {
if ($this->course->has_resources(RESOURCE_ATTENDANCE)) { if ($this->course->has_resources(RESOURCE_ATTENDANCE)) {
$table_attendance = Database :: get_course_table(TABLE_ATTENDANCE); $table_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
$table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR); $table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR);
$resources = $this->course->resources; $resources = $this->course->resources;
foreach ($resources[RESOURCE_ATTENDANCE] as $last_id => $obj) { foreach ($resources[RESOURCE_ATTENDANCE] as $last_id => $obj) {
if (is_numeric($last_id)) { if (is_numeric($last_id)) {
foreach($obj->attendance_calendar as $attendance_calendar) { foreach($obj->attendance_calendar as $attendance_calendar) {
$cond = array('id = ? AND c_id = ? '=>array($attendance_calendar['id'], $this->course_id)); $cond = array('id = ? AND c_id = ? '=>array($attendance_calendar['id'], $this->course_id));
Database::delete($table_attendance_calendar, $cond); Database::delete($table_attendance_calendar, $cond);

@ -1092,6 +1092,8 @@ class CourseRestorer
$table_doc = Database :: get_course_table(TABLE_DOCUMENT); $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
$resources = $this->course->resources; $resources = $this->course->resources;
foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) { foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) {
$quiz = $quiz->obj;
$doc = ''; $doc = '';
if (strlen($quiz->media) > 0) { if (strlen($quiz->media) > 0) {
if ($this->course->resources[RESOURCE_DOCUMENT][$quiz->media]->is_restored()) { if ($this->course->resources[RESOURCE_DOCUMENT][$quiz->media]->is_restored()) {
@ -1125,24 +1127,28 @@ class CourseRestorer
$quiz->end_time = null; $quiz->end_time = null;
} }
// Normal tests are stored in the database. // Normal tests are stored in the database.
$sql = "INSERT INTO ".$table_qui." SET $sql = "INSERT INTO ".$table_qui." SET
c_id = ".$this->destination_course_id." , c_id = ".$this->destination_course_id." ,
title = '".self::DBUTF8escapestring($quiz->title). title = '".self::DBUTF8escapestring($quiz->title).
"', description = '".self::DBUTF8escapestring($quiz->description). "', description = '".self::DBUTF8escapestring($quiz->description).
"', type = '".$quiz->quiz_type. "', type = '".$quiz->type.
"', random = '".$quiz->random. "', random = '".$quiz->random.
"', active = '".$quiz->active. "', active = '".$quiz->active.
"', sound = '".self::DBUTF8escapestring($doc). "', sound = '".self::DBUTF8escapestring($doc).
"', max_attempt = ".(int)$quiz->attempts. "', max_attempt = ".(int)$quiz->max_attempt.
", results_disabled = ".(int)$quiz->results_disabled. ", results_disabled = ".(int)$quiz->results_disabled.
", access_condition = '".$quiz->access_condition. ", access_condition = '".$quiz->access_condition.
"', start_time = '".$quiz->start_time. "', start_time = '".$quiz->start_time.
"', pass_percentage = '".$quiz->pass_percentage.
"', end_time = '".$quiz->end_time. "', end_time = '".$quiz->end_time.
"', feedback_type = ".(int)$quiz->feedback_type. "', feedback_type = ".(int)$quiz->feedback_type.
", random_answers = ".(int)$quiz->random_answers. ", random_answers = ".(int)$quiz->random_answers.
", expired_time = ".(int)$quiz->expired_time. ", random_by_category = ".$quiz->random_by_category.
", review_answers = ".$quiz->review_answers.
", propagate_neg = ".$quiz->propagate_neg.
", text_when_finished = '".$quiz->text_when_finished."',
expired_time = ".(int)$quiz->expired_time.
$condition_session; $condition_session;
Database::query($sql); Database::query($sql);
$new_id = Database::insert_id(); $new_id = Database::insert_id();
@ -1151,7 +1157,7 @@ class CourseRestorer
$new_id = -1; $new_id = -1;
} }
$this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id; $this->course->resources[RESOURCE_QUIZ][$id]->obj->destination_id = $new_id;
$order = 0; $order = 0;
foreach ($quiz->question_ids as $index => $question_id) { foreach ($quiz->question_ids as $index => $question_id) {

@ -210,10 +210,12 @@ class CourseSelectForm
echo '</div><br />'; echo '</div><br />';
foreach ($resources as $id => $resource) { foreach ($resources as $id => $resource) {
echo '<label class="checkbox">'; if ($resource) {
echo '<input type="checkbox" name="resource['.$type.']['.$id.']" id="resource['.$type.']['.$id.']" />'; echo '<label class="checkbox">';
$resource->show(); echo '<input type="checkbox" name="resource['.$type.']['.$id.']" id="resource['.$type.']['.$id.']" />';
echo '</label>'; $resource->show();
echo '</label>';
}
} }
echo '</blockquote>'; echo '</blockquote>';
echo '</div>'; echo '</div>';
@ -254,7 +256,6 @@ class CourseSelectForm
echo '</li>'; echo '</li>';
if (isset($forum_topics[$forum_id])) { if (isset($forum_topics[$forum_id])) {
$my_forum_topics = $forum_topics[$forum_id]; $my_forum_topics = $forum_topics[$forum_id];
if (!empty($my_forum_topics)) { if (!empty($my_forum_topics)) {
echo '<ul>'; echo '<ul>';
foreach ($my_forum_topics as $topic_id => $topic) { foreach ($my_forum_topics as $topic_id => $topic) {
@ -491,6 +492,7 @@ class CourseSelectForm
// check if document is in a quiz (audio/video) // check if document is in a quiz (audio/video)
if ($type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ)) { if ($type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ)) {
foreach($course->resources[RESOURCE_QUIZ] as $qid => $quiz) { foreach($course->resources[RESOURCE_QUIZ] as $qid => $quiz) {
$quiz = $quiz->obj;
if ($quiz->media == $id) { if ($quiz->media == $id) {
$resource_is_used_elsewhere = true; $resource_is_used_elsewhere = true;
} }
@ -568,7 +570,7 @@ class CourseSelectForm
echo '<script type="text/javascript">var myUpload = new upload(1000);</script>'; echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="myUpload.start(\'dynamic_div\',\''.api_get_path(WEB_CODE_PATH).'img/progress_bar.gif\',\''.get_lang('PleaseStandBy').'\',\'upload_form\')">'; echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="myUpload.start(\'dynamic_div\',\''.api_get_path(WEB_CODE_PATH).'img/progress_bar.gif\',\''.get_lang('PleaseStandBy').'\',\'upload_form\')">';
echo '<input type="hidden" name="action" value="course_select_form"/>'; echo '<input type="hidden" name="action" value="course_select_form"/>';
foreach($list_course as $course){ foreach ($list_course as $course){
foreach ($course->resources as $type => $resources) { foreach ($course->resources as $type => $resources) {
if (count($resources) > 0) { if (count($resources) > 0) {
echo '<img id="img_'.$course->code.'" src="../img/1.gif" onclick="javascript:exp('."'$course->code'".');" />'; echo '<img id="img_'.$course->code.'" src="../img/1.gif" onclick="javascript:exp('."'$course->code'".');" />';
@ -582,11 +584,10 @@ class CourseSelectForm
echo '</div><br />'; echo '</div><br />';
foreach ($resources as $id => $resource) { foreach ($resources as $id => $resource) {
echo ' <label class="checkbox" for="resource['.$course->code.']['.$id.']">'; echo '<label class="checkbox" for="resource['.$course->code.']['.$id.']">';
echo '<input type="checkbox" name="resource['.$course->code.']['.$id.']" id="resource['.$course->code.']['.$id.']"/>'; echo '<input type="checkbox" name="resource['.$course->code.']['.$id.']" id="resource['.$course->code.']['.$id.']"/>';
$resource->show(); $resource->show();
echo '</label>'; echo '</label>';
echo "\n";
} }
echo '</blockquote>'; echo '</blockquote>';
echo '</div>'; echo '</div>';

@ -1,4 +1,5 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* Exercises backup script * Exercises backup script
@ -8,6 +9,7 @@
* Code * Code
*/ */
require_once 'Resource.class.php'; require_once 'Resource.class.php';
/** /**
* An Quiz * An Quiz
* @author Bart Mollet <bart.mollet@hogent.be> * @author Bart Mollet <bart.mollet@hogent.be>
@ -15,117 +17,52 @@ require_once 'Resource.class.php';
*/ */
class Quiz extends Resource class Quiz extends Resource
{ {
/** /**
* The title * Create a new Quiz
*/ * @param string $title
var $title; * @param string $description
/** * @param int $random
* The description * @param int $type
*/ * @param int $active
var $description; */
/** // function Quiz($id, $title, $description, $random, $type, $active, $media, $attempts = 0, $results_disabled = 0, $access_condition = null, $start_time = '0000-00-00 00:00:00', $end_time = '0000-00-00 00:00:00', $feedback_type = 0, $random_answers = 0, $expired_time = 0, $session_id = 0) {
* random function Quiz($obj) {
*/ parent::Resource($obj->id, RESOURCE_QUIZ);
var $random; $this->obj = $obj;
/**
* Type /*
*/ $this->title = $title;
var $quiz_type; $this->description = $description;
/** $this->random = $random;
* Active $this->quiz_type = $type;
*/ $this->active = $active;
var $active; $this->media = $media;
/** $this->attempts = $attempts;
* Sound or video file $this->question_ids = array();
* This should be the id of the file and not the file-name like in the $this->question_orders = array();
* database! $this->results_disabled = $results_disabled;
*/ $this->access_condition = $access_condition;
var $media; $this->start_time = $start_time;
/** $this->end_time = $end_time;
* Questions $this->feedback_type = $feedback_type;
*/ $this->random_answers = $random_answers;
var $question_ids; $this->expired_time = $expired_time;
/** $this->session_id = $session_id;*/
* Questions orders }
*/
var $question_orders; /**
/** * Add a question to this Quiz
* Max attempts */
*/ function add_question($id, $question_order) {
var $attempts; $this->obj->question_ids[] = $id;
/** $this->obj->question_orders[] = $question_order;
* Results disabled }
*/
var $results_disabled; /**
/** * Show this question
* Access condition */
*/ function show() {
var $access_condition; parent::show();
/** echo $this->obj->title;
* Start time }
*/ }
var $start_time;
/**
* End time
*/
var $end_time;
/**
* Feedback type
*/
var $feedback_type;
/**
* Random answers
*/
var $random_answers;
/**
* Expired time
*/
var $expired_time;
/**
* Create a new Quiz
* @param string $title
* @param string $description
* @param int $random
* @param int $type
* @param int $active
*/
function Quiz($id, $title, $description, $random, $type, $active, $media, $attempts = 0, $results_disabled = 0, $access_condition = null,
$start_time = '0000-00-00 00:00:00', $end_time = '0000-00-00 00:00:00', $feedback_type = 0, $random_answers = 0, $expired_time = 0, $session_id = 0)
{
parent::Resource($id, RESOURCE_QUIZ);
$this->title = $title;
$this->description = $description;
$this->random = $random;
$this->quiz_type = $type;
$this->active = $active;
$this->media = $media;
$this->attempts = $attempts;
$this->question_ids = array();
$this->question_orders= array();
$this->results_disabled = $results_disabled;
$this->access_condition = $access_condition;
$this->start_time = $start_time;
$this->end_time = $end_time;
$this->feedback_type = $feedback_type;
$this->random_answers = $random_answers;
$this->expired_time = $expired_time;
$this->session_id = $session_id;
}
/**
* Add a question to this Quiz
*/
function add_question($id,$question_order)
{
$this->question_ids[] = $id;
$this->question_orders[] = $question_order;
}
/**
* Show this question
*/
function show()
{
parent::show();
echo $this->title;
}
}

@ -67,6 +67,8 @@ class Resource {
*/ */
var $item_properties; var $item_properties;
var $obj = null;
/** /**
* Create a new Resource * Create a new Resource
* @param int $id The id of this resource in the source course. * @param int $id The id of this resource in the source course.

@ -59,7 +59,7 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (is
} elseif (isset ($_POST['copy_option']) && $_POST['copy_option'] == 'select_items') { } elseif (isset ($_POST['copy_option']) && $_POST['copy_option'] == 'select_items') {
$cb = new CourseBuilder(); $cb = new CourseBuilder();
$course = $cb->build(); $course = $cb->build();
$hidden_fields = array(); $hidden_fields = array();
$hidden_fields['same_file_name_option'] = $_POST['same_file_name_option']; $hidden_fields['same_file_name_option'] = $_POST['same_file_name_option'];
$hidden_fields['destination_course'] = $_POST['destination_course']; $hidden_fields['destination_course'] = $_POST['destination_course'];

Loading…
Cancel
Save