本文整理汇总了PHP中CourseManager::create_course方法的典型用法代码示例。如果您正苦于以下问题:PHP CourseManager::create_course方法的具体用法?PHP CourseManager::create_course怎么用?PHP CourseManager::create_course使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CourseManager
的用法示例。
在下文中一共展示了CourseManager::create_course方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fill_courses
/**
* Loads the data and injects it into the Chamilo database, using the Chamilo
* internal functions.
* @return array List of user IDs for the users that have just been inserted
*/
function fill_courses()
{
$eol = PHP_EOL;
$courses = array();
//declare only to avoid parsing notice
require_once 'data_courses.php';
//fill the $users array
$output = array();
$output[] = array('title' => 'Courses Filling Report: ');
$i = 1;
foreach ($courses as $i => $course) {
//first check that the first item doesn't exist already
$output[$i]['line-init'] = $course['title'];
$output[$i]['line-info'] = $res = CourseManager::create_course($course) ? $res : get_lang('NotInserted');
$i++;
}
return $output;
}
示例2: accept_course_request
/**
* Accepts a given by its id course request. The requested course gets created immediately after the request acceptance.
* @param int/string $id The id (an integer number) of the corresponding database record.
* @return string/bool Returns the code of the newly created course or FALSE on failure.
*/
public static function accept_course_request($id)
{
$id = (int) $id;
// Retrieve request's data
$course_request_info = self::get_course_request_info($id);
if (!is_array($course_request_info)) {
return false;
}
// Make all the checks again before the new course creation.
/*if (CourseManager::course_code_exists($wanted_code)) {
return false;
}*/
$user_id = (int) $course_request_info['user_id'];
if ($user_id <= 0) {
return false;
}
$user_info = api_get_user_info($user_id);
if (!is_array($user_info)) {
return false;
}
// Create the requested course
$params = array();
$params['title'] = $course_request_info['title'];
$params['course_category'] = $course_request_info['category_code'];
$params['course_language'] = $course_request_info['course_language'];
$params['exemplary_content'] = intval($course_request_info['exemplary_content']) > 0;
$params['wanted_code'] = $course_request_info['code'];
$params['user_id'] = $course_request_info['user_id'];
$params['tutor_name'] = api_get_person_name($user_info['firstname'], $user_info['lastname']);
$course_info = CourseManager::create_course($params);
if (!empty($course_info)) {
// Mark the request as accepted.
$sql = "UPDATE " . Database::get_main_table(TABLE_MAIN_COURSE_REQUEST) . "\n SET status = " . COURSE_REQUEST_ACCEPTED . "\n WHERE id = " . $id;
Database::query($sql);
// E-mail notification.
// E-mail language: The platform language seems to be the best choice
$email_language = api_get_setting('platformLanguage');
$email_subject = sprintf(get_lang('CourseRequestAcceptedEmailSubject', null, $email_language), '[' . api_get_setting('siteName') . ']', $course_info['code']);
$email_body = get_lang('Dear', null, $email_language) . ' ';
$email_body .= api_get_person_name($user_info['firstname'], $user_info['lastname'], null, null, $email_language) . ",\n\n";
$email_body .= sprintf(get_lang('CourseRequestAcceptedEmailText', null, $email_language), $wanted_code, $course_info['code'], api_get_path(WEB_COURSE_PATH) . $course_info['directory'] . '/') . "\n";
$email_body .= "\n" . get_lang('Formula', null, $email_language) . "\n";
$email_body .= api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, null, $email_language) . "\n";
$email_body .= get_lang('Manager', null, $email_language) . ' ' . api_get_setting('siteName') . "\n";
$email_body .= get_lang('Phone', null, $email_language) . ': ' . api_get_setting('administratorTelephone') . "\n";
$email_body .= get_lang('Email', null, $email_language) . ': ' . api_get_setting('emailAdministrator', null, $email_language) . "\n";
$email_body .= "\n" . get_lang('CourseRequestLegalNote', null, $email_language) . "\n";
$sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
$sender_email = api_get_setting('emailAdministrator');
$recipient_name = api_get_person_name($user_info['firstname'], $user_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
$recipient_email = $user_info['mail'];
$extra_headers = 'Bcc: ' . $sender_email;
$additionalParameters = array('smsType' => SmsPlugin::COURSE_OPENING_REQUEST_CODE_APPROVED, 'userId' => $user_id, 'courseCode' => $course_info['code']);
api_mail_html($recipient_name, $recipient_email, $email_subject, $email_body, $sender_name, $sender_email, null, null, null, $additionalParameters);
return $course_info['code'];
}
return false;
}
示例3: WSCreateCourseByTitle
function WSCreateCourseByTitle($params)
{
global $firstExpirationDelay, $_configuration;
if (!WSHelperVerifyKey($params)) {
return return_error(WS_ERROR_SECRET_KEY);
}
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
$courses_params = $params['courses'];
$results = array();
$orig_course_id_value = array();
foreach ($courses_params as $course_param) {
$title = $course_param['title'];
$category_code = 'LANG';
// TODO: A hard-coded value.
$wanted_code = '';
$tutor_firstname = api_get_setting('administratorName');
$tutor_lastname = api_get_setting('administratorSurname');
$course_language = 'spanish';
// TODO: Incorrect default value, it should 'english'.
if (!empty($course_param['course_language'])) {
$course_language = $course_param['course_language'];
}
$tutor_name = api_get_person_name($tutor_firstname, $tutor_lastname, null, null, $course_language);
if (!empty($course_param['tutor_name'])) {
$tutor_name = $course_param['tutor_name'];
}
$original_course_id_name = $course_param['original_course_id_name'];
$original_course_id_value = $course_param['original_course_id_value'];
$orig_course_id_value[] = $course_param['original_course_id_value'];
$extra_list = $course_param['extra'];
// Ensure the database prefix + database name do not get over 40 characters
$maxlength = 40;
if (empty($wanted_code)) {
$wanted_code = CourseManager::generate_course_code(substr($title, 0, $maxlength));
}
$courseInfo = CourseManager::getCourseInfoFromOriginalId($original_course_id_value, $original_course_id_name);
if (!empty($courseInfo)) {
if ($courseInfo['visibility'] != 0) {
$sql = "UPDATE {$table_course} SET\n course_language='" . Database::escape_string($course_language) . "',\n title='" . Database::escape_string($title) . "',\n category_code='" . Database::escape_string($category_code) . "',\n tutor_name='" . Database::escape_string($tutor_name) . "',\n visual_code='" . Database::escape_string($wanted_code) . "',\n visibility = '3'\n WHERE id ='" . $courseInfo['real_id'] . "'";
Database::query($sql);
$results[] = $courseInfo['real_id'];
continue;
} else {
$results[] = 0;
continue;
}
}
// Set default values.
if (isset($_user['language']) && $_user['language'] != '') {
$values['course_language'] = $_user['language'];
} else {
$values['course_language'] = api_get_setting('platformLanguage');
}
$values['tutor_name'] = api_get_person_name($_user['firstName'], $_user['lastName'], null, null, $values['course_language']);
$keys = AddCourse::define_course_keys($wanted_code, '', $_configuration['db_prefix']);
$sql_check = sprintf('SELECT * FROM ' . $table_course . ' WHERE visual_code = "%s"', Database::escape_string($wanted_code));
$result_check = Database::query($sql_check);
// I don't know why this api function doesn't work...
if (Database::num_rows($result_check) < 1) {
$params = array();
$params['title'] = $title;
$params['wanted_code'] = $wanted_code;
$params['category_code'] = $category_code;
$params['tutor_name'] = $tutor_name;
$params['course_language'] = $course_language;
$params['user_id'] = api_get_user_id();
//$params['visibility'] = $visibility;
$course_info = CourseManager::create_course($params);
if (!empty($course_info)) {
$course_code = $course_info['code'];
// Save new fieldlabel into course_field table.
CourseManager::create_course_extra_field($original_course_id_name, 1, $original_course_id_name, '');
// Save the external system's id into user_field_value table.
CourseManager::update_course_extra_field_value($course_code, $original_course_id_name, $original_course_id_value);
if (is_array($extra_list) && count($extra_list) > 0) {
foreach ($extra_list as $extra) {
$extra_field_name = $extra['field_name'];
$extra_field_value = $extra['field_value'];
// Save new fieldlabel into course_field table.
CourseManager::create_course_extra_field($extra_field_name, 1, $extra_field_name, '');
// Save the external system's id into course_field_value table.
CourseManager::update_course_extra_field_value($course_code, $extra_field_name, $extra_field_value);
}
}
}
$results[] = $course_code;
continue;
} else {
$results[] = 0;
continue;
}
}
// end principal foreach
$count_results = count($results);
$output = array();
for ($i = 0; $i < $count_results; $i++) {
$output[] = array('original_course_id_value' => $orig_course_id_value[$i], 'result' => $results[$i]);
}
return $output;
}
示例4: importCourses
/**
* @param string $file
* @param bool $moveFile
* @param array $teacherBackup
* @param array $groupBackup
*/
private function importCourses($file, $moveFile = true, &$teacherBackup = array(), &$groupBackup = array())
{
$data = Import::csv_to_array($file);
if (!empty($data)) {
$this->logger->addInfo(count($data) . " records found.");
foreach ($data as $row) {
$row = $this->cleanCourseRow($row);
$courseCode = CourseManager::get_course_id_from_original_id($row['extra_' . $this->extraFieldIdNameList['course']], $this->extraFieldIdNameList['course']);
$courseInfo = api_get_course_info($courseCode);
if (empty($courseInfo)) {
// Create
$params = array();
$params['title'] = $row['title'];
$params['exemplary_content'] = false;
$params['wanted_code'] = $row['course_code'];
$params['course_category'] = $row['course_category'];
$params['course_language'] = $row['language'];
$params['teachers'] = $row['teachers'];
$courseInfo = CourseManager::create_course($params);
if (!empty($courseInfo)) {
CourseManager::update_course_extra_field_value($courseInfo['code'], 'external_course_id', $row['extra_' . $this->extraFieldIdNameList['course']]);
$this->logger->addInfo("Courses - Course created " . $courseInfo['code']);
} else {
$this->logger->addError("Courses - Can't create course:" . $row['title']);
}
} else {
// Update
$params = array('title' => $row['title'], 'category_code' => $row['course_category']);
$result = CourseManager::update_attributes($courseInfo['real_id'], $params);
$addTeacherToSession = isset($courseInfo['add_teachers_to_sessions_courses']) && !empty($courseInfo['add_teachers_to_sessions_courses']) ? true : false;
$teachers = $row['teachers'];
if (!is_array($teachers)) {
$teachers = array($teachers);
}
if ($addTeacherToSession) {
CourseManager::updateTeachers($courseInfo['id'], $row['teachers'], false, true, false, $teacherBackup);
} else {
CourseManager::updateTeachers($courseInfo['id'], $row['teachers'], false, false, false, $teacherBackup);
}
foreach ($teachers as $teacherId) {
if (isset($groupBackup['tutor'][$teacherId]) && isset($groupBackup['tutor'][$teacherId][$courseInfo['code']])) {
foreach ($groupBackup['tutor'][$teacherId][$courseInfo['code']] as $data) {
GroupManager::subscribe_tutors(array($teacherId), $data['group_id'], $data['c_id']);
}
}
if (isset($groupBackup['user'][$teacherId]) && isset($groupBackup['user'][$teacherId][$courseInfo['code']]) && !empty($groupBackup['user'][$teacherId][$courseInfo['code']])) {
foreach ($groupBackup['user'][$teacherId][$courseInfo['code']] as $data) {
GroupManager::subscribe_users(array($teacherId), $data['group_id'], $data['c_id']);
}
}
}
if ($result) {
$this->logger->addInfo("Courses - Course updated " . $courseInfo['code']);
} else {
$this->logger->addError("Courses - Course NOT updated " . $courseInfo['code']);
}
}
}
}
if ($moveFile) {
$this->moveFile($file);
}
}
示例5: api_utf8_decode
$params['title'] = api_utf8_decode($courseNode->CourseCode);
} else {
$params['title'] = api_utf8_decode($courseNode->CourseTitle);
}
$params['wanted_code'] = api_utf8_decode($courseNode->CourseCode);
$params['tutor_name'] = null;
$params['course_category'] = null;
$params['course_language'] = api_get_valid_language(api_utf8_decode($courseNode->CourseLanguage));
$params['user_id'] = api_get_user_id();
// Looking up for the teacher.
$username = trim(api_utf8_decode($courseNode->CourseTeacher));
$sql = "SELECT user_id, lastname, firstname FROM {$tbl_user} WHERE username='{$username}'";
$rs = Database::query($sql);
list($user_id, $lastname, $firstname) = Database::fetch_array($rs);
$params['teachers'] = $user_id;
CourseManager::create_course($params);
}
}
// Creating sessions from <Sessions> base node.
if (count($root->Session) > 0) {
foreach ($root->Session as $node_session) {
$course_counter = 0;
$user_counter = 0;
$session_name = trim(api_utf8_decode($node_session->SessionName));
$coach = UserManager::purify_username(api_utf8_decode($node_session->Coach), $purification_option_for_usernames);
if (!empty($coach)) {
$coach_id = UserManager::get_user_id_from_username($coach);
if ($coach_id === false) {
$error_message .= get_lang('UserDoesNotExist') . ' : ' . $coach . '<br />';
// Forcing the coach id if user does not exist.
$coach_id = api_get_user_id();
示例6: round
$values['disk_quota'] = round(api_get_setting('default_document_quotum') / 1024 / 1024, 1);
$default_course_visibility = api_get_setting('courses_default_creation_visibility');
if (isset($default_course_visibility)) {
$values['visibility'] = api_get_setting('courses_default_creation_visibility');
} else {
$values['visibility'] = COURSE_VISIBILITY_OPEN_PLATFORM;
}
$values['subscribe'] = 1;
$values['unsubscribe'] = 0;
$values['course_teachers'] = array(api_get_user_id());
$form->setDefaults($values);
// Validate the form
if ($form->validate()) {
$course = $form->exportValues();
$course_teachers = isset($course['course_teachers']) ? $course['course_teachers'] : null;
$course['disk_quota'] = $course['disk_quota'] * 1024 * 1024;
$course['exemplary_content'] = empty($course['exemplary_content']) ? false : true;
$course['teachers'] = $course_teachers;
$course['wanted_code'] = $course['visual_code'];
$course['gradebook_model_id'] = isset($course['gradebook_model_id']) ? $course['gradebook_model_id'] : null;
// Fixing category code
$course['course_category'] = $course['category_code'];
$course_info = CourseManager::create_course($course);
header('Location: course_list.php' . ($course_info === false ? '?action=show_msg&warn=' . api_get_last_failure() : ''));
exit;
}
// Display the form.
$content = $form->return_form();
$tpl = new Template($tool_name);
$tpl->assign('content', $content);
$tpl->display_one_col_template();
示例7: transaction_5
static function transaction_5($data, $web_service_details)
{
global $data_list;
$uidCursoId = $data['item_id'];
$course_info = Migration::soap_call($web_service_details, 'cursoDetalles', array('intIdSede' => $data['branch_id'], 'uididcurso' => $uidCursoId));
if ($course_info['error'] == false) {
unset($course_info['error']);
$course_info = CourseManager::create_course($course_info);
$course_info = api_get_course_info($course_info['code'], true);
if (!empty($course_info)) {
$data_list['courses'][$uidCursoId] = $course_info['code'];
return array('entity' => 'course', 'before' => null, 'after' => $course_info, 'message' => "Course was created code: {$course_info['code']} ", 'status_id' => self::TRANSACTION_STATUS_SUCCESSFUL);
} else {
return array('message' => "Course was NOT created", 'status_id' => self::TRANSACTION_STATUS_FAILED);
}
} else {
return $course_info;
}
}
示例8: array
// Check whether the requested course code has already been occupied.
if (!$course_validation_feature) {
$course_code_ok = !CourseManager::course_code_exists($wanted_code);
} else {
$course_code_ok = !CourseRequestManager::course_code_exists($wanted_code);
}
if ($course_code_ok) {
if (!$course_validation_feature) {
$params = array();
$params['title'] = $title;
$params['exemplary_content'] = $exemplary_content;
$params['wanted_code'] = $wanted_code;
$params['course_category'] = $category_code;
$params['course_language'] = $course_language;
$params['gradebook_model_id'] = isset($course_values['gradebook_model_id']) ? $course_values['gradebook_model_id'] : null;
$course_info = CourseManager::create_course($params);
if (!empty($course_info)) {
/*
$directory = $course_info['directory'];
$title = $course_info['title'];
// Preparing a confirmation message.
$link = api_get_path(WEB_COURSE_PATH).$directory.'/';
$tpl->assign('course_url', $link);
$tpl->assign('course_title', Display::url($title, $link));
$tpl->assign('course_id', $course_info['code']);
$add_course_tpl = $tpl->get_template('create_course/add_course.tpl');
$message = $tpl->fetch($add_course_tpl);*/
$url = api_get_path(WEB_CODE_PATH);
示例9: addCourseAction
/**
* @Route("/add_course", name="add_course")
* @Method({"GET|POST"})
* @Security("has_role('ROLE_USER')")
*
* @return Response
*/
public function addCourseAction()
{
// "Course validation" feature. This value affects the way of a new course creation:
// true - the new course is requested only and it is created after approval;
// false - the new course is created immediately, after filling this form.
$courseValidation = false;
if (api_get_setting('course.course_validation') == 'true' && !api_is_platform_admin()) {
$courseValidation = true;
}
// Displaying the header.
$tool_name = $courseValidation ? get_lang('CreateCourseRequest') : get_lang('CreateSite');
if (api_get_setting('course.allow_users_to_create_courses') == 'false' && !api_is_platform_admin()) {
api_not_allowed(true);
}
// Check access rights.
if (!api_is_allowed_to_create_course()) {
api_not_allowed(true);
}
$url = $this->generateUrl('add_course');
// Build the form.
$form = new \FormValidator('add_course', 'post', $url);
// Form title
$form->addElement('header', $tool_name);
// Title
$form->addElement('text', 'title', array(get_lang('CourseName'), get_lang('Ex')), array('id' => 'title'));
$form->applyFilter('title', 'html_filter');
$form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
$form->addButtonAdvancedSettings('advanced_params');
$form->addElement('html', '<div id="advanced_params_options" style="display:none">');
// Category category.
$url = api_get_path(WEB_AJAX_PATH) . 'course.ajax.php?a=search_category';
$form->addElement('select_ajax', 'category_code', get_lang('CourseFaculty'), null, array('url' => $url));
// Course code
$form->addText('wanted_code', array(get_lang('Code'), get_lang('OnlyLettersAndNumbers')), '', array('maxlength' => \CourseManager::MAX_COURSE_LENGTH_CODE, 'pattern' => '[a-zA-Z0-9]+', 'title' => get_lang('OnlyLettersAndNumbers')));
$form->applyFilter('wanted_code', 'html_filter');
$form->addRule('wanted_code', get_lang('Max'), 'maxlength', \CourseManager::MAX_COURSE_LENGTH_CODE);
// The teacher
//array(get_lang('Professor'), null), null, array('size' => '60', 'disabled' => 'disabled'));
$titular =& $form->addElement('hidden', 'tutor_name', '');
if ($courseValidation) {
// Description of the requested course.
$form->addElement('textarea', 'description', get_lang('Description'), array('rows' => '3'));
// Objectives of the requested course.
$form->addElement('textarea', 'objetives', get_lang('Objectives'), array('rows' => '3'));
// Target audience of the requested course.
$form->addElement('textarea', 'target_audience', get_lang('TargetAudience'), array('rows' => '3'));
}
// Course language.
$form->addElement('select_language', 'course_language', get_lang('Ln'), array(), array('style' => 'width:150px'));
$form->applyFilter('select_language', 'html_filter');
// Exemplary content checkbox.
$form->addElement('checkbox', 'exemplary_content', null, get_lang('FillWithExemplaryContent'));
if ($courseValidation) {
// A special URL to terms and conditions that is set
// in the platform settings page.
$terms_and_conditions_url = trim(api_get_setting('course_validation_terms_and_conditions_url'));
// If the special setting is empty,
// then we may get the URL from Chamilo's module "Terms and conditions",
// if it is activated.
if (empty($terms_and_conditions_url)) {
if (api_get_setting('registration.allow_terms_conditions') == 'true') {
$terms_and_conditions_url = api_get_path(WEB_CODE_PATH);
$terms_and_conditions_url .= 'auth/inscription.php?legal';
}
}
if (!empty($terms_and_conditions_url)) {
// Terms and conditions to be accepted before sending a course request.
$form->addElement('checkbox', 'legal', null, get_lang('IAcceptTermsAndConditions'), 1);
$form->addRule('legal', get_lang('YouHaveToAcceptTermsAndConditions'), 'required');
// Link to terms and conditions.
$link_terms_and_conditions = '
<script>
function MM_openBrWindow(theURL, winName, features) { //v2.0
window.open(theURL,winName,features);
}
</script>
';
$link_terms_and_conditions .= \Display::url(get_lang('ReadTermsAndConditions'), '#', ['onclick' => "javascript:MM_openBrWindow('{$terms_and_conditions_url}', 'Conditions', 'scrollbars=yes, width=800');"]);
$form->addElement('label', null, $link_terms_and_conditions);
}
}
$obj = new \GradeModel();
$obj->fill_grade_model_select_in_form($form);
$form->addElement('html', '</div>');
// Submit button.
$form->addButtonCreate($courseValidation ? get_lang('CreateThisCourseRequest') : get_lang('CreateCourseArea'));
// Set default values.
if (isset($_user['language']) && $_user['language'] != '') {
$values['course_language'] = $_user['language'];
} else {
$values['course_language'] = api_get_setting('language.platform_language');
}
$form->setDefaults($values);
//.........这里部分代码省略.........
示例10: WSCreateCourse
function WSCreateCourse($params)
{
global $_configuration;
if (!WSHelperVerifyKey($params)) {
return return_error(WS_ERROR_SECRET_KEY);
}
$t_cfv = Database::get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES);
$table_field = Database::get_main_table(TABLE_MAIN_COURSE_FIELD);
$table_course_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
$courses_params = $params['courses'];
$results = array();
$orig_course_id_value = array();
foreach ($courses_params as $course_param) {
$title = $course_param['title'];
$category_code = $course_param['category_code'];
$wanted_code = $course_param['wanted_code'];
$tutor_name = $course_param['tutor_name'];
$course_language = 'english';
// TODO: A hard-coded value.
$original_course_id_name = $course_param['original_course_id_name'];
$original_course_id_value = $course_param['original_course_id_value'];
$orig_course_id_value[] = $course_param['original_course_id_value'];
$visibility = null;
if ($course_param['visibility'] && $course_param['visibility'] >= 0 && $course_param['visibility'] <= 3) {
$visibility = $course_param['visibility'];
}
$extra_list = $course_param['extra'];
// Check whether exits $x_course_code into user_field_values table.
$course_id = CourseManager::get_course_id_from_original_id($course_param['original_course_id_value'], $course_param['original_course_id_name']);
if ($course_id > 0) {
// Check whether course is not active.
$sql = "SELECT code FROM {$table_course} WHERE id ='{$course_id}' AND visibility= '0'";
$resu = Database::query($sql);
$r_check_course = Database::fetch_row($resu);
if (!empty($r_check_course[0])) {
$sql = "UPDATE {$table_course} SET course_language='" . Database::escape_string($course_language) . "',\n title='" . Database::escape_string($title) . "',\n category_code='" . Database::escape_string($category_code) . "',\n tutor_name='" . Database::escape_string($tutor_name) . "',\n visual_code='" . Database::escape_string($wanted_code) . "'";
if ($visibility !== null) {
$sql .= ", visibility = '{$visibility}' ";
}
$sql .= " WHERE code='" . Database::escape_string($r_check_course[0]) . "'";
Database::query($sql);
if (is_array($extra_list) && count($extra_list) > 0) {
foreach ($extra_list as $extra) {
$extra_field_name = $extra['field_name'];
$extra_field_value = $extra['field_value'];
// Save the external system's id into course_field_value table.
$res = CourseManager::update_course_extra_field_value($r_check_course[0], $extra_field_name, $extra_field_value);
}
}
$results[] = $r_check_course[0];
continue;
} else {
$results[] = 0;
continue;
// Original course id already exits.
}
}
if (!empty($course_param['course_language'])) {
$course_language = $course_param['course_language'];
}
// Set default values
if (isset($_user['language']) && $_user['language'] != '') {
$values['course_language'] = $_user['language'];
} else {
$values['course_language'] = api_get_setting('platformLanguage');
}
$values['tutor_name'] = api_get_person_name($_user['firstName'], $_user['lastName'], null, null, $values['course_language']);
$params = array();
$params['title'] = $title;
$params['wanted_code'] = $wanted_code;
$params['category_code'] = $category_code;
$params['tutor_name'] = $tutor_name;
$params['course_language'] = $course_language;
$params['user_id'] = api_get_user_id();
$params['visibility'] = $visibility;
$course_info = CourseManager::create_course($params);
if (!empty($course_info)) {
$course_code = $course_info['code'];
// Save new fieldlabel into course_field table
$field_id = CourseManager::create_course_extra_field($original_course_id_name, 1, $original_course_id_name);
// Save the external system's id into user_field_value table.
$res = CourseManager::update_course_extra_field_value($course_code, $original_course_id_name, $original_course_id_value);
if (is_array($extra_list) && count($extra_list) > 0) {
foreach ($extra_list as $extra) {
$extra_field_name = $extra['field_name'];
$extra_field_value = $extra['field_value'];
// Save new fieldlabel into course_field table.
$field_id = CourseManager::create_course_extra_field($extra_field_name, 1, $extra_field_name);
// Save the external system's id into course_field_value table.
$res = CourseManager::update_course_extra_field_value($course_code, $extra_field_name, $extra_field_value);
}
}
$results[] = $course_code;
} else {
$results[] = 0;
}
}
// end principal foreach
$count_results = count($results);
//.........这里部分代码省略.........
示例11: save_data
/**
* Saves imported data.
* @param array List of courses
*/
function save_data($courses)
{
global $purification_option_for_usernames;
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$msg = '';
foreach ($courses as $index => $course) {
$course_language = api_get_valid_language($course['Language']);
$username = '';
$teachers = getTeacherListInArray($course['Teacher']);
$teacherList = array();
$creatorId = api_get_user_id();
if (!empty($teachers)) {
foreach ($teachers as $teacher) {
$teacherInfo = api_get_user_info_from_username($teacher);
if (!empty($teacherInfo)) {
$teacherList[] = $teacherInfo;
}
}
}
$params = array();
$params['title'] = $course['Title'];
$params['wanted_code'] = $course['Code'];
$params['tutor_name'] = null;
$params['course_category'] = $course['CourseCategory'];
$params['course_language'] = $course_language;
$params['user_id'] = $creatorId;
$course_info = CourseManager::create_course($params);
if (!empty($course_info)) {
if (!empty($teacherList)) {
foreach ($teacherList as $teacher) {
CourseManager::add_user_to_course($teacher['user_id'], $course_info['code'], COURSEMANAGER);
}
}
$msg .= '<a href="' . api_get_path(WEB_COURSE_PATH) . $course_info['directory'] . '/">
' . $course_info['title'] . '</a> ' . get_lang('Created') . '<br />';
}
}
if (!empty($msg)) {
Display::display_normal_message($msg, false);
}
}
示例12: importCourses
/**
* @param string $file
*/
private function importCourses($file)
{
$data = Import::csv_to_array($file);
//$language = $this->defaultLanguage;
if (!empty($data)) {
$this->logger->addInfo(count($data) . " records found.");
foreach ($data as $row) {
$row = $this->cleanCourseRow($row);
$courseCode = CourseManager::get_course_id_from_original_id($row['extra_' . $this->extraFieldIdNameList['course']], $this->extraFieldIdNameList['course']);
//$courseInfo = api_get_course_info($row['course_code']);
$courseInfo = api_get_course_info($courseCode);
if (empty($courseInfo)) {
// Create
$params = array();
$params['title'] = $row['title'];
$params['exemplary_content'] = false;
$params['wanted_code'] = $row['course_code'];
$params['course_category'] = $row['course_category'];
$params['course_language'] = $row['language'];
$params['teachers'] = $row['teachers'];
$courseInfo = CourseManager::create_course($params);
if (!empty($courseInfo)) {
CourseManager::update_course_extra_field_value($courseInfo['code'], 'external_course_id', $row['extra_' . $this->extraFieldIdNameList['course']]);
$this->logger->addInfo("Courses - Course created " . $courseInfo['code']);
} else {
$this->logger->addError("Courses - Can't create course:" . $row['title']);
}
} else {
// Update
$params = array('title' => $row['title']);
$result = CourseManager::update_attributes($courseInfo['real_id'], $params);
//CourseManager::updateTeachers($courseInfo['id'], $row['teachers']);
if ($result) {
$this->logger->addInfo("Courses - Course updated " . $courseInfo['code']);
} else {
$this->logger->addError("Courses - Course NOT updated " . $courseInfo['code']);
}
}
}
}
$this->moveFile($file);
}
示例13: save_data
/**
* Saves imported data.
* @param array $courses List of courses
*/
function save_data($courses)
{
$msg = '';
foreach ($courses as $course) {
$course_language = $course['Language'];
$teachers = getTeacherListInArray($course['Teacher']);
$teacherList = array();
$creatorId = api_get_user_id();
if (!empty($teachers)) {
foreach ($teachers as $teacher) {
$teacherInfo = api_get_user_info_from_username($teacher);
if (!empty($teacherInfo)) {
$teacherList[] = $teacherInfo;
}
}
}
$params = array();
$params['title'] = $course['Title'];
$params['wanted_code'] = $course['Code'];
$params['tutor_name'] = null;
$params['course_category'] = $course['CourseCategory'];
$params['course_language'] = $course_language;
$params['user_id'] = $creatorId;
$addMeAsTeacher = isset($_POST['add_me_as_teacher']) ? $_POST['add_me_as_teacher'] : false;
$params['add_user_as_teacher'] = $addMeAsTeacher;
$courseInfo = CourseManager::create_course($params);
if (!empty($courseInfo)) {
if (!empty($teacherList)) {
foreach ($teacherList as $teacher) {
CourseManager::add_user_to_course($teacher['user_id'], $courseInfo['code'], COURSEMANAGER);
}
}
$msg .= '<a href="' . api_get_path(WEB_COURSE_PATH) . $courseInfo['directory'] . '/">
' . $courseInfo['title'] . '</a> ' . get_lang('Created') . '<br />';
}
}
if (!empty($msg)) {
Display::display_normal_message($msg, false);
}
}
示例14: create_test_course
/**
* This function create in the database a test course and will also load sessions.
* This name will be change each time is used in the tests.
* @param string Course name
* @return void
*/
function create_test_course($course_code = 'TESTCOURSE')
{
/* Table definitions */
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
$course_table = Database::get_main_table(TABLE_MAIN_COURSE);
$course_cat_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
global $_configuration, $_user, $_course, $cidReq;
$cidReq = $course_code;
/* Check if the course exists */
$sql = "SELECT code FROM {$table_course} WHERE code = '{$cidReq}' ";
$rs = Database::query($sql, __FILE__, __LINE__);
$row = Database::fetch_row($rs);
/* Create the course in the database */
if (empty($row[0])) {
// Create a course
$course_data = array('wanted_code' => $cidReq, 'title' => $cidReq, 'tutor_name' => 'John Doe', 'category_code' => 'LANG', 'course_language' => 'spanish', 'course_admin_id' => '001', 'db_prefix' => $_configuration['db_prefix'], 'firstExpirationDelay' => '999');
$res = CourseManager::create_course($course_data['wanted_code'], $course_data['title'], $course_data['tutor_name'], $course_data['category_code'], $course_data['course_language'], $course_data['course_admin_id'], $course_data['db_prefix'], $course_data['firstExpirationDelay']);
}
$sql = "SELECT course.*, course_category.code faCode, course_category.name faName\n\t FROM {$course_table}\n\t LEFT JOIN {$course_cat_table}\n\t ON course.category_code = course_category.code\n\t WHERE course.code = '{$cidReq}'";
$result = Database::query($sql);
/* Create the session */
if (Database::num_rows($result) > 0) {
$cData = Database::fetch_array($result);
$_cid = $cData['code'];
$_course = array();
$_course['id'] = $cData['code'];
//auto-assigned integer
$_course['name'] = $cData['title'];
$_course['official_code'] = $cData['visual_code'];
// use in echo
$_course['sysCode'] = $cData['code'];
// use as key in db
$_course['path'] = $cData['directory'];
// use as key in path
$_course['dbName'] = $cData['db_name'];
// use as key in db list
//$_course['dbNameGlu'] = $_configuration['table_prefix'].$cData['db_name'].$_configuration['db_glue']; // use in all queries
$_course['titular'] = $cData['tutor_name'];
$_course['language'] = $cData['course_language'];
$_course['extLink']['url'] = $cData['department_url'];
$_course['extLink']['name'] = $cData['department_name'];
$_course['categoryCode'] = $cData['faCode'];
$_course['categoryName'] = $cData['faName'];
$_course['visibility'] = $cData['visibility'];
$_course['subscribe_allowed'] = $cData['subscribe'];
$_course['unsubscribe'] = $cData['unsubscribe'];
Session::write('_cid', $_cid);
Session::write('_course', $_course);
}
/* Load the session */
$_SESSION['_user']['user_id'] = 1;
$_SESSION['is_courseAdmin'] = 1;
$_SESSION['show'] = showall;
/* Load the user */
$_user['user_id'] = $_SESSION['_user']['user_id'];
}
示例15: importCourses
/**
* @param string $file
* @param bool $moveFile
*/
private function importCourses($file, $moveFile = true)
{
$data = Import::csvToArray($file);
if (!empty($data)) {
$this->logger->addInfo(count($data) . " records found.");
foreach ($data as $row) {
$row = $this->cleanCourseRow($row);
$courseId = CourseManager::getCourseInfoFromOriginalId($row['extra_' . $this->extraFieldIdNameList['course']], $this->extraFieldIdNameList['course']);
$courseInfo = api_get_course_info_by_id($courseId);
if (empty($courseInfo)) {
// Create
$params = array();
$params['title'] = $row['title'];
$params['exemplary_content'] = false;
$params['wanted_code'] = $row['course_code'];
$params['course_category'] = $row['course_category'];
$params['course_language'] = $row['language'];
$params['teachers'] = $row['teachers'];
$courseInfo = CourseManager::create_course($params);
if (!empty($courseInfo)) {
CourseManager::update_course_extra_field_value($courseInfo['code'], 'external_course_id', $row['extra_' . $this->extraFieldIdNameList['course']]);
$this->logger->addInfo("Courses - Course created " . $courseInfo['code']);
} else {
$this->logger->addError("Courses - Can't create course:" . $row['title']);
}
} else {
// Update
$params = array('title' => $row['title']);
$result = CourseManager::update_attributes($courseInfo['real_id'], $params);
$addTeacherToSession = isset($courseInfo['add_teachers_to_sessions_courses']) && !empty($courseInfo['add_teachers_to_sessions_courses']) ? true : false;
if ($addTeacherToSession) {
CourseManager::updateTeachers($courseInfo['real_id'], $row['teachers'], false, true, false);
} else {
CourseManager::updateTeachers($courseInfo['real_id'], $row['teachers'], false, false);
}
if ($result) {
$this->logger->addInfo("Courses - Course updated " . $courseInfo['code']);
} else {
$this->logger->addError("Courses - Course NOT updated " . $courseInfo['code']);
}
}
}
}
if ($moveFile) {
$this->moveFile($file);
}
}