Minor - format code.

1.9.x
Julio Montoya 11 years ago
parent 9bef19062e
commit 4ddc3be3fe
  1. 201
      main/coursecopy/classes/CourseRestorer.class.php
  2. 21
      main/coursecopy/classes/Quiz.class.php
  3. 66
      main/coursecopy/classes/QuizQuestion.class.php
  4. 16
      main/coursecopy/classes/QuizQuestionOption.class.php
  5. 12
      main/coursecopy/classes/Resource.class.php

@ -24,10 +24,10 @@ require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
define('FILE_SKIP', 1);
define('FILE_RENAME', 2);
define('FILE_OVERWRITE', 3);
define('UTF8_CONVERT', false); //false by default
define('FILE_SKIP', 1);
define('FILE_RENAME', 2);
define('FILE_OVERWRITE', 3);
define('UTF8_CONVERT', false); //false by default
/**
* Class CourseRestorer
@ -1271,7 +1271,10 @@ class CourseRestorer
if (!empty($quiz->sound)) {
if (isset($this->course->resources[RESOURCE_DOCUMENT][$quiz->sound]) &&
$this->course->resources[RESOURCE_DOCUMENT][$quiz->sound]->is_restored()) {
$sql = "SELECT path FROM ".$table_doc." WHERE c_id = ".$this->destination_course_id." AND id = ".$resources[RESOURCE_DOCUMENT][$quiz->sound]->destination_id;
$sql = "SELECT path FROM " . $table_doc . "
WHERE
c_id = " . $this->destination_course_id . " AND
id = " . $resources[RESOURCE_DOCUMENT][$quiz->sound]->destination_id;
$doc = Database::query($sql);
$doc = Database::fetch_object($doc);
$doc = str_replace('/audio/', '', $doc->path);
@ -1335,7 +1338,11 @@ class CourseRestorer
foreach ($quiz->question_ids as $index => $question_id) {
$qid = $this->restore_quiz_question($question_id);
$question_order = $quiz->question_orders[$index] ? $quiz->question_orders[$index] : ++$order;
$sql = "INSERT IGNORE INTO ".$table_rel." SET c_id = ".$this->destination_course_id.", question_id = ".$qid.", exercice_id = ".$new_id.", question_order = ".$question_order;
$sql = "INSERT IGNORE INTO " . $table_rel . " SET
c_id = " . $this->destination_course_id . ",
question_id = " . $qid . ",
exercice_id = " . $new_id . ",
question_order = " . $question_order;
Database::query($sql);
}
}
@ -1363,7 +1370,13 @@ class CourseRestorer
$table_options = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
// check resources inside html from fckeditor tool and copy correct urls into recipient course
$question->description = DocumentManager::replace_urls_inside_content_html_from_copy_course($question->description, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
$question->description = DocumentManager::replace_urls_inside_content_html_from_copy_course(
$question->description,
$this->course->code,
$this->course->destination_path,
$this->course->backup_path,
$this->course->info['path']
);
$sql = "INSERT INTO ".$table_que." SET
c_id = ".$this->destination_course_id." ,
@ -1393,7 +1406,11 @@ class CourseRestorer
$result = $question_temp->uploadPicture($old_picture, $picture_name, $picturePath);
if ($result) {
$sql = "UPDATE $table_que SET picture = '$picture_name' WHERE c_id = ".$this->destination_course_id." AND id = $new_id ";
$sql = "UPDATE $table_que SET
picture = '$picture_name'
WHERE
c_id = " . $this->destination_course_id . " AND
id = $new_id ";
Database::query($sql);
}
}
@ -1425,8 +1442,21 @@ class CourseRestorer
foreach ($question->answers as $index => $answer) {
// check resources inside html from fckeditor tool and copy correct urls into recipient course
$answer['answer'] = DocumentManager::replace_urls_inside_content_html_from_copy_course($answer['answer'], $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
$answer['comment'] = DocumentManager::replace_urls_inside_content_html_from_copy_course($answer['comment'], $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
$answer['answer'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
$answer['answer'],
$this->course->code,
$this->course->destination_path,
$this->course->backup_path,
$this->course->info['path']
);
$answer['comment'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
$answer['comment'],
$this->course->code,
$this->course->destination_path,
$this->course->backup_path,
$this->course->info['path']
);
$sql = "INSERT INTO ".$table_ans." SET
c_id = ".$this->destination_course_id." ,
@ -1463,11 +1493,33 @@ class CourseRestorer
$old_option_ids[$old_id] = $question_option_id;
}
if ($old_option_ids) {
$new_answers = Database::select('id, correct', $table_ans, array('WHERE' => array('question_id = ? AND c_id = ? '=> array($new_id, $this->destination_course_id))));
$new_answers = Database::select(
'id, correct',
$table_ans,
array(
'WHERE' => array(
'question_id = ? AND c_id = ? ' => array(
$new_id,
$this->destination_course_id
)
)
)
);
foreach ($new_answers as $answer_item) {
$params = array();
$params['correct'] = $old_option_ids[$answer_item['correct']];
$question_option_id = Database::update($table_ans, $params, array('id = ? AND c_id = ? AND question_id = ? '=> array($answer_item['id'], $this->destination_course_id, $new_id)), false);
$question_option_id = Database::update(
$table_ans,
$params,
array(
'id = ? AND c_id = ? AND question_id = ? ' => array(
$answer_item['id'],
$this->destination_course_id,
$new_id
)
),
false
);
}
}
} else {
@ -1516,17 +1568,16 @@ class CourseRestorer
$title = $CourseCopyTestcategory->title;
$description = $CourseCopyTestcategory->description;
if (Testcategory::category_exists_with_title($title))
{
switch ($this->file_option)
{
if (Testcategory::category_exists_with_title($title)) {
switch ($this->file_option) {
case FILE_SKIP:
//Do nothing
break;
case FILE_RENAME:
$new_title = $title."_";
while (Testcategory::category_exists_with_title($new_title))
{
while (Testcategory::category_exists_with_title(
$new_title
)) {
$new_title .= "_";
}
$test_category = new Testcategory(0, $new_title, $description);
@ -1541,9 +1592,7 @@ class CourseRestorer
$tab_test_category_id_old_new[$CourseCopyTestcategory->source_id] = $id;
break;
}
}
else
{
} else {
// create a new test_category
$test_category = new Testcategory(0, $title, $description);
$new_id = $test_category->addCategoryInBDD();
@ -1593,10 +1642,37 @@ class CourseRestorer
$result_check = Database::query($sql_check);
// check resources inside html from fckeditor tool and copy correct urls into recipient course
$survey->title = DocumentManager::replace_urls_inside_content_html_from_copy_course($survey->title, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
$survey->subtitle = DocumentManager::replace_urls_inside_content_html_from_copy_course($survey->subtitle, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
$survey->intro = DocumentManager::replace_urls_inside_content_html_from_copy_course($survey->intro, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
$survey->surveythanks = DocumentManager::replace_urls_inside_content_html_from_copy_course($survey->surveythanks, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
$survey->title = DocumentManager::replace_urls_inside_content_html_from_copy_course(
$survey->title,
$this->course->code,
$this->course->destination_path,
$this->course->backup_path,
$this->course->info['path']
);
$survey->subtitle = DocumentManager::replace_urls_inside_content_html_from_copy_course(
$survey->subtitle,
$this->course->code,
$this->course->destination_path,
$this->course->backup_path,
$this->course->info['path']
);
$survey->intro = DocumentManager::replace_urls_inside_content_html_from_copy_course(
$survey->intro,
$this->course->code,
$this->course->destination_path,
$this->course->backup_path,
$this->course->info['path']
);
$survey->surveythanks = DocumentManager::replace_urls_inside_content_html_from_copy_course(
$survey->surveythanks,
$this->course->code,
$this->course->destination_path,
$this->course->backup_path,
$this->course->info['path']
);
$sql = "INSERT INTO ".$table_sur." " ."SET
c_id = ".$this->destination_course_id." ,
@ -1749,7 +1825,13 @@ class CourseRestorer
$table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
// check resources inside html from fckeditor tool and copy correct urls into recipient course
$question->survey_question = DocumentManager::replace_urls_inside_content_html_from_copy_course($question->survey_question, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
$question->survey_question = DocumentManager::replace_urls_inside_content_html_from_copy_course(
$question->survey_question,
$this->course->code,
$this->course->destination_path,
$this->course->backup_path,
$this->course->info['path']
);
$sql = "INSERT INTO ".$table_que." SET
c_id = ".$this->destination_course_id." ,
@ -1768,7 +1850,13 @@ class CourseRestorer
foreach ($question->answers as $index => $answer) {
// check resources inside html from fckeditor tool and copy correct urls into recipient course
$answer['option_text'] = DocumentManager::replace_urls_inside_content_html_from_copy_course($answer['option_text'], $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
$answer['option_text'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
$answer['option_text'],
$this->course->code,
$this->course->destination_path,
$this->course->backup_path,
$this->course->info['path']
);
$sql = "INSERT INTO ".$table_ans." SET
c_id = ".$this->destination_course_id." ,
@ -2198,7 +2286,6 @@ class CourseRestorer
{
if ($this->course->has_resources(RESOURCE_GLOSSARY)) {
$table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
$t_item_propery = Database :: get_course_table(TABLE_ITEM_PROPERTY);
$resources = $this->course->resources;
foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) {
@ -2211,7 +2298,19 @@ class CourseRestorer
// check resources inside html from fckeditor tool and copy correct urls into recipient course
$glossary->description = DocumentManager::replace_urls_inside_content_html_from_copy_course($glossary->description, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
$sql = "INSERT INTO ".$table_glossary." SET c_id = ".$this->destination_course_id." , name = '".self::DBUTF8escapestring($glossary->name)."', description = '".self::DBUTF8escapestring($glossary->description)."', display_order='".self::DBUTF8escapestring($glossary->display_order)."' $condition_session ";
$sql = "INSERT INTO " . $table_glossary . " SET
c_id = " . $this->destination_course_id . " ,
name = '" . self::DBUTF8escapestring(
$glossary->name
) . "',
description = '" . self::DBUTF8escapestring(
$glossary->description
) . "',
display_order='" . self::DBUTF8escapestring(
$glossary->display_order
) . "'
$condition_session
";
Database::query($sql);
$my_id = Database::get_last_insert_id();
api_item_property_update($this->destination_course_info, TOOL_GLOSSARY, $my_id,"GlossaryAdded", api_get_user_id());
@ -2221,7 +2320,11 @@ class CourseRestorer
}
}
public function restore_wiki($session_id = 0) {
/**
* @param int $session_id
*/
public function restore_wiki($session_id = 0)
{
if ($this->course->has_resources(RESOURCE_WIKI)) {
// wiki table of the target course
$table_wiki = Database :: get_course_table('wiki');
@ -2249,7 +2352,7 @@ class CourseRestorer
'".self::DBUTF8escapestring($wiki->progress)."',
'".intval($wiki->version)."',
'".(!empty($session_id)?intval($session_id):0)."')";
$rs2 = Database::query($sql);
Database::query($sql);
$new_id = Database::insert_id();
$this->course->resources[RESOURCE_WIKI][$id]->destination_id = $new_id;
$sql = "UPDATE $table_wiki set page_id = '$new_id' WHERE c_id = ".$this->destination_course_id." AND id = '$new_id'";
@ -2258,14 +2361,15 @@ class CourseRestorer
// we also add an entry in wiki_conf
$sql = "INSERT INTO $table_wiki_conf (c_id, page_id, task, feedback1, feedback2, feedback3, fprogress1, fprogress2, fprogress3, max_size, max_text, max_version, startdate_assig, enddate_assig, delayedsubmit) VALUES
(".$this->destination_course_id." , '".intval($new_id)."', '', '', '', '', '', '', '', NULL, 0, 0, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0)";
$rs1 = Database::query($sql);
Database::query($sql);
}
}
}
/**
* Restore Thematics
*/
/**
* Restore Thematics
* @param int $session_id
*/
public function restore_thematic($session_id = 0)
{
if ($this->course->has_resources(RESOURCE_THEMATIC)) {
@ -2312,10 +2416,10 @@ class CourseRestorer
}
}
/**
* Restore Attendance
*/
/**
* Restore Attendance
* @param int $session_id
*/
public function restore_attendance($session_id = 0)
{
if ($this->course->has_resources(RESOURCE_ATTENDANCE)) {
@ -2335,11 +2439,14 @@ class CourseRestorer
if (is_numeric($last_id)) {
api_item_property_update($this->destination_course_info, TOOL_ATTENDANCE, $last_id,"AttendanceAdded", api_get_user_id());
foreach($obj->attendance_calendar as $attendance_calendar) {
foreach ($obj->attendance_calendar as $attendance_calendar) {
unset($attendance_calendar['id']);
$attendance_calendar['attendance_id'] = $last_id;
$attendance_calendar['c_id'] = $this->destination_course_id;
$my_id = Database::insert($table_attendance_calendar, $attendance_calendar);
Database::insert(
$table_attendance_calendar,
$attendance_calendar
);
}
}
}
@ -2428,6 +2535,10 @@ class CourseRestorer
}
}
/**
* @param string $str
* @return string
*/
public function DBUTF8($str)
{
if (UTF8_CONVERT) {
@ -2436,6 +2547,10 @@ class CourseRestorer
return $str;
}
/**
* @param string $str
* @return string
*/
public function DBUTF8escapestring($str)
{
if (UTF8_CONVERT) {
@ -2444,6 +2559,10 @@ class CourseRestorer
return Database::escape_string($str);
}
/**
* @param array $array
* @return mixed
*/
public function DBUTF8_array($array)
{
if (UTF8_CONVERT) {

@ -1,17 +1,11 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Exercises backup script
* @package chamilo.backup
*/
/**
* Code
*/
require_once 'Resource.class.php';
/**
* An Quiz
* Exercises backup script
* @author Bart Mollet <bart.mollet@hogent.be>
* @package chamilo.backup
*/
@ -27,7 +21,8 @@ class Quiz extends Resource
*/
public $obj; //question
function Quiz($obj) {
public function Quiz($obj)
{
$this->obj = $obj;
$this->obj->quiz_type = $this->obj->type;
parent::Resource($obj->id, RESOURCE_QUIZ);
@ -36,7 +31,8 @@ class Quiz extends Resource
/**
* Add a question to this Quiz
*/
function add_question($id, $question_order) {
public function add_question($id, $question_order)
{
$this->obj->question_ids[] = $id;
$this->obj->question_orders[] = $question_order;
}
@ -44,8 +40,9 @@ class Quiz extends Resource
/**
* Show this question
*/
function show() {
public function show()
{
parent::show();
echo $this->obj->title;
}
}
}

@ -1,69 +1,61 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Exercises questions backup script
* @package chamilo.backup
*/
/**
* Code
*/
require_once 'Resource.class.php';
/**
* An QuizQuestion
* Exercises questions backup script
* Class QuizQuestion
* @author Bart Mollet <bart.mollet@hogent.be>
* @package chamilo.backup
*/
class QuizQuestion extends Resource
{
/**
* The question
*/
var $question;
public $question;
/**
* The description
*/
var $description;
public $description;
/**
* Ponderation
*/
var $ponderation;
public $ponderation;
/**
* Type
*/
var $quiz_type;
public $quiz_type;
/**
* Position
*/
var $position;
public $position;
/**
* Level
*/
var $level;
public $level;
/**
* Answers
*/
var $answers;
public $answers;
/**
* Picture
*/
var $picture;
var $extra;
public $picture;
public $extra;
/**
* @var int the question category if any, 0 by default
*/
var $question_category;
public $question_category;
/**
* Create a new QuizQuestion
@ -73,7 +65,18 @@ class QuizQuestion extends Resource
* @param int $type
* @param int $position
*/
function QuizQuestion($id, $question, $description, $ponderation, $type, $position, $picture, $level, $extra, $question_category = 0) {
public function QuizQuestion(
$id,
$question,
$description,
$ponderation,
$type,
$position,
$picture,
$level,
$extra,
$question_category = 0
) {
parent::Resource($id, RESOURCE_QUIZQUESTION);
$this->question = $question;
$this->description = $description;
@ -90,7 +93,16 @@ class QuizQuestion extends Resource
/**
* Add an answer to this QuizQuestion
*/
function add_answer($answer_id, $answer_text, $correct, $comment, $ponderation, $position, $hotspot_coordinates, $hotspot_type) {
public function add_answer(
$answer_id,
$answer_text,
$correct,
$comment,
$ponderation,
$position,
$hotspot_coordinates,
$hotspot_type
) {
$answer = array();
$answer['id'] = $answer_id;
$answer['answer'] = $answer_text;
@ -103,15 +115,17 @@ class QuizQuestion extends Resource
$this->answers[] = $answer;
}
function add_option($option_obj) {
public function add_option($option_obj)
{
$this->question_options[$option_obj->obj->id] = $option_obj;
}
/**
* Show this question
*/
function show() {
public function show()
{
parent::show();
echo $this->question;
}
}
}

@ -1,17 +1,10 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Exercises questions backup script
* @package chamilo.backup
*/
/**
* Code
*/
require_once 'Resource.class.php';
/**
* An QuizQuestion
* Class QuizQuestionOption
* @author Bart Mollet <bart.mollet@hogent.be>
* @package chamilo.backup
*/
@ -27,8 +20,9 @@ class QuizQuestionOption extends Resource
* @param int $type
* @param int $position
*/
function QuizQuestionOption($obj) {
public function QuizQuestionOption($obj)
{
parent::Resource($obj->id, RESOURCE_QUIZQUESTION);
$this->obj = $obj;
}
}
}

@ -1,13 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
/**
* General resources backup script
* @package chamilo.backup
*/
/**
* Definition of all possible resource-types
*/
define('RESOURCE_DOCUMENT', 'document');
define('RESOURCE_GLOSSARY', 'glossary');
define('RESOURCE_EVENT', 'calendar_event');
@ -34,10 +27,11 @@ define('RESOURCE_ATTENDANCE', 'attendance');
define('RESOURCE_WORK', 'work');
/**
* Class Resource
* Representation of a resource in a Chamilo-course.
* This is a base class of which real resource-classes (for Links,
* Documents,...) should be derived.
* @author Bart Mollet <bart.mollet@hogent.be>s
* @author Bart Mollet <bart.mollet@hogent.be>s
* @package chamilo.backup
* @todo Use the gloabaly defined constants voor tools and remove the RESOURCE_*
* constants

Loading…
Cancel
Save