DbFace Plugins

Connect to MySQL or MariaDB in DbFace

Plugins

A plugin is a piece of software containing a group of functions that can be added to a DbFace application. They can extend functionality or add new features to your DbFace applications.

DbFace plugins are written in the PHP programming language and integrate seamlessly with DbFace.

Register Plugins

At the Settings Panel, switch to Script tab, and click Application Plugin to list all available plugins. register dbface plugins

Create Plugin

How Plugins works?

Each DbFace application plugin contains a getSubscribedEvents function, DbFace will call this function to initialize the plugin, and call the event function when executing at that point in core. Here is an example.

<?php
class HelloworldPlugin extends Plugin {
  public static function getSubscribedEvents()
    {
        return [
            'onAppQueryResult'  => ['onQueryResult', 0],
            'onPageInitialized' => ['onPageInitialized', 0],
            'onPageEnd' => ['onPageEnd', 0],
            'onShutDown' => ['onShutDown', 0]
        ];
    }

    function onPageInitialized($event) {
      return $event;
    }
    
    function onPageEnd($event) {
      return $event;
    }
    
    function onShutDown() {
    }
    
    function onQueryResult($event) {
      $fields = $event->offsetGet('fields');
      $data = $event->offsetGet('data');
      
      // append fields
      $new_data = array();
      foreach($fields as $field => $v) {
        $new_data[$field] = 'test';
      }
      $data[] = $new_data;
      
      $event['data'] = $data;
     
      return $event;
    }
}

Plugin Hooks Interface

When DbFace running at a specific point in the execution of Core, DbFace will fire an event to run plugins. Plugins can hook at this point, get all data in event parameter, modify data, and write back the modified data into the event return object.

onApplicationInitialized

onPluginInitialized

onAppTemplateInitialized

onAppQueryResult

Use this hook to modify the result set of application query result. The following plugin will modify all data to test. You can also append new field at this point.

function onQueryResult($event) {
  $fields = $event->offsetGet('fields');
  $data = $event->offsetGet('data');
  
  // append fields
  $new_data = array();
  foreach($fields as $field => $v) {
    $new_data[$field] = 'test';
  }
  $data[] = $new_data;
  
  $event['data'] = $data;
  
  return $event;
}

onSortFields

Use this hook to sort fields for tabular report.

onChartData

onShutDown


Last modified December 28, 2020: change the ticket (c5eeadc)