2016-06-08 01:17:39 +00:00
|
|
|
<?php
|
|
|
|
|
2022-02-16 04:08:28 +00:00
|
|
|
namespace Code\Lib;
|
2016-06-08 01:17:39 +00:00
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
class AbConfig
|
|
|
|
{
|
2016-06-08 01:17:39 +00:00
|
|
|
|
2022-08-27 04:01:22 +00:00
|
|
|
public static function Load($channel_id, $xchan_hash, $family = ''): array|bool|null
|
2021-12-03 03:01:39 +00:00
|
|
|
{
|
2022-08-13 11:34:00 +00:00
|
|
|
$where = ($family) ? sprintf(" and cat = '%s' ", dbesc($family)) : '';
|
|
|
|
return q(
|
2021-12-03 03:01:39 +00:00
|
|
|
"select * from abconfig where chan = %d and xchan = '%s' $where",
|
2022-08-27 04:01:22 +00:00
|
|
|
intval($channel_id),
|
|
|
|
dbesc($xchan_hash)
|
2021-12-03 03:01:39 +00:00
|
|
|
);
|
|
|
|
}
|
2016-06-08 01:17:39 +00:00
|
|
|
|
|
|
|
|
2022-08-27 04:01:22 +00:00
|
|
|
public static function Get($channel_id, $xchan_hash, $family, $key, $default = false)
|
2021-12-03 03:01:39 +00:00
|
|
|
{
|
|
|
|
$r = q(
|
|
|
|
"select * from abconfig where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' limit 1",
|
2022-08-27 04:01:22 +00:00
|
|
|
intval($channel_id),
|
|
|
|
dbesc($xchan_hash),
|
2021-12-03 03:01:39 +00:00
|
|
|
dbesc($family),
|
|
|
|
dbesc($key)
|
|
|
|
);
|
|
|
|
if ($r) {
|
|
|
|
return unserialise($r[0]['v']);
|
|
|
|
}
|
|
|
|
return $default;
|
|
|
|
}
|
2016-06-08 01:17:39 +00:00
|
|
|
|
|
|
|
|
2022-08-27 04:01:22 +00:00
|
|
|
public static function Set($channel_id, $xchan_hash, $family, $key, $value)
|
2021-12-03 03:01:39 +00:00
|
|
|
{
|
2016-06-08 01:17:39 +00:00
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
$dbvalue = ((is_array($value)) ? serialise($value) : $value);
|
|
|
|
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
|
2016-06-08 01:17:39 +00:00
|
|
|
|
2022-08-27 04:01:22 +00:00
|
|
|
if (self::Get($channel_id, $xchan_hash, $family, $key) === false) {
|
2021-12-03 03:01:39 +00:00
|
|
|
$r = q(
|
|
|
|
"insert into abconfig ( chan, xchan, cat, k, v ) values ( %d, '%s', '%s', '%s', '%s' ) ",
|
2022-08-27 04:01:22 +00:00
|
|
|
intval($channel_id),
|
|
|
|
dbesc($xchan_hash),
|
2021-12-03 03:01:39 +00:00
|
|
|
dbesc($family),
|
|
|
|
dbesc($key),
|
|
|
|
dbesc($dbvalue)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$r = q(
|
|
|
|
"update abconfig set v = '%s' where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' ",
|
|
|
|
dbesc($dbvalue),
|
2022-08-27 04:01:22 +00:00
|
|
|
dbesc($channel_id),
|
|
|
|
dbesc($xchan_hash),
|
2021-12-03 03:01:39 +00:00
|
|
|
dbesc($family),
|
|
|
|
dbesc($key)
|
|
|
|
);
|
|
|
|
}
|
2016-06-08 01:17:39 +00:00
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
if ($r) {
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-08 01:17:39 +00:00
|
|
|
|
|
|
|
|
2022-08-27 04:01:22 +00:00
|
|
|
public static function Delete($channel_id, $xchan_hash, $family, $key): bool
|
2021-12-03 03:01:39 +00:00
|
|
|
{
|
2022-08-13 11:34:00 +00:00
|
|
|
return q(
|
2021-12-03 03:01:39 +00:00
|
|
|
"delete from abconfig where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' ",
|
2022-08-27 04:01:22 +00:00
|
|
|
intval($channel_id),
|
|
|
|
dbesc($xchan_hash),
|
2021-12-03 03:01:39 +00:00
|
|
|
dbesc($family),
|
|
|
|
dbesc($key)
|
|
|
|
);
|
|
|
|
}
|
2016-06-24 01:12:26 +00:00
|
|
|
}
|