Download Protostrap

PHP


This is an overview of useful PHP functions and variables.
They let you work with data easily and make your prototype feel real.

Function Reference



Function Description and Parameters
__() (Two underscores) Returns the translation for the provided key. Returns the value of the key when no translation is found.
__($key);

Parameters

key
The key to translate
language   (optional)
The language the key is to be translated to. Defaults to the current active language of the prototype
__($key, $language);
alert() Builds the HTML for a Bootstrap Alert.
  • This is an alert, in case you wondered
    It has an icon and can contain a dismiss link

alert($text);

Parameters

text
The text you want to display, can contain HTML
class   (optional)
The name of one of the Boostrap alert modifier classes: info, success, warning or danger. defaults to info if not provided
alert($text, $class);
icon   (optional)
The name of the Font Awesome icon to be used for the alert. Defaults to a predefined icon for each modifier class:
info
success
warning
danger
alert($text, $icon);
id   (optional)
The id you want to give the alert. Defaults to alertid
alert($text, $id);
dismiss   (optional)
Boolean value to make the alert dismissable. Defaults to true
alert($text, $dismiss);
forceLogin() When called Protostrap will force the user to log into the prototype to access the page requested. Instead of the page requested Protostrap will show a login form if the user is not logged in,

The function is ideally called in the HTML before the <body> tag
forceLogin();

Parameters

None.

getDeeplink() Returns the link to the current page including GET Parameters and automatic user login.

This is especially useful in a rolebased prototype. Deeplinks make it possible to view a page the way it was when the Deeplink was generated. This includes anything that refers to the current role. Deeplinks are great for documentation and specification in development, not forcing developers to log in as a the user of the userstory.
getDeeplink();

Parameters

None.

getFirstUserLogin() Gets the email of the first user specified in the users array in the users.yml file.
getFirstUserLogin();

Parameters

None.

getUniqueId() Returns a number as a unique identifier. The id is incremented on each call.
getUniqueId();

Parameters

variableName   (optional)
Variable name, when added the function will use the variable with the paramater's name as unique id variable. If the variable does not exist it will create one.
getUniqueId($variableName);
hideIf() Will output the class hide if the current user is in one of the specified usergroups
hideIf($usergroups);

Parameters

usergroups
The names of the usergroups affected. Multiple groups can be specified as a comma-separated list: admin, superadmin
includeIf() Will include the specified file if the current user is in one of the specified usergroups
includeIf($usergroups, $file);

Parameters

usergroups
The names of the usergroups affected. Multiple groups can be specified as a comma-separated list: admin, superadmin
file
The path to the file to be included.
makeDateFromString() Returns a date from almost any English textual datetime description.
Examples:
  • last Thursday
  • first Monday of next Month
  • -1 Week
The returned value is in the format specified in the config.yml file in the variable defaultPHPdateFormat (default d.m.Y) "
makeDateFromString($string);

Parameters

string
The textual daytime description
format   (optional)
The formatting pattern for the date, corresponding to the PHP format parameter strings
makeDateFromString($string, $format);
reorder() Reorders an array by the values of the specified key. Think of the Array as a table and each key as a column. Returns a reordered copy of the original array.
reorder($array, $column);

Parameters

array
The array to reorder
column
The column or key by which the array is to be reordered
direction   (optional)
The direction in which the columns should be reordered. Defaults to ascending if none is provided. Possible values: asc and desc
reorder($array, $column, $direction);
showIf() Will not output the class hide if the current user is in one of the specified usergroups
showIf($usergroups);

Parameters

usergroups
The name of the usergroups affected. Multiple groups can be specified as a comma-separated list: admin, superadmin
today() Returns today's date in the format specified in the config.yml file in the variable defaultPHPdateFormat (default d.m.Y)
today();

Parameters

format   (optional)
The formatting pattern for the date, corresponding to the PHP format parameter strings
today($format);
tomorrow() Returns tomorrow's date in the format specified in the config.yml file in the variable defaultPHPdateFormat (default d.m.Y)
tomorrow();

Parameters

format   (optional)
The formatting pattern for the date, corresponding to the PHP format parameter strings
tomorrow($format);
yesterday() Returns yesterday's date in the format specified in the config.yml file in the variable defaultPHPdateFormat (default d.m.Y)
yesterday();

Parameters

format   (optional)
The formatting pattern for the date, corresponding to the PHP format parameter strings
yesterday($format);

Variables

Name Description
$lastUniqueId Retruns the value assigned to it by calling the function getUniqueId().
$currentYear Returns the current year as a four digit number
$loggedIn Tells you if a user is logged in. Returns false if not.
$justloggedIn Tells you if a user just logged in. This variable returns true only on the page called by the form.
$activeUser An array of the current active user. Will show false if no user is logged in.
$username The active user's username
$usermail The active user's email
$userrole The active user's role
$userpermissions An array of the permissions given to the user as defined in the users.yml file