Generic List: Difference between revisions From Online Manual

Jump to: navigation, search
(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 ...")
 
 
Line 2: Line 2:
==Create a list==
==Create a list==
=== Definitions ===
=== Definitions ===
  $listOptions = array(
* '''id''' - '''mandatory''', an id to identify the list
  'id' => [Required | string | An id for your list.  Should contain A-Z, a-z, 0-9, - and _ characters only],
* '''columns''' - '''mandatory''', an associative array of columns, the key of each column must be unique (of course) the value is an array of values:
  'title' => [Optional | string | If you would like the top of your list titled, add this option],
** '''sort''' - ''optional'', an associative array that holds the rules to sort the column, it can contain:
  'base_href' => [Partially Required | string | Full url to your list required if there will be sorting or more than one page],
*** '''default''' - '''mandatory''', the default sorting rule;
  'items_per_page' => [Optional | int | used if you would like your list spanning multiple pages],
*** '''reverse''' - '''mandatory''', the reverse sorting rule;
  '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]
** '''header''' - '''mandatory''', an associative array describing the header of the column, it can contain the following indexes:
  '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'],
*** '''eval''' - ''optional'' (alternative to value), php code that will be passed to the php function eval;
  'width' => [Optional | string | width of the list, should have px, %, em, ex, etc, etc],
*** '''value''' - ''optional'' (alternative to eval), a value (usually a string) that will be displayed as column header;
  'no_items_label' => [Optional | string | if your list has no items, this can display a message telling users that],
*** '''class''' - ''optional'', a css class to use for the header of the column;
  'no_items_align' => [Optional | string | sets the alignment of your no items label (Left, right, center)],
*** '''style''' - ''optional'', a css style to use for the header of the column;
  '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],
*** '''colspan''' - ''optional'', a number that will be used for the colspan attribute of the header;
  'request_vars' => array(
** '''data''' - '''mandatory''', an associative array that holds the information to display the information, it can contain:
      '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.],
*** '''db''' - ''optional'' (alternative to db_htmlsafe, sprintf, function, eval, value), the easiest way, a value straight from the database;
      '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.],
*** '''db_htmlsafe''' - ''optional'' (alternative to db, sprintf, function, eval, value), similar to db, but make the value HTML safe;
  ),
*** '''sprintf'''' - ''optional'' (alternative to db, db_htmlsafe, function, eval, value), uses vsprintf to prepare the value, it must be in the form of an associative array containing:
  'get_items' => array(
**** '''params''' - '''mandatory''', pairs of values: the key holds the string to be used as parameter of vsprintf and the value is a boolean that defines if the key must be html safe or not.
      'function' => [Required | string | function name to call that would perform the database query to actually get the items],
**** '''format''' - '''mandatory''', the format of the string (the first parameter of vsprintf).
      'file' => [Optional | string | full path to file that contains the function to be called],
*** '''function''' - ''optional'' (alternative to db, db_htmlsafe, sprintf, eval, value), a php function that returns the value that should be displayed;
      'params' => [Optional | array | if you would like to pass extra parameters to the function, add them in an array here: array('value1', $value2, etc...)],
*** '''eval''' - ''optional'' (alternative to db, db_htmlsafe, sprintf, function, value), code that is passed to the php eval function;
  ),
*** '''value''' - ''optional'' (alternative to db, db_htmlsafe, sprintf, function, eval), a literal value;
  'get_count' => array(
*** if none from db, db_htmlsafe, sprintf, function, eval, value is present an empty string will be displayed;
      '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'.],
*** '''comma_format''' - ''optional'', boolean if true the value is passed to the function comma_format;
      'file' => [Optional | string | full path to file that contains the function to be called],
*** '''timeformat''' - ''optional'', boolean if true the value is passed to the function timeformat;
      'params' => [Optional | array | if you would like to pass extra parameters to the function, add them in an array here: array('value1', $value2, etc...)],
*** '''class''' - ''optional'', a css class to use for the column;
  ),
*** '''style''' - ''optional'', a css style to use for the column;
  'columns' => array(
 
      '[column_id]' => array(
* '''data_check''' - ''optional'' (2.1 only), an associative array, the key can be ''class'' or ''style'', the value is a function that checks the value and return a class or a style to be used at the row (tr) level of the table.
        'header' => array(
* '''items_per_page''' - ''optional'' (mandatory if get_count or base_href are present), the number of items to show in each page of the table;
            'value' => [Optional | string | Only value or eval may be used.  Eval overrides value if both exist.],
* '''get_count''' - an associative array that allows find the number of elements of the list, it can contain the following parameters:
            'eval' => [Optional | string | this should be a proper PHP statement to be evaluated.  should begin with 'return' and end with a semicolon.],
** '''file''' - ''optional'' a file (including path) to include;
            'colspan' => [Optional | int | used if the column header spans multiple columns],
** '''function''' - '''mandatory''', the function that counts the elements and return the value;
            'class' => [Optional | string | custom class for this header cell],
** '''params''' - ''optional'', an array of parameters that will be passed to the function;
            'style' => [Optional | string | custom style for this header cell],
* '''base_href''' - ''optional'' (mandatory if items_per_page is present), the href to be user to construct the page index;
        ),
* '''get_items''' - ''optional'', an associative array that allows find the values of elements of the list, it can contain the following parameters:
        'data' => array(
** '''file''' - ''optional'' a file (including path) to include;
            'db' => [Optional | string | column name from the database to directly display with no modification],
** '''function''' - '''mandatory''', the function that returns the values of the elements;
            'db_htmlsafe' => [Optional | string | if you want the database column run through htmlspecialchars, use this option],
** '''params''' - ''optional'', an array of parameters that will be passed to the function;
            'eval' => [Optional | string | a proper php statment to be used. you can insert database columns by putting them in % signs (ie: 'return %id_member%;')],
* '''title''' - ''optional'', the title of the table
            'function' => [Optional | string | must start with create_function('$rowData', 'your function here').],
* '''start_var_name''' - ''optional'', the starting variable name ('''not so sure''')
            'sprintf' => array(
* '''default_sort_col''' - ''optional'', the default column used to sort the table;
              'format' => [Required | string | should be a properly formated sprintf string],
* '''width''' - ''optional'', the width of the table;
              'params' => array(
* '''request_vars''' - '''optional''', an associative array of values that can be taken from $_REQUEST to define the sorting ('''no idea what I'm writing'''), it can contain:
                  '[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]
** '''sort''' - ''optional'', a $_GET variable name that define the column to sort;
              ),
** '''desc''' - ''optional'', a $_GET variable name to define if the column should be sorted ascending or descending;
            ),
* '''form''' - ''optional'', an associative array of data to create a form, it can contain:
            'value' => [Optional | string | insert a non database value in this cell],
** '''hidden_fields''' - ''optional'', an associative array in the form $key => $value that will be translated in hidden fields where $key will be the name of the field and $value the value (it contains by default the session data).
            'style' => [Optional | string | custom style for this cell],
** '''token''' - ''optional'' (2.1 only), a token name to be included as hidden field of the form;
            'class' => [Optional | string | custom class for this cell],
** '''include_start''' - ''optiolnal'', boolean, if true include the starting page as hidden field (requires start_var_name);
        ),
** '''include_sort''' - ''optional'', booloean, if true add the parameter so that sorting remains the same after submitting;
        'sort' => array(
* '''no_items_label''' - ''optional'', a string to show when there are no items in the list;
            'default' => [Optional | string | database column to do default sorting on (if you want this column sorted)],
* '''no_items_align''' - ''optional'', value for the HTML property align (left, right, center, justify);
            'reverse' => [Optional | string | database column to do reverse sorting on (normally same as above, but with 'DESC' after it],
* '''additional_rows''' - ''optional'', an associative array or arrays that can contain HTML elements to be presented in different places on the list (supported positions are: top_of_list, after_title, above_column_headers, below_table_data, bottom_of_list), the position is the index of the associative array, than each array inside a certain position can contain:
        ),        
** '''value''' - '''mandatory''', the HTML that will be inserted in the specified position;
      ),
** '''class''' - ''optional'', the name of a css class to style the element;
  ),
** '''style''' - ''optional'', a css in-line style that will be applied to the element;
  'form' => array(
* '''javascript''' - ''optional'', raw javascript that will be inserted at the end of the list;
      'href' => [Required | string | if using a form, this field is required and should be the full url to post to],
* '''list_menu''' - ''optional'', an associative array that holds all the data to create a menu:
      'hidden_fields' => array(
** '''show_on''' - ''optional'', where the menu should be created (can be ''both'', ''top'', ''bottom'');
        '[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],
** '''style''' - '''mandatory''', can be ''button'' or ''tabs'';
      ),
** '''position''' - '''mandatory''', the position of the tabs/buttons, it can be ''left'' or ''right'' (default is left);
      'include_sort' => [Optional | true|false | after form submit, if you want the sorting to remain, set this to true],
** '''links''' - '''mandatory''', an array of associative data with the information to create the menu:
      'include_start' => [Optional | ture|false | after form submit, if you want to return to the same page, set this to true],
*** '''is_selected''' - '''mandatory''', boolean, true if the menu item is selected;
  ),
*** '''href''' - '''mandatory''', the url to be used for the menu;
  'additional_rows' => array(
*** '''label''' - '''mandatory''', the name of the menu;
      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===
===Calling the function===
  // Now that we have all the options, create the list.
  // Now that we have all the options, create the list.

Latest revision as of 23:43, 1 February 2014

Create a list

Definitions

  • id - mandatory, an id to identify the list
  • columns - mandatory, an associative array of columns, the key of each column must be unique (of course) the value is an array of values:
    • sort - optional, an associative array that holds the rules to sort the column, it can contain:
      • default - mandatory, the default sorting rule;
      • reverse - mandatory, the reverse sorting rule;
    • header - mandatory, an associative array describing the header of the column, it can contain the following indexes:
      • eval - optional (alternative to value), php code that will be passed to the php function eval;
      • value - optional (alternative to eval), a value (usually a string) that will be displayed as column header;
      • class - optional, a css class to use for the header of the column;
      • style - optional, a css style to use for the header of the column;
      • colspan - optional, a number that will be used for the colspan attribute of the header;
    • data - mandatory, an associative array that holds the information to display the information, it can contain:
      • db - optional (alternative to db_htmlsafe, sprintf, function, eval, value), the easiest way, a value straight from the database;
      • db_htmlsafe - optional (alternative to db, sprintf, function, eval, value), similar to db, but make the value HTML safe;
      • sprintf' - optional (alternative to db, db_htmlsafe, function, eval, value), uses vsprintf to prepare the value, it must be in the form of an associative array containing:
        • params - mandatory, pairs of values: the key holds the string to be used as parameter of vsprintf and the value is a boolean that defines if the key must be html safe or not.
        • format - mandatory, the format of the string (the first parameter of vsprintf).
      • function - optional (alternative to db, db_htmlsafe, sprintf, eval, value), a php function that returns the value that should be displayed;
      • eval - optional (alternative to db, db_htmlsafe, sprintf, function, value), code that is passed to the php eval function;
      • value - optional (alternative to db, db_htmlsafe, sprintf, function, eval), a literal value;
      • if none from db, db_htmlsafe, sprintf, function, eval, value is present an empty string will be displayed;
      • comma_format - optional, boolean if true the value is passed to the function comma_format;
      • timeformat - optional, boolean if true the value is passed to the function timeformat;
      • class - optional, a css class to use for the column;
      • style - optional, a css style to use for the column;
  • data_check - optional (2.1 only), an associative array, the key can be class or style, the value is a function that checks the value and return a class or a style to be used at the row (tr) level of the table.
  • items_per_page - optional (mandatory if get_count or base_href are present), the number of items to show in each page of the table;
  • get_count - an associative array that allows find the number of elements of the list, it can contain the following parameters:
    • file - optional a file (including path) to include;
    • function - mandatory, the function that counts the elements and return the value;
    • params - optional, an array of parameters that will be passed to the function;
  • base_href - optional (mandatory if items_per_page is present), the href to be user to construct the page index;
  • get_items - optional, an associative array that allows find the values of elements of the list, it can contain the following parameters:
    • file - optional a file (including path) to include;
    • function - mandatory, the function that returns the values of the elements;
    • params - optional, an array of parameters that will be passed to the function;
  • title - optional, the title of the table
  • start_var_name - optional, the starting variable name (not so sure)
  • default_sort_col - optional, the default column used to sort the table;
  • width - optional, the width of the table;
  • request_vars - optional, an associative array of values that can be taken from $_REQUEST to define the sorting (no idea what I'm writing), it can contain:
    • sort - optional, a $_GET variable name that define the column to sort;
    • desc - optional, a $_GET variable name to define if the column should be sorted ascending or descending;
  • form - optional, an associative array of data to create a form, it can contain:
    • hidden_fields - optional, an associative array in the form $key => $value that will be translated in hidden fields where $key will be the name of the field and $value the value (it contains by default the session data).
    • token - optional (2.1 only), a token name to be included as hidden field of the form;
    • include_start - optiolnal, boolean, if true include the starting page as hidden field (requires start_var_name);
    • include_sort - optional, booloean, if true add the parameter so that sorting remains the same after submitting;
  • no_items_label - optional, a string to show when there are no items in the list;
  • no_items_align - optional, value for the HTML property align (left, right, center, justify);
  • additional_rows - optional, an associative array or arrays that can contain HTML elements to be presented in different places on the list (supported positions are: top_of_list, after_title, above_column_headers, below_table_data, bottom_of_list), the position is the index of the associative array, than each array inside a certain position can contain:
    • value - mandatory, the HTML that will be inserted in the specified position;
    • class - optional, the name of a css class to style the element;
    • style - optional, a css in-line style that will be applied to the element;
  • javascript - optional, raw javascript that will be inserted at the end of the list;
  • list_menu - optional, an associative array that holds all the data to create a menu:
    • show_on - optional, where the menu should be created (can be both, top, bottom);
    • style - mandatory, can be button or tabs;
    • position - mandatory, the position of the tabs/buttons, it can be left or right (default is left);
    • links - mandatory, an array of associative data with the information to create the menu:
      • is_selected - mandatory, boolean, true if the menu item is selected;
      • href - mandatory, the url to be used for the menu;
      • label - mandatory, the name of the menu;

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: