When using the copy promotion feature we also save some course parameters see BT#2079

skala
Julio Montoya 15 years ago
parent 3ba90f0705
commit cc1aa215ba
  1. 5
      main/admin/promotions.php
  2. 1
      main/coursecopy/classes/CourseBuilder.class.php
  3. 49
      main/coursecopy/classes/CourseRestorer.class.php
  4. 3
      main/inc/lib/main_api.lib.php
  5. 6
      main/inc/lib/promotion.lib.php
  6. 58
      main/inc/lib/sessionmanager.lib.php

@ -64,7 +64,10 @@ $extra_params['autowidth'] = 'true'; //use the width of the parent
$extra_params['height'] = 'auto'; //use the width of the parent $extra_params['height'] = 'auto'; //use the width of the parent
//With this function we can add actions to the jgrid //With this function we can add actions to the jgrid
$action_links = 'function action_formatter (cellvalue, options, rowObject) { $action_links = 'function action_formatter (cellvalue, options, rowObject) {
return \'<a href="add_sessions_to_promotion.php?id=\'+options.rowId+\'"><img title="'.get_lang('AddSession').'" width="22px" src="../img/session_add.png"></a> <a href="?action=edit&id=\'+options.rowId+\'"><img width="20px" src="../img/edit.png" title="'.get_lang('Edit').'"></a> <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?action=delete&id=\'+options.rowId+\'"><img title="'.get_lang('Delete').'" src="../img/delete.png"></a> <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?action=copy&id=\'+options.rowId+\'"><img title="'.get_lang('Copy').'" src="../img/copy.gif" alt="'.get_lang('Copy').'"></a>\'; return \'<a href="add_sessions_to_promotion.php?id=\'+options.rowId+\'"><img title="'.get_lang('AddSession').'" width="22px" src="../img/session_add.png"></a> '.
'<a href="?action=edit&id=\'+options.rowId+\'"><img width="20px" src="../img/edit.png" title="'.get_lang('Edit').'"></a> '.
'<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?action=copy&id=\'+options.rowId+\'"><img title="'.get_lang('Copy').'" src="../img/copy.gif" alt="'.get_lang('Copy').'"></a> '.
'<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?action=delete&id=\'+options.rowId+\'"><img title="'.get_lang('Delete').'" src="../img/delete.png"></a> \';
}'; }';
?> ?>

@ -49,6 +49,7 @@ class CourseBuilder {
$this->course->backup_path = api_get_path(SYS_COURSE_PATH).$_course['path']; $this->course->backup_path = api_get_path(SYS_COURSE_PATH).$_course['path'];
$this->course->encoding = api_get_system_encoding(); //current platform encoding $this->course->encoding = api_get_system_encoding(); //current platform encoding
$this->course->db_name = $_course['dbName']; $this->course->db_name = $_course['dbName'];
$this->course->info = $_course;
} }
/** /**
* Get the created course * Get the created course

@ -60,10 +60,12 @@ class CourseRestorer
/** /**
* Restore a course. * Restore a course.
* @param string $destination_course_code The code of the Dokeos-course in * @param string The code of the Chamilo-course in
* which the resources should be stored. Default: Current Dokeos-course. * @param int The session id
* @param bool Course settings are going to be restore?
*/ */
function restore($destination_course_code = '',$session_id = 0) { function restore($destination_course_code = '', $session_id = 0, $update_course_settings = false) {
if ($destination_course_code == '') { if ($destination_course_code == '') {
$course_info = api_get_course_info(); $course_info = api_get_course_info();
$this->course->destination_db = $course_info['dbName']; $this->course->destination_db = $course_info['dbName'];
@ -96,7 +98,6 @@ class CourseRestorer
$this->course->to_system_encoding(); $this->course->to_system_encoding();
if (!empty($session_id)) { if (!empty($session_id)) {
$this->restore_documents($session_id, $destination_course_code); $this->restore_documents($session_id, $destination_course_code);
$this->restore_quizzes($session_id); $this->restore_quizzes($session_id);
$this->restore_glossary($session_id); $this->restore_glossary($session_id);
@ -120,6 +121,10 @@ class CourseRestorer
$this->restore_wiki(); $this->restore_wiki();
} }
if ($update_course_settings) {
$this->restore_course_settings($destination_course_code);
}
// Restore the item properties // Restore the item properties
$table = Database :: get_course_table(TABLE_ITEM_PROPERTY, $this->course->destination_db); $table = Database :: get_course_table(TABLE_ITEM_PROPERTY, $this->course->destination_db);
@ -182,6 +187,27 @@ class CourseRestorer
} }
} }
/**
* Restore only harmless course settings: course_language, visibility, department_name,department_url, subscribe, unsubscribe ,category_code
*
* @return unknown_type
*/
function restore_course_settings($destination_course_code) {
$origin_course_info = api_get_course_info($destination_course_code);
$course_info = $this->course->info;
$params['course_language'] = $course_info['language'];
$params['visibility'] = $course_info['visibility'];
$params['department_name'] = $course_info['department_name'];
$params['department_url'] = $course_info['department_url'];
$params['category_code'] = $course_info['categoryCode'];
$params['subscribe'] = $course_info['subscribe_allowed'];
$params['unsubscribe'] = $course_info['unubscribe_allowed'];
CourseManager::update_attributes($origin_course_info['real_id'], $params);
}
/** /**
* Restore documents * Restore documents
* @param int session id * @param int session id
@ -1442,18 +1468,15 @@ class CourseRestorer
/** /**
* restore works * restore works
*/ */
function restore_student_publication () function restore_student_publication() {
{
$my_course_id=api_get_course_id();
$my_course_info=api_get_course_info($my_course_id);//student_publication_assignment
$my_tbl_db_spa_origin=Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT,$my_course_info['dbName']); $my_tbl_db_spa_origin = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT, $this->course->db_name);
$my_tbl_db_spa_destination = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT, $this->course->destination_db); $my_tbl_db_spa_destination = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT, $this->course->destination_db);
$my_tbl_db_origin=Database :: get_course_table(TABLE_STUDENT_PUBLICATION,$my_course_info['dbName']); $my_tbl_db_origin = Database :: get_course_table(TABLE_STUDENT_PUBLICATION, $this->course->db_name);
$my_tbl_db_destination = Database :: get_course_table(TABLE_STUDENT_PUBLICATION, $this->course->destination_db); $my_tbl_db_destination = Database :: get_course_table(TABLE_STUDENT_PUBLICATION, $this->course->destination_db);
$my_tbl_db_item_property_origin=Database :: get_course_table(TABLE_ITEM_PROPERTY, $my_course_info['dbName']); $my_tbl_db_item_property_origin = Database :: get_course_table(TABLE_ITEM_PROPERTY, $this->course->db_name);
$my_tbl_db_item_property_destination = Database :: get_course_table(TABLE_ITEM_PROPERTY, $this->course->destination_db); $my_tbl_db_item_property_destination = Database :: get_course_table(TABLE_ITEM_PROPERTY, $this->course->destination_db);
//query in student publication //query in student publication
@ -1468,8 +1491,8 @@ class CourseRestorer
'parent_id,qualificator_id,session_id FROM '.$my_tbl_db_origin.' WHERE filetype="folder" '; 'parent_id,qualificator_id,session_id FROM '.$my_tbl_db_origin.' WHERE filetype="folder" ';
//var_dump($query_sql_ini_sp); //var_dump($query_sql_ini_sp);
$destination='../../courses/'.$this->course->destination_path.'/work/'; $destination='../../courses/'.$this->course->destination_path.'/work/';
$course_info=api_get_course_info(api_get_course_id());
$origin='../../courses/'.$course_info['path'].'/work/'; $origin='../../courses/'.$this->course->info['path'].'/work/';
self::allow_create_all_directory($origin,$destination,false); self::allow_create_all_directory($origin,$destination,false);

@ -1067,6 +1067,9 @@ function api_get_course_info($course_code = null) {
$_course['subscribe_allowed'] = $cData['subscribe' ]; $_course['subscribe_allowed'] = $cData['subscribe' ];
$_course['unubscribe_allowed'] = $cData['unsubscribe' ]; $_course['unubscribe_allowed'] = $cData['unsubscribe' ];
$_course['department_name'] = $cData['department_name'];
$_course['department_url'] = $cData['department_url' ];
// The real_id is an integer. It is mandatory for future implementations. // The real_id is an integer. It is mandatory for future implementations.
$_course['real_id' ] = $cData['id' ]; $_course['real_id' ] = $cData['id' ];
} }

@ -144,12 +144,13 @@ class Promotion extends Model {
break; break;
} }
} }
$pid = $this->save($new); $pid = false;
if ($copy_sessions) { if ($copy_sessions) {
/** /**
* When copying a session we do: * When copying a session we do:
* 1. Copy a new session from the source * 1. Copy a new session from the source
* 2. Copy all courses from the session (no user data, no user list) * 2. Copy all courses from the session (no user data, no user list)
* 3. Create the promotion
*/ */
require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php'; require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
$session_list = SessionManager::get_all_sessions_by_promotion($id); $session_list = SessionManager::get_all_sessions_by_promotion($id);
@ -158,10 +159,13 @@ class Promotion extends Model {
foreach($session_list as $item) { foreach($session_list as $item) {
$sid = SessionManager::copy_session($item['id'], true, false, true); $sid = SessionManager::copy_session($item['id'], true, false, true);
if ($sid != 0) { if ($sid != 0) {
$pid = $this->save($new);
SessionManager::suscribe_sessions_to_promotion($pid,array($sid)); SessionManager::suscribe_sessions_to_promotion($pid,array($sid));
} }
} }
} }
} else {
$pid = $this->save($new);
} }
return $pid; return $pid;
} }

@ -51,9 +51,10 @@ class SessionManager {
* @param integer Visibility after end date (0 = read-only, 1 = invisible, 2 = accessible) * @param integer Visibility after end date (0 = read-only, 1 = invisible, 2 = accessible)
* @param string Start limit = true if the start date has to be considered * @param string Start limit = true if the start date has to be considered
* @param string End limit = true if the end date has to be considered * @param string End limit = true if the end date has to be considered
* @todo use an array to replace all this parameters or use the model.lib.php ...
* @return mixed Session ID on success, error message otherwise * @return mixed Session ID on success, error message otherwise
**/ **/
public static function create_session($sname,$syear_start,$smonth_start,$sday_start,$syear_end,$smonth_end,$sday_end,$snb_days_acess_before,$snb_days_acess_after,$nolimit,$coach_username, $id_session_category,$id_visibility, $start_limit = true, $end_limit = true) { public static function create_session($sname,$syear_start,$smonth_start,$sday_start,$syear_end,$smonth_end,$sday_end,$snb_days_acess_before,$snb_days_acess_after,$nolimit,$coach_username, $id_session_category,$id_visibility, $start_limit = true, $end_limit = true, $fix_name = false) {
$name= Database::escape_string(trim($sname)); $name= Database::escape_string(trim($sname));
$year_start= intval($syear_start); $year_start= intval($syear_start);
$month_start=intval($smonth_start); $month_start=intval($smonth_start);
@ -109,12 +110,26 @@ class SessionManager {
} elseif(!empty($start_limit) && !empty($end_limit) && empty($nolimit) && $date_start >= $date_end) { } elseif(!empty($start_limit) && !empty($end_limit) && empty($nolimit) && $date_start >= $date_end) {
$msg=get_lang('StartDateShouldBeBeforeEndDate'); $msg=get_lang('StartDateShouldBeBeforeEndDate');
return $msg; return $msg;
} else {
$ready_to_create = false;
if ($fix_name) {
$name = self::generate_nice_next_session_name($name);
if ($name) {
$ready_to_create = true;
} else {
$msg=get_lang('SessionNameAlreadyExists');
return $msg;
}
} else { } else {
$rs = Database::query("SELECT 1 FROM $tbl_session WHERE name='".$name."'"); $rs = Database::query("SELECT 1 FROM $tbl_session WHERE name='".$name."'");
if (Database::num_rows($rs)) { if (Database::num_rows($rs)) {
$msg=get_lang('SessionNameAlreadyExists'); $msg=get_lang('SessionNameAlreadyExists');
return $msg; return $msg;
} else { }
$ready_to_create = true;
}
if ($ready_to_create) {
$sql_insert = "INSERT INTO $tbl_session(name,date_start,date_end,id_coach,session_admin_id, nb_days_access_before_beginning, nb_days_access_after_end, session_category_id,visibility) $sql_insert = "INSERT INTO $tbl_session(name,date_start,date_end,id_coach,session_admin_id, nb_days_access_before_beginning, nb_days_access_after_end, session_category_id,visibility)
VALUES('".$name."','$date_start','$date_end','$id_coach',".api_get_user_id().",".$nb_days_acess_before.", ".$nb_days_acess_after.", ".$id_session_category.", ".$id_visibility.")"; VALUES('".$name."','$date_start','$date_end','$id_coach',".api_get_user_id().",".$nb_days_acess_before.", ".$nb_days_acess_after.", ".$id_session_category.", ".$id_visibility.")";
Database::query($sql_insert); Database::query($sql_insert);
@ -130,6 +145,41 @@ class SessionManager {
} }
} }
function session_name_exists($session_name) {
$session_name = Database::escape_string($session_name);
$result = Database::fetch_array(Database::query("SELECT COUNT(*) as count FROM ".Database::get_main_table(TABLE_MAIN_SESSION)." WHERE name = '$session_name' "));
return $result['count'] > 0;
}
/**
* Creates a new course code based in given code
*
* @param string wanted code
* @example $wanted_code = 'curse' if there are in the DB codes like curse1 curse2 the function will return: course3
* if the course code doest not exist in the DB the same course code will be returned
* @return string wanted unused code
*/
function generate_nice_next_session_name($session_name) {
$session_name_ok = !self::session_name_exists($session_name);
if (!$session_name_ok) {
$table = Database::get_main_table(TABLE_MAIN_SESSION);
$session_name = Database::escape_string($session_name);
$sql = "SELECT count(*) as count FROM $table WHERE name LIKE '$session_name%'";
$result = Database::query($sql);
if (Database::num_rows($result) > 0 ) {
$row = Database::fetch_array($result);
$count = $row['count'] + 1;
$session_name = $session_name.'_'.$count;
$result = self::session_name_exists($session_name);
if (!$result) {
return $session_name;
}
}
return false;
}
return $session_name;
}
/** /**
* Edit a session * Edit a session
* @author Carlos Vargas from existing code * @author Carlos Vargas from existing code
@ -1337,7 +1387,8 @@ class SessionManager {
$s['year_end'],$s['month_end'],$s['day_end'], $s['year_end'],$s['month_end'],$s['day_end'],
$s['nb_days_acess_before_beginning'],$s['nb_days_acess_after_end'], $s['nb_days_acess_before_beginning'],$s['nb_days_acess_after_end'],
false,(int)$s['id_coach'], $s['session_category_id'], false,(int)$s['id_coach'], $s['session_category_id'],
(int)$s['visibility'],$consider_start, $consider_end); (int)$s['visibility'],$consider_start, $consider_end, true);
if (!is_numeric($sid)) { if (!is_numeric($sid)) {
return false; return false;
} }
@ -1352,6 +1403,7 @@ class SessionManager {
} }
} }
$courses = null; $courses = null;
//We will copy the current courses of the session to new courses //We will copy the current courses of the session to new courses
if (!empty($short_courses)) { if (!empty($short_courses)) {
if ($create_new_courses) { if ($create_new_courses) {

Loading…
Cancel
Save