Gazelle/classes/mass_user_bookmarks_editor.class.php

82 lines
1.8 KiB
PHP
Raw Normal View History

2012-10-29 08:00:20 +00:00
<?php
2013-05-27 08:00:58 +00:00
//require_once 'mass_user_torrents_editor.class.php';
2012-10-29 08:00:20 +00:00
/**
* This class helps with mass-editing bookmarked torrents.
*
* It can later be used for other bookmark tables.
*
*/
2013-05-27 08:00:58 +00:00
class MASS_USER_BOOKMARKS_EDITOR extends MASS_USER_TORRENTS_EDITOR {
2013-09-06 08:00:41 +00:00
public function __construct($Table = 'bookmarks_torrents') {
2012-10-29 08:00:20 +00:00
$this->set_table($Table);
}
/**
2013-02-25 21:16:55 +00:00
* Runs a SQL query and clears the Cache key
2012-10-29 08:00:20 +00:00
*
2013-08-28 23:08:41 +00:00
* G::$Cache->delete_value didn't always work, but setting the key to null, did. (?)
2012-10-29 08:00:20 +00:00
*
* @param string $sql
*/
2013-09-06 08:00:41 +00:00
protected function query_and_clear_cache($sql) {
2013-08-28 23:08:41 +00:00
$QueryID = G::$DB->get_query_id();
2013-09-06 08:00:41 +00:00
if (is_string($sql) && G::$DB->query($sql)) {
2013-08-28 23:08:41 +00:00
G::$Cache->delete_value('bookmarks_group_ids_' . G::$LoggedUser['ID']);
2013-09-06 08:00:41 +00:00
}
2013-08-28 23:08:41 +00:00
G::$DB->set_query_id($QueryID);
2012-10-29 08:00:20 +00:00
}
/**
* Uses (checkboxes) $_POST['remove'] to delete entries.
*
* Uses an IN() to match multiple items in one query.
*/
2013-09-06 08:00:41 +00:00
public function mass_remove() {
2012-10-29 08:00:20 +00:00
$SQL = array();
foreach ($_POST['remove'] as $GroupID => $K) {
2013-09-06 08:00:41 +00:00
if (is_number($GroupID)) {
2012-10-29 08:00:20 +00:00
$SQL[] = sprintf('%d', $GroupID);
2013-09-06 08:00:41 +00:00
}
2012-10-29 08:00:20 +00:00
}
if (!empty($SQL)) {
2013-09-06 08:00:41 +00:00
$SQL = sprintf('
DELETE FROM %s
WHERE UserID = %d
AND GroupID IN (%s)',
2012-10-29 08:00:20 +00:00
$this->Table,
2013-08-28 23:08:41 +00:00
G::$LoggedUser['ID'],
2012-10-29 08:00:20 +00:00
implode(', ', $SQL)
);
$this->query_and_clear_cache($SQL);
}
}
/**
* Uses $_POST['sort'] values to update the DB.
*/
2013-09-06 08:00:41 +00:00
public function mass_update() {
2012-10-29 08:00:20 +00:00
$SQL = array();
foreach ($_POST['sort'] as $GroupID => $Sort) {
2013-09-06 08:00:41 +00:00
if (is_number($Sort) && is_number($GroupID)) {
2013-08-28 23:08:41 +00:00
$SQL[] = sprintf('(%d, %d, %d)', $GroupID, $Sort, G::$LoggedUser['ID']);
2013-09-06 08:00:41 +00:00
}
2012-10-29 08:00:20 +00:00
}
if (!empty($SQL)) {
2013-09-06 08:00:41 +00:00
$SQL = sprintf('
INSERT INTO %s
(GroupID, Sort, UserID)
VALUES
%s
ON DUPLICATE KEY UPDATE
Sort = VALUES (Sort)',
$this->Table,
implode(', ', $SQL));
2012-10-29 08:00:20 +00:00
$this->query_and_clear_cache($SQL);
}
}
2013-05-27 08:00:58 +00:00
}