Creating an extension's Admin Controller - RelationalExtend/RelationalExtend GitHub Wiki

##fuel/extensions/sample/classes/controller/admin.php

<?php
/**
 * Main Admin controller for the sample extension.
 *
 * @author     Ahmed Maawy
 * @copyright  2011 - 2012 Ahmed Maawy
 */

namespace sample;

class Controller_Admin extends \cms\Controller_CMS {
	protected $controller_path = "sample/admin/";

	public function action_index()
	{
		$table_view_descriptor = new \ObjectModel_TabularView($this->controller_path, Sample_Setup::TABLE_BLOG,
            "id", "blog_title", "");
		$table_view_descriptor->page_number = $page_number;
		$table_view_descriptor->page_title = "Blog posts";
		$table_view_descriptor->page_content = "Manage blog posts";

		$list_interface = $this->build_admin_ui_tabular_list($table_view_descriptor, "index");


		$this->build_admin_interface($list_interface);
	}

	protected function special_field_operation($field_name, $value_sets)
	{
		$value = null;

		switch($field_name) {
			case "blog_slug":
				$value = \Utility::slugify($value_sets["blog_title"], "-");
				break;

			case "blog_creation_time":
				$value = false;
				break;
		}

		return $value;
	}
}

This sample controller demonstrates how the admin panel renders and uses the Sample Extension. It can either use built in methods to do this, or, render it manually using its own system of views and controller logic to complement the admin's default view.

build_admin_ui_tabular_list is a function used to display by default a tabular view of the data with a default Edit, Delete and Add Record button. It also supports paging

// Constructing a TabularListView
// For thumbnail views the $thumbnail_field is required

\ObjectModel_TabularView($controller_path, $table_name, $id_field, $description_field, $thumbnail_field = null)

// Functions within the admin controller

protected function build_admin_ui_tabular_list($tabular_view_descriptor, $action_name)
protected function build_admin_ui_thumbnail_list($tabular_view_descriptor, $action_name)

// Rendering a form view

protected function build_admin_ui_form_view($page_title, $page_content, $table_slug, $form_action,
    $record_id = 0, $return_path = "")
  1. Tabular List: A tabular list of records with Edit Delete and Add Record buttons.
  2. Thumbnail View: A thumbnail list view of records with Edit Delete and Add Records buttons.
  3. Form View: Render a record with the controls specified in the Setup file for the extension.
  4. Return Path parameter: is used to denote which action to return to when "Save and Exit" button is pressed.

##Customizing the look and feel for a specific tabular or thumbnail list view

The following is a brief example on customizing thumbnail and table views:

$table_view_descriptor = new \ObjectModel_TabularView($this->controller_path, Blog_Setup::TABLE_BLOG,
		"id", "blog_title", "");

// Set pagination off

$table_view_descriptor->paged = false;

// Current page number

$table_view_descriptor->page_number = $page_number;

// Content items

$table_view_descriptor->page_title = "Blog posts";
$table_view_descriptor->page_content = "Manage blog posts";

// Shows additional buttons on each row

$table_view_descriptor->set_additional_buttonfields(array("Select" => "addmedia/{{ table }}/{{ record_id }}/$page_number"));

// Activating and deactivating specific row level and control level buttons

$table_view_descriptor->add_button_visible = false;
$table_view_descriptor->delete_button_visible = false;
$table_view_descriptor->edit_button_visible = false;

// Render

$list_interface = $this->build_admin_ui_tabular_list($table_view_descriptor, "index");

##special_field_operation

Is a must to implement if you are going to make use of the build_admin_ui_form_view. For each field name that is a calculated field, you supply its calculated value. By default all calculated fields are given the CONTROL_HIDDEN value as the control type. If the value returned is false it sticks to its default designated value without processing a value.

##Verifying an extension or theme's installation status

if($this->is_extension_installed("extensionname"))
{
	// Extension active and installed
}
else {
	// Extension not active / not installed
}

if($this->is_theme_installed("themename")
{
	// Theme installed
}
else {
	// Theme not installed
}