Skip to content

Commit

Permalink
Channel: Fetch channel name instead of type
Browse files Browse the repository at this point in the history
Multiple channels can be defined with same type, so the channel name is more relevant.
  • Loading branch information
sukhwinder33445 committed Nov 20, 2023
1 parent 0bc7727 commit c663164
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
2 changes: 1 addition & 1 deletion application/forms/EscalationRecipientForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function assembleElements(): void
$this->registerElement($col);

$options = ['' => sprintf(' - %s - ', $this->translate('Please choose'))];
$options += Channel::fetchChannelTypes(Database::get());
$options += Channel::fetchChannelNames(Database::get());

$val = $this->createElement(
'select',
Expand Down
19 changes: 4 additions & 15 deletions library/Notifications/Model/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,17 @@ public function getIcon(): Icon
}

/**
* Fetch and map all the configured channel types to a key => value array
* Fetch and map all the configured channel names to a key => value array
*
* @param Connection $conn
*
* @return array<int, string> All the channel types mapped as id => type
* @return array<int, string> All the channel names mapped as id => name
*/
public static function fetchChannelTypes(Connection $conn): array
public static function fetchChannelNames(Connection $conn): array
{
$channels = [];
foreach (Channel::on($conn) as $channel) {
switch ($channel->type) {
case 'rocketchat':
$name = 'Rocket.Chat';
break;
case 'email':
$name = t('E-Mail');
break;
default:
$name = $channel->type;
}

$channels[$channel->id] = $name;
$channels[$channel->id] = $channel->name;
}

return $channels;
Expand Down
2 changes: 1 addition & 1 deletion library/Notifications/Web/Form/ContactForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected function assemble()
$this->addElement($contact);

$channelOptions = ['' => sprintf(' - %s - ', $this->translate('Please choose'))];
$channelOptions += Channel::fetchChannelTypes(Database::get());
$channelOptions += Channel::fetchChannelNames(Database::get());

$contact->addElement(
'text',
Expand Down

0 comments on commit c663164

Please sign in to comment.