- nova aba Redmine em Administração > Entidades (PluginRedmineEntity) - tabela glpi_plugin_redmine_entities (1:1 entidade -> projeto Redmine, + categoria) - hook resolve o projeto Redmine por: projeto vinculado OU, na ausência, a entidade do chamado (match exato, sem herança de árvore) - twigs do tab generalizados (owner_field/owner_id) p/ reuso projeto+entidade Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
99 lines
3.8 KiB
PHP
99 lines
3.8 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';
|
|
|
|
// 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,
|
|
'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).
|
|
$config_it = $DB->request(['FROM' => 'glpi_plugin_redmine_configs', 'WHERE' => ['id' => 1]]);
|
|
$config = count($config_it) > 0 ? $config_it->current() : [];
|
|
$metadata = !empty($config['metadata_cache']) ? json_decode($config['metadata_cache'], true) : [];
|
|
$redmine_projects = $metadata['projects'] ?? [];
|
|
|
|
$modules = [
|
|
'issue_tracking' => 'Gerenciamento de Tarefas',
|
|
'time_tracking' => 'Gerenciamento de tempo',
|
|
'news' => 'Notícias',
|
|
'documents' => 'Documentos',
|
|
'files' => 'Arquivos',
|
|
'wiki' => 'Wiki',
|
|
'repository' => 'Repositório',
|
|
'boards' => 'Fóruns',
|
|
'calendar' => 'Calendário',
|
|
'gantt' => 'Gantt'
|
|
];
|
|
|
|
$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,
|
|
'redmine_projects' => $redmine_projects,
|
|
'project_name' => $entity->fields['name'],
|
|
'project_description' => $description,
|
|
'project_identifier' => 'glpi-ent-' . $entities_id,
|
|
'modules' => $modules,
|
|
'csrf_token_value' => Session::getNewCSRFToken()
|
|
]);
|
|
}
|
|
}
|