• Payment Plugins Poll

    We need your feedback on the need for updated payment plugins. Please go here and give us your feedback.

  • Joomla 5.1

    For running J!5.1 you must install Fabrik 4.1
    See also Announcements

  • Subscription and download (Fabrik 4.1 for J!4.2+ and J!5.1) are working now

    See Announcement
    Please post subscription questions and issues here

    We have resolved the issue with the J! updater and this will be fixed in the next release.

PHP Events list plugin

  • Views Views: 18,814
  • Last updated Last updated:

Navigation

  • 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. Attention: Code added here is also run on form's onDelete (i.e. if Delete button is activated), so don't use a form php plugin OnDelete at the same time.
    • onQueryBuildWhere - after the where statement has been created

    OnLoadData​

    Changing the colour of a cell​

    based on the value stored in a colour picker element.​

    Add the following code to the plugin's 'onLoadData' option. This allows us to alter the list's data before it is displayed:
    Code:
    // $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​

    Add the following code to the plugin's 'onLoadData' option. This allows us to alter the list's data before it is displayed:
    Code:
    // $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);
    }
    }

    Remove some data conditionally​

    PHP:
    $data = $model->getData();
    foreach ($data as $group) {
    foreach ($group as $row) {
    $show = $row->employee___show_email_and_location;
    if ($show == 0) {
    $row->employee___e_mail_address = '';
    $row->employee___location = '';
    }
    }
    }

    OnDeleteRows​

    Sending an email onDeleteRows​

    Code:
    $data = $model->getData();

    //Fabrik4 and Fabrik3
    $app = Joomla\CMS\Factory::getApplication();

    foreach ($data as $group) {
    foreach ($group as $row) {
    FabrikWorker::sendMail(
    $app->getCfg('mailfrom'),
    $app->getCfg('fromname'),
    $row->tablename___email_raw,
    "A row has been deleted!",
    "Some message text, perhaps using some form data like this: {$row->tablename___element} "
    );
    }
    }

    Adding some filter onQueryBuildWhere​

    If some filter element is selected add more conditions
    PHP:
    $f=$model->filters;
    if (count($f)==0) return;// no filter active
    if (in_array('220',$f['elementid']) ||in_array('222',$f['elementid'])) //if a filter is set for element_id 220 or 222
    {
    $model->setPluginQueryWhere('some-keyword', "privacy=2");//exclude all records with privacy=2 (will add AND privacy=2 to filter condition)
    }
    else {
    $model->unsetPluginQueryWhere('some-keyword');//remove the additional filter condition
    }
Back
Top