PHP List Plugin

This plugin can be used to perform some modifications or validations on the list rows.

It can be launched in different stages:

  • onBeforePageLoad - Cannot change the data in the list. It can add some values ​​to be used in a list page;
  • onBeforeListLoad - before create elements (Can modify values);
  • onListLoad - before html list load (After element parameteres applied to element data. Can modify data before load in list view);
  • onBeforeDeleteRows;
  • onAfterDeleteRows;

Php code can be placed in php code area or run from php file.

In code area only you can use placeholders for logged in user data:

  • '{user_id}';
  • '{name}';
  • '{email}';
  • '{user_groups}' - json_encoded array;
  • '{lang_id}';

List Rows array for delete can be accessed via $this->brixy_data.

$this->brixy_data['rows'] // list rows
$this->brixy_data['list_id'] // list id

1. onBeforeListLoad - In this stage you can modify list rows data before list is created.

Add/Update element data:

$rows = &$this->brixy_data['output']['data'];
$rows[0]['db2__users___name'] = 'John'; // Change the name field data on first row from list.

//Change the name field data on all rows from list.
foreach($rows as &$row){
	//p($row, 'result');
	$row['db2__users___name'] = 'Mark';
        $row['new_key_name'] = 'value'; // Add additional data that is not part of the row data.
}

These changes only apply to the list view.

If you open any record for editing, viewing, printing ..., you will see the original data.

Besides replacing / adding / removing data, you can also change their style, make them links, buttons, etc.

Remove rows from list based on condition:

$rows = $this->brixy_data['output']['data'];

$db_conn = make_db_conn(1);

foreach($rows as $k=>$v){
    
    $reservation_id = $v['db1__app_payments___reservation_id'];
    $builder = $db_conn->table('app_reservations');
    $builder->select('*');
    
    $builder->where('id', $reservation_id);
    $builder->where('user_id', getUserID());
    //p($builder->getCompiledSelect()); //!!! RESET SELECTION IF ON !!!
    
    $query = $builder->get();
    $result = $query->getResultArray();

    if(!checkEmpty($result)){
		unset($this->brixy_data['output']['data'][$k]);
    }
}
$this->brixy_data['output']['data'] = array_values($this->brixy_data['output']['data']);
$this->brixy_data['output']['recordsTotal'] = count($this->brixy_data['output']['data']);
$this->brixy_data['output']['recordsFiltered'] = count($this->brixy_data['output']['data']);

Do not forget to add & (pass by reference).

2. onBeforePageLoad - Cannot change the data in the list. It can add some values ​​to be used in a list page.

$this->brixy_data['data']['some_new_key'] = 'value';	

3. onBeforeDeleteRows - if the php code returns false, the deletion of the row(s) will be aborted.

4. onAfterDeleteRows - can run some code to insert / update / delete data in another tables.