-
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathCreateComponentGroup.php
More file actions
38 lines (33 loc) · 1.15 KB
/
CreateComponentGroup.php
File metadata and controls
38 lines (33 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace Cachet\Actions\ComponentGroup;
use Cachet\Data\Requests\ComponentGroup\CreateComponentGroupRequestData;
use Cachet\Enums\ComponentGroupVisibilityEnum;
use Cachet\Enums\ResourceVisibilityEnum;
use Cachet\Models\ComponentGroup;
use Cachet\Verbs\Events\ComponentGroups\ComponentGroupCreated;
use Cachet\Verbs\Events\Components\ComponentUpdated;
class CreateComponentGroup
{
/**
* Handle the action.
*/
public function handle(CreateComponentGroupRequestData $data): ComponentGroup
{
$componentGroup = ComponentGroupCreated::commit(
name: $data->name,
order: $data->order ?? 0,
collapsed: ComponentGroupVisibilityEnum::expanded,
visible: $data->visible ?? ResourceVisibilityEnum::guest,
);
// Assign components to the group via update events
if ($data->components) {
foreach ($data->components as $componentId) {
ComponentUpdated::commit(
component_id: $componentId,
component_group_id: $componentGroup->id,
);
}
}
return $componentGroup;
}
}