Bug #1370 - Training backup tool: Adding possibility to process with this tool the test orphan questions. Orphan questions may be archieved, restored and *deleted*. Now it seems to me that the option "Delete everything" is real.

skala
Ivan Tcholakov 16 years ago
parent 469a7a5946
commit 20594dc3ee
  1. 2
      main/coursecopy/backup.php
  2. 61
      main/coursecopy/classes/CourseBuilder.class.php
  3. 57
      main/coursecopy/classes/CourseRecycler.class.php
  4. 13
      main/coursecopy/classes/CourseRestorer.class.php
  5. 2
      main/coursecopy/copy_course.php
  6. 2
      main/coursecopy/create_backup.php
  7. 2
      main/coursecopy/import_backup.php
  8. 2
      main/coursecopy/recycle_course.php

@ -33,7 +33,7 @@
*/
// name of the language file that needs to be included
$language_file = array('coursebackup','admin');
$language_file = array('exercice', 'coursebackup', 'admin');
// including the global file
include ('../inc/global.inc.php');

@ -264,8 +264,12 @@ class CourseBuilder
*/
function build_quiz_questions()
{
$table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
$table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
$table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
$table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
// Building normal tests.
$sql = 'SELECT * FROM '.$table_que;
$db_result = api_sql_query($sql, __FILE__, __LINE__);
while ($obj = Database::fetch_object($db_result))
@ -279,6 +283,63 @@ class CourseBuilder
}
$this->course->add_resource($question);
}
// Building a fictional test for collecting orphan questions.
$build_orphan_questions = !empty($_POST['recycle_option']); // When a course is emptied this option should be activated (true).
$sql = 'SELECT * FROM '.$table_que.
' as questions LEFT JOIN '.$table_rel.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$table_qui.
' as exercices ON exercice_id=exercices.id WHERE quizz_questions.exercice_id IS NULL OR exercices.active = -1'; // active = -1 means "deleted" test.
$db_result = api_sql_query($sql, __FILE__, __LINE__);
if (Database::num_rows($db_result) > 0)
{
$build_orphan_questions = true;
while ($obj = Database::fetch_object($db_result))
{
$question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level);
$sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->id;
$db_result2 = api_sql_query($sql, __FILE__, __LINE__);
while ($obj2 = Database::fetch_object($db_result2))
{
$question->add_answer($obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
}
$this->course->add_resource($question);
}
}
if ($build_orphan_questions)
{
$this->course->add_resource(new Quiz(-1, get_lang('OrphanQuestions', ''), '', 0, 0, 1, '', 0));
}
}
/**
* Build the orphan questions
*/
function build_quiz_orphan_questions()
{
$table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
$table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
$table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
$table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
$sql = 'SELECT * FROM '.$table_que.
' as questions LEFT JOIN '.$table_rel.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$table_qui.
' as exercices ON exercice_id=exercices.id WHERE quizz_questions.exercice_id IS NULL OR exercices.active = -1';
$db_result = api_sql_query($sql, __FILE__, __LINE__);
if (Database::num_rows($db_result) > 0)
{
$orphan_questions = new Quiz(-1, get_lang('OrphanQuestions', ''), '', 0, 0, 1, '', 0); // Tjis is the fictional test for collecting orphan questions.
$this->course->add_resource($orphan_questions);
while ($obj = Database::fetch_object($db_result))
{
$question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level);
$sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->id;
$db_result2 = api_sql_query($sql, __FILE__, __LINE__);
while ($obj2 = Database::fetch_object($db_result2))
{
$question->add_answer($obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
}
$this->course->add_resource($question);
}
}
}
/**
* Build the Surveys

@ -1,27 +1,27 @@
<?php
// $Id: CourseRecycler.class.php 12117 2007-04-24 22:06:36Z pcool $
/*
==============================================================================
==============================================================================
Dokeos - elearning and course management software
Copyright (c) 2004 Dokeos S.A.
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
Copyright (c) Bart Mollet (bart.mollet@hogent.be)
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See the GNU General Public License for more details.
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
Mail: info@dokeos.com
==============================================================================
==============================================================================
*/
require_once ('Course.class.php');
require_once ('rmdirr.php');
@ -247,16 +247,49 @@ class CourseRecycler
{
if ($this->course->has_resources(RESOURCE_QUIZ))
{
//$table_qui_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
//$table_qui_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
$table_qui_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
$table_qui_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
$table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
$table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
$ids = implode(',', (array_keys($this->course->resources[RESOURCE_QUIZ])));
$sql = "DELETE FROM ".$table_qui." WHERE id IN(".$ids.")";
$ids = array_keys($this->course->resources[RESOURCE_QUIZ]);
$delete_orphan_questions = in_array(-1, $ids);
$ids = implode(',', $ids);
// Deletion of the normal tests, questions in them are not deleted, they become orphan at this moment.
$sql = "DELETE FROM ".$table_qui." WHERE id <> -1 AND id IN(".$ids.")";
api_sql_query($sql,__FILE__,__LINE__);
$sql = "DELETE FROM ".$table_rel." WHERE exercice_id IN(".$ids.")";
$sql = "DELETE FROM ".$table_rel." WHERE exercice_id <> -1 AND exercice_id IN(".$ids.")";
api_sql_query($sql,__FILE__,__LINE__);
// Identifying again and deletion of the orphan questions, if it was desired.
if ($delete_orphan_questions)
{
$sql = 'SELECT questions.id FROM '.$table_qui_que.
' as questions LEFT JOIN '.$table_rel.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$table_qui.
' as exercices ON exercice_id=exercices.id WHERE quizz_questions.exercice_id IS NULL OR exercices.active = -1'; // active = -1 means "deleted" test.
$db_result = api_sql_query($sql, __FILE__, __LINE__);
if (Database::num_rows($db_result) > 0)
{
$orphan_ids = array();
while ($obj = Database::fetch_object($db_result))
{
$orphan_ids[] = $obj->id;
}
$orphan_ids = implode(',', $orphan_ids);
$sql = "DELETE FROM ".$table_rel." WHERE question_id IN(".$orphan_ids.")";
api_sql_query($sql,__FILE__,__LINE__);
$sql = "DELETE FROM ".$table_qui_ans." WHERE question_id IN(".$orphan_ids.")";
api_sql_query($sql,__FILE__,__LINE__);
$sql = "DELETE FROM ".$table_qui_que." WHERE id IN(".$orphan_ids.")";
api_sql_query($sql,__FILE__,__LINE__);
}
}
}
// Purge "deleted" tests (active = -1).
$sql = "DELETE FROM ".$table_qui." WHERE active = -1";
api_sql_query($sql,__FILE__,__LINE__);
}
/**
* Recycle surveys - removes everything

@ -707,9 +707,16 @@ class CourseRestorer
$doc = str_replace('/audio/', '', $doc->path);
}
}
$sql = "INSERT INTO ".$table_qui." SET title = '".Database::escape_string($quiz->title)."', description = '".Database::escape_string($quiz->description)."', type = '".$quiz->quiz_type."', random = '".$quiz->random."', active = '".$quiz->active."', sound = '".Database::escape_string($doc)."', max_attempt = '".$quiz->attempts."' ";
api_sql_query($sql, __FILE__, __LINE__);
$new_id = Database::get_last_insert_id();
if ($id != -1) // $id = -1 identifies the fictionary test for collecting orphan questions. We do not store it in the database.
{
$sql = "INSERT INTO ".$table_qui." SET title = '".Database::escape_string($quiz->title)."', description = '".Database::escape_string($quiz->description)."', type = '".$quiz->quiz_type."', random = '".$quiz->random."', active = '".$quiz->active."', sound = '".Database::escape_string($doc)."', max_attempt = '".$quiz->attempts."' ";
api_sql_query($sql, __FILE__, __LINE__);
$new_id = Database::get_last_insert_id();
}
else
{
$new_id = -1;
}
$this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id;
foreach ($quiz->question_ids as $index => $question_id)
{

@ -37,7 +37,7 @@
==============================================================================
*/
// name of the language file that needs to be included
$language_file = array('coursebackup','admin');
$language_file = array('exercice', 'coursebackup', 'admin');
require_once '../inc/global.inc.php';
include_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php';
require_once 'classes/CourseBuilder.class.php';

@ -33,7 +33,7 @@
*/
// name of the language file that needs to be included
$language_file = array ('admin','coursebackup');
$language_file = array ('exercice', 'admin', 'coursebackup');
// including the global file
include ('../inc/global.inc.php');

@ -36,7 +36,7 @@
==============================================================================
*/
// name of the language file that needs to be included
$language_file = array('coursebackup','admin');
$language_file = array('exercice', 'coursebackup', 'admin');
// including the global file
include ('../inc/global.inc.php');

@ -32,7 +32,7 @@
*/
// name of the language file that needs to be included
$language_file = array ('admin','course_info','coursebackup');
$language_file = array ('exercice', 'admin', 'course_info', 'coursebackup');
// including the global file
include ('../inc/global.inc.php');

Loading…
Cancel
Save