Administration module file – file modules/module_name/admin/module_name.admin.php, which defines class Module_name_admin. This class is based on a single frame, so should inherit class Frame_admin.
If a module has several parts, the administration part of the module can contain other files modules/module_name/admin/module_name.admin.part.php where the class described Module_name_admin_part.
Class properties can define the following settings variables:
public $table = 'name_of_table_in_DB';
public $variables = array (
'name_of first_fields_group' => array (
'first_field_name' => array(
'type' => 'field_type',
'name' => 'Field title',
'help' => 'Hint',
// field translated into other languages
'multilang' => true,
// default value
'default' => 'value',
// field can not be edited
'disabled' => true,
// not to save the value
'no_save' => true,
// visual editor field height
'height' => 400,
// list of values for type=select
'select' => array(
"value1" => "name1",
"value2" => "name2",
…
),
// values for the list obtained from the database
'select_db' => array(
"table" => "name of table in DB",
"id" => "field which is used as the value list; by default id",
// for the multilingual fields you can use square brackets
// example: [text]
"name" => "field which is used to display the user list; by default name",
// example: "trash='0' AND [act]='1'"
"where" => "condition for the SQL-query"
// example: sort ASC
"order" => "sorting",
// example: "All"
// if not specified, a null value can not be selected in the list
"empty" => "null in the list",
// values will be built taking into account the nesting
"hierarchy" => true|false,
…
),
// field displayed if the depend field is checked
// you can specify multiple fields by "," or "|"
// delimiter "," means for displaying the field must be
// checked all of the above fields
// delimiter "|" means for displaying the field must be
// checked one of the above fields
'depend' => 'affecting_output_of_the_field',
),
'second_field_name' => array(
…
),
// shortened form
'third_field_name' => 'field_type',
…
),
'name_of_second_fields_group' => array (
…
),
…
// group of additional fields
'other_rows' => array (
…
),
);
The following types:
For easy access to array $variables
the following functions:
variable ([string $key = ''], [string $type_info = 'type'], [mixed $value = NULL]) – returns designates information about the field.
Example:
if($this->diafan->variable('name') == 'editor')
{
echo 'The field "name" is edited using a WYSIWYG editor.';
}
if($this->diafan->variable('type', 'multilang'))
{
echo 'The field "type" is translated into other languages.';
}
// prohibit editing field values role_id
$this->diafan->variable('role_id', 'disabled', true);
is_variable (string $key) – returns whether the variable is defined in the field list.
Example:
if($this->diafan->is_variable('act'))
{
echo 'The field "act" specified in the field list.';
}
variable_unset (string $key) – deletes a variable from the list of fields.
Example:
// delete field "site_id" from the list of fields
$this->diafan->variable_unset('site_id');
variable_name ([string $key = '']) – returns the name of the field.
Example:
echo 'Name of current field: '.$this->diafan->variable_name();
echo 'Name of field "role_id": '.$this->diafan->variable_name('role_id');
variable_multilang ([string $key = '']) – determines whether a multilingual field.
Example:
if($this->diafan->variable_multilang('name'))
{
echo 'The field "name" is translated into other languages.';
}
variable_disabled ([string $key = ''], [boolean $value = NULL]) – returns, appoints the disabled attribute to the variable.
Example:
if($this->diafan->variable_disabled('counter'))
{
echo 'The field "counter" can not be edited.';
}
// prohibit the edit field "created"
$this->diafan->variable_disabled('created', true);
public $config
– set display a list of values:
Format:
public $config = array(
'setting',
…
);
Settings available via the function $this->diafan->config("name");
.
This feature can be turned off or disable the display setting. Format:
$this->diafan->config("name", true|false);
public $where
– an additional condition for the SQL-request to the database.
Example:
The administrative part of the list of comments should be formed only from the inactive comments.
public $where = " AND act='0'";
public $join
– part of the SQL-query – join to the table.
Example:
The orders are looking for a user name, order it.
$search = 'Ivan';
$this->diafan->join .= " LEFT JOIN {users} AS u ON u.id=e.user_id";
$this->diafan->where .= " AND u.fio LIKE '%%".$search."%%'";
public $fields
– part of the SQL-query – additional fields.
Example:
For news we will get the value of keywords.
$this->diafan->fields .= ", e.[keywords]";
public $variables_list
– array of fields to display in the list.
Формат:
public $variables_list = array (
'first_field_name' => array(
'type' => 'field_type',
'name' => 'name_column_header_in_the_list',
'class' => 'CSS-class',
'class_th' => 'CSS-class_ for_header_column',
// edit the value directly from the list
'fast_edit' => true|false,
// value will be hidden on narrow dysplays
'no_important' => true|false,
// value is taken from a database is inserted in the SQL-query
'sql' => true|false,
// values for select type=select
'select' => array(
"value1" => "name1",
"value2" => "name2",
…
),
// values for the list obtained from the database
'select_db' => array(
"table" => "name of table in DB",
"id" => "field which is used as the value list; by default id",
// for the multilingual fields you can use square brackets
// example: [text]
"name" => "field which is used to display the user list; by default name",
// example: "trash='0' AND [act]='1'"
"where" => "condition for the SQL-query"
// example: sort ASC
"order" => "sorting",
// example: "All"
// if not specified, a null value can not be selected in the list
"empty" => "null in the list",
// values will be built taking into account the nesting
"hierarchy" => true|false,
…
),
// any other attributes that may be used in user functions
),
'second_field_name' => array(
…
),
…
);
The following types:
$variables
;
'sql' => true
and is used in the custom function of another variable.For any type of format, you can define a custom function: list_variable_field($row, $var)
, where $row
– array of values for the current item, $var
– array of data about the current variable.
The file adm/includes/show.php describes some global user-defined functions, any one of which can be overridden in the file of module. Global functions list_variable_*() are described in the following variables:
Example:
public $variables_list = array (
'checkbox' => '',
// …
);
Example:
public $variables_list = array (
'sort' => array(
'name' => 'Sorting',
'type' => 'numtext',
'sql' => true,
'fast_edit' => true,
'desc' => true,
),
);
Example:
public $variables_list = array (
'plus' => '',
);
Example:
public $variables_list = array (
'created' => array(
// name column header in the list
'name' => 'Date and time',
// type can be "date" or "datetime"
'type' => 'datetime',
// to display the date you need to request it in the database
'sql' => true,
// value will be hidden on a narrow display
'no_important' => true,
),
);
Example:
public $variables_list = array (
'image' => array(
// name column header in the list
'name' => 'Фото',
// CSS-class for a column header in the list
'class_th' => 'item__th_image ipad',
// value will be hidden on a narrow display
'no_important' => true,
),
);
Example:
public $variables_list = array (
'name' => array(
// name column header in the list
'name' => 'Name and category'
// default value "name"
'variable' => 'Field_name_in_DB',
// is not the default
'text' => 'Text',
),
);
If you specify a field that is used to refer to this field. Multi-field is determined by the array $variables
.
Example:
In the "Comments" module for the link you want to use the comment. In the file modules/comments/admin/comments.admin.php:
public $variables_list = array (
'name' => array(
'name' => 'Comment',
'variable' => 'text',
),
);
If you specify the attribute text, the link text will be determined by this value.
Example:
In "Rating" module in the main table does not have the information that can be used for link. So we derive the "Edit". In the file modules/rating/admin/rating.admin.php:
public $variables_list = array (
'name' => array(
'text' => 'Edit',
),
);
You can substitute the value into the text field. To do this in the text indicate the descriptor type.
Example:
In the module "Online shop – Orders" for links you want to display "Order number 1, 2, ...." In the file modules/shop/admin/shop.admin.order.php:
public $variables_list = array (
'name' => array(
'name' => 'Order',
'variable' => 'id',
'text' => 'Order number %d'
),
);
menu – displays the menu icon in the list. The function list_variable_menu()
is called from list_variable_name()
, but can be used directly in the list.
parent – displays the name of the section / category listed. The function list_variable_parent()
is called from list_variable_name()
, and outputs the category entitled element sections, but can be used directly in the list.
adapt – displays the layout for adaptation to mobile devices in the list of items.
Example:
public $variables_list = array (
'adapt' => array(
'class_th' => 'item__th_adapt',
),
);
date_period – displays the period display. The function list_variable_date_period()
is called from list_variable_name()
, and outputs a time limit display element under the name, but can be used directly in the list.
actions – displays action buttons above the element. Displayed at the bottom of the list. This function has its own settings for output attributes necessary actions:
Example:
// derive from the list buttons "Move to recycle bin" and "Deactivate / Publish site"
public $variables_list = array (
// …
'actions' => array(
'act' => true,
'trash' => true,
),
);
For easy access to array $variables_list
following function is defined:
variable_list ([string $key = ''], [string $type_info = 'type'], [mixed $value = NULL]) – returns, assigns information about the field list.
Example:
if ($this->diafan->variable_list('plus'))
{
echo 'Use hierarchy of items.';
}
if($this->diafan->variable_list('actions', 'trash'))
{
echo 'Print the button "Move to recycle bin".';
}
// hide the button "Preview"
$this->diafan->variable_list('actions', 'view', false);
public $variables_filter
– array of fields, for which there is a search.
Формат:
public $variables_filter = array (
'first_field_name' => array(
'type' => 'field_type',
'name' => 'field_title',
'icon' => 'icon_for_type_checkbox',
// values for types select, radiobox, multiselect
'select' => array(
"value1" => "name1",
"value2" => "name2",
…
),
// values for the list obtained from the database
'select_db' => array(
"table" => "name of table in DB",
"id" => "field which is used as the value list; by default id",
// for the multilingual fields you can use square brackets
// example: [text]
"name" => "field which is used to display the user list; by default name",
// example: "trash='0' AND [act]='1'"
"where" => "condition for the SQL-query"
// example: sort ASC
"order" => "sorting",
// values will be built taking into account the nesting
"hierarchy" => true|false,
…
),
// display links to time periods (Today Month Year)
// for types "datetime_interval" and "date_interval"
'links' => true|false,
// any other attributes that may be used in user functions
),
'second_field_name' => array(
…
),
…
);
The following types:
$variables
or $variables_list
;The file adm/includes/show.php describes some global user-defined functions, any one of which can be overridden in the file of module.
For any type of format, you can define a custom function: get_filter_variable_field($row)
, where $row
– array of data on the current variable. To find the variables also can define a custom function save_filter_variable_field($row)
, where $row
– array of data about the current variable.
Example:
// search function on the field "No image"
public function save_filter_variable_no_img($row)
{
if (empty($_GET["filter_no_img"]))
{
return;
}
// add a condition in the SQL-query
$this->diafan->where .= " AND (SELECT COUNT(*) FROM {images} AS i WHERE i.element_id=e.id AND i.element_type='".$this->diafan->element_type()."' AND i.module_name='".$this->diafan->_admin->module."' AND i.param_id=0)=0";
// consider the set value in pagination links
$this->diafan->get_nav .= ($this->diafan->get_nav ? '&' : '?' ).'filter_no_img=1';
return 1;
}
For easy access to array $variables_filter
following function is defined:
Example:
if ($this->diafan->variable_filter('article'))
{
echo 'The filter will display a search box on the article.';
}
// add the values list "Blocks online" in filter
$blocks = DB::query_fetch_key_value("SELECT id, name FROM {forum_blocks} WHERE trash='0' ORDER BY sort ASC", "id", "name");
$this->diafan->variable_filter('block_id', 'select', $blocks);
To be able to attach the module to several pages, insert the following code:
public $variables = array (
'any_group_of_fields' => array (
'site_id' => array(
'type' => 'function',
'name' => 'Site section',
),
),
);
public $config = array('element_site', …);
If the values of the above-described properties of the module depend on any conditions, then these conditions are described in the function prepare_config()
.
Example:
If in the settings module "Photogallery" option disabled "Use albums", the setting "use of categories in the module" and "element may be attached to several categories" should be disabled.
public function prepare_config()
{
if(! $this->diafan->configmodules("cat", "photo", $this->diafan->site))
{
$this->diafan->config("element", false);
$this->diafan->config("element_multiple", false);
}
}
The current item for action edit (edit), preservation (save), validation (validate) in the variable $this->diafan->id
.
If the new element (with the addition), then $this->diafan->is_new = true;
. At the same time when editing and validation $this->diafan->id = 0;
.
The user-defined functions edit_variable_field()
, save_variable_field()
, validate_variable_field()
current value of the fields available through the function values()
.
Example:
echo 'The name of the edited news: '.$this->diafan->values('name');
When validation and preservation the current values are values before clicking "Save".
When editing function values()
accepts two additional values:
mixed values(string $field, [mixed $default = ''], [boolean $save = false]) – gets a field value.
There is also variable $this->diafan->value
. It is written for the value of the variable in the current function.
Example:
The function edit_variable_created()
of the variable $this->diafan->value
will be equal $this->diafan->values('created')
.
For the module elements can determine the type of item. The standard edition DIAFAN.CMS there are three types of elements:
Example:
The item type is used for the semantic URL records in the table {rewrite} to determine which page to open the module – product card, category page or brand page. Or to connect module rating to categories and items.
To work with the item type in the administrative part of the following functions.
string element_type() – defines the type of the items of the current edition.
Example:
echo 'Now we edit ':
switch($this->diafan->element_type())
{
case 'cat':
echo 'categories';
break;
case 'brand':
echo 'brands';
break;
case 'element':
echo 'products';
break;
}
string table_element_type(string $module_name, string $element_type) – specifies the table for the item type.
Example:
echo $this->diafan->table_element_type('shop', 'cat');
// output: shop_category
string is_action($action) – determines whether the current action specified in the argument.
Example:
if($this->diafan->is_action('edit'))
{
echo 'Open edit / add page.';
}