1. Fabrik 3.5.2 is now available to download. Read the blog for highlights about this release.

    As always, please back up your site prior to updating and if possible test in a dev environment first.

    Also, our 3.5.1 package file was hacked, the effected dates were 1/15/2017 - 1/17/2017. If during those days you downloaded the 3.5.1 package file from the JED or our site download page, please re-install the package with a fresh copy or upgrade to Fabrik 3.5.2. Github downloads were not effected.

PHP Events list plugin

Oct 23, 2015
PHP Events list plugin
  • The PHP Events plugin allows for certain hooks into the internals of a Fabrik list. For each option the list model is represented by the variable $model.

    The following events are supported
    • onFiltersGot - Called when the list's filter array has been populated
    • onMakeFilters - Called when the list HTML filters are loaded
    • process
    • onPreloadData - Run before the list loads its data
    • onLoadData - After the data has loaded
    • onDeleteRows - Called when the list mode deletes rows
    • onQueryBuildWhere - after the where statement has been created
    See the API reference here for full details.

    [h1]Examples[/h1]


    Changing the colour of a cell based on the value stored in a colour picker element.(top)


    Add the following code to the plugin's 'onLoadData' option. This allows us to alter the list's data before it is displayed:

    PHP:


    // $model is the list model, we want to get its data and then alter it.
    $data = $model->getData();

    foreach ($data as $group)
    {
      foreach ($group as $row)
      {
        // Set a default rgb colour that will be used if nothing has been filled in by the colour picker
        $default = '155,20,45' ;

        // tablename___colour_raw is the raw full name of the colour picker element
        $c = (string) $row->tablename___colour_raw === '' ? $default : $row->tablename___colour_raw;

        // Update the 'birthday' element, wrapping it with a span with our selected colour.
        $row->tablename___birthday = '<span style="color:rgb(' . $c . ')">' . $row->tablename___birthday . '<span>';
      }
    }
     

    Changing a date element, to show how many days old it is(top)


    Add the following code to the plugin's 'onLoadData' option. This allows us to alter the list's data before it is displayed:

    PHP:

    // $model is the list model, we want to get its data and then alter it.
    $data = $model->getData();

    foreach ($data as $group)
    {
      foreach ($group as $row)
      {
        $nowDate = strtotime($row->events___start_raw);
        $thenDate = strtotime("today");
        $dateDiff = $thenDate - $nowDate;
        $row->events___start = round($dateDiff / 86400);
      }
    }