Special fix in the document table when ordering elements by name see #2499

skala
Julio Montoya 15 years ago
parent 38ce4f1a69
commit 85a076b622
  1. 45
      main/document/document.php
  2. 12
      main/inc/lib/sortabletable.class.php
  3. 68
      main/inc/lib/tablesort.lib.php

@ -119,7 +119,6 @@ $curdirpathurl = urlencode($curdirpath);
// If the path is not found (no document id), set the path to / // If the path is not found (no document id), set the path to /
$document_id = DocumentManager::get_document_id($_course, $curdirpath); $document_id = DocumentManager::get_document_id($_course, $curdirpath);
if (!$document_id) { if (!$document_id) {
$document_id = DocumentManager::get_document_id(api_get_course_info(), $curdirpath); $document_id = DocumentManager::get_document_id(api_get_course_info(), $curdirpath);
} }
@ -170,7 +169,6 @@ if ($tool_visibility == '0' && $to_group_id == '0' && !($is_allowed_to_edit || $
api_not_allowed(true); api_not_allowed(true);
} }
$htmlHeadXtra[] = $htmlHeadXtra[] =
"<script type=\"text/javascript\"> "<script type=\"text/javascript\">
function confirmation (name) { function confirmation (name) {
@ -361,7 +359,7 @@ $image_files_only = '';
if ($is_certificate_mode) { if ($is_certificate_mode) {
$interbreadcrumb[]= array('url' => '../gradebook/index.php', 'name' => get_lang('Gradebook')); $interbreadcrumb[]= array('url' => '../gradebook/index.php', 'name' => get_lang('Gradebook'));
} else { } else {
if ( (isset($_GET['id']) && $_GET['id'] != 0) || isset($_GET['curdirpath'])) { if ((isset($_GET['id']) && $_GET['id'] != 0) || isset($_GET['curdirpath'])) {
$interbreadcrumb[]= array('url' => 'document.php', 'name' => get_lang('Documents')); $interbreadcrumb[]= array('url' => 'document.php', 'name' => get_lang('Documents'));
} else { } else {
$interbreadcrumb[]= array('url' => '#', 'name' => get_lang('Documents')); $interbreadcrumb[]= array('url' => '#', 'name' => get_lang('Documents'));
@ -683,7 +681,7 @@ if ($is_allowed_to_edit) {
/* TEMPLATE ACTION */ /* TEMPLATE ACTION */
//Only teacher and all users into their group //Only teacher and all users into their group
if($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $current_session_id)){ if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $current_session_id)){
if (isset($_GET['add_as_template']) && !isset($_POST['create_template'])) { if (isset($_GET['add_as_template']) && !isset($_POST['create_template'])) {
$document_id_for_template = intval($_GET['add_as_template']); $document_id_for_template = intval($_GET['add_as_template']);
@ -785,13 +783,13 @@ if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && isse
} }
} }
/* GET ALL DOCUMENT DATA FOR CURDIRPATH */ /* GET ALL DOCUMENT DATA FOR CURDIRPATH */
if(isset($_GET['keyword']) && !empty($_GET['keyword'])) { if(isset($_GET['keyword']) && !empty($_GET['keyword'])) {
$docs_and_folders = DocumentManager::get_all_document_data($_course, $curdirpath, $to_group_id, null, $is_allowed_to_edit || $group_member_with_upload_rights, $search=true); $docs_and_folders = DocumentManager::get_all_document_data($_course, $curdirpath, $to_group_id, null, $is_allowed_to_edit || $group_member_with_upload_rights, true);
} else { } else {
$docs_and_folders = DocumentManager::get_all_document_data($_course, $curdirpath, $to_group_id, null, $is_allowed_to_edit || $group_member_with_upload_rights, $search=false); $docs_and_folders = DocumentManager::get_all_document_data($_course, $curdirpath, $to_group_id, null, $is_allowed_to_edit || $group_member_with_upload_rights, false);
} }
$folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit || $group_member_with_upload_rights); $folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit || $group_member_with_upload_rights);
if ($folders === false) { if ($folders === false) {
$folders = array(); $folders = array();
@ -839,6 +837,8 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) {
//while (list($key, $id) = each($docs_and_folders)) { //while (list($key, $id) = each($docs_and_folders)) {
foreach ($docs_and_folders as $key => $document_data) { foreach ($docs_and_folders as $key => $document_data) {
$row = array(); $row = array();
$row['id'] = $document_data['id'];
$row['type'] = $document_data['filetype'];
// If the item is invisible, wrap it in a span with class invisible // If the item is invisible, wrap it in a span with class invisible
$invisibility_span_open = ($document_data['visibility'] == 0) ? '<span class="invisible">' : ''; $invisibility_span_open = ($document_data['visibility'] == 0) ? '<span class="invisible">' : '';
@ -852,6 +852,7 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) {
} else { } else {
$document_name = basename($document_data['path']); $document_name = basename($document_data['path']);
} }
$row['name'] = $document_name;
// Data for checkbox // Data for checkbox
if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($docs_and_folders) > 1) { if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($docs_and_folders) > 1) {
$row[] = $document_data['path']; $row[] = $document_data['path'];
@ -920,6 +921,7 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) {
} }
$row[] = $last_edit_date; $row[] = $last_edit_date;
$row[] = $size; $row[] = $size;
$row[] = $document_name;
$total_size = $total_size + $size; $total_size = $total_size + $size;
if ((isset($_GET['keyword']) && search_keyword($document_name, $_GET['keyword'])) || !isset($_GET['keyword']) || empty($_GET['keyword'])) { if ((isset($_GET['keyword']) && search_keyword($document_name, $_GET['keyword'])) || !isset($_GET['keyword']) || empty($_GET['keyword'])) {
@ -1043,22 +1045,29 @@ if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_fold
$column_show[] = 1; $column_show[] = 1;
} }
$column_show[] = 0; $column_show[] = 0;
$column_show[] = 0;
$column_order = array(); $column_order = array();
if (count($row) == 8) { if (count($row) == 12) {
//teacher
$column_order[2] = 8; //name
$column_order[3] = 7; $column_order[3] = 7;
$column_order[4] = 6; $column_order[4] = 6;
} elseif (count($row) == 6) { } elseif (count($row) == 10) {
//student
$column_order[1] = 6;
$column_order[2] = 5; $column_order[2] = 5;
$column_order[3] = 4; $column_order[3] = 4;
} }
$default_column = $is_allowed_to_edit ? 2 : 1; $default_column = $is_allowed_to_edit ? 2 : 1;
$tablename = $is_allowed_to_edit ? 'teacher_table' : 'student_table'; $tablename = $is_allowed_to_edit ? 'teacher_table' : 'student_table';
$table = new SortableTableFromArrayConfig($sortable_data, $default_column, 20, $tablename, $column_show, $column_order, 'ASC');
if(isset($_GET['keyword'])){ //var_dump($column_show,$column_order);
$table = new SortableTableFromArrayConfig($sortable_data, $default_column, 20, $tablename, $column_show, $column_order, 'ASC', true);
if(isset($_GET['keyword'])) {
$query_vars['keyword'] = Security::remove_XSS($_GET['keyword']); $query_vars['keyword'] = Security::remove_XSS($_GET['keyword']);
}else{ }else{
$query_vars['curdirpath'] = $curdirpath; $query_vars['curdirpath'] = $curdirpath;
@ -1073,17 +1082,15 @@ $table->set_additional_parameters($query_vars);
$column = 0; $column = 0;
if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($docs_and_folders) > 1) { if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($docs_and_folders) > 1) {
$table->set_header($column++, '', false,array ('style' => 'width:30px;')); $table->set_header($column++, '', false, array('style' => 'width:30px;'));
} }
$table->set_header($column++, get_lang('Type'),true,array ('style' => 'width:30px;')); $table->set_header($column++, get_lang('Type'),true, array('style' => 'width:30px;'));
$table->set_header($column++, get_lang('Name')); $table->set_header($column++, get_lang('Name'));
$table->set_header($column++, get_lang('Size'),true, array('style' => 'width:50px;'));
//$column_header[] = array(get_lang('Comment'), true); // Display comment under the document name $table->set_header($column++, get_lang('Date'),true, array('style' => 'width:150px;'));
$table->set_header($column++, get_lang('Size'),true,array ('style' => 'width:50px;'));
$table->set_header($column++, get_lang('Date'),true,array ('style' => 'width:150px;'));
// Admins get an edit column // Admins get an edit column
if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $current_session_id)) { if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $current_session_id)) {
$table->set_header($column++, get_lang('Actions'), false,array ('style' => 'width:180px;')); $table->set_header($column++, get_lang('Actions'), false, array ('style' => 'width:180px;'));
} }
// Actions on multiple selected documents // Actions on multiple selected documents
@ -1096,9 +1103,7 @@ if (count($docs_and_folders) > 1) {
$table->set_form_actions($form_action, 'path'); $table->set_form_actions($form_action, 'path');
} }
} }
//echo '<div class="thumbnails yoxview">';
$table->display(); $table->display();
//echo '</div>';
if (count($docs_and_folders) > 1) { if (count($docs_and_folders) > 1) {
if ($is_allowed_to_edit || $group_member_with_upload_rights) { if ($is_allowed_to_edit || $group_member_with_upload_rights) {

@ -902,6 +902,8 @@ class SortableTableFromArrayConfig extends SortableTable {
*/ */
private $table_data; private $table_data;
private $doc_filter;
/** /**
* Constructor * Constructor
* @param array $table_data All the information of the table * @param array $table_data All the information of the table
@ -910,10 +912,12 @@ class SortableTableFromArrayConfig extends SortableTable {
* @param int $tablename Name of the table * @param int $tablename Name of the table
* @param array $column_show An array with binary values 1: we show the column 2: we don't show it * @param array $column_show An array with binary values 1: we show the column 2: we don't show it
* @param array $column_order An array of integers that let us decide how the columns are going to be sort. * @param array $column_order An array of integers that let us decide how the columns are going to be sort.
* @param bool special modification to fix the document name order
*/ */
public function __construct ($table_data, $default_column = 1, $default_items_per_page = 20, $tablename = 'tablename', $column_show = null, $column_order = null, $direction = 'ASC') { public function __construct ($table_data, $default_column = 1, $default_items_per_page = 20, $tablename = 'tablename', $column_show = null, $column_order = null, $direction = 'ASC', $doc_filter = false) {
$this->column_show = $column_show; $this->column_show = $column_show;
$this->column_order = $column_order; $this->column_order = $column_order;
$this->doc_filter = $doc_filter;
parent :: __construct ($tablename, null, null, $default_column, $default_items_per_page, $direction); parent :: __construct ($tablename, null, null, $default_column, $default_items_per_page, $direction);
$this->table_data = $table_data; $this->table_data = $table_data;
} }
@ -923,7 +927,7 @@ class SortableTableFromArrayConfig extends SortableTable {
* @see SortableTable#get_table_data * @see SortableTable#get_table_data
*/ */
public function get_table_data($from = 1) { public function get_table_data($from = 1) {
$content = TableSort :: sort_table_config($this->table_data, $this->column, $this->direction == 'ASC' ? SORT_ASC : SORT_DESC, $this->column_show, $this->column_order); $content = TableSort :: sort_table_config($this->table_data, $this->column, $this->direction == 'ASC' ? SORT_ASC : SORT_DESC, $this->column_show, $this->column_order, SORT_REGULAR, $this->doc_filter);
return array_slice($content, $from, $this->per_page); return array_slice($content, $from, $this->per_page);
} }
@ -931,7 +935,7 @@ class SortableTableFromArrayConfig extends SortableTable {
* Get total number of items * Get total number of items
* @see SortableTable#get_total_number_of_items * @see SortableTable#get_total_number_of_items
*/ */
public function get_total_number_of_items () { public function get_total_number_of_items() {
return count($this->table_data); return count($this->table_data);
} }
} }

@ -81,7 +81,7 @@ class TableSort {
* @return array The sorted dataset * @return array The sorted dataset
* @author bart.mollet@hogent.be * @author bart.mollet@hogent.be
*/ */
public function sort_table_config($data, $column = 0, $direction = SORT_ASC, $column_show = null, $column_order = null, $type = SORT_REGULAR) { public function sort_table_config($data, $column = 0, $direction = SORT_ASC, $column_show = null, $column_order = null, $type = SORT_REGULAR, $doc_filter = false) {
if (!is_array($data) || empty($data)) { if (!is_array($data) || empty($data)) {
return array(); return array();
@ -113,26 +113,56 @@ class TableSort {
} }
} }
$compare_operator = $direction == SORT_ASC ? '>' : '<='; //This fixs only works in the document tool when ordering by name
switch ($type) { if ($doc_filter && in_array($type, array(SORT_STRING))) {
case SORT_NUMERIC: $data_to_sort = $folder_to_sort = array();
$compare_function = 'return strip_tags($a['.$column.']) '.$compare_operator.' strip_tags($b['.$column.']);'; $new_data = array();
break; if (!empty($data)) {
case SORT_IMAGE: foreach ($data as $document) {
$compare_function = 'return api_strnatcmp(api_strtolower(strip_tags($a['.$column.'], "<img>")), api_strtolower(strip_tags($b['.$column.'], "<img>"))) '.$compare_operator.' 0;'; if ($document['type'] == 'folder') {
break; $docs_to_sort[$document['id']] = api_strtolower($document['name']);
case SORT_DATE: } else {
$compare_function = 'return strtotime(strip_tags($a['.$column.'])) '.$compare_operator.' strtotime(strip_tags($b['.$column.']));'; $folder_to_sort[$document['id']] = api_strtolower($document['name']);
break; }
case SORT_STRING: $new_data[$document['id']] = $document;
default: }
$compare_function = 'return api_strnatcmp(api_strtolower(strip_tags($a['.$column.'])), api_strtolower(strip_tags($b['.$column.']))) '.$compare_operator.' 0;'; if ($direction == SORT_ASC) {
break; api_natrsort($docs_to_sort);
api_natrsort($folder_to_sort);
} else {
api_natsort($docs_to_sort);
api_natsort($folder_to_sort);
}
$new_data_order = array();
foreach($docs_to_sort as $id => $document) {
$new_data_order[] = $new_data[$id];
}
foreach($folder_to_sort as $id => $document) {
$new_data_order[] = $new_data[$id];
}
$data = $new_data_order;
}
} else {
$compare_operator = $direction == SORT_ASC ? '>' : '<=';
switch ($type) {
case SORT_NUMERIC:
$compare_function = 'return strip_tags($a['.$column.']) '.$compare_operator.' strip_tags($b['.$column.']);';
break;
case SORT_IMAGE:
$compare_function = 'return api_strnatcmp(api_strtolower(strip_tags($a['.$column.'], "<img>")), api_strtolower(strip_tags($b['.$column.'], "<img>"))) '.$compare_operator.' 0;';
break;
case SORT_DATE:
$compare_function = 'return strtotime(strip_tags($a['.$column.'])) '.$compare_operator.' strtotime(strip_tags($b['.$column.']));';
break;
case SORT_STRING:
default:
$compare_function = 'return api_strnatcmp(api_strtolower(strip_tags($a['.$column.'])), api_strtolower(strip_tags($b['.$column.']))) '.$compare_operator.' 0;';
break;
}
// Sort the content
usort($data, create_function('$a, $b', $compare_function));
} }
// Sort the content
usort($data, create_function('$a, $b', $compare_function));
if (is_array($column_show)) { if (is_array($column_show)) {
// We show only the columns data that were set up on the $column_show array // We show only the columns data that were set up on the $column_show array
$new_order_data = array(); $new_order_data = array();

Loading…
Cancel
Save