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

skala
Julio Montoya 15 years ago
parent 38ce4f1a69
commit 85a076b622
  1. 29
      main/document/document.php
  2. 8
      main/inc/lib/sortabletable.class.php
  3. 34
      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 /
$document_id = DocumentManager::get_document_id($_course, $curdirpath);
if (!$document_id) {
$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);
}
$htmlHeadXtra[] =
"<script type=\"text/javascript\">
function confirmation (name) {
@ -785,13 +783,13 @@ if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && isse
}
}
/* GET ALL DOCUMENT DATA FOR CURDIRPATH */
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 {
$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);
if ($folders === false) {
$folders = array();
@ -839,6 +837,8 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) {
//while (list($key, $id) = each($docs_and_folders)) {
foreach ($docs_and_folders as $key => $document_data) {
$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
$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 {
$document_name = basename($document_data['path']);
}
$row['name'] = $document_name;
// Data for checkbox
if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($docs_and_folders) > 1) {
$row[] = $document_data['path'];
@ -920,6 +921,7 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) {
}
$row[] = $last_edit_date;
$row[] = $size;
$row[] = $document_name;
$total_size = $total_size + $size;
if ((isset($_GET['keyword']) && search_keyword($document_name, $_GET['keyword'])) || !isset($_GET['keyword']) || empty($_GET['keyword'])) {
@ -1043,20 +1045,27 @@ if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_fold
$column_show[] = 1;
}
$column_show[] = 0;
$column_show[] = 0;
$column_order = array();
if (count($row) == 8) {
if (count($row) == 12) {
//teacher
$column_order[2] = 8; //name
$column_order[3] = 7;
$column_order[4] = 6;
} elseif (count($row) == 6) {
} elseif (count($row) == 10) {
//student
$column_order[1] = 6;
$column_order[2] = 5;
$column_order[3] = 4;
}
$default_column = $is_allowed_to_edit ? 2 : 1;
$tablename = $is_allowed_to_edit ? 'teacher_table' : 'student_table';
$table = new SortableTableFromArrayConfig($sortable_data, $default_column, 20, $tablename, $column_show, $column_order, 'ASC');
//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']);
@ -1077,8 +1086,6 @@ if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($docs_and
}
$table->set_header($column++, get_lang('Type'),true, array('style' => 'width:30px;'));
$table->set_header($column++, get_lang('Name'));
//$column_header[] = array(get_lang('Comment'), true); // Display comment under the document name
$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
@ -1096,9 +1103,7 @@ if (count($docs_and_folders) > 1) {
$table->set_form_actions($form_action, 'path');
}
}
//echo '<div class="thumbnails yoxview">';
$table->display();
//echo '</div>';
if (count($docs_and_folders) > 1) {
if ($is_allowed_to_edit || $group_member_with_upload_rights) {

@ -902,6 +902,8 @@ class SortableTableFromArrayConfig extends SortableTable {
*/
private $table_data;
private $doc_filter;
/**
* Constructor
* @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 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 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_order = $column_order;
$this->doc_filter = $doc_filter;
parent :: __construct ($tablename, null, null, $default_column, $default_items_per_page, $direction);
$this->table_data = $table_data;
}
@ -923,7 +927,7 @@ class SortableTableFromArrayConfig extends SortableTable {
* @see SortableTable#get_table_data
*/
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);
}

@ -81,7 +81,7 @@ class TableSort {
* @return array The sorted dataset
* @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)) {
return array();
@ -113,6 +113,36 @@ class TableSort {
}
}
//This fixs only works in the document tool when ordering by name
if ($doc_filter && in_array($type, array(SORT_STRING))) {
$data_to_sort = $folder_to_sort = array();
$new_data = array();
if (!empty($data)) {
foreach ($data as $document) {
if ($document['type'] == 'folder') {
$docs_to_sort[$document['id']] = api_strtolower($document['name']);
} else {
$folder_to_sort[$document['id']] = api_strtolower($document['name']);
}
$new_data[$document['id']] = $document;
}
if ($direction == SORT_ASC) {
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:
@ -129,9 +159,9 @@ class TableSort {
$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));
}
if (is_array($column_show)) {
// We show only the columns data that were set up on the $column_show array

Loading…
Cancel
Save