mirror of
https://github.com/Icinga/icingadb-web.git
synced 2026-05-28 04:36:06 -04:00
Add SPDX license headers and mark source files as GPL-3.0-or-later to preserve the option to relicense under later GPL versions.
53 lines
1.2 KiB
PHP
53 lines
1.2 KiB
PHP
<?php
|
|
|
|
// SPDX-FileCopyrightText: 2021 Icinga GmbH <https://icinga.com>
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
namespace Icinga\Module\Icingadb\Model\Behavior;
|
|
|
|
use ipl\Orm\Contract\PropertyBehavior;
|
|
|
|
class ActionAndNoteUrl extends PropertyBehavior
|
|
{
|
|
public function fromDb($value, $key, $_)
|
|
{
|
|
if (empty($value)) {
|
|
return [];
|
|
}
|
|
|
|
$links = [];
|
|
if (strpos($value, "' ") === false) {
|
|
$links[] = $value;
|
|
} else {
|
|
foreach (explode("' ", $value) as $url) {
|
|
$url = strpos($url, "'") === 0 ? substr($url, 1) : $url;
|
|
$url = strpos($url, "'") === strlen($url) - 1 ? substr($url, 0, strlen($url) - 1) : $url;
|
|
$links[] = $url;
|
|
}
|
|
}
|
|
|
|
return $links;
|
|
}
|
|
|
|
public function toDb($value, $key, $_)
|
|
{
|
|
if (empty($value) || ! is_array($value)) {
|
|
return $value;
|
|
}
|
|
|
|
if (count($value) === 1) {
|
|
return $value[0];
|
|
}
|
|
|
|
$links = '';
|
|
foreach ($value as $url) {
|
|
if (! empty($links)) {
|
|
$links .= ' ';
|
|
}
|
|
|
|
$links .= "'$url'";
|
|
}
|
|
|
|
return $links;
|
|
}
|
|
}
|