Basic operations

The logic basic operations for editing the data incorporated in the system kernel. This multiple files in the folder adm/includes, as described below. They are responsible for the basic steps of data management in the administrative part of the site. This means that if you create a module with simple content, DIAFAN.CMS automatically to load these files, and data can be managed using the basic steps.

The following steps are provided in DIAFAN.CMS:

  • data output in a list – file adm/includes/show.php;
  • editing, adding data – file adm/includes/edit.php;
  • validation data – file adm/includes/validate.php;
  • saving – file adm/includes/save.php;
  • delete, delete to recycle byn – file adm/includes/del.php;
  • publication or hide data – file adm/includes/act.php;
  • moving line (sorting and override parent) – file adm/includes/move.php;
  • POST-requests processing – file adm/includes/action.php.
Attention!
These operations are usually sufficient to control the majority of the data sets. For example, you need to create a module for personnel management. This will be a table with the names of employees. When creating a module to make enough employees table in the database, and basic functionality immediately automatically allows: displaying a list of employees, add new, edit existing, delete, sort, hide sample.

The module file can be used as a standard functional activities, and expand it, and even completely redefine its actions.

Let's see how this can be done.

Data output in a list

When you open a module calls the function show() defined in each class module administration. In this function, you can lay your presentation page administration module, you can call the standard function list_row() to generate a list of elements of the table.

Example:

public function show()
{
    
$this->diafan->list_row();
}

By default, the reference is used to edit the value of the field name. This can be changed using the properties $text_for_base_link.

If you need to generate a list introduce an additional condition in the SQL-queries to the database, then use the property $where.

List output settings are placed in the variable $config, defined in the file of module.

In the list you can add your column. For this is determined array $variables_list.

The link "Add new item" displays function show_add(). Usually this function is as follows:

Example:

public function show_add()
{
    
$this->diafan->addnew_init('Add news');
}

For some data fields will be filtered is defined in the array $variables_filter.

Editing, adding

If the URL are passed variables edit or addnew, then connects the function edit() of the file adm/includes/edit.php. The function generates an edit form based on the array $variables defined in the class module.

The function can be overridden in the module class.

You can also supplement the editing fields of its function. For this purpose, the module is determined function edit_variable_переменная() or function edit_config_variable_переменная() for the settings file.

A custom function is called always, if it is determined, regardless of the type of the variable. An exception is the type module.

Some custom fields editing functions are defined in the file adm/includes/edit_functions.php. For example, editing semantic URL, sorting section of the site and so on. They can also be overridden in the module class.

Some modules aggregate information about the elements of the other modules. And you need to edit the related information is also edited.

For example, when editing the news you need to edit images and attachments tags.

To do this, you want to create the file modules/module_name/admin/module_name.admin.inc.php in the modules-connections. The file class should be defined Module_name_admin_inc with function edit() or edit_config() for the settings file.

Then, the main module (in this example module "News") in the table $variables need to specify a variable called as well as a module-connection, and ask her type module.

Example:

public $variables = array(
    
'main' => array(
        
'images' => 'module',
        

    
),
    

);

Validation

Before you save the data is checked, and if an error message is displayed. For the validation corresponds the file file adm/includes/validate.php. DIAFAN.CMS check the data on the basis of the array $variables defined in the class module.

You can add a validation fields. For this purpose, the module class is determined function validate_variable_field() or function validate_config_variable_field() for the settings file.

A custom function is called always, if it is determined, regardless of the type of the variable. An exception is the type module.

Some custom fields editing functions are defined in the file adm/includes/validate_functions.php. For example, the validity period, additional fields, and so on. They can also be overridden in the module class.

Saving

If you pass variable $_POST["action"] = 'save'; and do not set the variable $_POST["module"], then connect the function save() from the file adm/includes/save.php. The function stores the data from the form on the basis of the array $variables defined in the class module.

The function can be overridden in the module class.

It is also possible to add the preservation of their treatment fields. For this purpose, the module grade is determined function save_variable_field() or save_config_variable_field() for the settings file.

This function defines:

  • $this->diafan->set_query("field_name='%f'");

To determine the mask, refer to the "Databases" section..

  • $this->diafan->set_value("field_value");

A custom function is called always, if it is determined, regardless of the type of the variable. An exception is the type module.

Some custom fields editing functions are defined in the file adm/includes/save_functions.php. For example, editing time, sorting, semantic URL and so on. They can also be overridden in the module class.

Some modules aggregate information about the elements of the other modules, and their preservation is necessary that the related information is also maintained.

For example, when saving the news you need to store information about the links in the menu on the news.

To do this, you want to create the file modules/module_name/admin/module_name.admin.inc.php in the modules-connections. The file must be specified class Module_name_admin_inc with the function save() or save_config() for the settings file.

Then, the main module (in this example module "News") in the table $variables need to specify a variable called as well as a module-connection, and ask her type module.

Example:

public $variables = array(
    
'main' => array(
        
'menu' => 'module',
        

    
),
    

);

Delete, delete to recycle bin

When you delete an item or several items of the module connects the function del() from the file adm/includes/del.php.

This function can be overridden in the module class.

In addition, if the class module defines a function delete($del_id, $trash_id), in addition to actions laid down in the core of it is carried out for each item to remove.

Keep in mind that if the items are removed in the recycle bin, the accompanying items must also be removed in a recycle bin. Therefore, instead of direct SQL-query to delete better use the function del_or_trash_where() defined in the file adm/includes/del.php.

Example:

/* When you delete a product must be disposed of in its price. To do this, Shop_admin class in the file modules/shop/admin/shop.admin.php define function: */
public function delete($del_id, $trash_id)
{
    
$this->del_or_trash_where("shop_price", "good_id=".$del_id, $trash_id);
}

Some modules aggregate information about the items of the other modules, and their removal is necessary that the related information is also removed. For example, when you remove the products necessary to delete the link in the menu on it and comments on this product.

To do this, you want to create the file modules/module_name/admin/module_name.admin.inc.php in modules-connections. The file must be specified class Module_name_admin_inc with the function delete().

string delete (integer $element_id, string $module_name, string $element_type, [integer $trash_id = 0]) – delete module items related to other items.

  • integer $element_id: ID of item to remove
  • string $module_name: name of the module, which item is removed
  • string $element_type: datatype
  • integer $trash_id: record ID in the recycle bin, which is associated with the removal

Publication, hide data

When you publication or hide item or several items of the module connects the function act() of the file adm/includes/act.php.

This function can be overridden in the module class.

Some modules aggregate information about the elements of the other modules, and when they need to block related information is also blocked.

To do this, you want to create the file modules/module_name/admin/module_name.admin.inc.php in the modules-connections. The file must be specified class Module_name_admin_inc with the function act().

string act (string $table, array $element_ids, integer $act) – locks / unlocks the items of the module associated with other elements.

  • string $table: table
  • array $element_ids: IDs of items to lock / unlock
  • integer $act: lock / unlock

Example:

/* modules/tags/admin/tags.admin.inc.php
lock / unlock override in the module "Tags"
*/
public function act($table, $element_ids, $act)
{
    if (!
$this->diafan->configmodules("tags"))
    {
        return;
    }
    if (
$this->diafan->config('category'))
    {
        
$table = str_replace('_category', '', $table);
        
$element_ids = DB::query_fetch_value("SELECT id FROM {".$table."} WHERE cat_id IN (%h)", implode(',', $element_ids), "id");
        if(
$element_ids)
        {
            
DB::query("UPDATE {tags} SET [act]='%d' WHERE module_name='%h' AND element_id IN (%h)", $act, $table, implode(',', $element_ids));
        }
    }
    else
    {
        
DB::query("UPDATE {tags} SET [act]='%d' WHERE module_name='%h' AND element_id IN (%h)", $act, $table, implode(',', $element_ids));
    }
}

POST-requests processing

Some queries require special handling. For example, uploading a site tree list when editing the page parent. This processing takes place the file in the file adm/includes/action.php.

Functions for general inquiries described in the file adm/includes/action_functions.php.

If you want to make POST-request processing module, it creates the file modules/module_name/admin/module_name.admin.action.php. Class Module_name_admin_action is described in the file. Data processing is performed in the function action(). For the system to connect a file, you need to send variable $_POST["module"] = 'module_name';