skala
Julio Montoya 12 years ago
commit 19af5453fb
  1. 7
      main/inc/ajax/exercise.ajax.php
  2. 106
      main/inc/lib/extra_field_value.lib.php
  3. 89
      main/inc/lib/sessionmanager.lib.php
  4. 87
      tests/migrate/migration.custom.class.php
  5. 55
      tests/migrate/report_sql.php

@ -70,11 +70,11 @@ switch ($action) {
$start = 0; $start = 0;
} }
$sql = "SELECT exe_id, exe_user_id, firstname, lastname, aa.status, start_date, exe_result, exe_weighting, exe_result/exe_weighting as score, exe_duration, questions_to_check, orig_lp_id $sql = "SELECT exe_id, exe_user_id, firstname, lastname, aa.status, start_date, exe_result, exe_weighting, exe_result/exe_weighting as score, exe_duration, questions_to_check, orig_lp_id, aa.qlist as qlist
FROM $user_table u FROM $user_table u
INNER JOIN ( INNER JOIN (
SELECT t.exe_id, t.exe_user_id, status, SELECT t.exe_id, t.exe_user_id, status,
start_date, exe_result, exe_weighting, exe_result/exe_weighting as score, exe_duration, questions_to_check, orig_lp_id start_date, exe_result, exe_weighting, exe_result/exe_weighting as score, exe_duration, questions_to_check, orig_lp_id, t.data_tracking as qlist
FROM $track_exercise t LEFT JOIN $track_attempt a ON (a.exe_id = t.exe_id AND t.exe_user_id = a.user_id ) FROM $track_exercise t LEFT JOIN $track_attempt a ON (a.exe_id = t.exe_id AND t.exe_user_id = a.user_id )
WHERE t.status = 'incomplete' AND WHERE t.status = 'incomplete' AND
$where_condition $where_condition
@ -100,6 +100,7 @@ switch ($action) {
if (!empty($results)) { if (!empty($results)) {
foreach($results as $row) { foreach($results as $row) {
$qcount = count(split(',',$row['qlist']));
$sql = "SELECT SUM(count_question_id) as count_question_id FROM ( $sql = "SELECT SUM(count_question_id) as count_question_id FROM (
SELECT 1 as count_question_id FROM $track_attempt a SELECT 1 as count_question_id FROM $track_attempt a
WHERE user_id = {$row['exe_user_id']} and exe_id = {$row['exe_id']} WHERE user_id = {$row['exe_user_id']} and exe_id = {$row['exe_id']}
@ -119,7 +120,7 @@ switch ($action) {
$array = array( $row['firstname'], $array = array( $row['firstname'],
$row['lastname'], $row['lastname'],
api_format_date($row['start_date'], DATE_TIME_FORMAT_LONG).' ['.($h>0?$h.':':'').sprintf("%02d",$m).':'.sprintf("%02d",$s).']', api_format_date($row['start_date'], DATE_TIME_FORMAT_LONG).' ['.($h>0?$h.':':'').sprintf("%02d",$m).':'.sprintf("%02d",$s).']',
$row['count_questions'], $row['count_questions'].'/'.$qcount,
round($row['score']*100).'%' round($row['score']*100).'%'
); );
$response->rows[$i]['cell'] = $array; $response->rows[$i]['cell'] = $array;

@ -1,10 +1,23 @@
<?php <?php
/**
* Declaration for the ExtraFieldValue class, managing the values in extra
* fields for any datatype
* @package chamilo.library
*/
/**
* Class managing the values in extra fields for any datatype
* @package chamilo.library.extrafields
*/
class ExtraFieldValue extends Model { class ExtraFieldValue extends Model {
public $type = null; public $type = null;
public $columns = array('id', 'field_id', 'field_value', 'tms'); public $columns = array('id', 'field_id', 'field_value', 'tms');
public $handler_id = null;//session_id, course_code, user_id public $handler_id = null;//session_id, course_code, user_id
/**
* Formats the necessary elements for the given datatype
* @param string The type of data to which this extra field applies (user, course, session, ...)
* @return void (or false if unmanaged datatype)
* @assert (-1) === false
*/
public function __construct($type) { public function __construct($type) {
$this->type = $type; $this->type = $type;
$extra_field = new ExtraField($this->type); $extra_field = new ExtraField($this->type);
@ -22,15 +35,29 @@ class ExtraFieldValue extends Model {
$this->table = Database::get_main_table(TABLE_MAIN_SESSION_FIELD_VALUES); $this->table = Database::get_main_table(TABLE_MAIN_SESSION_FIELD_VALUES);
$this->table_handler_field = Database::get_main_table(TABLE_MAIN_SESSION_FIELD); $this->table_handler_field = Database::get_main_table(TABLE_MAIN_SESSION_FIELD);
break; break;
default:
//unmanaged datatype, return false to let the caller know it
// didn't work
return false;
} }
$this->columns[] = $this->handler_id; $this->columns[] = $this->handler_id;
} }
/**
* Gets the number of values stored in the table (all fields together)
* for this type of resource
* @return integer Number of rows in the table
* @assert () !== false
*/
public function get_count() { public function get_count() {
$row = Database::select('count(*) as count', $this->table, array(), 'first'); $row = Database::select('count(*) as count', $this->table, array(), 'first');
return $row['count']; return $row['count'];
} }
/**
* Saves a series of records given as parameter into the coresponding table
* @param array Structured parameter for the insertion into the *_field_values table
* @return mixed false on empty params, void otherwise
* @assert (array()) === false
*/
public function save_field_values($params) { public function save_field_values($params) {
$extra_field = new ExtraField($this->type); $extra_field = new ExtraField($this->type);
if (empty($params[$this->handler_id])) { if (empty($params[$this->handler_id])) {
@ -53,7 +80,13 @@ class ExtraFieldValue extends Model {
} }
} }
} }
/**
* Save values in the *_field_values table
* @param array Structured array with the values to save
* @param boolean Whether to show the insert query (passed to the parent save() method)
* @result mixed The result sent from the parent method
* @assert (array()) === false
*/
public function save($params, $show_query = false) { public function save($params, $show_query = false) {
$extra_field = new ExtraField($this->type); $extra_field = new ExtraField($this->type);
@ -124,11 +157,12 @@ class ExtraFieldValue extends Model {
} }
/** /**
* * Returns the value of the given extra field on the given resource
* @param int handler_id (It could be a session_id, course_id or user_id) * @param int Item ID (It could be a session_id, course_id or user_id)
* @param int $field_id * @param int Field ID (the ID from the *_field table)
* @param bool transform the result to a human readable strings * @param bool Whether to transform the result to a human readable strings
* @return boolean * @return mixed A structured array with the field_id and field_value, or fals on error
* @assert (-1,-1) === false
*/ */
public function get_values_by_handler_and_field_id($item_id, $field_id, $transform = false) { public function get_values_by_handler_and_field_id($item_id, $field_id, $transform = false) {
$field_id = intval($field_id); $field_id = intval($field_id);
@ -172,7 +206,14 @@ class ExtraFieldValue extends Model {
return false; return false;
} }
} }
/**
* Gets a structured array of the original item and its extra values, using
* a specific original item and a field name (like "branch", or "birthdate")
* @param int Item ID from the original table
* @param string The name of the field we are looking for
* @return mixed Array of results, or false on error or not found
* @assert (-1,'') === false
*/
public function get_values_by_handler_and_field_variable($item_id, $field_variable, $transform = false) { public function get_values_by_handler_and_field_variable($item_id, $field_variable, $transform = false) {
$field_id = intval($field_id); $field_id = intval($field_id);
$item_id = Database::escape_string($item_id); $item_id = Database::escape_string($item_id);
@ -206,8 +247,14 @@ class ExtraFieldValue extends Model {
return false; return false;
} }
} }
/**
* Gets the ID from the item (course, session, etc) for which
* the given field is defined with the given value
* @param string Field (type of data) we want to check
* @param string Data we are looking for in the given field
* @return mixed Give the ID if found, or false on failure or not found
* @assert (-1,-1) === false
*/
public function get_item_id_from_field_variable_and_field_value($field_variable, $field_value, $transform = false) { public function get_item_id_from_field_variable_and_field_value($field_variable, $field_value, $transform = false) {
$field_value = Database::escape_string($field_value); $field_value = Database::escape_string($field_value);
$field_variable = Database::escape_string($field_variable); $field_variable = Database::escape_string($field_variable);
@ -219,16 +266,19 @@ class ExtraFieldValue extends Model {
"; ";
$result = Database::query($sql); $result = Database::query($sql);
if (Database::num_rows($result)) { if ($result !== false && Database::num_rows($result)) {
$result = Database::fetch_array($result, 'ASSOC'); $result = Database::fetch_array($result, 'ASSOC');
return $result; return $result;
} else { } else {
return false; return false;
} }
} }
/**
* Get all values for a specific field id
/* Get all values by field id */ * @param int Field ID
* @return mixed Array of values on success, false on failure or not found
* @assert (-1) === false
*/
public function get_values_by_field_id($field_id) { public function get_values_by_field_id($field_id) {
$sql = "SELECT s.*, field_type FROM {$this->table} s INNER JOIN {$this->table_handler_field} sf ON (s.field_id = sf.id) $sql = "SELECT s.*, field_type FROM {$this->table} s INNER JOIN {$this->table_handler_field} sf ON (s.field_id = sf.id)
WHERE field_id = '".$field_id."' ORDER BY id"; WHERE field_id = '".$field_id."' ORDER BY id";
@ -238,20 +288,36 @@ class ExtraFieldValue extends Model {
} }
return false; return false;
} }
/**
* Deletes all the values related to a specific field ID
* @param int Field ID
* @return void
* @assert ('a') == null
*/
public function delete_all_values_by_field_id($field_id) { public function delete_all_values_by_field_id($field_id) {
$field_id = intval($field_id); $field_id = intval($field_id);
$sql = "DELETE FROM {$this->table} WHERE field_id = $field_id"; $sql = "DELETE FROM {$this->table} WHERE field_id = $field_id";
Database::query($sql); Database::query($sql);
} }
/**
* Deletes values of a specific field for a specific item
* @param int Item ID (session id, course id, etc)
* @param int Field ID
* @return void
* @assert (-1,-1) == null
*/
public function delete_values_by_handler_and_field_id($item_id, $field_id) { public function delete_values_by_handler_and_field_id($item_id, $field_id) {
$field_id = intval($field_id); $field_id = intval($field_id);
$item_id = Database::escape_string($item_id); $item_id = Database::escape_string($item_id);
$sql = "DELETE FROM {$this->table} WHERE {$this->handler_id} = '$item_id' AND field_id = '".$field_id."' "; $sql = "DELETE FROM {$this->table} WHERE {$this->handler_id} = '$item_id' AND field_id = '".$field_id."' ";
Database::query($sql); Database::query($sql);
} }
/**
* Not yet implemented - Compares the field values of two items
* @param int Item 1
* @param int Item 2
* @return mixed Differential array generated from the comparison
*/
public function compare_item_values($item_id, $item_to_compare) { public function compare_item_values($item_id, $item_to_compare) {
} }
} }

@ -8,9 +8,10 @@
* @package chamilo.library * @package chamilo.library
*/ */
/** /**
* Code * The SessionManager class manages all the Chamilo sessions (as in course
* groups).
* @package chamilo.library.session
*/ */
class SessionManager { class SessionManager {
//See BT#4871 //See BT#4871
@ -24,6 +25,7 @@ class SessionManager {
* Fetches a session from the database * Fetches a session from the database
* @param int Session ID * @param int Session ID
* @return array Session details * @return array Session details
* @assert (-1) === array()
*/ */
public static function fetch($id) { public static function fetch($id) {
$t = Database::get_main_table(TABLE_MAIN_SESSION); $t = Database::get_main_table(TABLE_MAIN_SESSION);
@ -33,8 +35,13 @@ class SessionManager {
if (Database::num_rows($r) != 1) { return array(); } if (Database::num_rows($r) != 1) { return array(); }
return Database::fetch_array($r,'ASSOC'); return Database::fetch_array($r,'ASSOC');
} }
/**
public static function add($params) { * 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; global $_configuration;
//just in case //just in case
@ -54,6 +61,7 @@ class SessionManager {
return get_lang('PortalSessionsLimitReached'); return get_lang('PortalSessionsLimitReached');
} }
} }
if (!$allow_homonyms) {
$my_session_result = SessionManager::get_session_by_name($params['name']); $my_session_result = SessionManager::get_session_by_name($params['name']);
$session_id = null; $session_id = null;
@ -61,7 +69,12 @@ class SessionManager {
$session_model = new SessionModel(); $session_model = new SessionModel();
$session_id = $session_model->save($params); $session_id = $session_model->save($params);
} else { } else {
error_log('Session already exits with name: '.$params['name']." session_id: ".$my_session_result['id']); 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)) { if (!empty($session_id)) {
@ -129,8 +142,16 @@ class SessionManager {
} }
return $session_id; return $session_id;
} }
/**
* Updates a session with the given array of field values
* @param array An array of fields values
* @return void
* @assert (null) === false
*/
public static function update($params) { public static function update($params) {
if (empty($params) || count($params)<1) {
return false;
}
$session_model = new SessionModel(); $session_model = new SessionModel();
$session_model->update($params); $session_model->update($params);
@ -141,16 +162,23 @@ class SessionManager {
$session_field_value->save_field_values($params); $session_field_value->save_field_values($params);
} }
} }
/**
* Checks whether a session already exists with the given name (used in
* add() to avoid homonym sessions)
* @param string A session name
* @assert ('') === false
*/
function session_name_exists($session_name) { function session_name_exists($session_name) {
$session_name = Database::escape_string($session_name); $session_name = Database::escape_string($session_name);
$result = Database::fetch_array(Database::query("SELECT COUNT(*) as count FROM ".Database::get_main_table(TABLE_MAIN_SESSION)." WHERE name = '$session_name' ")); $result = Database::fetch_array(Database::query("SELECT COUNT(*) as count FROM ".Database::get_main_table(TABLE_MAIN_SESSION)." WHERE name = '$session_name' "));
return $result['count'] > 0; return $result['count'] > 0;
} }
/** /**
* Gets the admin session list callback of the admin/session_list.php page * Gets the admin session list callback of the admin/session_list.php page
* @param array order and limit keys * @param array order and limit keys
* @param boolean Whether to get all the results or only the count
* @return mixed Integer for number of rows, or array of results
* @assert (array(),true) !== false
*/ */
public static function get_sessions_admin($options = array(), $get_count = false) { public static function get_sessions_admin($options = array(), $get_count = false) {
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
@ -332,8 +360,17 @@ class SessionManager {
return $formatted_sessions; return $formatted_sessions;
} }
/**
* Gets the number of rows in the session table filtered through the given
* array of parameters
* @param array Array of options/filters/keys
* @return integer The number of rows, or false on wrong param
* @assert ('a') === false
*/
static function get_count_admin_complete($options = array()) { static function get_count_admin_complete($options = array()) {
if (!is_array($options)) {
return false;
}
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY); $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER); $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
@ -380,13 +417,17 @@ class SessionManager {
$num = $recorset['total_rows']; $num = $recorset['total_rows'];
return $num; return $num;
} }
/** /**
* Gets the admin session list callback of the admin/session_list.php page with all user/details * Gets the admin session list callback of the admin/session_list.php
* page with all user/details in the right fomat
* @param array order and limit keys * @param array order and limit keys
* @result array Array of rows results
* @asset ('a') === false
*/ */
public static function get_sessions_admin_complete($options = array()) { public static function get_sessions_admin_complete($options = array()) {
if (!is_array($options)) {
return false;
}
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY); $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER); $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
@ -403,7 +444,6 @@ class SessionManager {
} }
$coach_name = " CONCAT (u.lastname , ' ', u.firstname) as coach_name "; $coach_name = " CONCAT (u.lastname , ' ', u.firstname) as coach_name ";
if (api_is_western_name_order()) { if (api_is_western_name_order()) {
$coach_name = " CONCAT (u.firstname, ' ', u.lastname) as coach_name "; $coach_name = " CONCAT (u.firstname, ' ', u.lastname) as coach_name ";
} }
@ -530,9 +570,7 @@ class SessionManager {
foreach ($sessions as $session) { foreach ($sessions as $session) {
$session_id = $session['id']; $session_id = $session['id'];
$session['name'] = Display::url($session['name'], "resume_session.php?id_session=".$session['id']); $session['name'] = Display::url($session['name'], "resume_session.php?id_session=".$session['id']);
$session['coach_name'] = Display::url($session['coach_name'], "user_information.php?user_id=".$session['user_id']); $session['coach_name'] = Display::url($session['coach_name'], "user_information.php?user_id=".$session['user_id']);
if ($session['session_active'] == 1) { if ($session['session_active'] == 1) {
$session['session_active'] = Display::return_icon('accept.png', get_lang('Active'), array(), ICON_SIZE_SMALL); $session['session_active'] = Display::return_icon('accept.png', get_lang('Active'), array(), ICON_SIZE_SMALL);
} else { } else {
@ -591,7 +629,9 @@ class SessionManager {
return $formatted_sessions; return $formatted_sessions;
} }
/**
*
*/
static function compare_arrays_to_merge($array1, $array2) { static function compare_arrays_to_merge($array1, $array2) {
if (empty($array2)) { if (empty($array2)) {
return $array1; return $array1;
@ -606,8 +646,17 @@ class SessionManager {
} }
return $array1; return $array1;
} }
/**
* Converts all dates sent through the param array (given form) to correct
* dates with timezones
* @param array The dates
* @return array The same array, with times converted
* @assert ('a') === false
*/
static function convert_dates_to_local($params) { static function convert_dates_to_local($params) {
if (!is_array($params)) {
return false;
}
$params['display_start_date'] = api_get_local_time($params['display_start_date'], null, null, true); $params['display_start_date'] = api_get_local_time($params['display_start_date'], null, null, true);
$params['display_end_date'] = api_get_local_time($params['display_end_date'], null, null, true); $params['display_end_date'] = api_get_local_time($params['display_end_date'], null, null, true);
@ -624,8 +673,9 @@ class SessionManager {
* *
* @param string wanted code * @param string wanted code
* <code> * <code>
* $wanted_code = 'curse' if there are in the DB codes like curse1 curse2 the function will return: course3 * $wanted_code = 'sess' if there are names like sess, sess1, sess2 in the
* if the course code doest not exist in the DB the same course code will be returned * database already, the function will return: sess3
* if the session name doesn't exist in the DB the same name is returned
* </code> * </code>
* @return string wanted unused code * @return string wanted unused code
*/ */
@ -649,7 +699,6 @@ class SessionManager {
} }
return $session_name; return $session_name;
} }
/** /**
* Edit a session * Edit a session
* @author Carlos Vargas from existing code * @author Carlos Vargas from existing code

@ -47,6 +47,9 @@ class MigrationCustom {
const TRANSACTION_TYPE_ADD_INTENS = 25; const TRANSACTION_TYPE_ADD_INTENS = 25;
const TRANSACTION_TYPE_DEL_INTENS = 26; const TRANSACTION_TYPE_DEL_INTENS = 26;
const TRANSACTION_TYPE_EDIT_INTENS = 27; const TRANSACTION_TYPE_EDIT_INTENS = 27;
const TRANSACTION_TYPE_ADD_FASE = 28;
const TRANSACTION_TYPE_DEL_FASE = 29;
const TRANSACTION_TYPE_EDIT_FASE = 30;
static function get_transaction_status_list() { static function get_transaction_status_list() {
$table = Database::get_main_table(TABLE_MIGRATION_TRANSACTION_STATUS); $table = Database::get_main_table(TABLE_MIGRATION_TRANSACTION_STATUS);
@ -347,7 +350,7 @@ class MigrationCustom {
//Here the $data variable has $data['course_code'] that will be added when creating the session //Here the $data variable has $data['course_code'] that will be added when creating the session
// If session already exists, it will return the existing session id // If session already exists, it will return the existing session id
$session_id = SessionManager::add($data); $session_id = SessionManager::add($data, true);
//error_log('create_session'); //error_log('create_session');
if (!$session_id) { if (!$session_id) {
error_log('Error: Failed to create_session '.$data['name']); error_log('Error: Failed to create_session '.$data['name']);
@ -826,7 +829,6 @@ class MigrationCustom {
$uidIdPersona = $data['item_id']; $uidIdPersona = $data['item_id'];
$uidIdPrograma = $data['orig_id']; $uidIdPrograma = $data['orig_id'];
$uidIdProgramaDestination = $data['dest_id']; $uidIdProgramaDestination = $data['dest_id'];
$user_id = self::get_user_id_by_persona_id($uidIdPersona); $user_id = self::get_user_id_by_persona_id($uidIdPersona);
if (empty($user_id)) { if (empty($user_id)) {
@ -885,7 +887,8 @@ class MigrationCustom {
$session_id = self::get_session_id_by_programa_id($uidIdPrograma); $session_id = self::get_session_id_by_programa_id($uidIdPrograma);
if (!empty($session_id)) { if (!empty($session_id)) {
$before = SessionManager::get_user_status_in_session($session_id, $user_id); $before = SessionManager::get_user_status_in_session($session_id, $user_id);
SessionManager::suscribe_users_to_session($session_id, array($user_id), SESSION_VISIBLE_READ_ONLY, false, false); //SessionManager::suscribe_users_to_session($session_id, array($user_id), SESSION_VISIBLE_READ_ONLY, false, false);
SessionManager::unsubscribe_user_from_session($session_id, $user_id);
$message = "Move Session to empty"; $message = "Move Session to empty";
return self::check_if_user_is_subscribe_to_session($user_id, $session_id, $message, $before); return self::check_if_user_is_subscribe_to_session($user_id, $session_id, $message, $before);
} else { } else {
@ -1233,15 +1236,15 @@ class MigrationCustom {
//------- //-------
static function transaction_extra_field_agregar_generic($extra_field_variable, $original_data, $web_service_details) { static function transaction_extra_field_agregar_generic($extra_field_variable, $original_data, $web_service_details, $type='session') {
$function_name = $extra_field_variable."Detalles"; $function_name = $extra_field_variable."Detalles";
$data = Migration::soap_call($web_service_details, $function_name, array('intIdSede'=> $original_data['branch_id'], "uidid".$extra_field_variable => $original_data['item_id'])); $data = Migration::soap_call($web_service_details, $function_name, array('intIdSede'=> $original_data['branch_id'], "uidid".$extra_field_variable => $original_data['item_id']));
if ($data['error'] == false) { if ($data['error'] == false) {
$extra_field = new ExtraField('session'); $extra_field = new ExtraField($type);
$extra_field_info = $extra_field->get_handler_field_info_by_field_variable($extra_field_variable); $extra_field_info = $extra_field->get_handler_field_info_by_field_variable($extra_field_variable);
if ($extra_field_info) { if ($extra_field_info) {
$extra_field_option = new ExtraFieldOption('session'); $extra_field_option = new ExtraFieldOption($type);
$info_before = $extra_field_option->get_field_options_by_field($extra_field_info['id']); $info_before = $extra_field_option->get_field_options_by_field($extra_field_info['id']);
@ -1281,8 +1284,8 @@ class MigrationCustom {
} }
} }
static function transaction_extra_field_editar_generic($extra_field_variable, $original_data, $web_service_details) { static function transaction_extra_field_editar_generic($extra_field_variable, $original_data, $web_service_details, $type='session') {
$extra_field = new ExtraField('session'); $extra_field = new ExtraField($type);
$extra_field_info = $extra_field->get_handler_field_info_by_field_variable($extra_field_variable); $extra_field_info = $extra_field->get_handler_field_info_by_field_variable($extra_field_variable);
if (empty($extra_field_info)) { if (empty($extra_field_info)) {
return array( return array(
@ -1291,7 +1294,7 @@ class MigrationCustom {
); );
} }
$extra_field_option = new ExtraFieldOption('session'); $extra_field_option = new ExtraFieldOption($type);
$extra_field_option_info = $extra_field_option->get_field_option_by_field_and_option($extra_field_info['id'], $original_data['item_id']); $extra_field_option_info = $extra_field_option->get_field_option_by_field_and_option($extra_field_info['id'], $original_data['item_id']);
$function_name = $extra_field_variable."Detalles"; $function_name = $extra_field_variable."Detalles";
@ -1310,7 +1313,7 @@ class MigrationCustom {
//var_dump($extra_field_option_info); //var_dump($extra_field_option_info);
//Take the first one //Take the first one
error_log('Warning! There are several options with the same key. You should delete doubles. Check your DB with this query:'); error_log('Warning! There are several options with the same key. You should delete doubles. Check your DB with this query:');
error_log("SELECT * FROM session_field_options WHERE field_id = {$extra_field_info['id']} AND option_value = '{$original_data['item_id']}' "); error_log("SELECT * FROM ".$type."_field_options WHERE field_id = {$extra_field_info['id']} AND option_value = '{$original_data['item_id']}' ");
error_log('All options are going to be updated'); error_log('All options are going to be updated');
} }
@ -1324,6 +1327,7 @@ class MigrationCustom {
'option_order' => null 'option_order' => null
); );
$extra_field_option->update($extra_field_option_info); $extra_field_option->update($extra_field_option_info);
error_log('Editing extra field: '.print_r($extra_field_option_info,1));
$options_updated[] = $option['id']; $options_updated[] = $option['id'];
} }
@ -1350,11 +1354,11 @@ class MigrationCustom {
} }
/* Delete all options with option_value = item_id */ /* Delete all options with option_value = item_id */
static function transaction_extra_field_eliminar_generic($extra_field_variable, $original_data, $web_service_details) { //horario static function transaction_extra_field_eliminar_generic($extra_field_variable, $original_data, $web_service_details, $type='session') { //horario
$extra_field = new ExtraField('session'); $extra_field = new ExtraField($type);
$extra_field_info = $extra_field->get_handler_field_info_by_field_variable($extra_field_variable); $extra_field_info = $extra_field->get_handler_field_info_by_field_variable($extra_field_variable);
$extra_field_option = new ExtraFieldOption('session'); $extra_field_option = new ExtraFieldOption($type);
$extra_field_option_info = $extra_field_option->get_field_option_by_field_and_option($extra_field_info['id'], $original_data['item_id']); $extra_field_option_info = $extra_field_option->get_field_option_by_field_and_option($extra_field_info['id'], $original_data['item_id']);
if (!empty($extra_field_option_info)) { if (!empty($extra_field_option_info)) {
@ -1448,24 +1452,21 @@ class MigrationCustom {
return self::transaction_extra_field_editar_generic('sede', $data, $web_service_details); return self::transaction_extra_field_editar_generic('sede', $data, $web_service_details);
} }
//
// Frecuencia // Frecuencia
// añadir frec FID // añadir frec FID
// const TRANSACTION_TYPE_ADD_FREQ = 22; // const TRANSACTION_TYPE_ADD_FREQ = 22;
static function transaction_22($data, $web_service_details) { static function transaction_22($data, $web_service_details) {
return self::transaction_extra_field_agregar_generic('frecuencia', $data, $web_service_details); return self::transaction_extra_field_agregar_generic('frecuencia', $data, $web_service_details, 'course');
} }
// eliminar Freca_eliminar FID // eliminar Freca_eliminar FID
// const TRANSACTION_TYPE_DEL_FREQ = 23; // const TRANSACTION_TYPE_DEL_FREQ = 23;
static function transaction_23($data, $web_service_details) { static function transaction_23($data, $web_service_details) {
return self::transaction_extra_field_eliminar_generic('frecuencia', $data, $web_service_details); return self::transaction_extra_field_eliminar_generic('frecuencia', $data, $web_service_details, 'course');
} }
// editar aula_editar FID // editar aula_editar FID
// const TRANSACTION_TYPE_EDIT_FREQ = 24; // const TRANSACTION_TYPE_EDIT_FREQ = 24;
static function transaction_24($data, $web_service_details) { static function transaction_24($data, $web_service_details) {
return self::transaction_extra_field_editar_generic('frecuencia', $data, $web_service_details); return self::transaction_extra_field_editar_generic('frecuencia', $data, $web_service_details, 'course');
} }
// //
@ -1473,19 +1474,37 @@ class MigrationCustom {
// añadir intfase_agregar IID // añadir intfase_agregar IID
// const TRANSACTION_TYPE_ADD_INTENS = 25; // const TRANSACTION_TYPE_ADD_INTENS = 25;
static function transaction_25($data, $web_service_details) { static function transaction_25($data, $web_service_details) {
return self::transaction_extra_field_agregar_generic('intensidad', $data, $web_service_details); return self::transaction_extra_field_agregar_generic('intensidad', $data, $web_service_details, 'course');
} }
// eliminar intfase_eliminar IID // eliminar intfase_eliminar IID
// const TRANSACTION_TYPE_DEL_INTENS = 26; // const TRANSACTION_TYPE_DEL_INTENS = 26;
static function transaction_26($data, $web_service_details) { static function transaction_26($data, $web_service_details) {
return self::transaction_extra_field_eliminar_generic('intensidad', $data, $web_service_details); return self::transaction_extra_field_eliminar_generic('intensidad', $data, $web_service_details, 'course');
} }
// editar intfase_editar IID // editar intfase_editar IID
// const TRANSACTION_TYPE_EDIT_INTENS = 27; // const TRANSACTION_TYPE_EDIT_INTENS = 27;
static function transaction_27($data, $web_service_details) { static function transaction_27($data, $web_service_details) {
return self::transaction_extra_field_editar_generic('intensidad', $data, $web_service_details); return self::transaction_extra_field_editar_generic('intensidad', $data, $web_service_details, 'course');
}
// Fase
// añadir fase_agregar IID
// const TRANSACTION_TYPE_ADD_FASE = 28;
static function transaction_28($data, $web_service_details) {
return self::transaction_extra_field_agregar_generic('fase', $data, $web_service_details, 'course');
}
// eliminar fase_eliminar IID
// const TRANSACTION_TYPE_DEL_FASE = 29;
static function transaction_29($data, $web_service_details) {
return self::transaction_extra_field_eliminar_generic('fase', $data, $web_service_details, 'course');
}
// editar fase_editar IID
// const TRANSACTION_TYPE_EDIT_FASE = 30;
static function transaction_30($data, $web_service_details) {
return self::transaction_extra_field_editar_generic('fase', $data, $web_service_details, 'course');
} }
//custom class moved here //custom class moved here
@ -1579,9 +1598,9 @@ class MigrationCustom {
'transaction_id' => isset($transaction_info['idt']) ? $transaction_info['idt'] : null, 'transaction_id' => isset($transaction_info['idt']) ? $transaction_info['idt'] : null,
'action' => isset($transaction_info['ida']) ? $transaction_info['ida'] : null, 'action' => isset($transaction_info['ida']) ? $transaction_info['ida'] : null,
'item_id' => isset($transaction_info['id']) ? strtoupper($transaction_info['id']) : null, 'item_id' => isset($transaction_info['id']) ? strtoupper($transaction_info['id']) : null,
'orig_id' => isset($transaction_info['ido']) ? $transaction_info['ido'] : null, 'orig_id' => isset($transaction_info['orig']) ? $transaction_info['orig'] : null,
'branch_id' => isset($transaction_info['idsede']) ? $transaction_info['idsede'] : null, 'branch_id' => isset($transaction_info['idsede']) ? $transaction_info['idsede'] : null,
'dest_id' => isset($transaction_info['idd']) ? $transaction_info['idd'] : null, 'dest_id' => isset($transaction_info['dest']) ? $transaction_info['dest'] : null,
'status_id' => 0 'status_id' => 0
); );
@ -1703,6 +1722,7 @@ class MigrationCustom {
$result['status'] = $result['rol'] == 'profesor' ? COURSEMANAGER : STUDENT; $result['status'] = $result['rol'] == 'profesor' ? COURSEMANAGER : STUDENT;
$result['phone'] = (string)$result['phone']; $result['phone'] = (string)$result['phone'];
$result['active'] = (int)$result['bitvigencia'];
$result['extra_uidIdPersona'] = strtoupper($params['uididpersona']); $result['extra_uidIdPersona'] = strtoupper($params['uididpersona']);
unset($result['rol']); unset($result['rol']);
return $result; return $result;
@ -1754,6 +1774,14 @@ class MigrationCustom {
$sede_name = $extra_field_option_info_sede[0]['option_display_text']; $sede_name = $extra_field_option_info_sede[0]['option_display_text'];
} }
$extra_field_info = $extra_field->get_handler_field_info_by_field_variable('aula');
$extra_field_option_info_aula = $extra_field_option->get_field_option_by_field_and_option($extra_field_info['id'], $result['uididaula']);
$aula_name = null;
if (isset($extra_field_option_info_aula[0]) && !empty($extra_field_option_info_sede[0]['option_display_text'])) {
$aula_name = $extra_field_option_info_aula[0]['option_display_text'];
}
//Getting horario //Getting horario
$extra_field_info = $extra_field->get_handler_field_info_by_field_variable('horario'); $extra_field_info = $extra_field->get_handler_field_info_by_field_variable('horario');
$extra_field_option_info_horario = $extra_field_option->get_field_option_by_field_and_option($extra_field_info['id'], $result['uididhorario']); $extra_field_option_info_horario = $extra_field_option->get_field_option_by_field_and_option($extra_field_info['id'], $result['uididhorario']);
@ -1764,17 +1792,19 @@ class MigrationCustom {
} }
//Setting the session name //Setting the session name
$result['name'] = $result['chrperiodo']." - ".$course_info['title'].' '.$sede_name." ".$horario_name; $result['name'] = substr($sede_name,13).' - '.$result['chrperiodo']." - ".$course_info['title'].' '.$horario_name.' '.$aula_name;
$result['extra_uidIdPrograma'] = strtoupper($params['uididprograma']); $result['extra_uidIdPrograma'] = strtoupper($params['uididprograma']);
$result['extra_horario'] = strtoupper($result['uididhorario']); $result['extra_horario'] = strtoupper($result['uididhorario']);
$result['extra_sede'] = strtoupper($result['uididsede']); $result['extra_sede'] = strtoupper($result['uididsede']);
$result['extra_aula'] = strtoupper($result['uididaula']);
$result['extra_periodo'] = strtoupper($result['chrperiodo']); $result['extra_periodo'] = strtoupper($result['chrperiodo']);
$result['display_start_date'] = MigrationCustom::clean_date_time_from_ws($result['display_start_date']); $result['display_start_date'] = MigrationCustom::clean_date_time_from_ws($result['display_start_date']);
$result['display_end_date'] = MigrationCustom::clean_date_time_from_ws($result['display_end_date']); $result['display_end_date'] = MigrationCustom::clean_date_time_from_ws($result['display_end_date']);
$result['access_start_date'] = MigrationCustom::clean_date_time_from_ws($result['access_start_date']); $result['access_start_date'] = MigrationCustom::clean_date_time_from_ws($result['access_start_date']);
$result['access_end_date'] = MigrationCustom::clean_date_time_from_ws($result['access_end_date']); $result['access_end_date'] = MigrationCustom::clean_date_time_from_ws($result['access_end_date']);
//$result['estado'] = intval($result['estado']);
//Searching id_coach //Searching id_coach
$result['id_coach'] = MigrationCustom::get_user_id_by_persona_id($result['id_coach']); $result['id_coach'] = MigrationCustom::get_user_id_by_persona_id($result['id_coach']);
@ -1871,6 +1901,13 @@ class MigrationCustom {
return $result; return $result;
} }
static function aulaDetalles($data, $params) {
$result = self::genericDetalles($data, __FUNCTION__, $params);
if ($result['error'] == true) {
return $result;
}
return $result;
}
/*Calling sedeDetalles /*Calling sedeDetalles
array(1) { array(1) {
["name"]=> ["name"]=>

@ -0,0 +1,55 @@
<?php
require '../../main/inc/global.inc.php';
$alumnos = array();
$sql = "SELECT f.field_value, u.user_id from user_field_values f INNER JOIN user u ON u.user_id=f.user_id WHERE f.field_id='13' AND u.status=5";
$res = mysql_query($sql);
file_put_contents('/tmp/alumnos.sql','CREATE TABLE chamilo_alumno ( uididpersona char(36));'."\n", FILE_APPEND);
while ($row = mysql_fetch_array($res)) {
file_put_contents('/tmp/alumnos.sql', 'INSERT INTO chamilo_alumno(uididpersona) values (\''.$row[0].'\');'."\n", FILE_APPEND);
$alumnos[$row[1]] = $row[0];
}
$sql = "SELECT f.field_value, u.user_id from user_field_values f INNER JOIN user u ON u.user_id=f.user_id WHERE f.field_id='13' AND u.status=1";
$res = mysql_query($sql);
file_put_contents('/tmp/profesores.sql','CREATE TABLE chamilo_profesor ( uididpersona char(36));'."\n", FILE_APPEND);
while ($row = mysql_fetch_array($res)) {
file_put_contents('/tmp/profesores.sql', 'INSERT INTO chamilo_profesor(uididpersona) values (\''.$row[0].'\');'."\n", FILE_APPEND);
$alumnos[$row[1]] = $row[0];
}
$sql = "SELECT f.field_value from course_field_values f INNER JOIN course c ON c.code=f.course_code WHERE f.field_id='5'";
$res = mysql_query($sql);
file_put_contents('/tmp/cursos.sql','CREATE TABLE chamilo_curso ( uididcurso char(36));'."\n", FILE_APPEND);
while ($row = mysql_fetch_array($res)) {
file_put_contents('/tmp/cursos.sql', 'INSERT INTO chamilo_curso (uididcurso) values (\''.$row[0].'\');'."\n", FILE_APPEND);
}
$branches = array(
1 => '8F67B2B3-667E-4EBC-8605-766D2FF71B55',
2 => '7379A7D3-6DC5-42CA-9ED4-97367519F1D9',
3 => '30DE73B6-8203-4F81-96C8-3B27977BB924',
4 => '8BA65461-60B5-4716-BEB3-22BC7B71BC09',
5 => '257AD17D-91F7-4BC8-81D4-71EBD35A4E50',
);
foreach ($branches as $idbranch => $branch) {
// First, get all sessions with the given branch
$sql = "SELECT s.id from session_field_values f INNER JOIN session s ON s.id=f.session_id WHERE f.field_id='4' AND f.field_value = '$branch'";
echo $sql."\n";
$res = mysql_query($sql);
file_put_contents('/tmp/programas'.$idbranch.'.sql','CREATE TABLE chamilo_programa'.$idbranch.' ( uididprograma char(36));'."\n", FILE_APPEND);
file_put_contents('/tmp/matriculas'.$idbranch.'.sql','CREATE TABLE chamilo_matricula'.$idbranch.' ( uididprograma char(36), uididmatricula char(36));'."\n", FILE_APPEND);
while ($row = mysql_fetch_array($res)) {
// Get uididprograma from programas (there should be only one by "programa")
$sql2 = "SELECT f.field_value from session_field_values f WHERE f.field_id='2' AND f.session_id = ".$row[0];
$res2 = mysql_query($sql2);
$row2 = mysql_fetch_array($res2);
file_put_contents('/tmp/programas'.$idbranch.'.sql', 'INSERT INTO chamilo_programa'.$idbranch.' (uididprograma) values (\''.$row2[0].'\');'."\n", FILE_APPEND);
// get subscriptions from session_rel_user
$sql3 = "SELECT id_session, id_user FROM session_rel_user WHERE id_session='".$row[0]."'";
//echo $sql3."\n";
$res3 = mysql_query($sql3);
while ($row3 = mysql_fetch_array($res3)) {
file_put_contents('/tmp/matriculas'.$idbranch.'.sql','INSERT INTO chamilo_matricula'.$idbranch.' (uididprograma, uididmatricula) values (\''.$row2[0].'\',\''.$alumnos[$row3[1]].'\');'."\n", FILE_APPEND);
}
}
}
Loading…
Cancel
Save