skala
Julio Montoya 12 years ago
commit 19af5453fb
  1. 9
      main/inc/ajax/exercise.ajax.php
  2. 256
      main/inc/lib/extra_field_value.lib.php
  3. 2
      main/inc/lib/main_api.lib.php
  4. 227
      main/inc/lib/sessionmanager.lib.php
  5. 107
      tests/migrate/migration.custom.class.php
  6. 55
      tests/migrate/report_sql.php

@ -70,11 +70,11 @@ switch ($action) {
$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
INNER JOIN (
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 )
WHERE t.status = 'incomplete' AND
$where_condition
@ -99,7 +99,8 @@ switch ($action) {
$i=0;
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 (
SELECT 1 as count_question_id FROM $track_attempt a
WHERE user_id = {$row['exe_user_id']} and exe_id = {$row['exe_id']}
@ -119,7 +120,7 @@ switch ($action) {
$array = array( $row['firstname'],
$row['lastname'],
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).'%'
);
$response->rows[$i]['cell'] = $array;

@ -1,10 +1,23 @@
<?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 {
public $type = null;
public $columns = array('id', 'field_id', 'field_value', 'tms');
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) {
$this->type = $type;
$extra_field = new ExtraField($this->type);
@ -12,143 +25,164 @@ class ExtraFieldValue extends Model {
switch ($this->type) {
case 'course':
$this->table = Database::get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES);
$this->table_handler_field = Database::get_main_table(TABLE_MAIN_COURSE_FIELD);
$this->table_handler_field = Database::get_main_table(TABLE_MAIN_COURSE_FIELD);
break;
case 'user':
$this->table = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
$this->table_handler_field = Database::get_main_table(TABLE_MAIN_USER_FIELD);
$this->table_handler_field = Database::get_main_table(TABLE_MAIN_USER_FIELD);
break;
case 'session':
$this->table = Database::get_main_table(TABLE_MAIN_SESSION_FIELD_VALUES);
$this->table_handler_field = Database::get_main_table(TABLE_MAIN_SESSION_FIELD);
break;
$this->table_handler_field = Database::get_main_table(TABLE_MAIN_SESSION_FIELD);
break;
default:
//unmanaged datatype, return false to let the caller know it
// didn't work
return false;
}
$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() {
$row = Database::select('count(*) as count', $this->table, array(), 'first');
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) {
$extra_field = new ExtraField($this->type);
if (empty($params[$this->handler_id])) {
return false;
return false;
}
//Parse params
//Parse params
foreach ($params as $key => $value) {
if (substr($key, 0, 6) == 'extra_') { //an extra field
$field_variable = substr($key, 6);
$extra_field_info = $extra_field->get_handler_field_info_by_field_variable($field_variable);
if ($extra_field_info) {
$extra_field_info = $extra_field->get_handler_field_info_by_field_variable($field_variable);
if ($extra_field_info) {
$new_params = array(
$this->handler_id => $params[$this->handler_id],
'field_id' => $extra_field_info['id'],
'field_value' => $value
);
);
self::save($new_params);
}
}
}
}
}
public function save($params, $show_query = false) {
/**
* 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) {
$extra_field = new ExtraField($this->type);
//Setting value to insert
$value = $params['field_value'];
$value = $params['field_value'];
$value_to_insert = null;
if (is_array($value)) {
$value_to_insert = implode(';', $value);
} else {
$value_to_insert = Database::escape_string($value);
}
$value_to_insert = implode(';', $value);
} else {
$value_to_insert = Database::escape_string($value);
}
$params['field_value'] = $value_to_insert;
//If field id exists
$extra_field_info = $extra_field->get($params['field_id']);
if ($extra_field_info) {
switch ($extra_field_info['field_type']) {
case ExtraField::FIELD_TYPE_TAG :
break;
case ExtraField::FIELD_TYPE_RADIO:
case ExtraField::FIELD_TYPE_SELECT:
case ExtraField::FIELD_TYPE_SELECT_MULTIPLE:
//$field_options = $session_field_option->get_field_options_by_field($params['field_id']);
//$params['field_value'] = split(';', $value_to_insert);
/*
if ($field_options) {
$check = false;
foreach ($field_options as $option) {
if (in_array($option['option_value'], $values)) {
$check = true;
break;
}
}
if (!$check) {
return false; //option value not found
}
} else {
return false; //enumerated type but no option found
}*/
case ExtraField::FIELD_TYPE_SELECT:
case ExtraField::FIELD_TYPE_SELECT_MULTIPLE:
//$field_options = $session_field_option->get_field_options_by_field($params['field_id']);
//$params['field_value'] = split(';', $value_to_insert);
/*
if ($field_options) {
$check = false;
foreach ($field_options as $option) {
if (in_array($option['option_value'], $values)) {
$check = true;
break;
}
}
if (!$check) {
return false; //option value not found
}
} else {
return false; //enumerated type but no option found
}*/
break;
case ExtraField::FIELD_TYPE_TEXT:
case ExtraField::FIELD_TYPE_TEXTAREA:
break;
case ExtraField::FIELD_TYPE_DOUBLE_SELECT:
if (is_array($value)) {
if (is_array($value)) {
if (isset($value['extra_'.$extra_field_info['field_variable']]) &&
isset($value['extra_'.$extra_field_info['field_variable'].'_second'])
) {
$value_to_insert = $value['extra_'.$extra_field_info['field_variable']].'::'.$value['extra_'.$extra_field_info['field_variable'].'_second'];
$value_to_insert = $value['extra_'.$extra_field_info['field_variable']].'::'.$value['extra_'.$extra_field_info['field_variable'].'_second'];
} else {
$value_to_insert = null;
}
}
default:
break;
}
$field_values = self::get_values_by_handler_and_field_id($params[$this->handler_id], $params['field_id']);
}
$field_values = self::get_values_by_handler_and_field_id($params[$this->handler_id], $params['field_id']);
if ($field_values) {
self::delete_values_by_handler_and_field_id($params[$this->handler_id], $params['field_id']);
}
self::delete_values_by_handler_and_field_id($params[$this->handler_id], $params['field_id']);
}
$params['field_value'] = $value_to_insert;
$params['tms'] = api_get_utc_datetime();
$params['tms'] = api_get_utc_datetime();
return parent::save($params, $show_query);
}
}
}
/**
*
* @param int handler_id (It could be a session_id, course_id or user_id)
* @param int $field_id
* @param bool transform the result to a human readable strings
* @return boolean
* Returns the value of the given extra field on the given resource
* @param int Item ID (It could be a session_id, course_id or user_id)
* @param int Field ID (the ID from the *_field table)
* @param bool Whether to transform the result to a human readable strings
* @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) {
$field_id = intval($field_id);
$item_id = Database::escape_string($item_id);
$sql = "SELECT s.*, field_type FROM {$this->table} s
INNER JOIN {$this->table_handler_field} sf ON (s.field_id = sf.id)
WHERE {$this->handler_id} = '$item_id' AND
field_id = '".$field_id."'
ORDER BY id";
$result = Database::query($sql);
if (Database::num_rows($result)) {
ORDER BY id";
$result = Database::query($sql);
if (Database::num_rows($result)) {
$result = Database::fetch_array($result, 'ASSOC');
if ($transform) {
if (!empty($result['field_value'])) {
switch ($result['field_type']) {
case ExtraField::FIELD_TYPE_DOUBLE_SELECT:
$field_option = new ExtraFieldOption($this->type);
$options = explode('::', $result['field_value']);
$options = explode('::', $result['field_value']);
// only available for PHP 5.4 :( $result['field_value'] = $field_option->get($options[0])['id'].' -> ';
$result = $field_option->get($options[0]);
$result_second = $field_option->get($options[1]);
@ -160,37 +194,44 @@ class ExtraFieldValue extends Model {
case ExtraField::FIELD_TYPE_SELECT:
$field_option = new ExtraFieldOption($this->type);
$extra_field_option_result = $field_option->get_field_option_by_field_and_option($result['field_id'], $result['field_value']);
if (isset($extra_field_option_result[0])) {
if (isset($extra_field_option_result[0])) {
$result['field_value'] = $extra_field_option_result[0]['option_display_text'];
}
}
break;
}
}
}
}
return $result;
} else {
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) {
$field_id = intval($field_id);
$item_id = Database::escape_string($item_id);
$field_variable = Database::escape_string($field_variable);
$sql = "SELECT s.*, field_type FROM {$this->table} s
INNER JOIN {$this->table_handler_field} sf ON (s.field_id = sf.id)
WHERE {$this->handler_id} = '$item_id' AND
field_variable = '".$field_variable."'
ORDER BY id";
$result = Database::query($sql);
if (Database::num_rows($result)) {
ORDER BY id";
$result = Database::query($sql);
if (Database::num_rows($result)) {
$result = Database::fetch_array($result, 'ASSOC');
if ($transform) {
if ($result['field_type'] == ExtraField::FIELD_TYPE_DOUBLE_SELECT) {
if (!empty($result['field_value'])) {
$field_option = new ExtraFieldOption($this->type);
$options = explode('::', $result['field_value']);
$options = explode('::', $result['field_value']);
// only available for PHP 5.4 :( $result['field_value'] = $field_option->get($options[0])['id'].' -> ';
$result = $field_option->get($options[0]);
$result_second = $field_option->get($options[1]);
@ -198,7 +239,7 @@ class ExtraFieldValue extends Model {
$result['field_value'] = $result['option_display_text'].' -> ';
$result['field_value'] .= $result_second['option_display_text'];
}
}
}
}
}
return $result;
@ -206,52 +247,77 @@ class ExtraFieldValue extends Model {
return false;
}
}
public function get_item_id_from_field_variable_and_field_value($field_variable, $field_value, $transform = 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) {
$field_value = Database::escape_string($field_value);
$field_variable = Database::escape_string($field_variable);
$sql = "SELECT {$this->handler_id} FROM {$this->table} s
INNER JOIN {$this->table_handler_field} sf ON (s.field_id = sf.id)
WHERE field_value = '$field_value' AND
field_variable = '".$field_variable."'
";
";
$result = Database::query($sql);
if (Database::num_rows($result)) {
$result = Database::fetch_array($result, 'ASSOC');
$result = Database::query($sql);
if ($result !== false && Database::num_rows($result)) {
$result = Database::fetch_array($result, 'ASSOC');
return $result;
} else {
return false;
}
}
/* Get all values by field id */
public function get_values_by_field_id($field_id) {
/**
* Get all values for a specific 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) {
$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";
$result = Database::query($sql);
if (Database::num_rows($result)) {
$result = Database::query($sql);
if (Database::num_rows($result)) {
return Database::store_result($result, 'ASSOC');
}
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) {
$field_id = intval($field_id);
$sql = "DELETE FROM {$this->table} WHERE field_id = $field_id";
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) {
$field_id = intval($field_id);
$item_id = Database::escape_string($item_id);
$sql = "DELETE FROM {$this->table} WHERE {$this->handler_id} = '$item_id' AND field_id = '".$field_id."' ";
Database::query($sql);
}
public function compare_item_values($item_id, $item_to_compare) {
/**
* 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) {
}
}
}

@ -6382,4 +6382,4 @@ function api_coach_can_edit_view_results($course_code = null, $session_id = null
}
return false;
}
}
}

@ -8,9 +8,10 @@
* @package chamilo.library
*/
/**
* Code
* The SessionManager class manages all the Chamilo sessions (as in course
* groups).
* @package chamilo.library.session
*/
class SessionManager {
//See BT#4871
@ -22,8 +23,9 @@ class SessionManager {
/**
* Fetches a session from the database
* @param int Session ID
* @return array Session details
* @param int Session ID
* @return array Session details
* @assert (-1) === array()
*/
public static function fetch($id) {
$t = Database::get_main_table(TABLE_MAIN_SESSION);
@ -33,8 +35,13 @@ class SessionManager {
if (Database::num_rows($r) != 1) { return array(); }
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;
//just in case
@ -54,14 +61,20 @@ class SessionManager {
return get_lang('PortalSessionsLimitReached');
}
}
$my_session_result = SessionManager::get_session_by_name($params['name']);
$session_id = null;
if (!$allow_homonyms) {
$my_session_result = SessionManager::get_session_by_name($params['name']);
$session_id = null;
if ($my_session_result == false) {
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);
} else {
error_log('Session already exits with name: '.$params['name']." session_id: ".$my_session_result['id']);
}
if (!empty($session_id)) {
@ -129,8 +142,16 @@ class SessionManager {
}
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) {
if (empty($params) || count($params)<1) {
return false;
}
$session_model = new SessionModel();
$session_model->update($params);
@ -141,16 +162,23 @@ class SessionManager {
$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) {
$session_name = Database::escape_string($session_name);
$result = Database::fetch_array(Database::query("SELECT COUNT(*) as count FROM ".Database::get_main_table(TABLE_MAIN_SESSION)." WHERE name = '$session_name' "));
return $result['count'] > 0;
}
/**
* Gets the admin session list callback of the admin/session_list.php page
* @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) {
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
@ -332,8 +360,17 @@ class SessionManager {
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()) {
if (!is_array($options)) {
return false;
}
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
@ -380,35 +417,38 @@ class SessionManager {
$num = $recorset['total_rows'];
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
* @result array Array of rows results
* @asset ('a') === false
*/
public static function get_sessions_admin_complete($options = array()) {
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
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_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_session_field_values = Database::get_main_table(TABLE_MAIN_SESSION_FIELD_VALUES);
$tbl_session_field_options = Database::get_main_table(TABLE_MAIN_SESSION_FIELD_OPTIONS);
$where = 'WHERE 1 = 1 ';
$user_id = api_get_user_id();
$where = 'WHERE 1 = 1 ';
$user_id = api_get_user_id();
if (api_is_session_admin() && api_get_setting('allow_session_admins_to_manage_all_sessions') == 'false') {
$where.=" AND s.session_admin_id = $user_id ";
}
$coach_name = " CONCAT (u.lastname , ' ', u.firstname) as coach_name ";
if (api_is_session_admin() && api_get_setting('allow_session_admins_to_manage_all_sessions') == 'false') {
$where.=" AND s.session_admin_id = $user_id ";
}
if (api_is_western_name_order()) {
$coach_name = " CONCAT (u.firstname, ' ', u.lastname) as coach_name ";
}
$coach_name = " CONCAT (u.lastname , ' ', u.firstname) as coach_name ";
if (api_is_western_name_order()) {
$coach_name = " CONCAT (u.firstname, ' ', u.lastname) as coach_name ";
}
$today = api_get_utc_datetime();
$today = api_get_utc_datetime();
$inject_extra_fields = null;
@ -448,7 +488,7 @@ class SessionManager {
//var_dump($options_by_double);
//sc.name as category_name,
$select = "
$select = "
SELECT * FROM (
SELECT DISTINCT
IF (
@ -482,12 +522,12 @@ class SessionManager {
$options['where'] = str_replace('course_title', 'c.title', $options['where']);
$where .= ' AND '.$options['where'];
}
}
if (!empty($options['limit'])) {
$where .= " LIMIT ".$options['limit'];
}
$query = "$select FROM $tbl_session s
$query = "$select FROM $tbl_session s
LEFT JOIN $tbl_session_field_values fv ON (fv.session_id = s.id)
INNER JOIN $tbl_session_field_options fvo ON (fv.field_id = fvo.field_id)
LEFT JOIN $tbl_session_rel_course src ON (src.id_session = s.id)
@ -496,61 +536,59 @@ class SessionManager {
INNER JOIN $tbl_user u ON (s.id_coach = u.user_id) ".
$where;
if (api_is_multiple_url_enabled()) {
$table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$where.= " AND ar.access_url_id = $access_url_id ";
$query = "$select
if (api_is_multiple_url_enabled()) {
$table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$where.= " AND ar.access_url_id = $access_url_id ";
$query = "$select
FROM $tbl_session s
LEFT JOIN $tbl_session_field_values fv ON (fv.session_id = s.id)
LEFT JOIN $tbl_session_rel_course src ON (src.id_session = s.id)
LEFT JOIN $tbl_session_rel_course src ON (src.id_session = s.id)
LEFT JOIN $tbl_course c ON (src.course_code = c.code)
LEFT JOIN $tbl_session_category sc ON (s.session_category_id = sc.id)
INNER JOIN $tbl_user u ON (s.id_coach = u.user_id)
INNER JOIN $table_access_url_rel_session ar ON (ar.session_id = s.id)
INNER JOIN $tbl_user u ON (s.id_coach = u.user_id)
INNER JOIN $table_access_url_rel_session ar ON (ar.session_id = s.id)
$where";
}
}
}
}
$query .= ") AS session_table";
$query .= ") AS session_table";
if (!empty($options['order'])) {
$query .= " ORDER BY ".$options['order'];
}
//error_log($query);
// echo $query;
// echo $query;
$result = Database::query($query);
$formatted_sessions = array();
$result = Database::query($query);
$formatted_sessions = array();
if (Database::num_rows($result)) {
$sessions = Database::store_result($result, 'ASSOC');
foreach ($sessions as $session) {
if (Database::num_rows($result)) {
$sessions = Database::store_result($result, 'ASSOC');
foreach ($sessions as $session) {
$session_id = $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']);
if ($session['session_active'] == 1) {
$session['session_active'] = Display::return_icon('accept.png', get_lang('Active'), array(), ICON_SIZE_SMALL);
} else {
$session['session_active'] = Display::return_icon('error.png', get_lang('Inactive'), array(), ICON_SIZE_SMALL);
}
$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']);
if ($session['session_active'] == 1) {
$session['session_active'] = Display::return_icon('accept.png', get_lang('Active'), array(), ICON_SIZE_SMALL);
} else {
$session['session_active'] = Display::return_icon('error.png', get_lang('Inactive'), array(), ICON_SIZE_SMALL);
}
$session = self::convert_dates_to_local($session);
switch ($session['visibility']) {
case SESSION_VISIBLE_READ_ONLY: //1
$session['visibility'] = get_lang('ReadOnly');
switch ($session['visibility']) {
case SESSION_VISIBLE_READ_ONLY: //1
$session['visibility'] = get_lang('ReadOnly');
break;
case SESSION_VISIBLE: //2
case SESSION_VISIBLE: //2
case SESSION_AVAILABLE: //4
$session['visibility'] = get_lang('Visible');
$session['visibility'] = get_lang('Visible');
break;
case SESSION_INVISIBLE: //3
$session['visibility'] = api_ucfirst(get_lang('Invisible'));
case SESSION_INVISIBLE: //3
$session['visibility'] = api_ucfirst(get_lang('Invisible'));
break;
}
@ -586,12 +624,14 @@ class SessionManager {
} else {
$formatted_sessions[$session_id] = $session;
}
}
}
}
}
return $formatted_sessions;
}
return $formatted_sessions;
}
/**
*
*/
static function compare_arrays_to_merge($array1, $array2) {
if (empty($array2)) {
return $array1;
@ -606,8 +646,17 @@ class SessionManager {
}
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) {
if (!is_array($params)) {
return false;
}
$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);
@ -624,17 +673,18 @@ class SessionManager {
*
* @param string wanted code
* <code>
* $wanted_code = 'curse' if there are in the DB codes like curse1 curse2 the function will return: course3
* if the course code doest not exist in the DB the same course code will be returned
* $wanted_code = 'sess' if there are names like sess, sess1, sess2 in the
* database already, the function will return: sess3
* if the session name doesn't exist in the DB the same name is returned
* </code>
* @return string wanted unused code
*/
function generate_nice_next_session_name($session_name) {
$session_name_ok = !self::session_name_exists($session_name);
if (!$session_name_ok) {
function generate_nice_next_session_name($session_name) {
$session_name_ok = !self::session_name_exists($session_name);
if (!$session_name_ok) {
$table = Database::get_main_table(TABLE_MAIN_SESSION);
$session_name = Database::escape_string($session_name);
$sql = "SELECT count(*) as count FROM $table WHERE name LIKE '$session_name%'";
$sql = "SELECT count(*) as count FROM $table WHERE name LIKE '$session_name%'";
$result = Database::query($sql);
if (Database::num_rows($result) > 0 ) {
$row = Database::fetch_array($result);
@ -643,13 +693,12 @@ class SessionManager {
$result = self::session_name_exists($session_name);
if (!$result) {
return $session_name;
}
}
}
return false;
}
return false;
}
return $session_name;
}
/**
* Edit a session
* @author Carlos Vargas from existing code
@ -2687,4 +2736,4 @@ class SessionManager {
);
return $return_array;
}
}
}

@ -47,6 +47,9 @@ class MigrationCustom {
const TRANSACTION_TYPE_ADD_INTENS = 25;
const TRANSACTION_TYPE_DEL_INTENS = 26;
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() {
$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
// 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');
if (!$session_id) {
error_log('Error: Failed to create_session '.$data['name']);
@ -826,7 +829,6 @@ class MigrationCustom {
$uidIdPersona = $data['item_id'];
$uidIdPrograma = $data['orig_id'];
$uidIdProgramaDestination = $data['dest_id'];
$user_id = self::get_user_id_by_persona_id($uidIdPersona);
if (empty($user_id)) {
@ -870,7 +872,7 @@ class MigrationCustom {
$befores = array($before1, $before2);
$message = "Move Session A to Session B";
$message = "Move Session A to Session B";
return self::check_if_user_is_subscribe_to_session($user_id, $destination_session_id, $message, $befores);
} else {
return array(
@ -885,7 +887,8 @@ class MigrationCustom {
$session_id = self::get_session_id_by_programa_id($uidIdPrograma);
if (!empty($session_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";
return self::check_if_user_is_subscribe_to_session($user_id, $session_id, $message, $before);
} else {
@ -1233,15 +1236,15 @@ class MigrationCustom {
//-------
static function transaction_extra_field_agregar_generic($extra_field_variable, $original_data, $web_service_details) {
$function_name = $extra_field_variable."Detalles";
static function transaction_extra_field_agregar_generic($extra_field_variable, $original_data, $web_service_details, $type='session') {
$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']));
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);
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']);
@ -1251,7 +1254,7 @@ class MigrationCustom {
'option_display_text' => $data['name'],
'option_order' => null
);
$result = $extra_field_option->save_one_item($params);
$info_after = $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) {
$extra_field = new ExtraField('session');
static function transaction_extra_field_editar_generic($extra_field_variable, $original_data, $web_service_details, $type='session') {
$extra_field = new ExtraField($type);
$extra_field_info = $extra_field->get_handler_field_info_by_field_variable($extra_field_variable);
if (empty($extra_field_info)) {
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']);
$function_name = $extra_field_variable."Detalles";
@ -1310,7 +1313,7 @@ class MigrationCustom {
//var_dump($extra_field_option_info);
//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("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');
}
@ -1324,6 +1327,7 @@ class MigrationCustom {
'option_order' => null
);
$extra_field_option->update($extra_field_option_info);
error_log('Editing extra field: '.print_r($extra_field_option_info,1));
$options_updated[] = $option['id'];
}
@ -1350,11 +1354,11 @@ class MigrationCustom {
}
/* Delete all options with option_value = item_id */
static function transaction_extra_field_eliminar_generic($extra_field_variable, $original_data, $web_service_details) { //horario
$extra_field = new ExtraField('session');
static function transaction_extra_field_eliminar_generic($extra_field_variable, $original_data, $web_service_details, $type='session') { //horario
$extra_field = new ExtraField($type);
$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']);
if (!empty($extra_field_option_info)) {
@ -1447,45 +1451,60 @@ class MigrationCustom {
static function transaction_21($data, $web_service_details) {
return self::transaction_extra_field_editar_generic('sede', $data, $web_service_details);
}
//
// Frecuencia
// añadir frec FID
// const TRANSACTION_TYPE_ADD_FREQ = 22;
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
// const TRANSACTION_TYPE_DEL_FREQ = 23;
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
// const TRANSACTION_TYPE_EDIT_FREQ = 24;
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');
}
//
// Intensidad/Fase
// añadir intfase_agregar IID
// const TRANSACTION_TYPE_ADD_INTENS = 25;
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
// const TRANSACTION_TYPE_DEL_INTENS = 26;
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
// const TRANSACTION_TYPE_EDIT_INTENS = 27;
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
@ -1579,9 +1598,9 @@ class MigrationCustom {
'transaction_id' => isset($transaction_info['idt']) ? $transaction_info['idt'] : null,
'action' => isset($transaction_info['ida']) ? $transaction_info['ida'] : 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,
'dest_id' => isset($transaction_info['idd']) ? $transaction_info['idd'] : null,
'dest_id' => isset($transaction_info['dest']) ? $transaction_info['dest'] : null,
'status_id' => 0
);
@ -1703,6 +1722,7 @@ class MigrationCustom {
$result['status'] = $result['rol'] == 'profesor' ? COURSEMANAGER : STUDENT;
$result['phone'] = (string)$result['phone'];
$result['active'] = (int)$result['bitvigencia'];
$result['extra_uidIdPersona'] = strtoupper($params['uididpersona']);
unset($result['rol']);
return $result;
@ -1753,6 +1773,14 @@ class MigrationCustom {
if (isset($extra_field_option_info_sede[0]) && !empty($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
$extra_field_info = $extra_field->get_handler_field_info_by_field_variable('horario');
@ -1764,17 +1792,19 @@ class MigrationCustom {
}
//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_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['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['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['estado'] = intval($result['estado']);
//Searching id_coach
$result['id_coach'] = MigrationCustom::get_user_id_by_persona_id($result['id_coach']);
@ -1871,6 +1901,13 @@ class MigrationCustom {
return $result;
}
static function aulaDetalles($data, $params) {
$result = self::genericDetalles($data, __FUNCTION__, $params);
if ($result['error'] == true) {
return $result;
}
return $result;
}
/*Calling sedeDetalles
array(1) {
["name"]=>
@ -1908,4 +1945,4 @@ class MigrationCustom {
unset($result['end']);
return $result;
}
}
}

@ -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