Adding missing function needed for the widescale plugin see BT#5637

skala
Julio Montoya 13 years ago
parent 26cb8635ea
commit 68fe06f9b6
  1. 1
      main/admin/user_list.php
  2. 95
      main/inc/lib/usermanager.lib.php
  3. 6
      plugin/widescale_exam/readme.txt
  4. 27
      plugin/widescale_exam/user_list.php

@ -270,7 +270,6 @@ function get_number_of_users() {
* @see SortableTable#get_table_data($from)
*/
function get_user_data($from, $number_of_items, $column, $direction, $get_count = false) {
global $origin;
$user_table = Database :: get_main_table(TABLE_MAIN_USER);
$admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);

@ -10,7 +10,8 @@
* Class
* @package chamilo.include.user
*/
class UserManager {
class UserManager
{
static public $columns = array(
'user_id',
'lastname',
@ -4114,4 +4115,96 @@ class UserManager {
$send_to['users'] = array_unique($userlist);
return $send_to;
}
/** Used by the widescale plugin */
static function get_user_data($from, $number_of_items, $column, $direction, $get_count = false) {
$user_table = Database :: get_main_table(TABLE_MAIN_USER);
$select = "SELECT
u.user_id,
u.username,
u.firstname,
u.lastname,
ufv1.field_value as exam_password
";
if ($get_count) {
$select = "SELECT count(u.user_id) as total_rows";
}
$sql = "$select FROM $user_table u ";
// adding the filter to see the user's only of the current access_url
if ((api_is_platform_admin() || api_is_session_admin()) && api_get_multiple_access_url()) {
$access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)";
}
$extra_fields = array('exam_password', 'exam_room', 'exam_schedule');
$counter = 1;
$where_condition = "";
$and_conditions = array();
foreach ($extra_fields as $keyword_extra_data) {
$extra_info = UserManager::get_extra_field_information_by_name($keyword_extra_data);
$field_id = $extra_info['id'];
$table_alias = "ufv$counter";
$sql.= " INNER JOIN user_field_values $table_alias ON u.user_id = $table_alias.user_id AND $table_alias.field_id = $field_id ";
$counter++;
if ($keyword_extra_data == 'exam_password') {
continue;
}
$keyword_extra_data_text = UserManager::get_extra_user_data_by_field(api_get_user_id(), $extra_info['field_variable']);
$keyword_extra_data_text = $keyword_extra_data_text[$extra_info['field_variable']];
if (!empty($keyword_extra_data_text)) {
$and_conditions[] = " $table_alias.field_value LIKE '%".trim($keyword_extra_data_text)."%' ";
}
}
if (!empty($and_conditions)) {
$where_condition = implode(' AND ', $and_conditions);
}
if (!empty($where_condition)) {
$sql .= " WHERE $where_condition ";
}
$sql .= " AND u.user_id <> ".api_get_user_id();
// adding the filter to see the user's only of the current access_url
if ((api_is_platform_admin() || api_is_session_admin()) && api_get_multiple_access_url()) {
$sql.= " AND url_rel_user.access_url_id=".api_get_current_access_url_id();
}
if (!in_array($direction, array('ASC','DESC'))) {
$direction = 'ASC';
}
if (in_array($column, array('username', 'firstname', 'lastname'))) {
$column = $column;
}
$from = intval($from);
$number_of_items = intval($number_of_items);
//Returns counts and exits function
if ($get_count) {
$res = Database::query($sql);
$user = Database::fetch_array($res);
return $user['total_rows'];
}
$sql .= " ORDER BY $column $direction ";
$sql .= " LIMIT $from, $number_of_items";
$res = Database::query($sql);
$users = array();
while ($user = Database::fetch_array($res, 'ASSOC')) {
$users[] = $user;
}
return $users;
}
}

@ -2,5 +2,7 @@ Adds 3 new user fields: exam_room, exam_schedule, exam_password.
Installation:
1. Install the plugin (check in the user profiling there are 3 new field types)
2. Add the plugin to a region, for example: menu_bottom
3.
2. Add the plugin to a region, for example: menu_bottom and go to the chamilo homepage
you will see a new Link "Course list". You can also go to plugin/widescale_exam/user_list.php

@ -12,22 +12,22 @@ if (!$allowed) {
api_not_allowed(true);
}
Display::display_header($tool_name);
Display::display_header();
//jqgrid will use this URL to do the selects
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_user_list_plugin_widescale';
//The order is important you need to check the the $column variable in the model.ajax.php file
$columns = array(get_lang('Username'), get_lang('Firstname'), get_lang('Lastname'), get_lang('Password'));
$columns = array(get_lang('Username'), get_lang('Firstname'), get_lang('Lastname'), get_lang('Password'));
//Column config
$column_model = array(
array('name'=>'username', 'index'=>'username', 'width'=>'100', 'align'=>'left'),
array('name'=>'firstname', 'index'=>'firstname', 'width'=>'100', 'align'=>'left'),
array('name'=>'lastname', 'index'=>'lastname', 'width'=>'100', 'align'=>'left'),
array('name'=>'exam_password', 'index'=>'exam_password', 'width'=>'100', 'align'=>'left','sortable'=>'false'),
//array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false')
);
array('name'=>'username', 'index'=>'username', 'width'=>'100', 'align'=>'left'),
array('name'=>'firstname', 'index'=>'firstname', 'width'=>'100', 'align'=>'left'),
array('name'=>'lastname', 'index'=>'lastname', 'width'=>'100', 'align'=>'left'),
array('name'=>'exam_password', 'index'=>'exam_password', 'width'=>'100', 'align'=>'left','sortable'=>'false'),
//array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false')
);
//Autowidth
$extra_params['autowidth'] = 'true';
//height auto
@ -36,11 +36,12 @@ $extra_params['height'] = 'auto';
//With this function we can add actions to the jgrid (edit, delete, etc)
/*
$action_links = 'function action_formatter(cellvalue, options, rowObject) {
return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
'&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?sec_token='.$token.'&action=copy&id=\'+options.rowId+\'">'.Display::return_icon('copy.png',get_lang('Copy'),'',ICON_SIZE_SMALL).'</a>'.
'&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
'\';
}';*/
return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
'&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?sec_token='.$token.'&action=copy&id=\'+options.rowId+\'">'.Display::return_icon('copy.png',get_lang('Copy'),'',ICON_SIZE_SMALL).'</a>'.
'&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
'\';
}';*/
$action_links = null;
$room = UserManager::get_extra_user_data_by_field(api_get_user_id(), 'exam_room');
$room = $room['exam_room'];

Loading…
Cancel
Save