bulk image rater
This commit is contained in:
parent
4f0bd7935e
commit
5fe8ca4c9c
@ -7,10 +7,10 @@
|
||||
*/
|
||||
|
||||
class RatingSetEvent extends Event {
|
||||
var $image_id, $user, $rating;
|
||||
var $image, $user, $rating;
|
||||
|
||||
public function RatingSetEvent($image_id, $user, $rating) {
|
||||
$this->image_id = $image_id;
|
||||
public function RatingSetEvent(Image $image, User $user, $rating) {
|
||||
$this->image = $image;
|
||||
$this->user = $user;
|
||||
$this->rating = $rating;
|
||||
}
|
||||
@ -23,6 +23,35 @@ class Ratings implements Extension {
|
||||
global $config, $database, $page, $user;
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
|
||||
if($event instanceof AdminBuildingEvent) {
|
||||
$this->theme->display_bulk_rater();
|
||||
}
|
||||
|
||||
if(($event instanceof PageRequestEvent) && $event->page_matches("admin/bulk_rate")) {
|
||||
global $database, $user, $page;
|
||||
if(!$user->is_admin()) {
|
||||
throw PermissionDeniedException();
|
||||
}
|
||||
else {
|
||||
$n = 0;
|
||||
while(true) {
|
||||
$images = Image::find_images($n, 100, Tag::explode($_POST["query"]));
|
||||
if(count($images) == 0) break;
|
||||
foreach($images as $image) {
|
||||
send_event(new RatingSetEvent($image, $user, $_POST['rating']));
|
||||
}
|
||||
$n += 100;
|
||||
}
|
||||
#$database->execute("
|
||||
# update images set rating=? where images.id in (
|
||||
# select image_id from image_tags join tags
|
||||
# on image_tags.tag_id = tags.id where tags.tag = ?);
|
||||
# ", array($_POST["rating"], $_POST["tag"]));
|
||||
$page->set_mode("redirect");
|
||||
$page->set_redirect(make_link("admin"));
|
||||
}
|
||||
}
|
||||
|
||||
if($event instanceof InitExtEvent) {
|
||||
if($config->get_int("ext_ratings2_version") < 2) {
|
||||
$this->install();
|
||||
@ -34,7 +63,7 @@ class Ratings implements Extension {
|
||||
}
|
||||
|
||||
if($event instanceof RatingSetEvent) {
|
||||
$this->set_rating($event->image_id, $event->rating);
|
||||
$this->set_rating($event->image->id, $event->rating);
|
||||
}
|
||||
|
||||
if($event instanceof ImageInfoBoxBuildingEvent) {
|
||||
@ -45,7 +74,7 @@ class Ratings implements Extension {
|
||||
|
||||
if($event instanceof ImageInfoSetEvent) {
|
||||
if($user->is_admin()) {
|
||||
send_event(new RatingSetEvent($event->image->id, $user, $_POST['rating']));
|
||||
send_event(new RatingSetEvent($event->image, $user, $_POST['rating']));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,37 @@ class RatingsTheme extends Themelet {
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function display_bulk_rater() {
|
||||
global $page;
|
||||
$html = "
|
||||
<form action='".make_link("admin/bulk_rate")."' method='POST'>
|
||||
<table style='width: 300px'>
|
||||
<tr>
|
||||
<td>Search</td>
|
||||
<td>
|
||||
<input type='text' name='query'>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Rating</td>
|
||||
<td>
|
||||
<select name='rating'>
|
||||
<option value='s'>Safe</option>
|
||||
<option value='q'>Questionable</option>
|
||||
<option value='e'>Explicit</option>
|
||||
<option value='u'>Unrated</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan='2'><input type='submit' value='Go'></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
";
|
||||
$page->add_block(new Block("Bulk Rating", $html));
|
||||
}
|
||||
|
||||
public function rating_to_name($rating) {
|
||||
switch($rating) {
|
||||
case 's': return "Safe";
|
||||
|
Loading…
x
Reference in New Issue
Block a user