The module works with files attached to elements in other modules. The module consists of three parts: the hook part of the module work in the administrative section and the file turns the attached files.
Подключаемая часть – файл modules/attachments/attachments.inc.php. В нем описан класс
Attachments_inc. В модуле к объекту класса можно обратиться через переменную $this->diafan->_attachments
. Экземпляр класса создается при первом вызове
переменной.
array get (integer $element_id, string $module_name, [integer $param_id = 0]) – Отдает информацию о прикрепленных файлах.
Example:
// get files attached to the question in the module "Question-Answer"
// in the file modules/faq/faq.model.php
$attachments = $this->diafan->_attachments->get($id, 'faq');
// outputs the files in the module template
// in the file modules/faq/views/faq.view.id.php
foreach($attachments as $att)
{
if($att["is_image"])
{
if($row["use_animation"])
{
$a_href = '<a href="'.$att["link"].'" rel="prettyPhoto[gallery'
.$att["element_id"].$att["module_name"].'_1]">';
$a_href2 = '<a href="'.$att["link"].'" rel="prettyPhoto[gallery'
.$att["element_id"].$att["module_name"].'_2]">';
}
else
{
$a_href .= '<a href="'.$att["link"].'" rel="big_image" width="'
.$att["width"].'" height="'.$att["height"].'">';
$a_href2 = $a_href;
}
echo '<p id="attachment'.$att["id"].'">'.$a_href.$att["name"].'</a>
('.$att["size"].')'
.' '.$a_href2.'<img src="'.$att["link_preview"].'"></a></p>';
}
else
{
echo '<p id="attachment'.$att["id"].'"><a href="'.$att["link"].'">'
.$att["name"].'</a> ('.$att["size"].')</p>';
}
}
void prepare (integer $element_id, string $module_name, [integer $param_id = 0]) – Запоминает данные элемента, которому нужно вывести информацию о прикрепленных файлах.
Example:
// in this example, it will meet the following three SQL-request to the database to retrieve a file to all the questions posed
$ids = array(3, 5, 7);
foreach($ids as $id)
{
$files[$id] = $this->diafan->_attachments->get($id, 'faq');
}
Example:
// in this example, a SQL-query the database to obtain the Centre the instrument will file all the questions posed
$ids = array(3, 5, 7);
foreach($ids as $id)
{
$this->diafan->_attachments->prepare($id, 'faq');
}
foreach($ids as $id)
{
$files[$id] = $this->diafan->_attachments->get($id, 'faq');
}
boolean save (integer $element_id, string $module_name, [array $config = array()]) – Сохраняет добавленные файлы.
Example:
// upload files that are attached to the asked question
// in the file modules/faq/faq.action.php
$config = array('site_id' => $site_id, 'type' => 'configmodules');
try
{
// upload files to issue ID=3 in the module "Question-Answer"
$this->diafan->_attachments->save(3, "faq", $config);
}
catch(Exception $e)
{
// loading error message
echo $e->getMessage();
}
boolean upload (array $file, string $module_name, integer $element_id, [integer|boolean $n = false], [array $config = array()]) – Загружает файлы.
Example:
try
{
// upload files to issue ID=3 in the module "Question-Answer"
$this->diafan->_attachments->upload($_FILES['attachment'], 'faq', 3);
}
catch(Exception $e)
{
// loading error message
echo $e->getMessage();
}
void delete (integer|array $element_ids, string $module_name, [integer $attachment_id = 0], [integer $param_id = 0]) – Удаляет прикрепленные файлы/файл.
Example:
// delete files attached to the question in the module "Question-Answer"
$this->diafan->_attachments->delete(3, "faq");
// delete files attached to issues ID=3,5,6 in the module "Question-Answer"
$this->diafan->_attachments->delete(array(3, 5, 6), "faq");
void delete_module (string $module_name) – Удаляет все прикрепленные файлы модуля.
Example:
// remove the files attached to all questions in the module "Question-Answer"
$this->diafan->_attachments->delete_module('faq');
In the file of module settings (modules/модуль/admin/модуль.admin.config.php) and in the file of editing elements of the module (modules/модуль/admin/модуль.admin.php) you must add the parameter
'attachments'
:
Example:
public $variables = array(
'main' => array(
'attachments' => 'module',
…
),
…
);
Module settings are specified in the module settings, which are attached to the files. All settings are optional. You can define the following parameters of the module:
Allow adding of files – allows users to attach files to the module element.
Maximum files to add – the amount of added files.
Accessible types of files (through a comma)
Example:
doc, gif, jpg, mpg, pdf, png, txt, zipRecognize image – allows message attachments in JPEG, GIF, PNG display both images.
Size larger image – the size of the image displayed in the user part of the site with an increase in the preview image.
Size small image – the size of the preview image.
Use animation when increasing images – adds find JavaScript-code you can activate the animation by increasing the image.
Maximum size of uploaded files – this parameter indicates the maximum size of uploaded files, installed in the hosting settings.
Downloaded files can be opened at the following address: http://site.com/attachments/get/file_id/file_name
{attachments} – Attached files
modules/attachments/admin/attachments.admin.inc.php – Connecting the module to the administrative part of other modules;
modules/attachments/admin/js/attachments.admin.inc.js – Connecting the module to the administrative part of other modules, JS-сценарий;
modules/attachments/attachments.get.php – Вывод прикрепленных файлов;
modules/attachments/attachments.inc.php – Подключение для работы с прикрепленными файлами;
modules/attachments/attachments.install.php – Module installation.