Redmine/inc/entity.class.php
Gemini 6f844e7336 fix: dropdown gravava índice (Twig merge) em vez do ID real do projeto (1.5.3)
- opções do projeto Redmine montadas no PHP (Twig merge renumera chaves inteiras)
- aba mostra o NOME do projeto vinculado (não só o ID)
- botão Desvincular (projeto e entidade) + dropdown só com projetos ativos

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 15:27:18 -03:00

85 lines
3.2 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),
'project_name' => $entity->fields['name'],
'project_description' => $description,
'project_identifier' => 'glpi-ent-' . $entities_id,
'modules' => PluginRedmineProject::getModules(),
'csrf_token_value' => Session::getNewCSRFToken()
]);
}
}