88 lines
3.5 KiB
PHP
88 lines
3.5 KiB
PHP
<?php
|
|
|
|
if (!defined('GLPI_ROOT')) {
|
|
die("Sorry. You can't access this file directly");
|
|
}
|
|
|
|
class PluginRedmineEntity extends CommonDBTM {
|
|
|
|
static function getTypeName($nb = 0) {
|
|
return 'Redmine';
|
|
}
|
|
|
|
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
|
|
if ($item->getType() == 'Entity') {
|
|
return self::createTabEntry(__('Redmine', 'redmine'), 0, $item::getType(), 'fas fa-sitemap');
|
|
}
|
|
return '';
|
|
}
|
|
|
|
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
|
|
if ($item->getType() == 'Entity') {
|
|
self::showForEntity($item);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
static function getIcon() {
|
|
return 'fas fa-sitemap';
|
|
}
|
|
|
|
static function showForEntity(Entity $entity) {
|
|
global $DB, $CFG_GLPI;
|
|
|
|
$entities_id = $entity->getID();
|
|
$form_url = $CFG_GLPI['root_doc'] . '/plugins/redmine/front/entity.form.php';
|
|
|
|
// {id: name} montado no PHP (Twig merge corrompe chaves inteiras).
|
|
$project_options = PluginRedmineProject::getRedmineProjectOptions();
|
|
|
|
// Already linked?
|
|
$iterator = $DB->request([
|
|
'FROM' => 'glpi_plugin_redmine_entities',
|
|
'WHERE' => ['entities_id' => $entities_id]
|
|
]);
|
|
|
|
if (count($iterator) > 0) {
|
|
$link = $iterator->current();
|
|
$redmineProjectId = (int) $link['redmine_project_id'];
|
|
|
|
$cat_options = [];
|
|
foreach (PluginRedmineRedmineapi::getProjectCategories($redmineProjectId) as $c) {
|
|
if (isset($c['id'], $c['name'])) {
|
|
$cat_options[$c['id']] = $c['name'];
|
|
}
|
|
}
|
|
|
|
\Glpi\Application\View\TemplateRenderer::getInstance()->display('@redmine/project_linked.html.twig', [
|
|
'action_url' => $form_url,
|
|
'owner_field' => 'entities_id',
|
|
'owner_id' => $entities_id,
|
|
'redmine_project_id' => $redmineProjectId,
|
|
'redmine_project_name' => $project_options[$redmineProjectId] ?? '',
|
|
'cat_options' => $cat_options,
|
|
'default_category_id' => (int) ($link['default_category_id'] ?? 0),
|
|
'csrf_token_value' => Session::getNewCSRFToken(),
|
|
]);
|
|
return;
|
|
}
|
|
|
|
// Not linked: show the link/create form (reuses the project tab template).
|
|
$description = \Glpi\RichText\RichText::getTextFromHtml($entity->fields['comment'] ?? '', false, true, true);
|
|
|
|
\Glpi\Application\View\TemplateRenderer::getInstance()->display('@redmine/project_form.html.twig', [
|
|
'action_url' => $form_url,
|
|
'owner_field' => 'entities_id',
|
|
'owner_id' => $entities_id,
|
|
'project_options' => PluginRedmineProject::getRedmineProjectOptions(true),
|
|
'custom_fields' => PluginRedmineProject::getProjectCustomFieldDefs(),
|
|
'tracker_options' => PluginRedmineProject::getTrackerOptions(),
|
|
'default_tracker_ids' => ($dt = (int) (PluginRedmineConfig::getConfigRow()['default_tracker_id'] ?? 0)) ? [$dt] : [],
|
|
'project_name' => $entity->fields['name'],
|
|
'project_description' => $description,
|
|
'project_identifier' => 'glpi-ent-' . $entities_id,
|
|
'modules' => PluginRedmineProject::getModules(),
|
|
'csrf_token_value' => Session::getNewCSRFToken()
|
|
]);
|
|
}
|
|
}
|