Compare commits

...

2 Commits

Author SHA1 Message Date
gravel d5cb336170
feat: add local room overrides 2 months ago
gravel 53964f09d9
refactor: staff count function 2 months ago

3
.gitignore vendored

@ -21,6 +21,9 @@ listings/lp-output/*
cache
cache-lt
# Local config
config/*.ini
# Archives
/etc/archives/logrotate.status

@ -94,6 +94,11 @@
*/
$SOURCES_CACHE="$LONG_TERM_CACHE_ROOT/sources";
/**
* @var string $CONFIG_ROOT
* Directory containing local config files.
*/
$CONFIG_ROOT="$PROJECT_ROOT/config";
/**
* @var string $LISTING_PROVIDER_ROOT

@ -0,0 +1,2 @@
[room+1234]
staff_count=4

@ -11,6 +11,7 @@
require_once 'assets/room-icons.php';
require_once 'assets/room-invites.php';
require_once 'utils/numeric.php';
require_once 'utils/read-config.php';
/**
* Represents a Session Community.
@ -399,6 +400,18 @@
));
}
/**
* Return the number of unique Community staff.
* @return int
*/
function get_staff_count(): int {
global $LOCAL_CONFIG;
return (
$LOCAL_CONFIG->get_room_staff_count_override($this->get_room_identifier())
?? count($this->get_staff())
);
}
/**
* Return duration in seconds since room was created.
*/
@ -691,7 +704,7 @@
* @return bool
*/
public function has_good_staff_rating(): bool {
$staff_count = count($this->get_staff());
$staff_count = $this->get_staff_count();
return $staff_count >= $this->get_recommended_staff_count();
}
@ -702,7 +715,7 @@
*/
public function get_numeric_staff_rating(): float {
if (!$this->write || !$this->read) return 2;
return min(2, count($this->get_staff()) / $this->get_recommended_staff_count());
return min(2, $this->get_staff_count() / $this->get_recommended_staff_count());
}
/**
@ -720,7 +733,7 @@
* Estimate whether the Community does not have enough staff.
*/
public function has_poor_staff_rating(): bool {
return count($this->get_staff()) < $this->get_minimal_staff_count();
return $this->get_staff_count() < $this->get_minimal_staff_count();
}
/**

@ -0,0 +1,54 @@
<?php
require_once 'php/utils/logging.php';
/**
* @var string $CONFIG_ROOT
*/
class LocalConfig {
private function __construct() {
$this->room_overrides =
LocalConfig::maybe_parse_ini_file(LocalConfig::ROOM_OVERRIDES_CONFIG)
?? array();
}
private const ROOM_OVERRIDES_CONFIG = "room-overrides.ini";
private readonly array $room_overrides;
private static function maybe_parse_ini_file(string $filename): array | null {
global $CONFIG_ROOT;
$file = "$CONFIG_ROOT/$filename";
if (!file_exists($file)) {
log_warning("config file not found: $file");
return null;
}
return parse_ini_file($file, process_sections: true, scanner_mode: INI_SCANNER_RAW);
}
/**
* Read local config from the filesystem.
*/
public static function read_from_files() {
return new LocalConfig();
}
private function get_room_override(string $room_id, string $override_key) {
$room_overrides = $this->room_overrides[$room_id] ?? array();
return $room_overrides[$override_key] ?? null;
}
public function get_room_staff_count_override(string $room_id) {
return $this->get_room_override($room_id, 'staff_count');
}
}
/**
* @var LocalConfig $LOCAL_CONFIG
*/
$LOCAL_CONFIG = LocalConfig::read_from_files();
?>
Loading…
Cancel
Save