2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2007-10-02 21:59:20 +00:00
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
2023-06-29 05:50:32 +00:00
|
|
|
use MicroHTML\HTMLElement;
|
|
|
|
|
2023-06-29 17:44:57 +00:00
|
|
|
use function MicroHTML\emptyHTML;
|
|
|
|
use function MicroHTML\{DIV,INPUT,P,PRE,SPAN,TABLE,TD,TH,TR};
|
2023-06-29 05:50:32 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class RatingsTheme extends Themelet
|
|
|
|
{
|
2023-06-29 05:50:32 +00:00
|
|
|
public function get_selection_rater_html(string $name = "rating", array $ratings = [], array $selected_options = []): HTMLElement
|
|
|
|
{
|
|
|
|
return $this->build_selector($name, !empty($ratings) ? $ratings : Ratings::get_ratings_dict(), required: true, selected_options: $selected_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_rater_html(int $image_id, string $rating, bool $can_rate): HTMLElement
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
$human_rating = Ratings::rating_to_human($rating);
|
2023-06-29 05:50:32 +00:00
|
|
|
|
|
|
|
$html = TR(TH("Rating"));
|
|
|
|
|
|
|
|
if ($can_rate) {
|
|
|
|
$selector = $this->get_selection_rater_html(selected_options: [$rating]);
|
|
|
|
|
|
|
|
$html->appendChild(TD(
|
|
|
|
SPAN(["class"=>"view"], $human_rating),
|
|
|
|
SPAN(["class"=>"edit"], $selector)
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
$html->appendChild(TD($human_rating));
|
|
|
|
}
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
return $html;
|
|
|
|
}
|
2007-11-04 08:16:41 +00:00
|
|
|
|
2023-06-25 23:05:38 +00:00
|
|
|
public function display_form(array $current_ratings)
|
2019-06-27 04:11:59 +00:00
|
|
|
{
|
2019-10-02 10:23:57 +00:00
|
|
|
global $page;
|
2019-06-27 04:11:59 +00:00
|
|
|
|
2023-06-29 17:44:57 +00:00
|
|
|
$html = make_form_microhtml(make_link("admin/update_ratings"));
|
2023-06-25 23:05:38 +00:00
|
|
|
|
2023-06-29 17:44:57 +00:00
|
|
|
$html->appendChild(TABLE(
|
|
|
|
["class"=>"form"],
|
|
|
|
TR(TH("Change"), TD($this->get_selection_rater_html("rating_old", $current_ratings))),
|
|
|
|
TR(TH("To"), TD($this->get_selection_rater_html("rating_new"))),
|
|
|
|
TR(TD(["colspan"=>"2"], INPUT(["type"=>"submit", "value"=>"Update"])))
|
|
|
|
));
|
2023-06-25 23:05:38 +00:00
|
|
|
|
2019-06-27 04:11:59 +00:00
|
|
|
$page->add_block(new Block("Update Ratings", $html));
|
|
|
|
}
|
|
|
|
|
2023-06-29 17:44:57 +00:00
|
|
|
public function get_help_html(array $ratings): HTMLElement
|
2019-08-02 20:05:49 +00:00
|
|
|
{
|
2023-06-29 17:44:57 +00:00
|
|
|
$output = emptyHTML(
|
|
|
|
P("Search for posts with one or more possible ratings."),
|
|
|
|
DIV(
|
|
|
|
["class"=>"command_example"],
|
|
|
|
PRE("rating:" . $ratings[0]->search_term),
|
|
|
|
P("Returns posts with the " . $ratings[0]->name . " rating.")
|
|
|
|
),
|
|
|
|
P("Ratings can be abbreviated to a single letter as well."),
|
|
|
|
DIV(
|
|
|
|
["class"=>"command_example"],
|
|
|
|
PRE("rating:" . $ratings[0]->code),
|
|
|
|
P("Returns posts with the " . $ratings[0]->name . " rating.")
|
|
|
|
),
|
|
|
|
P("If abbreviations are used, multiple ratings can be searched for."),
|
|
|
|
DIV(
|
|
|
|
["class"=>"command_example"],
|
|
|
|
PRE("rating:" . $ratings[0]->code . $ratings[1]->code),
|
|
|
|
P("Returns posts with the " . $ratings[0]->name . " or " . $ratings[1]->name . " rating.")
|
|
|
|
),
|
|
|
|
P("Available ratings:")
|
|
|
|
);
|
|
|
|
|
2023-06-29 17:57:35 +00:00
|
|
|
$table = TABLE(TR(TH("Name"), TH("Search Term"), TH("Abbreviation")));
|
2023-06-29 17:44:57 +00:00
|
|
|
|
2019-08-02 20:05:49 +00:00
|
|
|
foreach ($ratings as $rating) {
|
2023-06-29 17:57:35 +00:00
|
|
|
$table->appendChild(TR(TD($rating->name), TD($rating->search_term), TD($rating->code)));
|
2019-08-02 20:05:49 +00:00
|
|
|
}
|
2023-06-29 17:44:57 +00:00
|
|
|
|
|
|
|
$output->appendChild($table);
|
|
|
|
|
2019-08-02 20:05:49 +00:00
|
|
|
return $output;
|
2019-08-14 14:07:45 +00:00
|
|
|
}
|
2019-10-02 10:23:57 +00:00
|
|
|
|
2023-06-25 23:05:38 +00:00
|
|
|
// This wasn't being used at all
|
|
|
|
|
|
|
|
/* public function get_user_options(User $user, array $selected_ratings, array $available_ratings): string
|
2019-06-27 04:11:59 +00:00
|
|
|
{
|
|
|
|
$html = "
|
|
|
|
<p>".make_form(make_link("user_admin/default_ratings"))."
|
|
|
|
<input type='hidden' name='id' value='$user->id'>
|
|
|
|
<table style='width: 300px;'>
|
|
|
|
<thead>
|
2020-10-26 15:13:28 +00:00
|
|
|
<tr><th colspan='2'></th></tr>
|
2019-06-27 04:11:59 +00:00
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr><td>This controls the default rating search results will be filtered by, and nothing else. To override in your search results, add rating:* to your search.</td></tr>
|
|
|
|
<tr><td>
|
2023-06-29 05:50:32 +00:00
|
|
|
".$this->build_selector("ratings", selected_options: $selected_ratings, multiple: true, options: $available_ratings)."
|
2019-06-27 04:11:59 +00:00
|
|
|
</td></tr>
|
|
|
|
</tbody>
|
|
|
|
<tfoot>
|
|
|
|
<tr><td><input type='submit' value='Save'></td></tr>
|
|
|
|
</tfoot>
|
|
|
|
</table>
|
|
|
|
</form>
|
|
|
|
";
|
|
|
|
return $html;
|
2023-06-25 23:05:38 +00:00
|
|
|
} */
|
2007-10-02 21:59:20 +00:00
|
|
|
}
|