2023-04-20 12:22:43 +00:00
|
|
|
<?php
|
2023-10-17 20:47:35 +00:00
|
|
|
|
2023-04-20 12:22:43 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Dotclear\Plugin\activityReport;
|
|
|
|
|
|
|
|
/**
|
2023-10-17 20:47:35 +00:00
|
|
|
* @brief activityReport actions groups stack class.
|
|
|
|
* @ingroup activityReport
|
|
|
|
*
|
|
|
|
* @author Jean-Christian Denis (author)
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
2023-04-20 12:22:43 +00:00
|
|
|
*/
|
|
|
|
class Groups
|
|
|
|
{
|
2023-10-18 21:32:44 +00:00
|
|
|
/**
|
|
|
|
* The actions groups stack.
|
|
|
|
*
|
|
|
|
* @var array<string, Group> $stack
|
|
|
|
*/
|
2023-04-20 12:22:43 +00:00
|
|
|
private array $stack = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Chek if a group exists.
|
|
|
|
*
|
|
|
|
* @param string $id The group ID
|
|
|
|
*
|
|
|
|
* @return bool True if it exists
|
|
|
|
*/
|
|
|
|
public function has(string $id): bool
|
|
|
|
{
|
|
|
|
return isset($this->stack[$id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a group.
|
|
|
|
*
|
2023-10-18 21:32:44 +00:00
|
|
|
* Existing group will be overwritten.
|
|
|
|
*
|
2023-04-20 12:22:43 +00:00
|
|
|
* @param Group $group The group object
|
|
|
|
*
|
|
|
|
* @return Groups The groups instance
|
|
|
|
*/
|
|
|
|
public function add(Group $group): Groups
|
|
|
|
{
|
|
|
|
$this->stack[$group->id] = $group;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a group.
|
|
|
|
*
|
|
|
|
* @param string $id The group ID
|
|
|
|
*
|
|
|
|
* @return Group The group descriptor
|
|
|
|
*/
|
|
|
|
public function get(string $id): Group
|
|
|
|
{
|
|
|
|
return $this->stack[$id] ?? new Group($id, 'undefined');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all groups.
|
|
|
|
*
|
|
|
|
* @return array<string, Group> The groups stack
|
|
|
|
*/
|
|
|
|
public function dump(): array
|
|
|
|
{
|
|
|
|
return $this->stack;
|
|
|
|
}
|
|
|
|
}
|