Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 13 additions & 34 deletions pinc/ThemedTable.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,28 @@ class ThemedTable
/** @var string[] */
private array $column_alignments;

/**
* @param array{
* theme_striped?: mixed,
* border?: int,
* width?: int|string,
* subtitle?: string,
* } $options
* TODO: Make these into keyword args
*/
public function __construct(int $n_cols, string $title, array $options = [])
{
public function __construct(
int $n_cols,
string $title,
bool $theme_striped = false,
string $border = "",
string $width = "",
string $subtitle = "",
) {
$this->n_cols = $n_cols;

$class = "themed";
$border = 1;
$width = "";
$subtitle = null;
foreach ($options as $option_name => $option_value) {
switch ($option_name) {
case 'theme_striped':
$class .= ' theme_striped';
break;
case 'border':
$border = $option_value;
break;
case 'width':
$width = " width: $option_value;";
break;
case 'subtitle':
$subtitle = $option_value;
break;
}
if ($theme_striped) {
$class .= ' theme_striped';
}
$width_css = $width === "" ? "" : " width: $width;";

echo "\n";
echo "<table class='$class' style='border-width: {$border}px; {$width}'>";
echo "<table class='$class' style='border-width: {$border}px; {$width_css}'>";

{
$possible_subtitle =
is_null($subtitle)
? ''
: "<br>$subtitle";

$possible_subtitle = $subtitle === "" ? "" : "<br>$subtitle";
echo "\n";
echo "<tr>";
$maybe_colspan = "";
Expand Down
4 changes: 2 additions & 2 deletions stats/includes/member.inc
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ function showMbrNeighbors(User $user, string $tally_name): void
$t = new ThemedTable(
4,
_("Neighbors"),
['theme_striped' => true]
theme_striped: true
);
$t->set_column_widths(15, 28, 28, 29);
$t->column_headers(
Expand Down Expand Up @@ -546,7 +546,7 @@ function showMbrTeams(User $user): void
$t = new ThemedTable(
2,
_("Teams"),
['theme_striped' => true]
theme_striped: true
);
$t->set_column_widths(50, 50);
$t->column_headers(
Expand Down
10 changes: 4 additions & 6 deletions stats/includes/team.inc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function showTeamProfile(array $curTeam, bool $preview = false): void
$t = new ThemedTable(
2,
html_safe($curTeam['teamname']) . "&nbsp;$xml_button$editlink$joinquitlink",
['width' => 100]
width: "100"
);
$t->set_column_widths(25, 75);
$t->set_column_alignments('left', 'left');
Expand Down Expand Up @@ -271,7 +271,7 @@ function showTeamStats(array $curTeam, ?string $tally_name): void
$t = new ThemedTable(
2,
_("Team Statistics"),
['theme_striped' => true]
theme_striped: true
);
$t->set_column_widths(60, 40);

Expand Down Expand Up @@ -317,10 +317,8 @@ function showTeamMbrs(array $curTeam, ?string $tally_name): void
$t = new ThemedTable(
3,
_("Team Member Details"),
[
'theme_striped' => true,
'subtitle' => $subtitle,
]
theme_striped: true,
subtitle: $subtitle
);
$t->set_column_widths(35, 35, 30);

Expand Down
2 changes: 1 addition & 1 deletion stats/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function count_books_in_state(string $state, string $clauses = ""): int
$table = new ThemedTable(
2,
_('General Site Statistics'),
['width' => 'auto']
width: 'auto'
);

$table->set_column_alignments('left', 'right');
Expand Down