+
+TWIG, $twig_params);
+ }
+
+ $entries = [];
+ $entity_cache = [];
+ $type_cache = [];
+ foreach ($contracts as $data) {
+ $entry = [
+ 'itemtype' => self::class,
+ 'id' => $data['linkid'],
+ 'row_class' => $data['is_deleted'] ? 'table-danger' : '',
+ 'num' => $data['num']
+ ];
+ $contract = new Contract();
+ $contract->getFromResultSet($data);
+
+ $entry['name'] = $contract->getLink();
+
+ if (!isset($entity_cache[$contract->fields["entities_id"]])) {
+ $entity_cache[$contract->fields["entities_id"]] = Dropdown::getDropdownName(
+ "glpi_entities",
+ $contract->fields["entities_id"]
+ );
+ }
+ $entry['entity'] = $entity_cache[$contract->fields["entities_id"]];
+
+ if (!isset($type_cache[$contract->fields["contracttypes_id"]])) {
+ $type_cache[$contract->fields["contracttypes_id"]] = Dropdown::getDropdownName(
+ "glpi_contracttypes",
+ $contract->fields["contracttypes_id"]
+ );
+ }
+ $entry['type'] = $type_cache[$contract->fields["contracttypes_id"]];
+
+ $entry['supplier'] = $contract->getSuppliersNames();
+ $entry['begin_date'] = $contract->fields["begin_date"];
+
+ $duration = sprintf(
+ __('%1$s %2$s'),
+ $contract->fields["duration"],
+ _n('month', 'months', $contract->fields["duration"])
+ );
+
+ if (!empty($contract->fields["begin_date"])) {
+ $duration .= ' -> ' . Infocom::getWarrantyExpir(
+ $contract->fields["begin_date"],
+ $contract->fields["duration"],
+ 0,
+ true
+ );
+ }
+ $entry['duration'] = $duration;
+
+ $entries[] = $entry;
+ }
+
+ TemplateRenderer::getInstance()->display('components/datatable.html.twig', [
+ 'is_tab' => true,
+ 'nopager' => true,
+ 'nofilter' => true,
+ 'nosort' => true,
+ 'columns' => [
+ 'name' => __('Name'),
+ 'entity' => Entity::getTypeName(1),
+ 'type' => _n('Type', 'Types', 1),
+ 'supplier' => Supplier::getTypeName(1),
+ 'begin_date' => __('Start date'),
+ 'duration' => __('Initial contract period'),
+ ],
+ 'formatters' => [
+ 'name' => 'raw_html',
+ 'supplier' => 'raw_html',
+ 'begin_date' => 'date',
+ ],
+ 'entries' => $entries,
+ 'total_number' => count($entries),
+ 'filtered_number' => count($entries),
+ 'showmassiveactions' => $canedit && (int) $withtemplate !== 2,
+ 'massiveactionparams' => [
+ 'num_displayed' => count($entries),
+ 'container' => 'mass' . static::class . $rand,
+ ]
+ ]);
+ }
+}
diff --git a/src/User.php b/src/User.php
index 6776221739f..9ae77a29470 100644
--- a/src/User.php
+++ b/src/User.php
@@ -405,6 +405,7 @@ public function defineTabs($options = [])
$this->addStandardTab('Auth', $ong, $options);
$this->addStandardTab('ManualLink', $ong, $options);
$this->addStandardTab('Certificate_Item', $ong, $options);
+ $this->addStandardTab(Contract_User::class, $ong, $options);
$this->addStandardTab('Log', $ong, $options);
return $ong;