Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased]
## [Unreleased]

### Fixed

Expand Down
3 changes: 3 additions & 0 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@

use GlpiPlugin\Moreoptions\Config;
use GlpiPlugin\Moreoptions\Escalation;
use GlpiPlugin\Moreoptions\Group_Link;

function plugin_moreoptions_install(): bool
{
$migration = new Migration(PLUGIN_MOREOPTIONS_VERSION);

Config::install($migration);
Escalation::install($migration);
Group_Link::install($migration);
$migration->executeMigration();
return true;
}
Expand All @@ -52,6 +54,7 @@ function plugin_moreoptions_uninstall(): bool

Config::uninstall($migration);
Escalation::uninstall($migration);
Group_Link::uninstall($migration);

return true;
}
3 changes: 3 additions & 0 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use GlpiPlugin\Moreoptions\Config;
use GlpiPlugin\Moreoptions\Controller;
use GlpiPlugin\Moreoptions\Escalation;
use GlpiPlugin\Moreoptions\Group_Link;

/** @phpstan-ignore theCodingMachineSafe.function (safe to assume this isn't already defined) */
define('PLUGIN_MOREOPTIONS_VERSION', '1.0.0-rc2');
Expand Down Expand Up @@ -67,6 +68,8 @@ function plugin_init_moreoptions(): void

Plugin::registerClass(Config::class, ['addtabon' => 'Entity']);

Plugin::registerClass(Group_Link::class, ['addtabon' => 'Group']);

$PLUGIN_HOOKS[Hooks::ADD_CSS]['moreoptions'][] = 'css/moreoptions.scss';

$PLUGIN_HOOKS[Hooks::ITEM_ADD]['moreoptions'][Entity::class] = Config::addConfig(...);
Expand Down
150 changes: 150 additions & 0 deletions src/Group_Link.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?php

/**
* -------------------------------------------------------------------------
* MoreOptions plugin for GLPI
* -------------------------------------------------------------------------
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2025 by the MoreOptions plugin team.
* @license MIT https://opensource.org/licenses/mit-license.php
* @link https://github.com/pluginsGLPI/moreoptions
* @link https://gitlab.teclib.com/glpi-network/moreoptions/
* -------------------------------------------------------------------------
*/

namespace GlpiPlugin\Moreoptions;

use CommonDBRelation;
use CommonGLPI;
use DBConnection;
use DBmysql;
use Glpi\Application\View\TemplateRenderer;
use GlpiPlugin\Moreoptions\LinkStrategy\LinkStrategyEnum;
use Group;
use Migration;

/**
* Escalation hierarchy between groups: the destination groups a source group can escalate to.
* Managed from the "Escalation" tab of the source group.
*/
class Group_Link extends CommonDBRelation
{
public static $itemtype_1 = Group::class;

public static $items_id_1 = 'groups_id_source';

public static $itemtype_2 = Group::class;

public static $items_id_2 = 'groups_id_destination';

public static function getTypeName($nb = 0): string
{
return __('Escalation', 'moreoptions');
}

public static function getIcon(): string
{
return 'ti ti-escalator-up';
}

public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0): string
{
if (!$item instanceof Group || $item->isNewItem()) {
return '';
}

return self::createTabEntry(self::getTypeName(), 0, $item::class, self::getIcon());
}

public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0): bool
{
if ($item instanceof Group) {
self::showForGroup($item);
}

return true;
}

/**
* Renders the "Escalation" tab of the given group.
*/
public static function showForGroup(Group $group): void
{
TemplateRenderer::getInstance()->display('@moreoptions/group_link.html.twig');
}

/**
* The links applying in the given entity. For each pair of groups, the link of the closest
* entity wins, from the given entity up to the root entity: a LinkStrategyEnum::BASIC link
* only applies in its own entity, a LinkStrategyEnum::INHERITED one also in its sub-entities,
* and a LinkStrategyEnum::NONE one removes the inherited link from its entity and its
* sub-entities.
*
* @return array<int, array<string, mixed>>
*/
public static function getLinksForEntity(int $entities_id): array
{
return [];
}

public function getLinkStrategy(): LinkStrategyEnum
{
return LinkStrategyEnum::tryFrom((string) ($this->fields['link_type'] ?? '')) ?? LinkStrategyEnum::getDefault();
}

public static function install(Migration $migration): void
{
/** @var DBmysql $DB */
global $DB;

$table = self::getTable();
if (!$DB->tableExists($table)) {
$migration->displayMessage('Installing ' . $table);
$default_charset = DBConnection::getDefaultCharset();
$default_collation = DBConnection::getDefaultCollation();
$default_key_sign = DBConnection::getDefaultPrimaryKeySignOption();

$DB->doQuery("CREATE TABLE `{$table}` (
`id` int {$default_key_sign} NOT NULL AUTO_INCREMENT,
`groups_id_source` int {$default_key_sign} NOT NULL DEFAULT '0',
`groups_id_destination` int {$default_key_sign} NOT NULL DEFAULT '0',
`entities_id` int {$default_key_sign} NOT NULL DEFAULT '0',
`link_type` varchar(30) NOT NULL DEFAULT '',
`date_creation` timestamp NULL DEFAULT NULL,
`date_mod` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `unicity` (`entities_id`, `groups_id_source`, `groups_id_destination`),
KEY `groups_id_source` (`groups_id_source`),
KEY `groups_id_destination` (`groups_id_destination`),
KEY `date_creation` (`date_creation`),
KEY `date_mod` (`date_mod`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;
");
}
}

public static function uninstall(Migration $migration): void
{
$migration->dropTable(self::getTable());
}
}
74 changes: 74 additions & 0 deletions src/LinkStrategy/AbstractLinkStrategy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/**
* -------------------------------------------------------------------------
* MoreOptions plugin for GLPI
* -------------------------------------------------------------------------
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2025 by the MoreOptions plugin team.
* @license MIT https://opensource.org/licenses/mit-license.php
* @link https://github.com/pluginsGLPI/moreoptions
* @link https://gitlab.teclib.com/glpi-network/moreoptions/
* -------------------------------------------------------------------------
*/

namespace GlpiPlugin\Moreoptions\LinkStrategy;

abstract class AbstractLinkStrategy
{
/**
* Get the display options of the arrow representing the link between the two groups
*
* @return array<string, mixed>
*/
public function getArrowOptions(): array
{
return [];
}

/**
* Whether the link is replicated in the sub-entities of its entity
*/
public function appliesToSubEntities(): bool
{
return false;
}

/**
* Whether the link stops, from its entity, the replication of an inherited link
*/
public function blocksInheritance(): bool
{
return false;
}

/**
* Get the label of the link strategy
*/
abstract public function getLabel(): string;

/**
* Get the icon of the link strategy
*/
abstract public function getIcon(): string;
}
51 changes: 51 additions & 0 deletions src/LinkStrategy/BasicLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* -------------------------------------------------------------------------
* MoreOptions plugin for GLPI
* -------------------------------------------------------------------------
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2025 by the MoreOptions plugin team.
* @license MIT https://opensource.org/licenses/mit-license.php
* @link https://github.com/pluginsGLPI/moreoptions
* @link https://gitlab.teclib.com/glpi-network/moreoptions/
* -------------------------------------------------------------------------
*/

namespace GlpiPlugin\Moreoptions\LinkStrategy;

/**
* Link restricted to its entity
*/
final class BasicLink extends AbstractLinkStrategy
{
public function getLabel(): string
{
return __('Basic', 'moreoptions');
}

public function getIcon(): string
{
return 'ti ti-arrow-right';
}
}
56 changes: 56 additions & 0 deletions src/LinkStrategy/InheritedLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/**
* -------------------------------------------------------------------------
* MoreOptions plugin for GLPI
* -------------------------------------------------------------------------
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2025 by the MoreOptions plugin team.
* @license MIT https://opensource.org/licenses/mit-license.php
* @link https://github.com/pluginsGLPI/moreoptions
* @link https://gitlab.teclib.com/glpi-network/moreoptions/
* -------------------------------------------------------------------------
*/

namespace GlpiPlugin\Moreoptions\LinkStrategy;

/**
* Link replicated in the sub-entities of its entity
*/
final class InheritedLink extends AbstractLinkStrategy
{
public function appliesToSubEntities(): bool
{
return true;
}

public function getLabel(): string
{
return __('Inherited', 'moreoptions');
}

public function getIcon(): string
{
return 'ti ti-sitemap';
}
}
Loading
Loading