You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1053 lines
41 KiB
1053 lines
41 KiB
|
16 years ago
|
<?php
|
||
|
11 years ago
|
/* For licensing terms, see /license.txt */
|
||
|
19 years ago
|
|
||
|
7 years ago
|
use Chamilo\CoreBundle\Framework\Container;
|
||
|
8 years ago
|
use Chamilo\CourseBundle\Entity\CToolIntro;
|
||
|
8 years ago
|
|
||
|
13 years ago
|
/**
|
||
|
8 years ago
|
* Class AddCourse.
|
||
|
13 years ago
|
*/
|
||
|
11 years ago
|
class AddCourse
|
||
|
|
{
|
||
|
7 years ago
|
public const FIRST_EXPIRATION_DATE = 31536000; // 365 days in seconds
|
||
|
|
|
||
|
11 years ago
|
/**
|
||
|
|
* Defines the four needed keys to create a course based on several parameters.
|
||
|
8 years ago
|
*
|
||
|
11 years ago
|
* @param string The code you want for this course
|
||
|
|
* @param string Prefix added for ALL keys
|
||
|
|
* @param string Prefix added for databases only
|
||
|
|
* @param string Prefix added for paths only
|
||
|
|
* @param bool Add unique prefix
|
||
|
|
* @param bool Use code-independent keys
|
||
|
8 years ago
|
*
|
||
|
7 years ago
|
* @return array An array with the needed keys ['currentCourseCode'], ['currentCourseId'], ['currentCourseDbName'],
|
||
|
|
* ['currentCourseRepository']
|
||
|
8 years ago
|
*
|
||
|
11 years ago
|
* @todo Eliminate the global variables.
|
||
|
|
* @assert (null) === false
|
||
|
|
*/
|
||
|
10 years ago
|
public static function define_course_keys(
|
||
|
|
$wanted_code,
|
||
|
|
$prefix_for_all = '',
|
||
|
|
$prefix_for_base_name = '',
|
||
|
|
$prefix_for_path = '',
|
||
|
|
$add_unique_prefix = false,
|
||
|
|
$use_code_indepedent_keys = true
|
||
|
|
) {
|
||
|
9 years ago
|
$course_table = Database::get_main_table(TABLE_MAIN_COURSE);
|
||
|
11 years ago
|
$wanted_code = CourseManager::generate_course_code($wanted_code);
|
||
|
|
$keys_course_code = $wanted_code;
|
||
|
|
if (!$use_code_indepedent_keys) {
|
||
|
|
$wanted_code = '';
|
||
|
|
}
|
||
|
18 years ago
|
|
||
|
11 years ago
|
if ($add_unique_prefix) {
|
||
|
|
$unique_prefix = substr(md5(uniqid(rand())), 0, 10);
|
||
|
|
} else {
|
||
|
|
$unique_prefix = '';
|
||
|
|
}
|
||
|
19 years ago
|
|
||
|
8 years ago
|
$keys = [];
|
||
|
|
$final_suffix = ['CourseId' => '', 'CourseDb' => '', 'CourseDir' => ''];
|
||
|
11 years ago
|
$limit_numb_try = 100;
|
||
|
|
$keys_are_unique = false;
|
||
|
|
$try_new_fsc_id = $try_new_fsc_db = $try_new_fsc_dir = 0;
|
||
|
19 years ago
|
|
||
|
11 years ago
|
while (!$keys_are_unique) {
|
||
|
9 years ago
|
$keys_course_id = $prefix_for_all.$unique_prefix.$wanted_code.$final_suffix['CourseId'];
|
||
|
|
$keys_course_repository = $prefix_for_path.$unique_prefix.$wanted_code.$final_suffix['CourseDir'];
|
||
|
11 years ago
|
$keys_are_unique = true;
|
||
|
19 years ago
|
|
||
|
11 years ago
|
// Check whether they are unique.
|
||
|
9 years ago
|
$query = "SELECT 1 FROM $course_table
|
||
|
|
WHERE code='".$keys_course_id."'
|
||
|
|
LIMIT 0, 1";
|
||
|
11 years ago
|
$result = Database::query($query);
|
||
|
19 years ago
|
|
||
|
11 years ago
|
if (Database::num_rows($result)) {
|
||
|
|
$keys_are_unique = false;
|
||
|
9 years ago
|
$try_new_fsc_id++;
|
||
|
11 years ago
|
$final_suffix['CourseId'] = substr(md5(uniqid(rand())), 0, 4);
|
||
|
|
}
|
||
|
|
if (file_exists(api_get_path(SYS_COURSE_PATH).$keys_course_repository)) {
|
||
|
|
$keys_are_unique = false;
|
||
|
9 years ago
|
$try_new_fsc_dir++;
|
||
|
11 years ago
|
$final_suffix['CourseDir'] = substr(md5(uniqid(rand())), 0, 4);
|
||
|
|
}
|
||
|
19 years ago
|
|
||
|
11 years ago
|
if (($try_new_fsc_id + $try_new_fsc_db + $try_new_fsc_dir) > $limit_numb_try) {
|
||
|
|
return $keys;
|
||
|
|
}
|
||
|
15 years ago
|
}
|
||
|
19 years ago
|
|
||
|
11 years ago
|
$keys['currentCourseCode'] = $keys_course_code;
|
||
|
|
$keys['currentCourseId'] = $keys_course_id;
|
||
|
|
$keys['currentCourseRepository'] = $keys_course_repository;
|
||
|
14 years ago
|
|
||
|
11 years ago
|
return $keys;
|
||
|
|
}
|
||
|
19 years ago
|
|
||
|
11 years ago
|
/**
|
||
|
|
* Initializes a file repository for a newly created course.
|
||
|
8 years ago
|
*
|
||
|
11 years ago
|
* @param string Course repository
|
||
|
|
* @param string Course code
|
||
|
8 years ago
|
*
|
||
|
|
* @return int
|
||
|
11 years ago
|
* @assert (null,null) === false
|
||
|
|
*/
|
||
|
8 years ago
|
public static function prepare_course_repository($course_repository)
|
||
|
11 years ago
|
{
|
||
|
6 years ago
|
return true;
|
||
|
|
|
||
|
11 years ago
|
$perm = api_get_permissions_for_new_directories();
|
||
|
|
$perm_file = api_get_permissions_for_new_files();
|
||
|
|
$htmlpage = "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <title>Not authorized</title>\n </head>\n <body>\n </body>\n</html>";
|
||
|
9 years ago
|
$cp = api_get_path(SYS_COURSE_PATH).$course_repository;
|
||
|
10 years ago
|
|
||
|
11 years ago
|
//Creating document folder
|
||
|
|
mkdir($cp, $perm);
|
||
|
9 years ago
|
mkdir($cp.'/document', $perm);
|
||
|
|
$cpt = $cp.'/document/index.html';
|
||
|
11 years ago
|
$fd = fopen($cpt, 'w');
|
||
|
|
fwrite($fd, $htmlpage);
|
||
|
|
fclose($fd);
|
||
|
19 years ago
|
|
||
|
11 years ago
|
/*
|
||
|
|
@chmod($cpt, $perm_file);
|
||
|
|
@copy($cpt, $cp . '/document/index.html');
|
||
|
|
mkdir($cp . '/document/images', $perm);
|
||
|
|
@copy($cpt, $cp . '/document/images/index.html');
|
||
|
|
mkdir($cp . '/document/images/gallery/', $perm);
|
||
|
|
@copy($cpt, $cp . '/document/images/gallery/index.html');
|
||
|
|
mkdir($cp . '/document/shared_folder/', $perm);
|
||
|
|
@copy($cpt, $cp . '/document/shared_folder/index.html');
|
||
|
|
mkdir($cp . '/document/audio', $perm);
|
||
|
|
@copy($cpt, $cp . '/document/audio/index.html');
|
||
|
|
mkdir($cp . '/document/flash', $perm);
|
||
|
|
@copy($cpt, $cp . '/document/flash/index.html');
|
||
|
|
mkdir($cp . '/document/video', $perm);
|
||
|
|
@copy($cpt, $cp . '/document/video/index.html'); */
|
||
|
|
|
||
|
|
//Creatind dropbox folder
|
||
|
9 years ago
|
mkdir($cp.'/dropbox', $perm);
|
||
|
|
$cpt = $cp.'/dropbox/index.html';
|
||
|
11 years ago
|
$fd = fopen($cpt, 'w');
|
||
|
|
fwrite($fd, $htmlpage);
|
||
|
|
fclose($fd);
|
||
|
|
@chmod($cpt, $perm_file);
|
||
|
9 years ago
|
mkdir($cp.'/group', $perm);
|
||
|
|
@copy($cpt, $cp.'/group/index.html');
|
||
|
|
mkdir($cp.'/page', $perm);
|
||
|
|
@copy($cpt, $cp.'/page/index.html');
|
||
|
|
mkdir($cp.'/scorm', $perm);
|
||
|
|
@copy($cpt, $cp.'/scorm/index.html');
|
||
|
|
mkdir($cp.'/upload', $perm);
|
||
|
|
@copy($cpt, $cp.'/upload/index.html');
|
||
|
|
mkdir($cp.'/upload/forum', $perm);
|
||
|
|
@copy($cpt, $cp.'/upload/forum/index.html');
|
||
|
|
mkdir($cp.'/upload/forum/images', $perm);
|
||
|
|
@copy($cpt, $cp.'/upload/forum/images/index.html');
|
||
|
|
mkdir($cp.'/upload/test', $perm);
|
||
|
|
@copy($cpt, $cp.'/upload/test/index.html');
|
||
|
|
mkdir($cp.'/upload/blog', $perm);
|
||
|
|
@copy($cpt, $cp.'/upload/blog/index.html');
|
||
|
|
mkdir($cp.'/upload/learning_path', $perm);
|
||
|
|
@copy($cpt, $cp.'/upload/learning_path/index.html');
|
||
|
|
mkdir($cp.'/upload/learning_path/images', $perm);
|
||
|
|
@copy($cpt, $cp.'/upload/learning_path/images/index.html');
|
||
|
|
mkdir($cp.'/upload/calendar', $perm);
|
||
|
|
@copy($cpt, $cp.'/upload/calendar/index.html');
|
||
|
|
mkdir($cp.'/upload/calendar/images', $perm);
|
||
|
|
@copy($cpt, $cp.'/upload/calendar/images/index.html');
|
||
|
|
mkdir($cp.'/work', $perm);
|
||
|
|
@copy($cpt, $cp.'/work/index.html');
|
||
|
|
mkdir($cp.'/upload/announcements', $perm);
|
||
|
|
@copy($cpt, $cp.'/upload/announcements/index.html');
|
||
|
|
mkdir($cp.'/upload/announcements/images', $perm);
|
||
|
|
@copy($cpt, $cp.'/upload/announcements/images/index.html');
|
||
|
11 years ago
|
|
||
|
|
//Oral expression question type
|
||
|
9 years ago
|
mkdir($cp.'/exercises', $perm);
|
||
|
|
@copy($cpt, $cp.'/exercises/index.html');
|
||
|
11 years ago
|
|
||
|
|
// Create .htaccess in the dropbox directory.
|
||
|
9 years ago
|
$fp = fopen($cp.'/dropbox/.htaccess', 'w');
|
||
|
11 years ago
|
fwrite(
|
||
|
|
$fp,
|
||
|
|
"AuthName AllowLocalAccess
|
||
|
|
AuthType Basic
|
||
|
|
|
||
|
|
order deny,allow
|
||
|
|
deny from all
|
||
|
|
|
||
|
|
php_flag zlib.output_compression off"
|
||
|
|
);
|
||
|
|
fclose($fp);
|
||
|
|
|
||
|
|
// Build index.php of the course.
|
||
|
11 years ago
|
/*$fd = fopen($cp . '/index.php', 'w');
|
||
|
11 years ago
|
|
||
|
|
// str_replace() removes \r that cause squares to appear at the end of each line
|
||
|
|
//@todo fix the harcoded include
|
||
|
|
$string = str_replace(
|
||
|
|
"\r",
|
||
|
|
"",
|
||
|
|
"<?" . "php
|
||
|
|
\$cidReq = \"$course_code\";
|
||
|
|
\$dbname = \"$course_code\";
|
||
|
|
|
||
|
|
include(\"" . api_get_path(SYS_CODE_PATH) . "course_home/course_home.php\");
|
||
|
|
?>"
|
||
|
|
);
|
||
|
|
fwrite($fd, $string);
|
||
|
11 years ago
|
@chmod($cp . '/index.php', $perm_file);*/
|
||
|
11 years ago
|
return 0;
|
||
|
|
}
|
||
|
14 years ago
|
|
||
|
11 years ago
|
/**
|
||
|
8 years ago
|
* Gets an array with all the course tables (deprecated?).
|
||
|
|
*
|
||
|
6 years ago
|
* @return array
|
||
|
|
*
|
||
|
11 years ago
|
* @assert (null) !== null
|
||
|
|
*/
|
||
|
|
public static function get_course_tables()
|
||
|
|
{
|
||
|
8 years ago
|
$tables = [];
|
||
|
9 years ago
|
$tables[] = 'item_property';
|
||
|
11 years ago
|
$tables[] = 'tool';
|
||
|
|
$tables[] = 'tool_intro';
|
||
|
|
$tables[] = 'group_info';
|
||
|
|
$tables[] = 'group_category';
|
||
|
|
$tables[] = 'group_rel_user';
|
||
|
|
$tables[] = 'group_rel_tutor';
|
||
|
|
$tables[] = 'userinfo_content';
|
||
|
|
$tables[] = 'userinfo_def';
|
||
|
|
$tables[] = 'course_description';
|
||
|
|
$tables[] = 'calendar_event';
|
||
|
|
$tables[] = 'calendar_event_repeat';
|
||
|
|
$tables[] = 'calendar_event_repeat_not';
|
||
|
|
$tables[] = 'calendar_event_attachment';
|
||
|
|
$tables[] = 'announcement';
|
||
|
|
$tables[] = 'announcement_attachment';
|
||
|
6 years ago
|
//$tables[] = 'resource';
|
||
|
11 years ago
|
$tables[] = 'student_publication';
|
||
|
|
$tables[] = 'student_publication_assignment';
|
||
|
|
$tables[] = 'document';
|
||
|
7 years ago
|
$tables[] = 'forum_category';
|
||
|
|
$tables[] = 'forum_forum';
|
||
|
7 years ago
|
$tables[] = 'forum_thread';
|
||
|
7 years ago
|
$tables[] = 'forum_post';
|
||
|
11 years ago
|
$tables[] = 'forum_mailcue';
|
||
|
|
$tables[] = 'forum_attachment';
|
||
|
|
$tables[] = 'forum_notification';
|
||
|
|
$tables[] = 'forum_thread_qualify';
|
||
|
|
$tables[] = 'forum_thread_qualify_log';
|
||
|
|
$tables[] = 'link';
|
||
|
|
$tables[] = 'link_category';
|
||
|
|
$tables[] = 'online_connected';
|
||
|
|
$tables[] = 'online_link';
|
||
|
|
$tables[] = 'chat_connected';
|
||
|
|
$tables[] = 'quiz';
|
||
|
|
$tables[] = 'quiz_rel_question';
|
||
|
|
$tables[] = 'quiz_question';
|
||
|
|
$tables[] = 'quiz_answer';
|
||
|
|
$tables[] = 'quiz_question_option';
|
||
|
|
$tables[] = 'quiz_question_category';
|
||
|
|
$tables[] = 'quiz_question_rel_category';
|
||
|
|
$tables[] = 'dropbox_post';
|
||
|
|
$tables[] = 'dropbox_file';
|
||
|
|
$tables[] = 'dropbox_person';
|
||
|
|
$tables[] = 'dropbox_category';
|
||
|
|
$tables[] = 'dropbox_feedback';
|
||
|
|
$tables[] = 'lp';
|
||
|
|
$tables[] = 'lp_item';
|
||
|
|
$tables[] = 'lp_view';
|
||
|
|
$tables[] = 'lp_item_view';
|
||
|
|
$tables[] = 'lp_iv_interaction';
|
||
|
|
$tables[] = 'lp_iv_objective';
|
||
|
|
$tables[] = 'blog';
|
||
|
|
$tables[] = 'blog_comment';
|
||
|
|
$tables[] = 'blog_post';
|
||
|
|
$tables[] = 'blog_rating';
|
||
|
|
$tables[] = 'blog_rel_user';
|
||
|
|
$tables[] = 'blog_task';
|
||
|
|
$tables[] = 'blog_task_rel_user';
|
||
|
|
$tables[] = 'blog_attachment';
|
||
|
|
$tables[] = 'permission_group';
|
||
|
|
$tables[] = 'permission_user';
|
||
|
|
$tables[] = 'permission_task';
|
||
|
|
$tables[] = 'role';
|
||
|
|
$tables[] = 'role_group';
|
||
|
|
$tables[] = 'role_permissions';
|
||
|
|
$tables[] = 'role_user';
|
||
|
|
$tables[] = 'survey';
|
||
|
|
$tables[] = 'survey_question';
|
||
|
|
$tables[] = 'survey_question_option';
|
||
|
|
$tables[] = 'survey_invitation';
|
||
|
|
$tables[] = 'survey_answer';
|
||
|
|
$tables[] = 'survey_group';
|
||
|
|
$tables[] = 'wiki';
|
||
|
|
$tables[] = 'wiki_conf';
|
||
|
|
$tables[] = 'wiki_discuss';
|
||
|
|
$tables[] = 'wiki_mailcue';
|
||
|
|
$tables[] = 'course_setting';
|
||
|
|
$tables[] = 'glossary';
|
||
|
|
$tables[] = 'notebook';
|
||
|
|
$tables[] = 'attendance';
|
||
|
|
$tables[] = 'attendance_sheet';
|
||
|
|
$tables[] = 'attendance_calendar';
|
||
|
|
$tables[] = 'attendance_result';
|
||
|
|
$tables[] = 'attendance_sheet_log';
|
||
|
|
$tables[] = 'thematic';
|
||
|
|
$tables[] = 'thematic_plan';
|
||
|
|
$tables[] = 'thematic_advance';
|
||
|
|
|
||
|
|
return $tables;
|
||
|
14 years ago
|
}
|
||
|
14 years ago
|
|
||
|
11 years ago
|
/**
|
||
|
8 years ago
|
* Executed only before create_course_tables().
|
||
|
|
*
|
||
|
11 years ago
|
* @assert (null) === null
|
||
|
|
*/
|
||
|
|
public static function drop_course_tables()
|
||
|
|
{
|
||
|
|
$list = self::get_course_tables();
|
||
|
|
foreach ($list as $table) {
|
||
|
9 years ago
|
$sql = "DROP TABLE IF EXISTS ".DB_COURSE_PREFIX.$table;
|
||
|
11 years ago
|
Database::query($sql);
|
||
|
11 years ago
|
}
|
||
|
15 years ago
|
}
|
||
|
|
|
||
|
11 years ago
|
/**
|
||
|
8 years ago
|
* Sorts pictures by type (used?).
|
||
|
|
*
|
||
|
11 years ago
|
* @param array List of files (sthg like array(0=>array('png'=>1)))
|
||
|
10 years ago
|
* @param string $type
|
||
|
8 years ago
|
*
|
||
|
11 years ago
|
* @return array The received array without files not matching type
|
||
|
|
* @assert (array(),null) === array()
|
||
|
|
*/
|
||
|
|
public static function sort_pictures($files, $type)
|
||
|
|
{
|
||
|
8 years ago
|
$pictures = [];
|
||
|
|
foreach ($files as $value) {
|
||
|
11 years ago
|
if (isset($value[$type]) && $value[$type] != '') {
|
||
|
11 years ago
|
$pictures[][$type] = $value[$type];
|
||
|
|
}
|
||
|
15 years ago
|
}
|
||
|
8 years ago
|
|
||
|
11 years ago
|
return $pictures;
|
||
|
15 years ago
|
}
|
||
|
19 years ago
|
|
||
|
11 years ago
|
/**
|
||
|
|
* Fills the course database with some required content and example content.
|
||
|
8 years ago
|
*
|
||
|
7 years ago
|
* @param array $courseInfo
|
||
|
11 years ago
|
* @param bool Whether to fill the course with example content
|
||
|
9 years ago
|
* @param int $authorId
|
||
|
8 years ago
|
*
|
||
|
11 years ago
|
* @return bool False on error, true otherwise
|
||
|
8 years ago
|
*
|
||
|
11 years ago
|
* @version 1.2
|
||
|
|
* @assert (null, '', '', null) === false
|
||
|
|
* @assert (1, 'ABC', null, null) === false
|
||
|
|
* @assert (1, 'TEST', 'spanish', true) === true
|
||
|
|
*/
|
||
|
7 years ago
|
public static function fillCourse(
|
||
|
|
$courseInfo,
|
||
|
9 years ago
|
$fill_with_exemplary_content = null,
|
||
|
|
$authorId = 0
|
||
|
11 years ago
|
) {
|
||
|
|
if (is_null($fill_with_exemplary_content)) {
|
||
|
7 years ago
|
$fill_with_exemplary_content = api_get_setting('example_material_course_creation') !== 'false';
|
||
|
11 years ago
|
}
|
||
|
7 years ago
|
|
||
|
|
$course_id = (int) $courseInfo['real_id'];
|
||
|
15 years ago
|
|
||
|
7 years ago
|
if (empty($courseInfo)) {
|
||
|
11 years ago
|
return false;
|
||
|
|
}
|
||
|
9 years ago
|
$authorId = empty($authorId) ? api_get_user_id() : (int) $authorId;
|
||
|
11 years ago
|
|
||
|
9 years ago
|
$TABLEGROUPCATEGORIES = Database::get_course_table(TABLE_GROUP_CATEGORY);
|
||
|
11 years ago
|
$TABLESETTING = Database::get_course_table(TABLE_COURSE_SETTING);
|
||
|
9 years ago
|
$TABLEGRADEBOOK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
|
||
|
|
$TABLEGRADEBOOKLINK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
|
||
|
11 years ago
|
$visible_for_course_admin = 0;
|
||
|
8 years ago
|
$em = Database::getManager();
|
||
|
|
$course = api_get_course_entity($course_id);
|
||
|
|
$settingsManager = CourseManager::getCourseSettingsManager();
|
||
|
|
$settingsManager->setCourse($course);
|
||
|
8 years ago
|
|
||
|
11 years ago
|
$alert = api_get_setting('email_alert_manager_on_new_quiz');
|
||
|
7 years ago
|
$defaultEmailExerciseAlert = 0;
|
||
|
11 years ago
|
if ($alert === 'true') {
|
||
|
|
$defaultEmailExerciseAlert = 1;
|
||
|
11 years ago
|
}
|
||
|
12 years ago
|
|
||
|
11 years ago
|
/* course_setting table (courseinfo tool) */
|
||
|
11 years ago
|
$settings = [
|
||
|
10 years ago
|
'email_alert_manager_on_new_doc' => ['title' => '', 'default' => 0, 'category' => 'work'],
|
||
|
11 years ago
|
'email_alert_on_new_doc_dropbox' => ['default' => 0, 'category' => 'dropbox'],
|
||
|
|
'allow_user_edit_agenda' => ['default' => 0, 'category' => 'agenda'],
|
||
|
|
'allow_user_edit_announcement' => ['default' => 0, 'category' => 'announcement'],
|
||
|
|
'email_alert_manager_on_new_quiz' => ['default' => $defaultEmailExerciseAlert, 'category' => 'quiz'],
|
||
|
|
'allow_user_image_forum' => ['default' => 1, 'category' => 'forum'],
|
||
|
|
'course_theme' => ['default' => '', 'category' => 'theme'],
|
||
|
|
'allow_learning_path_theme' => ['default' => 1, 'category' => 'theme'],
|
||
|
|
'allow_open_chat_window' => ['default' => 1, 'category' => 'chat'],
|
||
|
8 years ago
|
'email_alert_to_teacher_on_new_user_in_course' => ['default' => 0, 'category' => 'registration'],
|
||
|
|
'allow_user_view_user_list' => ['default' => 1, 'category' => 'user'],
|
||
|
|
'display_info_advance_inside_homecourse' => ['default' => 1, 'category' => 'thematic_advance'],
|
||
|
|
'email_alert_students_on_new_homework' => ['default' => 0, 'category' => 'work'],
|
||
|
|
'enable_lp_auto_launch' => ['default' => 0, 'category' => 'learning_path'],
|
||
|
7 years ago
|
'enable_exercise_auto_launch' => ['default' => 0, 'category' => 'exercise'],
|
||
|
|
'enable_document_auto_launch' => ['default' => 0, 'category' => 'document'],
|
||
|
8 years ago
|
'pdf_export_watermark_text' => ['default' => '', 'category' => 'learning_path'],
|
||
|
10 years ago
|
'allow_public_certificates' => [
|
||
|
|
'default' => api_get_setting('allow_public_certificates') === 'true' ? 1 : '',
|
||
|
8 years ago
|
'category' => 'certificates',
|
||
|
10 years ago
|
],
|
||
|
8 years ago
|
'documents_default_visibility' => ['default' => 'visible', 'category' => 'document'],
|
||
|
10 years ago
|
'show_course_in_user_language' => ['default' => 2, 'category' => null],
|
||
|
7 years ago
|
'email_to_teachers_on_new_work_feedback' => ['default' => 1, 'category' => null],
|
||
|
11 years ago
|
];
|
||
|
7 years ago
|
|
||
|
11 years ago
|
$counter = 1;
|
||
|
11 years ago
|
foreach ($settings as $variable => $setting) {
|
||
|
7 years ago
|
$title = $setting['title'] ?? '';
|
||
|
11 years ago
|
Database::query(
|
||
|
10 years ago
|
"INSERT INTO $TABLESETTING (id, c_id, title, variable, value, category)
|
||
|
7 years ago
|
VALUES ($counter, $course_id, '".$title."', '".$variable."', '".$setting['default']."', '".$setting['category']."')"
|
||
|
11 years ago
|
);
|
||
|
|
$counter++;
|
||
|
|
}
|
||
|
12 years ago
|
|
||
|
11 years ago
|
/* Course homepage tools for platform admin only */
|
||
|
|
/* Group tool */
|
||
|
9 years ago
|
Database::insert(
|
||
|
|
$TABLEGROUPCATEGORIES,
|
||
|
|
[
|
||
|
|
'c_id' => $course_id,
|
||
|
|
'id' => 2,
|
||
|
6 years ago
|
'title' => get_lang('Default groups'),
|
||
|
9 years ago
|
'description' => '',
|
||
|
7 years ago
|
'max_student' => 0,
|
||
|
9 years ago
|
'self_reg_allowed' => 0,
|
||
|
|
'self_unreg_allowed' => 0,
|
||
|
|
'groups_per_user' => 0,
|
||
|
|
'display_order' => 0,
|
||
|
|
'doc_state' => 1,
|
||
|
|
'calendar_state' => 1,
|
||
|
|
'work_state' => 1,
|
||
|
|
'announcements_state' => 1,
|
||
|
|
'forum_state' => 1,
|
||
|
|
'wiki_state' => 1,
|
||
|
8 years ago
|
'chat_state' => 1,
|
||
|
9 years ago
|
]
|
||
|
11 years ago
|
);
|
||
|
13 years ago
|
|
||
|
11 years ago
|
$now = api_get_utc_datetime();
|
||
|
7 years ago
|
|
||
|
11 years ago
|
$files = [
|
||
|
6 years ago
|
['path' => '/shared_folder', 'title' => get_lang('Folders of users'), 'filetype' => 'folder', 'size' => 0],
|
||
|
|
['path' => '/chat_files', 'title' => get_lang('Chat conversations history'), 'filetype' => 'folder', 'size' => 0],
|
||
|
|
['path' => '/certificates', 'title' => get_lang('Certificates'), 'filetype' => 'folder', 'size' => 0],
|
||
|
11 years ago
|
];
|
||
|
12 years ago
|
|
||
|
11 years ago
|
$counter = 1;
|
||
|
|
foreach ($files as $file) {
|
||
|
7 years ago
|
self::insertDocument($courseInfo, $counter, $file, $authorId);
|
||
|
11 years ago
|
$counter++;
|
||
|
|
}
|
||
|
11 years ago
|
|
||
|
7 years ago
|
$certificateId = 'NULL';
|
||
|
|
|
||
|
11 years ago
|
/* Documents */
|
||
|
|
if ($fill_with_exemplary_content) {
|
||
|
11 years ago
|
$files = [
|
||
|
|
['path' => '/images', 'title' => get_lang('Images'), 'filetype' => 'folder', 'size' => 0],
|
||
|
6 years ago
|
['path' => '/images/gallery', 'title' => get_lang('Gallery'), 'filetype' => 'folder', 'size' => 0],
|
||
|
11 years ago
|
['path' => '/audio', 'title' => get_lang('Audio'), 'filetype' => 'folder', 'size' => 0],
|
||
|
|
['path' => '/flash', 'title' => get_lang('Flash'), 'filetype' => 'folder', 'size' => 0],
|
||
|
|
['path' => '/video', 'title' => get_lang('Video'), 'filetype' => 'folder', 'size' => 0],
|
||
|
|
];
|
||
|
|
|
||
|
|
foreach ($files as $file) {
|
||
|
7 years ago
|
self::insertDocument($courseInfo, $counter, $file, $authorId);
|
||
|
11 years ago
|
$counter++;
|
||
|
|
}
|
||
|
11 years ago
|
|
||
|
7 years ago
|
$finder = new Symfony\Component\Finder\Finder();
|
||
|
7 years ago
|
$defaultPath = api_get_path(SYS_PUBLIC_PATH).'img/document';
|
||
|
7 years ago
|
$finder->in($defaultPath);
|
||
|
|
/** @var SplFileInfo $file */
|
||
|
|
foreach ($finder as $file) {
|
||
|
|
$path = str_replace($defaultPath, '', $file->getRealPath());
|
||
|
|
$parentName = dirname(str_replace($defaultPath, '', $file->getRealPath()));
|
||
|
|
$title = $file->getFilename();
|
||
|
|
if ($file->isDir()) {
|
||
|
|
create_unexisting_directory(
|
||
|
|
$courseInfo,
|
||
|
|
api_get_user_id(),
|
||
|
|
0,
|
||
|
|
0,
|
||
|
|
0,
|
||
|
|
$path,
|
||
|
7 years ago
|
$path,
|
||
|
7 years ago
|
$title
|
||
|
|
);
|
||
|
|
} else {
|
||
|
|
$parent = DocumentManager::getDocumentByPathInCourse($courseInfo, $parentName);
|
||
|
|
$parentId = 0;
|
||
|
|
if (!empty($parent)) {
|
||
|
|
$parent = $parent[0];
|
||
|
|
$parentId = $parent['iid'];
|
||
|
15 years ago
|
}
|
||
|
7 years ago
|
|
||
|
7 years ago
|
$realPath = str_replace($defaultPath, '', $file->getRealPath());
|
||
|
|
$document = DocumentManager::addDocument(
|
||
|
7 years ago
|
$courseInfo,
|
||
|
7 years ago
|
$realPath,
|
||
|
7 years ago
|
'file',
|
||
|
|
$file->getSize(),
|
||
|
|
$title,
|
||
|
|
'',
|
||
|
|
null,
|
||
|
|
null,
|
||
|
|
null,
|
||
|
|
null,
|
||
|
|
null,
|
||
|
|
false,
|
||
|
|
null,
|
||
|
7 years ago
|
$parentId,
|
||
|
|
$file->getRealPath()
|
||
|
7 years ago
|
);
|
||
|
7 years ago
|
|
||
|
|
if ($document && $document->getTitle() === 'default.html') {
|
||
|
|
$certificateId = $document->getIid();
|
||
|
|
}
|
||
|
15 years ago
|
}
|
||
|
15 years ago
|
}
|
||
|
14 years ago
|
|
||
|
9 years ago
|
$agenda = new Agenda('course');
|
||
|
11 years ago
|
$agenda->set_course($courseInfo);
|
||
|
|
$agenda->addEvent(
|
||
|
|
$now,
|
||
|
|
$now,
|
||
|
|
0,
|
||
|
6 years ago
|
get_lang('Course creation'),
|
||
|
|
get_lang('This course was created at this time')
|
||
|
11 years ago
|
);
|
||
|
|
|
||
|
|
/* Links tool */
|
||
|
11 years ago
|
$link = new Link();
|
||
|
|
$link->setCourse($courseInfo);
|
||
|
|
$links = [
|
||
|
|
[
|
||
|
|
'c_id' => $course_id,
|
||
|
|
'url' => 'http://www.google.com',
|
||
|
6 years ago
|
'title' => 'Quick and powerful search engine',
|
||
|
|
'description' => get_lang('Quick and powerful search engine'),
|
||
|
11 years ago
|
'category_id' => 0,
|
||
|
|
'on_homepage' => 0,
|
||
|
|
'target' => '_self',
|
||
|
8 years ago
|
'session_id' => 0,
|
||
|
11 years ago
|
],
|
||
|
|
[
|
||
|
|
'c_id' => $course_id,
|
||
|
|
'url' => 'http://www.wikipedia.org',
|
||
|
6 years ago
|
'title' => 'Free online encyclopedia',
|
||
|
|
'description' => get_lang('Free online encyclopedia'),
|
||
|
11 years ago
|
'category_id' => 0,
|
||
|
|
'on_homepage' => 0,
|
||
|
|
'target' => '_self',
|
||
|
8 years ago
|
'session_id' => 0,
|
||
|
|
],
|
||
|
11 years ago
|
];
|
||
|
11 years ago
|
|
||
|
9 years ago
|
foreach ($links as $params) {
|
||
|
11 years ago
|
$link->save($params);
|
||
|
|
}
|
||
|
11 years ago
|
|
||
|
11 years ago
|
/* Announcement tool */
|
||
|
|
AnnouncementManager::add_announcement(
|
||
|
9 years ago
|
$courseInfo,
|
||
|
|
0,
|
||
|
6 years ago
|
get_lang('This is an announcement example'),
|
||
|
|
get_lang('This is an announcement example. Only trainers are allowed to publish announcements.'),
|
||
|
11 years ago
|
['everyone' => 'everyone'],
|
||
|
|
null,
|
||
|
|
null,
|
||
|
|
$now
|
||
|
|
);
|
||
|
11 years ago
|
|
||
|
11 years ago
|
$manager = Database::getManager();
|
||
|
|
|
||
|
11 years ago
|
/* Introduction text */
|
||
|
|
$intro_text = '<p style="text-align: center;">
|
||
|
8 years ago
|
<img src="'.api_get_path(REL_CODE_PATH).'img/mascot.png" alt="Mr. Chamilo" title="Mr. Chamilo" />
|
||
|
6 years ago
|
<h2>'.get_lang('Introduction text').'</h2>
|
||
|
11 years ago
|
</p>';
|
||
|
|
|
||
|
8 years ago
|
$toolIntro = new CToolIntro();
|
||
|
11 years ago
|
$toolIntro
|
||
|
|
->setCId($course_id)
|
||
|
|
->setId(TOOL_COURSE_HOMEPAGE)
|
||
|
|
->setSessionId(0)
|
||
|
|
->setIntroText($intro_text);
|
||
|
|
$manager->persist($toolIntro);
|
||
|
|
|
||
|
8 years ago
|
$toolIntro = new CToolIntro();
|
||
|
11 years ago
|
$toolIntro
|
||
|
|
->setCId($course_id)
|
||
|
|
->setId(TOOL_STUDENTPUBLICATION)
|
||
|
|
->setSessionId(0)
|
||
|
6 years ago
|
->setIntroText(get_lang('This page allows users and groups to publish documents.'));
|
||
|
11 years ago
|
$manager->persist($toolIntro);
|
||
|
|
|
||
|
8 years ago
|
$toolIntro = new CToolIntro();
|
||
|
11 years ago
|
$toolIntro
|
||
|
|
->setCId($course_id)
|
||
|
|
->setId(TOOL_WIKI)
|
||
|
|
->setSessionId(0)
|
||
|
6 years ago
|
->setIntroText(get_lang('The word Wiki is short for WikiWikiWeb. Wikiwiki is a Hawaiian word, meaning "fast" or "speed". In a wiki, people write pages together. If one person writes something wrong, the next person can correct it. The next person can also add something new to the page. Because of this, the pages improve continuously.'));
|
||
|
11 years ago
|
$manager->persist($toolIntro);
|
||
|
|
|
||
|
|
$manager->flush();
|
||
|
11 years ago
|
|
||
|
|
/* Exercise tool */
|
||
|
11 years ago
|
$exercise = new Exercise($course_id);
|
||
|
6 years ago
|
$exercise->exercise = get_lang('Sample test');
|
||
|
11 years ago
|
$html = '<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
||
|
|
<tr>
|
||
|
10 years ago
|
<td width="220" valign="top" align="left">
|
||
|
7 years ago
|
<img src="'.api_get_path(WEB_PUBLIC_PATH).'img/document/images/mr_chamilo/doubts.png">
|
||
|
11 years ago
|
</td>
|
||
|
6 years ago
|
<td valign="top" align="left">'.get_lang('Irony').'</td></tr>
|
||
|
11 years ago
|
</table>';
|
||
|
|
$exercise->type = 1;
|
||
|
|
$exercise->setRandom(0);
|
||
|
|
$exercise->active = 1;
|
||
|
|
$exercise->results_disabled = 0;
|
||
|
|
$exercise->description = $html;
|
||
|
|
$exercise->save();
|
||
|
|
|
||
|
|
$exercise_id = $exercise->id;
|
||
|
|
|
||
|
|
$question = new MultipleAnswer();
|
||
|
6 years ago
|
$question->question = get_lang('Socratic irony is...');
|
||
|
|
$question->description = get_lang('(more than one answer can be true)');
|
||
|
11 years ago
|
$question->weighting = 10;
|
||
|
|
$question->position = 1;
|
||
|
|
$question->course = $courseInfo;
|
||
|
9 years ago
|
$question->save($exercise);
|
||
|
11 years ago
|
$questionId = $question->id;
|
||
|
|
|
||
|
|
$answer = new Answer($questionId, $courseInfo['real_id']);
|
||
|
|
|
||
|
6 years ago
|
$answer->createAnswer(get_lang('Ridiculise one\'s interlocutor in order to have him concede he is wrong.'), 0, get_lang('No. Socratic irony is not a matter of psychology, it concerns argumentation.'), -5, 1);
|
||
|
|
$answer->createAnswer(get_lang('Admit one\'s own errors to invite one\'s interlocutor to do the same.'), 0, get_lang('No. Socratic irony is not a seduction strategy or a method based on the example.'), -5, 2);
|
||
|
|
$answer->createAnswer(get_lang('Compell one\'s interlocutor, by a series of questions and sub-questions, to admit he doesn\'t know what he claims to know.'), 1, get_lang('Indeed'), 5, 3);
|
||
|
|
$answer->createAnswer(get_lang('Use the Principle of Non Contradiction to force one\'s interlocutor into a dead end.'), 1, get_lang('This answer is not false. It is true that the revelation of the interlocutor\'s ignorance means showing the contradictory conclusions where lead his premisses.'), 5, 4);
|
||
|
11 years ago
|
$answer->save();
|
||
|
11 years ago
|
|
||
|
11 years ago
|
/* Forum tool */
|
||
|
11 years ago
|
|
||
|
11 years ago
|
require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
|
||
|
11 years ago
|
|
||
|
11 years ago
|
$params = [
|
||
|
6 years ago
|
'forum_category_title' => get_lang('Example Forum Category'),
|
||
|
8 years ago
|
'forum_category_comment' => '',
|
||
|
11 years ago
|
];
|
||
|
11 years ago
|
|
||
|
11 years ago
|
$forumCategoryId = store_forumcategory($params, $courseInfo, false);
|
||
|
11 years ago
|
|
||
|
11 years ago
|
$params = [
|
||
|
|
'forum_category' => $forumCategoryId,
|
||
|
6 years ago
|
'forum_title' => get_lang('Example Forum'),
|
||
|
11 years ago
|
'forum_comment' => '',
|
||
|
|
'default_view_type_group' => ['default_view_type' => 'flat'],
|
||
|
|
];
|
||
|
11 years ago
|
|
||
|
11 years ago
|
$forumId = store_forum($params, $courseInfo, true);
|
||
|
|
|
||
|
|
$forumInfo = get_forum_information($forumId, $courseInfo['real_id']);
|
||
|
|
|
||
|
|
$params = [
|
||
|
6 years ago
|
'post_title' => get_lang('Example Thread'),
|
||
|
11 years ago
|
'forum_id' => $forumId,
|
||
|
6 years ago
|
'post_text' => get_lang('Example ThreadContent'),
|
||
|
11 years ago
|
'calification_notebook_title' => '',
|
||
|
|
'numeric_calification' => '',
|
||
|
|
'weight_calification' => '',
|
||
|
10 years ago
|
'forum_category' => $forumCategoryId,
|
||
|
|
'thread_peer_qualify' => 0,
|
||
|
11 years ago
|
];
|
||
|
|
|
||
|
|
store_thread($forumInfo, $params, $courseInfo, false);
|
||
|
|
|
||
|
11 years ago
|
/* Gradebook tool */
|
||
|
11 years ago
|
$course_code = $courseInfo['code'];
|
||
|
11 years ago
|
// father gradebook
|
||
|
|
Database::query(
|
||
|
7 years ago
|
"INSERT INTO $TABLEGRADEBOOK (name, locked, generate_certificates, description, user_id, c_id, parent_id, weight, visible, certif_min_score, session_id, document_id)
|
||
|
7 years ago
|
VALUES ('$course_code','0',0,'',1,$course_id,0,100,0,75,NULL,$certificateId)"
|
||
|
11 years ago
|
);
|
||
|
|
$gbid = Database:: insert_id();
|
||
|
|
Database::query(
|
||
|
7 years ago
|
"INSERT INTO $TABLEGRADEBOOK (name, locked, generate_certificates, description, user_id, c_id, parent_id, weight, visible, certif_min_score, session_id, document_id)
|
||
|
7 years ago
|
VALUES ('$course_code','0',0,'',1,$course_id,$gbid,100,1,75,NULL,$certificateId)"
|
||
|
11 years ago
|
);
|
||
|
|
$gbid = Database:: insert_id();
|
||
|
|
Database::query(
|
||
|
7 years ago
|
"INSERT INTO $TABLEGRADEBOOKLINK (type, ref_id, user_id, c_id, category_id, created_at, weight, visible, locked)
|
||
|
|
VALUES (1,$exercise_id,1,$course_id,$gbid,'$now',100,1,0)"
|
||
|
11 years ago
|
);
|
||
|
|
}
|
||
|
14 years ago
|
|
||
|
7 years ago
|
// Installing plugins in course
|
||
|
11 years ago
|
$app_plugin = new AppPlugin();
|
||
|
|
$app_plugin->install_course_plugins($course_id);
|
||
|
8 years ago
|
|
||
|
15 years ago
|
return true;
|
||
|
|
}
|
||
|
11 years ago
|
|
||
|
|
/**
|
||
|
7 years ago
|
* @param array $courseInfo
|
||
|
8 years ago
|
* @param int $counter
|
||
|
11 years ago
|
* @param array $file
|
||
|
8 years ago
|
* @param int $authorId
|
||
|
11 years ago
|
*/
|
||
|
7 years ago
|
public static function insertDocument($courseInfo, $counter, $file, $authorId = 0)
|
||
|
11 years ago
|
{
|
||
|
7 years ago
|
DocumentManager::addDocument(
|
||
|
7 years ago
|
$courseInfo,
|
||
|
|
$file['path'],
|
||
|
|
$file['filetype'],
|
||
|
|
$file['size'],
|
||
|
|
$file['title'],
|
||
|
|
null,
|
||
|
|
0,
|
||
|
7 years ago
|
null,
|
||
|
7 years ago
|
0,
|
||
|
|
0,
|
||
|
|
0,
|
||
|
|
false
|
||
|
|
);
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
11 years ago
|
/**
|
||
|
|
* string2binary converts the string "true" or "false" to the boolean true false (0 or 1)
|
||
|
|
* This is used for the Chamilo Config Settings as these store true or false as string
|
||
|
|
* and the api_get_setting('course_create_active_tools') should be 0 or 1 (used for
|
||
|
8 years ago
|
* the visibility of the tool).
|
||
|
|
*
|
||
|
11 years ago
|
* @param string $variable
|
||
|
8 years ago
|
*
|
||
|
8 years ago
|
* @return bool
|
||
|
8 years ago
|
*
|
||
|
11 years ago
|
* @author Patrick Cool, patrick.cool@ugent.be
|
||
|
|
* @assert ('true') === true
|
||
|
|
* @assert ('false') === false
|
||
|
|
*/
|
||
|
|
public static function string2binary($variable)
|
||
|
|
{
|
||
|
|
if ($variable == 'true') {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if ($variable == 'false') {
|
||
|
|
return false;
|
||
|
14 years ago
|
}
|
||
|
|
}
|
||
|
12 years ago
|
|
||
|
11 years ago
|
/**
|
||
|
8 years ago
|
* Function register_course to create a record in the course table of the main database.
|
||
|
|
*
|
||
|
7 years ago
|
* @param array $params Course details (see code for details).
|
||
|
|
* @param int $accessUrlId Optional.
|
||
|
8 years ago
|
*
|
||
|
|
* @return int Created course ID
|
||
|
|
*
|
||
|
11 years ago
|
* @todo use an array called $params instead of lots of params
|
||
|
|
* @assert (null) === false
|
||
|
|
*/
|
||
|
7 years ago
|
public static function register_course($params, $accessUrlId = 1)
|
||
|
11 years ago
|
{
|
||
|
7 years ago
|
global $error_msg;
|
||
|
11 years ago
|
$title = $params['title'];
|
||
|
8 years ago
|
// Fix amp
|
||
|
|
$title = str_replace('&', '&', $title);
|
||
|
11 years ago
|
$code = $params['code'];
|
||
|
|
$visual_code = $params['visual_code'];
|
||
|
|
$directory = $params['directory'];
|
||
|
|
$tutor_name = isset($params['tutor_name']) ? $params['tutor_name'] : null;
|
||
|
6 years ago
|
$categoryId = isset($params['category_id']) ? (int) $params['category_id'] : '';
|
||
|
11 years ago
|
$course_language = isset($params['course_language']) && !empty($params['course_language']) ? $params['course_language'] : api_get_setting(
|
||
|
|
'platformLanguage'
|
||
|
|
);
|
||
|
11 years ago
|
$user_id = empty($params['user_id']) ? api_get_user_id() : intval($params['user_id']);
|
||
|
7 years ago
|
$department_name = isset($params['department_name']) ? $params['department_name'] : null;
|
||
|
|
$department_url = isset($params['department_url']) ? $params['department_url'] : null;
|
||
|
|
$disk_quota = isset($params['disk_quota']) ? $params['disk_quota'] : null;
|
||
|
11 years ago
|
|
||
|
|
if (!isset($params['visibility'])) {
|
||
|
|
$default_course_visibility = api_get_setting(
|
||
|
|
'courses_default_creation_visibility'
|
||
|
|
);
|
||
|
|
if (isset($default_course_visibility)) {
|
||
|
|
$visibility = $default_course_visibility;
|
||
|
|
} else {
|
||
|
|
$visibility = COURSE_VISIBILITY_OPEN_PLATFORM;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
$visibility = $params['visibility'];
|
||
|
|
}
|
||
|
15 years ago
|
|
||
|
9 years ago
|
$subscribe = isset($params['subscribe']) ? (int) $params['subscribe'] : $visibility == COURSE_VISIBILITY_OPEN_PLATFORM ? 1 : 0;
|
||
|
7 years ago
|
$unsubscribe = isset($params['unsubscribe']) ? (int) $params['unsubscribe'] : 0;
|
||
|
11 years ago
|
$expiration_date = isset($params['expiration_date']) ? $params['expiration_date'] : null;
|
||
|
|
$teachers = isset($params['teachers']) ? $params['teachers'] : null;
|
||
|
|
$status = isset($params['status']) ? $params['status'] : null;
|
||
|
|
|
||
|
9 years ago
|
$TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
|
||
|
11 years ago
|
$ok_to_register_course = true;
|
||
|
|
|
||
|
|
// Check whether all the needed parameters are present.
|
||
|
|
if (empty($code)) {
|
||
|
|
$error_msg[] = 'courseSysCode is missing';
|
||
|
|
$ok_to_register_course = false;
|
||
|
|
}
|
||
|
|
if (empty($visual_code)) {
|
||
|
|
$error_msg[] = 'courseScreenCode is missing';
|
||
|
|
$ok_to_register_course = false;
|
||
|
|
}
|
||
|
|
if (empty($directory)) {
|
||
|
|
$error_msg[] = 'courseRepository is missing';
|
||
|
|
$ok_to_register_course = false;
|
||
|
|
}
|
||
|
15 years ago
|
|
||
|
11 years ago
|
if (empty($title)) {
|
||
|
|
$error_msg[] = 'title is missing';
|
||
|
|
$ok_to_register_course = false;
|
||
|
|
}
|
||
|
15 years ago
|
|
||
|
11 years ago
|
if (empty($expiration_date)) {
|
||
|
|
$expiration_date = api_get_utc_datetime(
|
||
|
7 years ago
|
time() + self::FIRST_EXPIRATION_DATE
|
||
|
11 years ago
|
);
|
||
|
|
} else {
|
||
|
|
$expiration_date = api_get_utc_datetime($expiration_date);
|
||
|
|
}
|
||
|
14 years ago
|
|
||
|
11 years ago
|
if ($visibility < 0 || $visibility > 4) {
|
||
|
|
$error_msg[] = 'visibility is invalid';
|
||
|
|
$ok_to_register_course = false;
|
||
|
|
}
|
||
|
15 years ago
|
|
||
|
11 years ago
|
if (empty($disk_quota)) {
|
||
|
|
$disk_quota = api_get_setting('default_document_quotum');
|
||
|
|
}
|
||
|
15 years ago
|
|
||
|
11 years ago
|
if (stripos($department_url, 'http://') === false && stripos(
|
||
|
|
$department_url,
|
||
|
|
'https://'
|
||
|
|
) === false
|
||
|
|
) {
|
||
|
9 years ago
|
$department_url = 'http://'.$department_url;
|
||
|
11 years ago
|
}
|
||
|
7 years ago
|
|
||
|
|
// just in case
|
||
|
11 years ago
|
if ($department_url == 'http://') {
|
||
|
|
$department_url = '';
|
||
|
|
}
|
||
|
|
$course_id = 0;
|
||
|
14 years ago
|
|
||
|
11 years ago
|
if ($ok_to_register_course) {
|
||
|
6 years ago
|
$repo = Container::getCourseRepository();
|
||
|
|
$course = new \Chamilo\CoreBundle\Entity\Course();
|
||
|
6 years ago
|
/** @var \Chamilo\CoreBundle\Entity\CourseCategory $courseCategory */
|
||
|
|
$courseCategory = Container::getCourseCategoryRepository()->find($categoryId);
|
||
|
7 years ago
|
$urlId = 1;
|
||
|
|
if (api_get_current_access_url_id() !== -1) {
|
||
|
|
$urlId = api_get_current_access_url_id();
|
||
|
|
}
|
||
|
|
|
||
|
|
$url = api_get_url_entity($urlId);
|
||
|
|
$course
|
||
|
|
->setCode($code)
|
||
|
|
->setDirectory($directory)
|
||
|
|
->setCourseLanguage($course_language)
|
||
|
|
->setTitle($title)
|
||
|
6 years ago
|
->setDescription(get_lang('Course Description'))
|
||
|
6 years ago
|
->setCategory($courseCategory)
|
||
|
7 years ago
|
->setVisibility($visibility)
|
||
|
|
->setShowScore(1)
|
||
|
|
->setDiskQuota($disk_quota)
|
||
|
|
->setCreationDate(new \DateTime())
|
||
|
|
->setExpirationDate(new \DateTime($expiration_date))
|
||
|
|
->setDepartmentName($department_name)
|
||
|
|
->setDepartmentUrl($department_url)
|
||
|
|
->setSubscribe($subscribe)
|
||
|
|
->setUnsubscribe($unsubscribe)
|
||
|
|
->setVisualCode($visual_code)
|
||
|
|
->addUrl($url)
|
||
|
|
;
|
||
|
6 years ago
|
$repo->getEntityManager()->persist($course);
|
||
|
|
$repo->getEntityManager()->flush();
|
||
|
7 years ago
|
$course_id = $course->getId();
|
||
|
11 years ago
|
|
||
|
|
if ($course_id) {
|
||
|
6 years ago
|
$repo->addResourceNode(
|
||
|
|
$course,
|
||
|
|
api_get_user_entity(api_get_user_id()),
|
||
|
|
$url
|
||
|
|
);
|
||
|
11 years ago
|
$sort = api_max_sort_value('0', api_get_user_id());
|
||
|
|
// Default true
|
||
|
|
$addTeacher = isset($params['add_user_as_teacher']) ? $params['add_user_as_teacher'] : true;
|
||
|
|
if ($addTeacher) {
|
||
|
7 years ago
|
$i_course_sort = CourseManager::userCourseSort(
|
||
|
11 years ago
|
$user_id,
|
||
|
|
$code
|
||
|
|
);
|
||
|
|
if (!empty($user_id)) {
|
||
|
9 years ago
|
$sql = "INSERT INTO ".$TABLECOURSUSER." SET
|
||
|
8 years ago
|
c_id = '".$course_id."',
|
||
|
|
user_id = '".intval($user_id)."',
|
||
|
11 years ago
|
status = '1',
|
||
|
11 years ago
|
is_tutor = '0',
|
||
|
8 years ago
|
sort = '".($i_course_sort)."',
|
||
|
10 years ago
|
relation_type = 0,
|
||
|
11 years ago
|
user_course_cat = '0'";
|
||
|
11 years ago
|
Database::query($sql);
|
||
|
|
}
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
11 years ago
|
if (!empty($teachers)) {
|
||
|
|
if (!is_array($teachers)) {
|
||
|
8 years ago
|
$teachers = [$teachers];
|
||
|
14 years ago
|
}
|
||
|
11 years ago
|
foreach ($teachers as $key) {
|
||
|
|
//just in case
|
||
|
|
if ($key == $user_id) {
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (empty($key)) {
|
||
|
|
continue;
|
||
|
|
}
|
||
|
9 years ago
|
$sql = "INSERT INTO ".$TABLECOURSUSER." SET
|
||
|
8 years ago
|
c_id = '".Database::escape_string($course_id)."',
|
||
|
|
user_id = '".Database::escape_string($key)."',
|
||
|
11 years ago
|
status = '1',
|
||
|
11 years ago
|
is_tutor = '0',
|
||
|
8 years ago
|
sort = '".($sort + 1)."',
|
||
|
10 years ago
|
relation_type = 0,
|
||
|
11 years ago
|
user_course_cat = '0'";
|
||
|
|
Database::query($sql);
|
||
|
14 years ago
|
}
|
||
|
14 years ago
|
}
|
||
|
14 years ago
|
|
||
|
11 years ago
|
// Adding the course to an URL.
|
||
|
7 years ago
|
UrlManager::add_course_to_url($course_id, $accessUrlId);
|
||
|
14 years ago
|
|
||
|
11 years ago
|
// Add event to the system log.
|
||
|
|
$user_id = api_get_user_id();
|
||
|
11 years ago
|
Event::addEvent(
|
||
|
11 years ago
|
LOG_COURSE_CREATE,
|
||
|
|
LOG_COURSE_CODE,
|
||
|
|
$code,
|
||
|
|
api_get_utc_datetime(),
|
||
|
|
$user_id,
|
||
|
11 years ago
|
$course_id
|
||
|
11 years ago
|
);
|
||
|
11 years ago
|
|
||
|
7 years ago
|
$send_mail_to_admin = api_get_setting('send_email_to_admin_when_create_course');
|
||
|
11 years ago
|
|
||
|
|
// @todo Improve code to send to all current portal administrators.
|
||
|
7 years ago
|
if ($send_mail_to_admin === 'true') {
|
||
|
11 years ago
|
$siteName = api_get_setting('siteName');
|
||
|
|
$recipient_email = api_get_setting('emailAdministrator');
|
||
|
|
$recipient_name = api_get_person_name(
|
||
|
|
api_get_setting('administratorName'),
|
||
|
|
api_get_setting('administratorSurname')
|
||
|
|
);
|
||
|
|
$iname = api_get_setting('Institution');
|
||
|
|
$subject = get_lang(
|
||
|
|
'NewCourseCreatedIn'
|
||
|
9 years ago
|
).' '.$siteName.' - '.$iname;
|
||
|
11 years ago
|
$message = get_lang(
|
||
|
|
'Dear'
|
||
|
9 years ago
|
).' '.$recipient_name.",\n\n".get_lang(
|
||
|
11 years ago
|
'MessageOfNewCourseToAdmin'
|
||
|
9 years ago
|
).' '.$siteName.' - '.$iname."\n";
|
||
|
6 years ago
|
$message .= get_lang('Course name').' '.$title."\n";
|
||
|
6 years ago
|
|
||
|
|
if ($courseCategory) {
|
||
|
|
$message .= get_lang(
|
||
|
|
'Category'
|
||
|
|
).' '.$courseCategory->getCode()."\n";
|
||
|
|
}
|
||
|
6 years ago
|
$message .= get_lang('Coach').' '.$tutor_name."\n";
|
||
|
9 years ago
|
$message .= get_lang('Language').' '.$course_language;
|
||
|
11 years ago
|
|
||
|
|
$userInfo = api_get_user_info($user_id);
|
||
|
11 years ago
|
|
||
|
8 years ago
|
$additionalParameters = [
|
||
|
11 years ago
|
'smsType' => SmsPlugin::NEW_COURSE_BEEN_CREATED,
|
||
|
11 years ago
|
'userId' => $user_id,
|
||
|
|
'courseName' => $title,
|
||
|
8 years ago
|
'creatorUsername' => $userInfo['username'],
|
||
|
8 years ago
|
];
|
||
|
11 years ago
|
|
||
|
|
api_mail_html(
|
||
|
|
$recipient_name,
|
||
|
|
$recipient_email,
|
||
|
|
$subject,
|
||
|
|
$message,
|
||
|
|
$siteName,
|
||
|
|
$recipient_email,
|
||
|
|
null,
|
||
|
|
null,
|
||
|
|
null,
|
||
|
|
$additionalParameters
|
||
|
|
);
|
||
|
|
}
|
||
|
15 years ago
|
}
|
||
|
|
}
|
||
|
14 years ago
|
|
||
|
11 years ago
|
return $course_id;
|
||
|
|
}
|
||
|
19 years ago
|
|
||
|
11 years ago
|
/**
|
||
|
8 years ago
|
* Generate a new id for c_tool table.
|
||
|
|
*
|
||
|
11 years ago
|
* @param int $courseId The course id
|
||
|
8 years ago
|
*
|
||
|
11 years ago
|
* @return int the new id
|
||
|
|
*/
|
||
|
|
public static function generateToolId($courseId)
|
||
|
|
{
|
||
|
|
$newIdResultData = Database::select(
|
||
|
|
'id + 1 AS new_id',
|
||
|
|
Database::get_course_table(TABLE_TOOL_LIST),
|
||
|
|
[
|
||
|
|
'where' => ['c_id = ?' => intval($courseId)],
|
||
|
|
'order' => 'id',
|
||
|
8 years ago
|
'limit' => 1,
|
||
|
11 years ago
|
],
|
||
|
|
'first'
|
||
|
|
);
|
||
|
|
|
||
|
|
if ($newIdResultData === false) {
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
return $newIdResultData['new_id'] > 0 ? $newIdResultData['new_id'] : 1;
|
||
|
|
}
|
||
|
17 years ago
|
}
|