[ratings] add ratings field to upload
This commit is contained in:
parent
571839ec4a
commit
8af5b2f3db
2 changed files with 48 additions and 6 deletions
|
@ -42,6 +42,17 @@ add_rating(new ImageRating("e", "Explicit", "explicit", 1000));
|
|||
/** @noinspection PhpIncludeInspection */
|
||||
@include_once "data/config/ratings.conf.php";
|
||||
|
||||
class RatingSetException extends UserError
|
||||
{
|
||||
public ?string $redirect;
|
||||
|
||||
public function __construct(string $msg, ?string $redirect = null)
|
||||
{
|
||||
parent::__construct($msg);
|
||||
$this->redirect = $redirect;
|
||||
}
|
||||
}
|
||||
|
||||
class RatingSetEvent extends Event
|
||||
{
|
||||
public Image $image;
|
||||
|
@ -197,7 +208,7 @@ class Ratings extends Extension
|
|||
{
|
||||
global $user;
|
||||
$event->add_part(
|
||||
$this->theme->get_rater_html(
|
||||
$this->theme->get_image_rater_html(
|
||||
$event->image->id,
|
||||
$event->image['rating'],
|
||||
$user->can(Permissions::EDIT_IMAGE_RATING)
|
||||
|
@ -208,11 +219,27 @@ class Ratings extends Extension
|
|||
|
||||
public function onImageInfoSet(ImageInfoSetEvent $event): void
|
||||
{
|
||||
global $user;
|
||||
$rating = $event->get_param('rating');
|
||||
if ($user->can(Permissions::EDIT_IMAGE_RATING) && !is_null($rating)) {
|
||||
global $page, $user;
|
||||
if (
|
||||
$user->can(Permissions::EDIT_IMAGE_RATING) && (
|
||||
isset($event->params['rating'])
|
||||
|| isset($event->params["rating{$event->slot}"])
|
||||
)
|
||||
) {
|
||||
$common_rating = $event->params['rating'] ?? "";
|
||||
$my_rating = $event->params["rating{$event->slot}"] ?? "";
|
||||
$rating = Ratings::rating_is_valid($my_rating) ? $my_rating : $common_rating;
|
||||
if (Ratings::rating_is_valid($rating)) {
|
||||
try {
|
||||
send_event(new RatingSetEvent($event->image, $rating));
|
||||
} catch (RatingSetException $e) {
|
||||
if ($e->redirect) {
|
||||
$page->flash("{$e->getMessage()}, please see {$e->redirect}");
|
||||
} else {
|
||||
$page->flash($e->getMessage());
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -387,6 +414,16 @@ class Ratings extends Extension
|
|||
}
|
||||
}
|
||||
|
||||
public function onUploadHeaderBuilding(UploadHeaderBuildingEvent $event): void
|
||||
{
|
||||
$event->add_part("Rating");
|
||||
}
|
||||
|
||||
public function onUploadSpecificBuilding(UploadSpecificBuildingEvent $event): void
|
||||
{
|
||||
$event->add_part($this->theme->get_upload_specific_rater_html($event->suffix));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ImageRating[]
|
||||
*/
|
||||
|
|
|
@ -20,7 +20,7 @@ class RatingsTheme extends Themelet
|
|||
return SHM_SELECT($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
|
||||
public function get_image_rater_html(int $image_id, string $rating, bool $can_rate): HTMLElement
|
||||
{
|
||||
return SHM_POST_INFO(
|
||||
"Rating",
|
||||
|
@ -29,6 +29,11 @@ class RatingsTheme extends Themelet
|
|||
);
|
||||
}
|
||||
|
||||
public function get_upload_specific_rater_html(string $suffix): HTMLElement
|
||||
{
|
||||
return TD($this->get_selection_rater_html(name:"rating${suffix}", selected_options: ["?"]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,string> $current_ratings
|
||||
*/
|
||||
|
|
Reference in a new issue