Minor - format code.

1.9.x
Julio Montoya 11 years ago
parent b7708be08a
commit cc92e0bfbc
  1. 12
      main/inc/lib/document.lib.php
  2. 150
      main/inc/lib/sortable_table.class.php
  3. 266
      main/inc/lib/table_sort.class.php

@ -526,9 +526,11 @@ class DocumentManager
last.insert_user_id
FROM $TABLE_ITEMPROPERTY AS last
INNER JOIN $TABLE_DOCUMENT AS docs
ON (docs.id = last.ref AND last.tool = '".TOOL_DOCUMENT."' AND
docs.c_id = {$_course['real_id']} AND
last.c_id = {$_course['real_id']})
ON (
docs.id = last.ref AND last.tool = '".TOOL_DOCUMENT."' AND
docs.c_id = {$_course['real_id']} AND
last.c_id = {$_course['real_id']}
)
WHERE
docs.path LIKE '" . $path . $added_slash . "%' AND
docs.path NOT LIKE '" . $path . $added_slash . "%/%' AND
@ -572,8 +574,8 @@ class DocumentManager
$sql = "SELECT id FROM $table_template
WHERE
course_code = '" . $_course['code'] . "' AND
user_id = '" . api_get_user_id() . "' AND
ref_doc = '" . $row['id'] . "'";
user_id = '".api_get_user_id()."' AND
ref_doc = '".$row['id']."'";
$template_result = Database::query($sql);
$row['is_template'] = (Database::num_rows($template_result) > 0) ? 1 : 0;
}

@ -8,7 +8,7 @@
*/
require_once 'pear/HTML/Table.php';
require_once 'pear/Pager/Pager.php';
//require_once 'tablesort.lib.php'; moved to autoload table_sort.class.php
/**
* This class allows you to display a sortable data-table. It is possible to
* split the data in several pages.
@ -21,7 +21,8 @@ require_once 'pear/Pager/Pager.php';
* - navigate through all data-pages
* @package chamilo.library
*/
class SortableTable extends HTML_Table {
class SortableTable extends HTML_Table
{
/**
* A name for this table
*/
@ -113,6 +114,7 @@ class SortableTable extends HTML_Table {
* on one page
* @param string $default_order_direction The default order direction;
* either the constant 'ASC' or 'DESC'
* @param string $table_id
*/
public function __construct(
$table_name = 'table',
@ -128,17 +130,17 @@ class SortableTable extends HTML_Table {
}
$this->table_id = $table_id;
parent :: __construct (array ('class' => 'data_table', 'id' => $table_id));
parent::__construct(array('class' => 'data_table', 'id' => $table_id));
$this->table_name = $table_name;
$this->additional_parameters = array();
$this->param_prefix = $table_name.'_';
$this->page_nr = isset ($_SESSION[$this->param_prefix.'page_nr']) ? intval($_SESSION[$this->param_prefix.'page_nr']) : 1;
$this->page_nr = isset ($_GET[$this->param_prefix.'page_nr']) ? intval($_GET[$this->param_prefix.'page_nr']) : $this->page_nr;
$this->column = isset ($_SESSION[$this->param_prefix.'column']) ? intval($_SESSION[$this->param_prefix.'column']) : $default_column;
$this->column = isset ($_GET[$this->param_prefix.'column']) ? intval($_GET[$this->param_prefix.'column']) : $this->column;
$this->page_nr = isset($_SESSION[$this->param_prefix.'page_nr']) ? intval($_SESSION[$this->param_prefix.'page_nr']) : 1;
$this->page_nr = isset($_GET[$this->param_prefix.'page_nr']) ? intval($_GET[$this->param_prefix.'page_nr']) : $this->page_nr;
$this->column = isset($_SESSION[$this->param_prefix.'column']) ? intval($_SESSION[$this->param_prefix.'column']) : $default_column;
$this->column = isset($_GET[$this->param_prefix.'column']) ? intval($_GET[$this->param_prefix.'column']) : $this->column;
//Default direction
// Default direction.
if (in_array(strtoupper($default_order_direction), array('ASC', 'DESC'))) {
$this->direction = $default_order_direction;
@ -170,12 +172,11 @@ class SortableTable extends HTML_Table {
}
}
// Allow to change paginate in multiples tabs
unset($_SESSION[$this->param_prefix.'per_page']);
$this->per_page = isset ($_SESSION[$this->param_prefix.'per_page']) ? intval($_SESSION[$this->param_prefix.'per_page']) : $default_items_per_page;
$this->per_page = isset ($_GET[$this->param_prefix.'per_page']) ? intval($_GET[$this->param_prefix.'per_page']) : $this->per_page;
$this->per_page = isset($_SESSION[$this->param_prefix.'per_page']) ? intval($_SESSION[$this->param_prefix.'per_page']) : $default_items_per_page;
$this->per_page = isset($_GET[$this->param_prefix.'per_page']) ? intval($_GET[$this->param_prefix.'per_page']) : $this->per_page;
$_SESSION[$this->param_prefix.'per_page'] = $this->per_page;
$_SESSION[$this->param_prefix.'direction'] = $this->direction ;
@ -197,7 +198,8 @@ class SortableTable extends HTML_Table {
/**
* Get the Pager object to split the showed data in several pages
*/
public function get_pager() {
public function get_pager()
{
if (is_null($this->pager)) {
$total_number_of_items = $this->get_total_number_of_items();
$params['mode'] = 'Sliding';
@ -228,15 +230,20 @@ class SortableTable extends HTML_Table {
return $this->pager;
}
/**
* Display the table
*/
public function display()
{
echo $this->return_table();
}
/**
* Displays the table, complete with navigation buttons to browse through
* the data-pages.
*/
public function return_table() {
public function return_table()
{
$empty_table = false;
$content = $this->get_table_html();
@ -337,7 +344,8 @@ class SortableTable extends HTML_Table {
* This function shows the content of a table in a grid.
* Should not be use to edit information (edit/delete rows) only.
* */
public function display_grid() {
public function display_grid()
{
$empty_table = false;
if ($this->get_total_number_of_items() == 0) {
@ -425,40 +433,8 @@ class SortableTable extends HTML_Table {
}
}
$html .= '</div>'; //close grid_container
$html .= '</div>'; //close main grid
$html .= '<div class="clear"></div>';
/*
if (!$empty_table) {
$html .= '<table style="width:100%;">';
$html .= '<tr>';
$html .= '<td colspan="2">';
if (count($this->form_actions) > 0) {
$html .= '<br />';
$html .= '<a href="?'.$params.'&amp;'.$this->param_prefix.'selectall=1" onclick="javascript:setCheckbox(true);return false;">'.get_lang('SelectAll').'</a> - ';
$html .= '<a href="?'.$params.'" onclick="javascript:setCheckbox(false);return false;">'.get_lang('UnSelectAll').'</a> ';
$html .= '<select name="action">';
foreach ($this->form_actions as $action => $label) {
$html .= '<option value="'.$action.'">'.$label.'</option>';
}
$html .= '</select>';
$html .= '&nbsp;&nbsp;<button type="submit" class="save" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."'".')) return false;">'.get_lang('Select').'</button>';
} else {
$html .= $form;
}
$html .= '</td>';
$html .= '<td style="text-align:right;">';
$html .= $nav;
$html .= '</td>';
$html .= '</tr>';
$html .= '</div>';
if (count($this->form_actions) > 0) {
$html .= '</form>';
}
}
*/
echo $html;
}
@ -471,8 +447,8 @@ class SortableTable extends HTML_Table {
* @param bool sort data optionally
* @return string grid html
*/
public function display_simple_grid($visibility_options, $hide_navigation = true, $per_page = 20, $sort_data = true, $grid_class = array()) {
public function display_simple_grid($visibility_options, $hide_navigation = true, $per_page = 20, $sort_data = true, $grid_class = array())
{
$empty_table = false;
$total = $this->get_total_number_of_items();
@ -578,7 +554,8 @@ class SortableTable extends HTML_Table {
* Get the HTML-code with the navigational buttons to browse through the
* data-pages.
*/
public function get_navigation_html () {
public function get_navigation_html()
{
$pager = $this->get_pager();
$pager_links = $pager->getLinks();
@ -591,7 +568,8 @@ class SortableTable extends HTML_Table {
/**
* Get the HTML-code with the data-table.
*/
public function get_table_html() {
public function get_table_html()
{
$pager = $this->get_pager();
$offset = $pager->getOffsetByPageId();
$from = $offset[0] - 1;
@ -628,7 +606,8 @@ class SortableTable extends HTML_Table {
* @param bool true for sorting table data or false otherwise
* @return array table row items
*/
public function get_clean_html($sort = true) {
public function get_clean_html($sort = true)
{
$pager = $this->get_pager();
$offset = $pager->getOffsetByPageId();
$from = $offset[0] - 1;
@ -646,10 +625,11 @@ class SortableTable extends HTML_Table {
}
/**
* Get the HTML-code wich represents a form to select how many items a page
* Get the HTML-code which represents a form to select how many items a page
* should contain.
*/
public function get_page_select_form () {
public function get_page_select_form()
{
$total_number_of_items = $this->get_total_number_of_items();
if ($total_number_of_items <= $this->default_items_per_page) {
return '';
@ -686,7 +666,8 @@ class SortableTable extends HTML_Table {
/**
* Get the table title.
*/
public function get_table_title () {
public function get_table_title()
{
$pager = $this->get_pager();
$showed_items = $pager->getOffsetByPageId();
return $showed_items[0].' - '.$showed_items[1].' / '.$this->get_total_number_of_items();
@ -703,7 +684,8 @@ class SortableTable extends HTML_Table {
* @param string $td_attributes Additional attributes for the td-tags of the
* column
*/
public function set_header ($column, $label, $sortable = true, $th_attributes = null, $td_attributes = null) {
public function set_header($column, $label, $sortable = true, $th_attributes = null, $td_attributes = null)
{
$param['direction'] = 'ASC';
if ($this->column == $column && $this->direction == 'ASC') {
$param['direction'] = 'DESC';
@ -737,7 +719,8 @@ class SortableTable extends HTML_Table {
* Get the parameter-string with additional parameters to use in the URLs
* generated by this SortableTable
*/
public function get_additional_url_paramstring () {
public function get_additional_url_paramstring()
{
$param_string_parts = array ();
if (is_array($this->additional_parameters) && count($this->additional_parameters) > 0) {
foreach ($this->additional_parameters as $key => & $value) {
@ -779,7 +762,8 @@ class SortableTable extends HTML_Table {
* Get the parameter-string with the SortableTable-related parameters to use
* in URLs
*/
public function get_sortable_table_param_string () {
public function get_sortable_table_param_string()
{
$param[$this->param_prefix.'direction'] = $this->direction;
$param[$this->param_prefix.'page_nr'] = $this->page_nr;
$param[$this->param_prefix.'per_page'] = $this->per_page;
@ -799,7 +783,8 @@ class SortableTable extends HTML_Table {
* @param string $function The name of the filter-function. This should be a
* function wich requires 1 parameter and returns the filtered value.
*/
public function set_column_filter ($column, $function) {
public function set_column_filter($column, $function)
{
$this->column_filters[$column] = $function;
}
@ -812,7 +797,8 @@ class SortableTable extends HTML_Table {
* @param string $checkbox_name The name of the generated checkboxes. The
* value of the checkbox will be the value of the first column.
*/
public function set_form_actions ($actions, $checkbox_name = 'id') {
public function set_form_actions ($actions, $checkbox_name = 'id')
{
$this->form_actions = $actions;
$this->checkbox_name = $checkbox_name;
}
@ -822,7 +808,8 @@ class SortableTable extends HTML_Table {
* <code>$parameters['action'] = 'test'; will be convert in <input type="hidden" name="action" value="test"></code>
* @param array $parameters
*/
public function set_additional_parameters ($parameters) {
public function set_additional_parameters($parameters)
{
$this->additional_parameters = $parameters;
}
/**
@ -895,7 +882,7 @@ class SortableTable extends HTML_Table {
* @param string $direction In which order should the data be sorted (ASC
* or DESC)
*/
public function get_table_data ($from = null, $per_page = null, $column = null, $direction = null, $sort = null)
public function get_table_data($from = null, $per_page = null, $column = null, $direction = null, $sort = null)
{
if (!is_null($this->get_data_function)) {
return call_user_func($this->get_data_function, $from, $this->per_page, $this->column, $this->direction);
@ -908,7 +895,8 @@ class SortableTable extends HTML_Table {
* Sortable table which can be used for data available in an array
* @package chamilo.library
*/
class SortableTableFromArray extends SortableTable {
class SortableTableFromArray extends SortableTable
{
/**
* The array containing all data for this table
*/
@ -929,9 +917,10 @@ class SortableTableFromArray extends SortableTable {
* Get table data to show on current page
* @see SortableTable#get_table_data
*/
public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = true) {
public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = true)
{
if ($sort) {
$content = TableSort :: sort_table($this->table_data, $this->column, $this->direction == 'ASC' ? SORT_ASC : SORT_DESC);
$content = TableSort::sort_table($this->table_data, $this->column, $this->direction == 'ASC' ? SORT_ASC : SORT_DESC);
} else {
$content = $this->table_data;
}
@ -964,7 +953,8 @@ class SortableTableFromArray extends SortableTable {
* @package chamilo.library
*/
class SortableTableFromArrayConfig extends SortableTable {
class SortableTableFromArrayConfig extends SortableTable
{
/**
* The array containing the columns that will be show i.e $column_show=array('1','0','0'); we will show only the 1st column
*/
@ -978,7 +968,6 @@ class SortableTableFromArrayConfig extends SortableTable {
* The array containing all data for this table
*/
private $table_data;
private $doc_filter;
/**
@ -989,13 +978,23 @@ 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
* @param string $direction
* @param bool $doc_filter 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', $doc_filter = false) {
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);
parent::__construct($tablename, null, null, $default_column, $default_items_per_page, $direction);
$this->table_data = $table_data;
}
@ -1003,8 +1002,14 @@ class SortableTableFromArrayConfig extends SortableTable {
* Get table data to show on current page
* @see SortableTable#get_table_data
*/
public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = true) {
$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);
public function get_table_data(
$from = 1,
$per_page = null,
$column = null,
$direction = null,
$sort = true
) {
$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);
}
@ -1012,7 +1017,8 @@ class SortableTableFromArrayConfig extends 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);
}
}

@ -14,64 +14,65 @@ define('SORT_IMAGE', 4);
/**
* @package chamilo.library
*/
class TableSort {
class TableSort
{
/**
* Sorts 2-dimensional table.
* @param array $data The data to be sorted.
* @param int $column The column on which the data should be sorted (default = 0)
* @param int $direction The direction to sort (SORT_ASC (default) or SORT_DESC)
* @param int $type How should data be sorted (SORT_REGULAR, SORT_NUMERIC,
* SORT_STRING,SORT_DATE,SORT_IMAGE)
* @return array The sorted dataset
* @author bart.mollet@hogent.be
*/
public static function sort_table($data, $column = 0, $direction = SORT_ASC, $type = SORT_REGULAR)
{
if (!is_array($data) || empty($data)) {
return array();
}
if ($column != strval(intval($column))) {
// Probably an attack
return $data;
}
if (!in_array($direction, array(SORT_ASC, SORT_DESC))) {
// Probably an attack
return $data;
}
/**
* Sorts 2-dimensional table.
* @param array $data The data to be sorted.
* @param int $column The column on which the data should be sorted (default = 0)
* @param string $direction The direction to sort (SORT_ASC (default) or SORT_DESC)
* @param constant $type How should data be sorted (SORT_REGULAR, SORT_NUMERIC,
* SORT_STRING,SORT_DATE,SORT_IMAGE)
* @return array The sorted dataset
* @author bart.mollet@hogent.be
*/
public static function sort_table($data, $column = 0, $direction = SORT_ASC, $type = SORT_REGULAR) {
if (!is_array($data) || empty($data)) {
return array();
}
if ($column != strval(intval($column))) {
// Probably an attack
return $data;
}
if (!in_array($direction, array(SORT_ASC, SORT_DESC))) {
// Probably an attack
return $data;
}
if ($type == SORT_REGULAR) {
if (TableSort::is_image_column($data, $column)) {
$type = SORT_IMAGE;
} elseif (TableSort::is_date_column($data, $column)) {
$type = SORT_DATE;
} elseif (TableSort::is_numeric_column($data, $column)) {
$type = SORT_NUMERIC;
} else {
$type = SORT_STRING;
}
}
if ($type == SORT_REGULAR) {
if (TableSort::is_image_column($data, $column)) {
$type = SORT_IMAGE;
} elseif (TableSort::is_date_column($data, $column)) {
$type = SORT_DATE;
} elseif (TableSort::is_numeric_column($data, $column)) {
$type = SORT_NUMERIC;
} else {
$type = SORT_STRING;
}
}
$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;
}
$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));
return $data;
return $data;
}
/**
@ -85,58 +86,65 @@ class TableSort {
* @return array The sorted dataset
* @author bart.mollet@hogent.be
*/
public static function sort_table_config($data, $column = 0, $direction = SORT_ASC, $column_show = null, $column_order = null, $type = SORT_REGULAR, $doc_filter = false) {
public static 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();
}
if ($column != strval(intval($column))) {
// Probably an attack
return $data;
}
if (!in_array($direction, array(SORT_ASC, SORT_DESC))) {
// Probably an attack
return $data;
}
if (!is_array($data) || empty($data)) {
return array();
}
if ($column != strval(intval($column))) {
// Probably an attack
return $data;
}
if (!in_array($direction, array(SORT_ASC, SORT_DESC))) {
// Probably an attack
return $data;
}
// Change columns sort
// Here we say that the real way of how the columns are going to be order is manage by the $column_order array
if (is_array($column_order)) {
$column = isset($column_order[$column]) ? $column_order[$column] : $column;
}
// Change columns sort
// Here we say that the real way of how the columns are going to be order is manage by the $column_order array
if (is_array($column_order)) {
$column = isset($column_order[$column]) ? $column_order[$column] : $column;
}
if ($type == SORT_REGULAR) {
if (TableSort::is_image_column($data, $column)) {
$type = SORT_IMAGE;
} elseif (TableSort::is_date_column($data, $column)) {
$type = SORT_DATE;
} elseif (TableSort::is_numeric_column($data, $column)) {
$type = SORT_NUMERIC;
} else {
$type = SORT_STRING;
}
}
if ($type == SORT_REGULAR) {
if (TableSort::is_image_column($data, $column)) {
$type = SORT_IMAGE;
} elseif (TableSort::is_date_column($data, $column)) {
$type = SORT_DATE;
} elseif (TableSort::is_numeric_column($data, $column)) {
$type = SORT_NUMERIC;
} else {
$type = SORT_STRING;
}
}
//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;
}
//This fixs only works in the document tool when ordering by name
if ($doc_filter && in_array($type, array(SORT_STRING))) {
$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) {
if (!empty($docs_to_sort)) {
api_natrsort($docs_to_sort);
}
if (!empty($folder_to_sort)) {
api_natrsort($folder_to_sort);
}
}
} else {
if (!empty($docs_to_sort)) {
api_natsort($docs_to_sort);
@ -148,36 +156,42 @@ class TableSort {
$new_data_order = array();
if (!empty($docs_to_sort)) {
foreach($docs_to_sort as $id => $document) {
$new_data_order[] = $new_data[$id];
if (isset($new_data[$id])) {
$new_data_order[] = $new_data[$id];
}
}
}
if (!empty($folder_to_sort)) {
foreach($folder_to_sort as $id => $document) {
$new_data_order[] = $new_data[$id];
if (isset($new_data[$id])) {
$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));
}
$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));
}
if (is_array($column_show)) {
// We show only the columns data that were set up on the $column_show array
@ -208,7 +222,8 @@ class TableSort {
* @todo Take locale into account (eg decimal point or comma ?)
* @author bart.mollet@hogent.be
*/
private static function is_numeric_column(& $data, $column) {
private static function is_numeric_column(& $data, $column)
{
$is_numeric = true;
foreach ($data as $index => & $row) {
$is_numeric &= is_numeric(strip_tags($row[$column]));
@ -226,7 +241,8 @@ class TableSort {
* @return bool TRUE if column contains only dates, FALSE otherwise
* @author bart.mollet@hogent.be
*/
private static function is_date_column(& $data, $column) {
private static function is_date_column(& $data, $column)
{
$is_date = true;
foreach ($data as $index => & $row) {
if (strlen(strip_tags($row[$column])) != 0) {
@ -251,7 +267,8 @@ class TableSort {
* @return bool TRUE if column contains only images, FALSE otherwise
* @author bart.mollet@hogent.be
*/
private static function is_image_column(& $data, $column) {
private static function is_image_column(& $data, $column)
{
$is_image = true;
foreach ($data as $index => & $row) {
$is_image &= strlen(trim(strip_tags($row[$column], '<img>'))) > 0; // at least one img-tag
@ -262,5 +279,4 @@ class TableSort {
}
return $is_image;
}
}

Loading…
Cancel
Save