Building Administrative Extensions

Extension Directory Structure

Create a directory within the "/custom/admin_extensions/extension_name" folder with the following structure:

/custom/extension_name

  • func
  • add.php
  • delete.php
  • edit.php
  • views
  • popup
  • add.php
  • edit.php
  • list.php
  • package.php

Package Information

  • package.php contains the settings for your new extension. Example:
return array(
    'table' => 'DatabaseTableName',

    'menu' => 'My Extension Name',

    'permission' => 'members', // or contacts, accounts, events, etc.

    'fields' => array(
        'date' => array(
            'display' => 'Date Field',
            'type' => 'date',
            'required' => false,
        ),
        'field1' => array(
            'display' => 'Field 1 Name',
            'type' => 'string',
            'required' => false,
        ),
        'field2' => array(
            'display' => 'Field 2 Name',
            'type' => 'string',
            'required' => false,
        ),
    ),
);
  • "DatabaseTableName" maps to a custom table within your database. You will need to manually create this!
  • The "fields" array maps to the columns within your "DatabaseTableName" table. The key in the area should match exactly the column's name in the database.
  • The "fields" array will also be used to generate a table listing, should you create a "list.php" view.

"list" functionality

  • Create a file called "list.php" within the "views" folder.
  • The standard template would be as follows:
<?php
// This matches the extension folder's name.
$extension = 'extension_name';

$admin = new admin();
$filter_array_default = array();
$table = $settings['table'];


// Example: DatabaseTableName.date
$order = 'DatabaseTableName.field_to_sort_on';

// DESC or ASC
$dir = 'DESC';

// How many results to display in the table by default.
$display = '50';

// Default page to display.
$page = '1';

$defaults = array(
    'sort'    => $order,
    'order'   => $dir,
    'page'    => $page,
    'display' => $display,
    'filters' => $filter_array_default,
);

$force_filters = array();

$force_headings = array_keys($settings['fields']);

// Update these to determine which fields users will be permitted to filter on.
// The first parameter corresponds to the key in the "fields" array in the "package.php" file.
$thefilters = array(
    'date:::',
    'field1:::',
    'field2:::',
);

// -----------------------------------------

$gen_table = $admin->get_table($table, $_GET, $defaults, $force_filters, '', $force_headings);

include PP_ADMINPATH . "/cp-includes/base_table.php";

"add" functionality

  • Create a file named "add.php" within the "func" folder. This file will contain the logic for adding data into the database.
  • Create a file named "add.php" within the "views/popup" folder. This file will contain the form used for adding an entry into the database.

"edit" functionality

  • Create a file named "edit.php" within the "func" folder. This file will contain the logic for editing data into the database.
  • Create a file named "edit.php" within the "views/popup" folder. This file will contain the form used for editing an entry into the database.

"delete" functionality

  • Create a file named "delete.php" within the "func" folder. This file will contain the logic for deleting data from the database.
  • The standard template would be as follows:
<?php
if (! empty($input['id'])) {
    $q1 = $this->delete("
        DELETE FROM `DatabaseTableName`
        WHERE `id`='" . $this->mysql_clean($input['id']) . "'
        LIMIT 1
    ");
}

Article Links

Related Articles

Article Tags

  • No tags found.

Details

Published on 2015/05/28.
Last updated on 2015/05/28.

Was this article helpful?
Yes (0) - No (0)