/** * Creates a session * @param array Fields to use in the creation of the session * @param boolean Whether to allow for same-name sessions or not. * @assert (array()) === false */ public static function add($params, $allow_homonyms = false) { global $_configuration; //just in case if (isset($params['id'])) { unset($params['id']); } //Check portal limits $access_url_id = 1; if (api_is_multiple_url_enabled()) { $access_url_id = api_get_current_access_url_id(); } if (is_array($_configuration[$access_url_id]) && isset($_configuration[$access_url_id]['hosting_limit_sessions']) && $_configuration[$access_url_id]['hosting_limit_sessions'] > 0) { $num = self::count_sessions(); if ($num >= $_configuration[$access_url_id]['hosting_limit_sessions']) { return get_lang('PortalSessionsLimitReached'); } } if (!$allow_homonyms) { $my_session_result = SessionManager::get_session_by_name($params['name']); $session_id = null; if ($my_session_result == false) { $session_model = new SessionModel(); $session_id = $session_model->save($params); } else { error_log('Session already exists with name: ' . $params['name'] . " session_id: " . $my_session_result['id']); } } else { //with the allow_homonyms option, two sessions can share names $session_model = new SessionModel(); $session_id = $session_model->save($params); } if (!empty($session_id)) { /* Sends a message to the user_id = 1 $user_info = api_get_user_info(1); $complete_name = $user_info['firstname'].' '.$user_info['lastname']; $subject = api_get_setting('siteName').' - '.get_lang('ANewSessionWasCreated'); $message = get_lang('ANewSessionWasCreated')." <br /> ".get_lang('NameOfTheSession').' : '.$name; api_mail_html($complete_name, $user_info['email'], $subject, $message); * */ //Saving extra fields $session_field_value = new SessionFieldValue(); $params['session_id'] = $session_id; $session_field_value->save_field_values($params); //Adding to the correct URL $access_url_id = api_get_current_access_url_id(); UrlManager::add_session_to_url($session_id, $access_url_id); // Add event to system log event_system(LOG_SESSION_CREATE, LOG_SESSION_ID, $session_id, api_get_utc_datetime(), api_get_user_id()); if (isset($params['course_code'])) { $courseInfo = api_get_course_info($params['course_code']); self::add_courses_to_session($session_id, array($courseInfo['real_id'])); //Update default course gradebook to the session if exists $create_gradebook_evaluation = isset($params['create_gradebook_evaluation']) ? $params['create_gradebook_evaluation'] : false; if ($create_gradebook_evaluation) { require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/gradebook_functions.inc.php'; $category_id = create_default_course_gradebook($params['course_code'], false, $session_id); /* if ($category_id && isset($params['gradebook_params'])) { $eval = new Evaluation(); $eval->set_name($params['gradebook_params']['name']); $eval->set_user_id($params['gradebook_params']['user_id']); $eval->set_course_code($params['course_code']); $eval->set_category_id($category_id); $eval->set_weight($params['gradebook_params']['weight']); $eval->set_max($params['gradebook_params']['max']); $eval->set_visible(0); $eval->add(); }*/ /*$tbl_gradebook_category = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); $sql = "SELECT id FROM $tbl_gradebook_category WHERE course_code = {$params['course_code']} AND session_id = 0 LIMIT 1"; $result = Database::query($sql); if (Database::num_rows($result)) { $gradebook_data = Database::fetch_array($result, 'ASSOC'); if (!empty($gradebook_data)) { $sql = "UPDATE SET session_id = $session_id WHERE id = {$gradebook_data['id']}"; Database::query($sql); } }*/ } } } else { if (isset($params['return_item_if_already_exists']) && $params['return_item_if_already_exists']) { $my_session_result = SessionManager::get_session_by_name($params['name']); $session_id = $my_session_result['id']; } } return $session_id; }
static function transaction_32($original_data, $web_service_details) { global $data_list; $data = Migration::soap_call($web_service_details, 'notaDetalles', array('uididpersona' => $original_data['item_id'], 'uididprograma' => $original_data['orig_id'], 'intIdSede' => $original_data['branch_id'])); if ($data['error'] == false) { $uidIdPrograma = $original_data['orig_id']; $uidIdPersona = $original_data['item_id']; $session_id = self::get_session_id_by_programa_id($uidIdPrograma, $data_list); $user_id = self::get_user_id_by_persona_id($uidIdPersona, $data_list); if (empty($user_id)) { return array('message' => "User does not exists in DB: {$uidIdPersona}", 'status_id' => self::TRANSACTION_STATUS_FAILED); } if (empty($session_id)) { return array('message' => "Session does not exists in DB: {$uidIdPrograma}", 'status_id' => self::TRANSACTION_STATUS_FAILED); } $course_list = SessionManager::get_course_list_by_session_id($session_id); if (!empty($course_list)) { $course_data = current($course_list); if (isset($course_data['code'])) { $gradebook = null; if (!empty($data_list['session_course_gradebook'][$course_data['code']][$session_id])) { $gradebook['id'] = $data_list['session_course_gradebook'][$course_data['code']][$session_id]; } else { $gradebook = new Gradebook(); $gradebook = $gradebook->get_first(array('where' => array('course_code = ? AND session_id = ?' => array($course_data['code'], $session_id)))); error_log("Searching for gradebook in course code: {$course_data['code']} - session_id: {$session_id}"); if (count($gradebook) === 0) { require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/gradebook_functions.inc.php'; $gradebook = array('id' => create_default_course_gradebook($course_data['code'], false, $session_id)); error_log('Gradebook not found. Creating one with ID ' . $gradebook['id']); $data_list['session_course_gradebook'][$course_data['code']][$session_id] = $gradebook['id']; } } // At this point we tried 3 different ways of obtaining a // gradebook id, so no chance to fail (hopefully) if (!empty($gradebook)) { //Check if gradebook exists $eval = new Evaluation(); $evals_found = $eval->load(null, null, null, $gradebook['id'], null, null); if (!empty($evals_found)) { error_log("Gradebook exists: {$gradebook['id']}"); $evaluation = current($evals_found); $eval_id = $evaluation->get_id(); //Eval found $res = new Result(); $check_result = Result::load(null, $user_id, $eval_id); if (!empty($check_result)) { $res->set_evaluation_id($eval_id); $res->set_user_id($user_id); $res->delete(); $eval_result = Result::load(null, $user_id, $eval_id); return array('entity' => 'gradebook_evaluation_result', 'before' => $check_result, 'after' => $eval_result, 'message' => "Gradebook result deleted ", 'status_id' => self::TRANSACTION_STATUS_SUCCESSFUL); } else { $message = "Gradebook result does not exist for user_id: {$user_id} - eval_id {$eval_id} - in course: {$course_data['code']} - session_id: {$session_id} "; } } else { $message = "Evaluation not found in gradebook: {$gradebook['id']} : in course: {$course_data['code']} - session_id: {$session_id}"; } } else { $message = "Gradebook does not exists in course: {$course_data['code']} - session_id: {$session_id}"; } } else { $message = "Something is wrong with the course "; } } else { $message = "NO course found for session id: {$session_id}"; } return array('message' => $message, 'status_id' => self::TRANSACTION_STATUS_FAILED); } else { return $data; } }
function load_gradebook_select_in_tool($form) { $course_code = api_get_course_id(); $session_id = api_get_session_id(); if (api_is_allowed_to_edit(true, true)) { create_default_course_gradebook(); } //Cat list $all_categories = Category::load(null, null, $course_code, null, null, $session_id, false); $select_gradebook = $form->addElement('select', 'category_id', get_lang('SelectGradebook')); if (!empty($all_categories)) { foreach ($all_categories as $my_cat) { if ($my_cat->get_course_code() == api_get_course_id()) { $grade_model_id = $my_cat->get_grade_model_id(); if (empty($grade_model_id)) { if ($my_cat->get_parent_id() == 0) { //$default_weight = $my_cat->get_weight(); $select_gradebook->addoption(get_lang('Default'), $my_cat->get_id()); $cats_added[] = $my_cat->get_id(); } else { $select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id()); $cats_added[] = $my_cat->get_id(); } } else { $select_gradebook->addoption(get_lang('Select'), 0); } /*if ($this->evaluation_object->get_category_id() == $my_cat->get_id()) { $default_weight = $my_cat->get_weight(); } */ } } } }
/** * Creates a course * @param array with the columns in the main.course table * @param mixed false if the course was not created, array with the course info * @return mixed False on error, or an array with course attributes on success * @todo remove globals * @assert () === false */ public static function create_course($params) { global $_configuration; // Check portal limits $access_url_id = 1; if (api_get_multiple_access_url()) { $access_url_id = api_get_current_access_url_id(); } if (is_array($_configuration[$access_url_id]) && isset($_configuration[$access_url_id]['hosting_limit_courses']) && $_configuration[$access_url_id]['hosting_limit_courses'] > 0) { $num = self::count_courses(); if ($num >= $_configuration[$access_url_id]['hosting_limit_courses']) { return api_set_failure('PortalCoursesLimitReached'); } } if (empty($params['title'])) { return false; } if (empty($params['wanted_code'])) { $params['wanted_code'] = $params['title']; // Check whether the requested course code has already been occupied. $params['wanted_code'] = self::generate_course_code(api_substr($params['title'], 0, self::MAX_COURSE_LENGTH_CODE)); } // Create the course keys $keys = self::define_course_keys($params['wanted_code']); $params['exemplary_content'] = isset($params['exemplary_content']) ? $params['exemplary_content'] : false; if (count($keys)) { $params['code'] = $keys['currentCourseCode']; $params['visual_code'] = $keys['currentCourseId']; $params['directory'] = $keys['currentCourseRepository']; $course_info = api_get_course_info($params['code']); if (empty($course_info)) { $course_id = self::register_course($params); $course_info = api_get_course_info_by_id($course_id); if (!empty($course_info)) { self::prepare_course_repository($course_info['directory'], $course_info['code']); self::fill_db_course($course_id, $course_info['directory'], $course_info['course_language'], $params['exemplary_content']); //Create an empty gradebook if (isset($params['create_gradebook_evaluation']) && $params['create_gradebook_evaluation'] == true) { require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/gradebook_functions.inc.php'; $category_id = create_default_course_gradebook($course_info['code']); if ($category_id && isset($params['gradebook_params'])) { $eval = new Evaluation(); $eval->set_name($params['gradebook_params']['name']); $eval->set_user_id($params['gradebook_params']['user_id']); $eval->set_course_code($course_info['code']); $eval->set_category_id($category_id); $eval->set_weight($params['gradebook_params']['weight']); $eval->set_max($params['gradebook_params']['max']); $eval->set_visible(0); $eval->add(); } } if (api_get_setting('gradebook.gradebook_enable_grade_model') == 'true') { //Create gradebook_category for the new course and add a gradebook model for the course if (isset($params['gradebook_model_id']) && !empty($params['gradebook_model_id']) && $params['gradebook_model_id'] != '-1') { require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/gradebook_functions.inc.php'; create_default_course_gradebook($course_info['code'], $params['gradebook_model_id']); } } //Saving extra course fields $field_value = new ExtraFieldValue('course'); $params['course_code'] = $course_info['code']; $field_value->save_field_values($params); return $course_info; } } else { //Course already exists if (isset($params['return_item_if_already_exists']) && $params['return_item_if_already_exists']) { return $course_info; } } } return false; }
/** * Creates a course * @param array $params columns in the main.course table * * @return mixed false if the course was not created, array with the course info */ public static function create_course($params) { global $_configuration; // Check portal limits $access_url_id = 1; if (api_get_multiple_access_url()) { $access_url_id = api_get_current_access_url_id(); } if (isset($_configuration[$access_url_id]) && is_array($_configuration[$access_url_id])) { if (isset($_configuration[$access_url_id]['hosting_limit_courses']) && $_configuration[$access_url_id]['hosting_limit_courses'] > 0) { $num = self::count_courses($access_url_id); if ($num >= $_configuration[$access_url_id]['hosting_limit_courses']) { api_warn_hosting_contact('hosting_limit_courses'); return api_set_failure(get_lang('PortalCoursesLimitReached')); } } if (isset($_configuration[$access_url_id]['hosting_limit_active_courses']) && $_configuration[$access_url_id]['hosting_limit_active_courses'] > 0) { $num = self::countActiveCourses($access_url_id); if ($num >= $_configuration[$access_url_id]['hosting_limit_active_courses']) { api_warn_hosting_contact('hosting_limit_active_courses'); return api_set_failure(get_lang('PortalActiveCoursesLimitReached')); } } } if (empty($params['title'])) { return false; } if (empty($params['wanted_code'])) { $params['wanted_code'] = $params['title']; // Check whether the requested course code has already been occupied. $params['wanted_code'] = generate_course_code(api_substr($params['title'], 0, self::MAX_COURSE_LENGTH_CODE)); } // Create the course keys $keys = define_course_keys($params['wanted_code']); $params['exemplary_content'] = isset($params['exemplary_content']) ? $params['exemplary_content'] : false; if (count($keys)) { $params['code'] = $keys['currentCourseCode']; $params['visual_code'] = $keys['currentCourseId']; $params['directory'] = $keys['currentCourseRepository']; $course_info = api_get_course_info($params['code']); if (empty($course_info)) { $course_id = register_course($params); $course_info = api_get_course_info_by_id($course_id); if (!empty($course_info)) { prepare_course_repository($course_info['directory'], $course_info['code']); fill_db_course($course_id, $course_info['directory'], $course_info['course_language'], $params['exemplary_content']); if (api_get_setting('gradebook_enable_grade_model') == 'true') { //Create gradebook_category for the new course and add a gradebook model for the course if (isset($params['gradebook_model_id']) && !empty($params['gradebook_model_id']) && $params['gradebook_model_id'] != '-1') { require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/gradebook_functions.inc.php'; create_default_course_gradebook($course_info['code'], $params['gradebook_model_id']); } } // If parameter defined, copy the contents from a specific // template course into this new course if (!empty($_configuration['course_creation_use_template'])) { // Include the necessary libraries to generate a course copy require_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php'; require_once api_get_path(SYS_CODE_PATH) . 'coursecopy/classes/CourseBuilder.class.php'; require_once api_get_path(SYS_CODE_PATH) . 'coursecopy/classes/CourseRestorer.class.php'; require_once api_get_path(SYS_CODE_PATH) . 'coursecopy/classes/CourseSelectForm.class.php'; // Call the course copy object $originCourse = api_get_course_info_by_id($_configuration['course_creation_use_template']); $originCourse['official_code'] = $originCourse['code']; $cb = new CourseBuilder(null, $originCourse); $course = $cb->build(null, $originCourse['code']); $cr = new CourseRestorer($course); $cr->set_file_option(); $cr->restore($course_info['id']); //course_info[id] is the course.code value (I know...) } return $course_info; } } } return false; }