AdminLists

From GeeklogWiki
Revision as of 06:06, 23 August 2007 by Tokyoahead (talk | contribs) (Aditional Form Fields)

Jump to: navigation, search

Introduction

Geeklog 1.4 has an engine to create tables/lists from data. This engine can be used to make sure that all tabular information looks similar all over the site. It is also helpful to reduce the amount of code that has to be written for a table, including template files.

To use this function, you have to choose between two main differences: Simple & Complex lists. The main difference is that the simple lists need an array of data and the complex lists need an SQL string of data. So if you do not have your data in a database table, you will need to use a simple list. Also, the simple lists only can be displayed several times on a page (such as used on the moderation and statistics screens).

Generally it is recommended to take any of the existing lists and changing the details. This makes sure that you use the required set of data for a complete table.

Simple Lists

The header

The first element of a list is the header, the line where you can read what the information below represents. To define those use an array, each of the elements of the array define one column:

$header_arr = array(
    array(                         // Column 1
        'text' => $LANG10[1], 
        'field' => 'title', 
        'width' => '90%', 
        'header_class' => 'stats-header-title'
    ),
    array(                         // Column 2
        'text' => "", 
        'field' => 'stats', 
        'header_class' => 'stats-header-count', 
        'field_class' => 'stats-list-count'
    ),
);

You can see that you need to create a multi-dimensional array with several fields, most of which are optional. Required are the first two.

Field/Array NameContentData TypeRequired
textThe text that the user sees on top of the columnstringYes
fieldThe field in the data-array that is used to show the datastringYes
header_classThe CSS class that should be assigned to the header fieldstringNo
field_classThe CSS class that should be assigned to the data fields belowstringNo

Text fields & Settings

Then, you need a text-array, defining some other details of the table:

$text_arr = array(
    'has_menu' => false,
    'title' => $LANG10[1],
);
<td>string</th><td>No</td>

<tr><td>instructions</td><td>Some text to explain how the table works. This only shows if has_menu = true</td><td>string</td><td>no</td></tr> <tr><td>no_data</td><td>The string that is shown in case the table is empty. If this is not given, $LANG_ADMIN['no_results'] is shown</td><td>string</td><td>No</td></tr> </table>

The Menu

In case the $text_arr stats has_menu = true, you need to give the following array for the menu details:

$menu_arr = array(
    array(                         // Menu Item 1
        'text' => $LANG10[1], 
        'url' => 'http://...'
    ),
    array(                         // Menu Item 2
        'text' => $LANG10[2], 
        'url' => 'http://...'
    ),
);

This pretty straight-forward Array gives a text to display and a url to link for each desired menu item. The next array is called $form_arr and is optional:

Aditional Form Fields

$form_arr = array(
    'top' = '<input type='hidden' name='text' value='text'>',
    'bottom' = '<input type='hidden' name='text' value='text'>'
);

This optional array allows you to display additional information above and below the table, specifically for form elements such as extra buttons, dropdowns, explanatory texts etc, since the tables have a form around them. Please take a look at the templates under /layout/professional/admin/lists/list.thtml to understand what you can do with them. Those forms are used for example in moderation.php.

The Data

The actual data is given through an array that holds one element for each cell.

$data_arr = array();
$data_arr[] = array(
    'title' => $LANG10[2], 
    'stats' => COM_NumberFormat ($totalhits)
);

This would create one line in the table. You can extend the array as you whish, but each field must match the fields given as 'field' the $header_arr().


... To be continued

Field/Array NameContentData TypeRequired
has_menuIf set to truebooleanYes
titleThe title of the table. Since the table will be in a block, the block needs a titlestringYes
help_urlThe url that shows help for the blockstringNo
form_urlThe form used in case the menu is therestringif has_menu=true
icon</th><td>An Icon to be displayed