Add gradebook category backup

1.10.x
jmontoya 9 years ago
parent a377c0fd29
commit ca3d375966
  1. 22
      main/coursecopy/classes/CourseBuilder.class.php
  2. 88
      main/coursecopy/classes/CourseRestorer.class.php
  3. 7
      main/coursecopy/classes/CourseSelectForm.class.php
  4. 31
      main/coursecopy/classes/GradeBookBackup.php
  5. 24
      main/coursecopy/classes/Resource.class.php

@ -2,6 +2,7 @@
/* For licensing terms, see /license.txt */
require_once 'Resource.class.php';
require_once 'GradeBookBackup.php';
require_once 'Course.class.php';
require_once 'Event.class.php';
require_once 'Link.class.php';
@ -59,7 +60,8 @@ class CourseBuilder
'tool_intro',
'thematic',
'wiki',
'works'
'works',
'gradebook'
);
/* With this array you can filter wich elements of the tools are going
@ -1581,4 +1583,22 @@ class CourseBuilder
$this->course->add_resource($obj);
}
}
/**
* @param int $session_id
* @param int $courseId
* @param bool $with_base_content
*/
public function build_gradebook(
$session_id = 0,
$courseId = 0,
$with_base_content = false
) {
$courseInfo = api_get_course_info_by_id($courseId);
$courseCode = $courseInfo['code'];
$cats = Category:: load(null, null, $courseCode, null, null, $session_id);
$obj = new GradeBookBackup($cats);
$this->course->add_resource($obj);
}
}

@ -2,6 +2,7 @@
/* For licensing terms, see /license.txt */
require_once 'Resource.class.php';
require_once 'GradeBookBackup.php';
require_once 'Course.class.php';
require_once 'Event.class.php';
require_once 'Link.class.php';
@ -68,6 +69,7 @@ class CourseRestorer
'thematic',
'wiki',
'works',
'gradebook',
);
/** Setting per tool */
@ -442,7 +444,7 @@ class CourseRestorer
'title' => self::DBUTF8($document->title),
'filetype' => self::DBUTF8($document->file_type),
'size' => self::DBUTF8($document->size),
'session_id' => $my_session_id
'session_id' => $my_session_id,
];
$document_id = Database::insert($table, $params);
@ -475,7 +477,7 @@ class CourseRestorer
'title' => self::DBUTF8($document->title),
'filetype' => self::DBUTF8($document->file_type),
'size' => self::DBUTF8($document->size),
'session_id' => $my_session_id
'session_id' => $my_session_id,
];
Database::update(
@ -532,7 +534,7 @@ class CourseRestorer
[
'c_id = ? AND id = ?' => [
$this->destination_course_id,
$document_id
$document_id,
],
]
);
@ -652,7 +654,7 @@ class CourseRestorer
'title' => self::DBUTF8(basename($path_title)),
'filetype' => self::DBUTF8($document->file_type),
'size' => self::DBUTF8($document->size),
'session_id' => $my_session_id
'session_id' => $my_session_id,
];
$document_id = Database::insert($table, $params);
@ -708,7 +710,7 @@ class CourseRestorer
'title' => self::DBUTF8($document->title),
'filetype' => self::DBUTF8($document->file_type),
'size' => self::DBUTF8($document->size),
'session_id' => $my_session_id
'session_id' => $my_session_id,
];
$document_id = Database::insert($table, $params);
@ -762,7 +764,7 @@ class CourseRestorer
'title' => self::DBUTF8($document->title),
'filetype' => self::DBUTF8($document->file_type),
'size' => self::DBUTF8($document->size),
'session_id' => $my_session_id
'session_id' => $my_session_id,
];
$document_id = Database::insert($table, $params);
@ -826,7 +828,7 @@ class CourseRestorer
'title' => self::DBUTF8($document->title),
'filetype' => self::DBUTF8($document->file_type),
'size' => self::DBUTF8($document->size),
'session_id' => $my_session_id
'session_id' => $my_session_id,
];
$document_id = Database::insert($table, $params);
@ -1310,7 +1312,7 @@ class CourseRestorer
'c_id' => $this->destination_course_id,
'id' => self::DBUTF8($tool_intro->id),
'intro_text' => self::DBUTF8($tool_intro->intro_text),
'session_id' => $sessionId
'session_id' => $sessionId,
];
$id = Database::insert($tool_intro_table, $params);
@ -1354,7 +1356,7 @@ class CourseRestorer
'all_day' => $event->all_day,
'start_date' => $event->start_date,
'end_date' => $event->end_date,
'session_id' => $sessionId
'session_id' => $sessionId,
];
$new_event_id = Database::insert($table, $params);
@ -1398,7 +1400,7 @@ class CourseRestorer
'comment' => self::DBUTF8($attachment_event->comment),
'size' => $attachment_event->size,
'filename' => $attachment_event->filename,
'agenda_id' => $new_event_id
'agenda_id' => $new_event_id,
];
$id = Database::insert($table_attachment, $params);
if ($id) {
@ -1424,7 +1426,7 @@ class CourseRestorer
'comment' => self::DBUTF8($event->attachment_comment),
'size' => $event->size,
'filename' => $event->filename,
'agenda_id' => $new_event_id
'agenda_id' => $new_event_id,
];
$id = Database::insert($table_attachment, $params);
@ -1508,7 +1510,7 @@ class CourseRestorer
'end_date' => $announcement->date,
'display_order' => $announcement->display_order,
'email_sent' => $announcement->email_sent,
'session_id' => $sessionId
'session_id' => $sessionId,
];
$new_announcement_id = Database::insert($table, $params);
@ -1556,7 +1558,7 @@ class CourseRestorer
'comment' => self::DBUTF8($attachment_event->comment),
'size' => $attachment_event->size,
'filename' => $attachment_event->filename,
'announcement_id' => $new_announcement_id
'announcement_id' => $new_announcement_id,
];
$attachmentId = Database::insert($table_attachment, $params);
@ -1592,7 +1594,7 @@ class CourseRestorer
'comment' => self::DBUTF8($announcement->attachment_comment),
'size' => $announcement->attachment_size,
'filename' => $announcement->attachment_filename,
'announcement_id' => $new_announcement_id
'announcement_id' => $new_announcement_id,
];
$attachmentId = Database::insert($table_attachment, $params);
@ -1769,7 +1771,7 @@ class CourseRestorer
'type' => self::DBUTF8($question->quiz_type),
'picture' => self::DBUTF8($question->picture),
'level' => self::DBUTF8($question->level),
'extra' => self::DBUTF8($question->extra)
'extra' => self::DBUTF8($question->extra),
];
$new_id = Database::insert($table_que, $params);
@ -1822,7 +1824,7 @@ class CourseRestorer
'ponderation' => $answer['ponderation'],
'position' => $answer['position'],
'hotspot_coordinates' => $answer['hotspot_coordinates'],
'hotspot_type' => $answer['hotspot_type']
'hotspot_type' => $answer['hotspot_type'],
];
$answerId = Database::insert($table_ans, $params);
@ -1863,7 +1865,7 @@ class CourseRestorer
'ponderation' => $answer['ponderation'],
'position' => $answer['position'],
'hotspot_coordinates' => $answer['hotspot_coordinates'],
'hotspot_type' => $answer['hotspot_type']
'hotspot_type' => $answer['hotspot_type'],
];
$answerId = Database::insert($table_ans, $params);
@ -1911,9 +1913,9 @@ class CourseRestorer
'WHERE' => array(
'question_id = ? AND c_id = ? ' => array(
$new_id,
$this->destination_course_id
)
)
$this->destination_course_id,
),
),
)
);
@ -1927,8 +1929,8 @@ class CourseRestorer
'iid = ? AND c_id = ? AND question_id = ? ' => array(
$answer_item['iid'],
$this->destination_course_id,
$new_id
)
$new_id,
),
),
false
);
@ -2122,7 +2124,7 @@ class CourseRestorer
'answered' => '0',
'invite_mail' => self::DBUTF8($survey->invite_mail),
'reminder_mail' => self::DBUTF8($survey->reminder_mail),
'session_id' => $sessionId
'session_id' => $sessionId,
];
//An existing survey exists with the same code and the same language
@ -2427,7 +2429,7 @@ class CourseRestorer
'visibility' => '0',
'admin' => '0',
'address' => 'squaregrey.gif',
'session_id' => $session_id
'session_id' => $session_id,
];
$insertId = Database::insert($table_tool, $params);
if ($insertId) {
@ -2504,7 +2506,7 @@ class CourseRestorer
'prerequisite' => self::DBUTF8($item['prerequisite']),
'parameters' => self::DBUTF8($item['parameters']),
'audio' => self::DBUTF8($item['audio']),
'launch_data' => self::DBUTF8($item['launch_data'])
'launch_data' => self::DBUTF8($item['launch_data']),
];
$new_item_id = Database::insert($table_item, $params);
@ -2875,7 +2877,7 @@ class CourseRestorer
'max_version' => 0,
'startdate_assig' => '',
'enddate_assig' => '',
'delayedsubmit' => 0
'delayedsubmit' => 0,
];
Database::insert($table_wiki_conf, $params);
@ -3139,6 +3141,40 @@ class CourseRestorer
}
}
/**
* Restore Works
* @param int $sessionId
*/
public function restore_gradebook($sessionId = 0)
{
if ($this->course->has_resources(RESOURCE_GRADEBOOK)) {
$resources = $this->course->resources;
/**
* @var GradeBookBackup $obj
*/
foreach ($resources[RESOURCE_GRADEBOOK] as $id => $obj) {
if (!empty($obj->categories)) {
$categoryIdList = [];
/** @var Category $cat */
foreach ($obj->categories as $cat) {
$cat->set_course_code($this->destination_course_info['code']);
$cat->set_session_id($sessionId);
$parentId = $cat->get_parent_id();
if (!empty($parentId)) {
if (isset($categoryIdList[$parentId])) {
$cat->set_parent_id($categoryIdList[$parentId]);
}
}
$oldId = $cat->get_id();
$categoryId = $cat->add();
$categoryIdList[$oldId] = $categoryId;
}
}
}
}
}
/**
* @param string $str
* @return string

@ -19,6 +19,7 @@ class CourseSelectForm
static function display_form($course, $hidden_fields = null, $avoid_serialize = false)
{
global $charset;
$resource_titles[RESOURCE_GRADEBOOK] = get_lang('Gradebook');
$resource_titles[RESOURCE_EVENT] = get_lang('Events');
$resource_titles[RESOURCE_ANNOUNCEMENT] = get_lang('Announcements');
$resource_titles[RESOURCE_DOCUMENT] = get_lang('Documents');
@ -176,7 +177,7 @@ class CourseSelectForm
if (count($resources) > 0) {
switch ($type) {
//Resources to avoid
case RESOURCE_FORUMCATEGORY :
case RESOURCE_FORUMCATEGORY:
foreach ($resources as $id => $resource) {
$forum_categories[$id] = $resource;
}
@ -194,8 +195,8 @@ class CourseSelectForm
}
$element_count++;
break;
case RESOURCE_LINKCATEGORY :
case RESOURCE_FORUMPOST :
case RESOURCE_LINKCATEGORY:
case RESOURCE_FORUMPOST:
case RESOURCE_QUIZQUESTION:
case RESOURCE_SURVEYQUESTION:
case RESOURCE_SURVEYINVITATION:

@ -0,0 +1,31 @@
<?php
/* For licensing terms, see /license.txt */
require_once 'Resource.class.php';
/**
* Class GradeBookBackup
*/
class GradeBookBackup extends Coursecopy\Resource
{
public $categories;
/**
* GradeBookBackup constructor.
* @param array $categories
*/
public function __construct($categories)
{
parent::__construct(uniqid(), RESOURCE_GRADEBOOK);
$this->categories = $categories;
}
/**
* @return string
*/
public function show()
{
parent::show();
echo get_lang('All');
}
}

@ -1,5 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
namespace Coursecopy;
define('RESOURCE_DOCUMENT', 'document');
@ -27,6 +28,7 @@ define('RESOURCE_THEMATIC', 'thematic');
define('RESOURCE_ATTENDANCE', 'attendance');
define('RESOURCE_WORK', 'work');
define('RESOURCE_SESSION_COURSE', 'session_course');
define('RESOURCE_GRADEBOOK', 'gradebook');
/**
* Class Resource
@ -35,7 +37,7 @@ define('RESOURCE_SESSION_COURSE', 'session_course');
* Documents,...) should be derived.
* @author Bart Mollet <bart.mollet@hogent.be>s
* @package chamilo.backup
* @todo Use the gloabaly defined constants voor tools and remove the RESOURCE_*
* @todo Use the globally defined constants voor tools and remove the RESOURCE_*
* constants
*/
class Resource
@ -70,7 +72,7 @@ class Resource
/**
* Create a new Resource
* @param int $id The id of this resource in the source course.
* @param constant $type The type of this resource.
* @param integer $type The type of this resource.
*/
public function __construct($id, $type)
{
@ -84,7 +86,7 @@ class Resource
/**
* Add linked resource
*/
function add_linked_resource($type, $id)
public function add_linked_resource($type, $id)
{
$this->linked_resources[$type][] = $id;
}
@ -92,7 +94,7 @@ class Resource
/**
* Get linked resources
*/
function get_linked_resources()
public function get_linked_resources()
{
return $this->linked_resources;
}
@ -100,7 +102,7 @@ class Resource
/**
* Checks if this resource links to a given resource
*/
function links_to(& $resource)
public function links_to(& $resource)
{
self::setClassType($resource);
$type = $resource->get_type();
@ -119,7 +121,7 @@ class Resource
* Returns the id of this resource.
* @return int The id of this resource in the source course.
*/
function get_id()
public function get_id()
{
return $this->source_id;
}
@ -128,7 +130,7 @@ class Resource
* Resturns the type of this resource
* @return constant The type.
*/
function get_type()
public function get_type()
{
return $this->type;
}
@ -145,7 +147,7 @@ class Resource
* @todo once the RESOURCE_* constants are replaced by the globally
* defined TOOL_* constants, this function will be replaced by get_type()
*/
function get_tool($for_item_property_table = true)
public function get_tool($for_item_property_table = true)
{
switch ($this->get_type()) {
case RESOURCE_DOCUMENT:
@ -208,7 +210,7 @@ class Resource
* Set the destination id
* @param int $id The id of this resource in the destination course.
*/
function set_new_id($id)
public function set_new_id($id)
{
$this->destination_id = $id;
}
@ -217,7 +219,7 @@ class Resource
* Check if this resource is allready restored in the destination course.
* @return bool true if allready restored (i.e. destination_id is set).
*/
function is_restored()
public function is_restored()
{
return $this->destination_id > -1;
}
@ -225,7 +227,7 @@ class Resource
/**
* Show this resource
*/
function show()
public function show()
{
//echo 'RESOURCE: '.$this->get_id().' '.$type[$this->get_type()].' ';
}

Loading…
Cancel
Save