Skip to content

Commit

Permalink
refactor(targetticket): remove workaround
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Jan 30, 2020
1 parent 3f03e52 commit 12b47b4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 96 deletions.
29 changes: 0 additions & 29 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,35 +82,6 @@ public static function getGlpiVersion() {
: GLPI_VERSION;
}

/**
* Get Link Name
*
* @param integer $value Current value
* @param boolean $inverted Whether to invert label
*
* @return string
*/
public static function getLinkName($value, $inverted = false) {
$tmp = [];

if (!$inverted) {
$tmp[Ticket_Ticket::LINK_TO] = __('Linked to');
$tmp[Ticket_Ticket::DUPLICATE_WITH] = __('Duplicates');
$tmp[Ticket_Ticket::SON_OF] = __('Son of');
$tmp[Ticket_Ticket::PARENT_OF] = __('Parent of');
} else {
$tmp[Ticket_Ticket::LINK_TO] = __('Linked to');
$tmp[Ticket_Ticket::DUPLICATE_WITH] = __('Duplicated by');
$tmp[Ticket_Ticket::SON_OF] = __('Parent of');
$tmp[Ticket_Ticket::PARENT_OF] = __('Son of');
}

if (isset($tmp[$value])) {
return $tmp[$value];
}
return NOT_AVAILABLE;
}

/**
* Gets the ID of Formcreator request type
*/
Expand Down
25 changes: 12 additions & 13 deletions inc/targetticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,19 @@ protected function showCompositeTicketSettings($rand) {

// show already linked items
foreach ($rows as $row) {
$icons = '&nbsp;'.Html::getSimpleForm(PluginFormcreatorItem_TargetTicket::getFormURL(), 'purge',
_x('button', 'Delete permanently'),
['id' => $row['id']],
'fa-times-circle');
$itemtype = $row['itemtype'];
$item = new $itemtype();
$item->getFromDB($row['items_id']);
$icons = '&nbsp;'.Html::getSimpleForm(
PluginFormcreatorItem_TargetTicket::getFormURL(),
'purge',
_x('button', 'Delete permanently'),
['id' => $row['id']],
'fa-times-circle'
);
$itemtype = $row['itemtype'];
$item = new $itemtype();
$item->getFromDB($row['items_id']);
switch ($itemtype) {
case Ticket::getType():
//TODO: when merge of https://github.com/glpi-project/glpi/pull/2840 (this is a BC)
//echo Ticket_Ticket::getLinkName($row['link']);
echo PluginFormcreatorCommon::getLinkName($row['link']);
echo Ticket_Ticket::getLinkName($row['link']);
echo ' ';
echo $itemtype::getTypeName();
echo ' ';
Expand All @@ -342,9 +343,7 @@ protected function showCompositeTicketSettings($rand) {
break;

case PluginFormcreatorTargetTicket::getType():
// TODO: when merge of https://github.com/glpi-project/glpi/pull/2840 (this is a BC)
//echo Ticket_Ticket::getLinkName($row['link']);
echo PluginFormcreatorCommon::getLinkName($row['link']);
echo Ticket_Ticket::getLinkName($row['link']);
echo ' ';
echo $itemtype::getTypeName();
echo ' ';
Expand Down
54 changes: 0 additions & 54 deletions tests/suite-unit/PluginFormcreatorCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,60 +62,6 @@ public function testSetNotification() {
$this->integer((int) $CFG_GLPI['use_notifications'])->isEqualTo('1');
}

public function providerGetLinkName() {
return [
[
'value' => '1',
'inverted' => false,
'expected' => 'Linked to',
],
[
'value' => '2',
'inverted' => false,
'expected' => 'Duplicates',
],
[
'value' => '3',
'inverted' => false,
'expected' => 'Son of',
],
[
'value' => '4',
'inverted' => false,
'expected' => 'Parent of',
],
[
'value' => '1',
'inverted' => true,
'expected' => 'Linked to',
],
[
'value' => '2',
'inverted' => true,
'expected' => 'Duplicated by',
],
[
'value' => '3',
'inverted' => true,
'expected' => 'Parent of',
],
[
'value' => '4',
'inverted' => true,
'expected' => 'Son of',
],
];
}

/**
* @dataProvider providerGetLinkName
*/
public function testGetLinkName($value, $inverted, $expected) {
$output = \PluginFormcreatorCommon::getLinkName($value, $inverted);
$this->string($output)->isEqualTo($expected);
}


public function providerGetPictoFilename() {
return [
[
Expand Down

0 comments on commit 12b47b4

Please sign in to comment.