Generic List From Online Manual

Revision as of 00:46, 26 January 2014 by Live627 (talk | contribs) (Created page with "{{TOCright}} ==Create a list== === Definitions === $listOptions = array( 'id' => [Required | string | An id for your list. Should contain A-Z, a-z, 0-9, - and _ characters ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Create a list

Definitions

 $listOptions = array(
  'id' => [Required | string | An id for your list.  Should contain A-Z, a-z, 0-9, - and _ characters only],
  'title' => [Optional | string | If you would like the top of your list titled, add this option],
  'base_href' => [Partially Required | string | Full url to your list required if there will be sorting or more than one page],
  'items_per_page' => [Optional | int | used if you would like your list spanning multiple pages],
  'default_sort_col' => [Optional | string | Default column to sort the list by.  Value here should be the index in the column array that you wish to sort by]
  'default_sort_dir' => [Optional | string | If this is not specified, the default sort column is sorted in ascending order.  If you wish to sort in decending order, this would be 'desc'],
  'width' => [Optional | string | width of the list, should have px, %, em, ex, etc, etc],
  'no_items_label' => [Optional | string | if your list has no items, this can display a message telling users that],
  'no_items_align' => [Optional | string | sets the alignment of your no items label (Left, right, center)],
  'start_var_name' => [Optional | string | if your list spans multiple pages, normally the url will contain 'start=40' to start at the 40th item.  You can change 'start' to something else with this variable],
  'request_vars' => array(
     'desc' => [Optional | string | instead of using 'desc' in the url to sort in decending order, you can specify a different value.  If you have more than one list created per page, you will need to specify a different value for each list.],
     'sort' => [Optional | string | instead of using 'sort' in the url to specify a sort column, you can specify a different value.  If you have more than one list created per page, you will need to specify a different value for each list.],
  ),
  'get_items' => array(
     'function' => [Required | string | function name to call that would perform the database query to actually get the items],
     'file' => [Optional | string | full path to file that contains the function to be called],
     'params' => [Optional | array | if you would like to pass extra parameters to the function, add them in an array here: array('value1', $value2, etc...)],
  ),
  'get_count' => array(
     'function' => [Partially Required | string | function name to call that would perform the database query to only get a count of items.  Required only if you specify 'items_per_page'.],
     'file' => [Optional | string | full path to file that contains the function to be called],
     'params' => [Optional | array | if you would like to pass extra parameters to the function, add them in an array here: array('value1', $value2, etc...)],
  ),
  'columns' => array(
     '[column_id]' => array(
        'header' => array(
           'value' => [Optional | string | Only value or eval may be used.  Eval overrides value if both exist.],
           'eval' => [Optional | string | this should be a proper PHP statement to be evaluated.  should begin with 'return' and end with a semicolon.],
           'colspan' => [Optional | int | used if the column header spans multiple columns],
           'class' => [Optional | string | custom class for this header cell],
           'style' => [Optional | string | custom style for this header cell],
        ),
        'data' => array(
           'db' => [Optional | string | column name from the database to directly display with no modification],
           'db_htmlsafe' => [Optional | string | if you want the database column run through htmlspecialchars, use this option],
           'eval' => [Optional | string | a proper php statment to be used.  you can insert database columns by putting them in % signs (ie: 'return %id_member%;')],
           'function' => [Optional | string | must start with create_function('$rowData', 'your function here').],
           'sprintf' => array(
              'format' => [Required | string | should be a properly formated sprintf string],
              'params' => array(
                 '[database column]' => [Requred | true|false | [database column] should be the column you want to insert, and it should be set to true to run through htmlspecialchars, or false to insert as is.  You may do as many entries here as you need for each column you're inserting]
              ),
           ),
           'value' => [Optional | string | insert a non database value in this cell],
           'style' => [Optional | string | custom style for this cell],
           'class' => [Optional | string | custom class for this cell],
        ),
        'sort' => array(
           'default' => [Optional | string | database column to do default sorting on (if you want this column sorted)],
           'reverse' => [Optional | string | database column to do reverse sorting on (normally same as above, but with 'DESC' after it],
        ),         
     ),
  ),
  'form' => array(
     'href' => [Required | string | if using a form, this field is required and should be the full url to post to],
     'hidden_fields' => array(
        '[name]' => [Required | string | [name] should be your hidden form value name, and the value should be a string to insert.  You may add as many as you want to this array],
     ),
     'include_sort' => [Optional | true|false | after form submit, if you want the sorting to remain, set this to true],
     'include_start' => [Optional | ture|false | after form submit, if you want to return to the same page, set this to true],
  ),
  'additional_rows' => array(
     array(
        'position' => [Required | string | must be one of the following: top_of_list, after_title, above_column_headers, below_table_data, bottom_of_list],
        'value' => [Required | string | whatever you want to place here],
     ),
  ),
  'javascript' => [Optional | string | proper javascript to be included at bottom of list],
  'list_menu' => array(
     'style' => [Required | tabs|buttons | needs to be 'tabs' or 'buttons'],
     'position' => [Required | left|right | position for menu],
     'links' => array(
        'name' => array(
           'href' => [Required | string | full link to where the menu item points,
           'label' => [Required | string | what should be on the link],
           'is_selected' => [Required | true|false | If we use tabs instead of buttons we highlight the current tab. Must use conditions to determine if its selected or not.],
        ),
     ),
  );

Calling the function

// Now that we have all the options, create the list.
require_once($sourcedir . '/Subs-List.php');
createList($listOptions);

Setting up the template

$context['sub_template'] = 'show_list';
$context['default_list'] = 'member_list'; // this must be the same as the id in $listOptions


Advertisement: