BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mass_user_bookmarks_editor.class.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. #declare(strict_types=1);
  3. //require_once 'mass_user_torrents_editor.class.php';
  4. /**
  5. * This class helps with mass-editing bookmarked torrents.
  6. *
  7. * It can later be used for other bookmark tables.
  8. *
  9. */
  10. class MASS_USER_BOOKMARKS_EDITOR extends MASS_USER_TORRENTS_EDITOR
  11. {
  12. public function __construct($Table = 'bookmarks_torrents')
  13. {
  14. $this->set_table($Table);
  15. }
  16. /**
  17. * Runs a SQL query and clears the Cache key
  18. *
  19. * G::$Cache->delete_value didn't always work, but setting the key to null, did. (?)
  20. *
  21. * @param string $sql
  22. */
  23. protected function query_and_clear_cache($sql)
  24. {
  25. $QueryID = G::$DB->get_query_id();
  26. if (is_string($sql) && G::$DB->query($sql)) {
  27. G::$Cache->delete_value('bookmarks_group_ids_' . G::$LoggedUser['ID']);
  28. }
  29. G::$DB->set_query_id($QueryID);
  30. }
  31. /**
  32. * Uses (checkboxes) $_POST['remove'] to delete entries.
  33. *
  34. * Uses an IN() to match multiple items in one query.
  35. */
  36. public function mass_remove()
  37. {
  38. $SQL = [];
  39. foreach ($_POST['remove'] as $GroupID => $K) {
  40. if (is_number($GroupID)) {
  41. $SQL[] = sprintf('%d', $GroupID);
  42. }
  43. }
  44. if (!empty($SQL)) {
  45. $SQL = sprintf(
  46. '
  47. DELETE FROM %s
  48. WHERE UserID = %d
  49. AND GroupID IN (%s)',
  50. $this->Table,
  51. G::$LoggedUser['ID'],
  52. implode(', ', $SQL)
  53. );
  54. $this->query_and_clear_cache($SQL);
  55. }
  56. }
  57. /**
  58. * Uses $_POST['sort'] values to update the DB.
  59. */
  60. public function mass_update()
  61. {
  62. $SQL = [];
  63. foreach ($_POST['sort'] as $GroupID => $Sort) {
  64. if (is_number($Sort) && is_number($GroupID)) {
  65. $SQL[] = sprintf('(%d, %d, %d)', $GroupID, $Sort, G::$LoggedUser['ID']);
  66. }
  67. }
  68. if (!empty($SQL)) {
  69. $SQL = sprintf(
  70. '
  71. INSERT INTO %s
  72. (GroupID, Sort, UserID)
  73. VALUES
  74. %s
  75. ON DUPLICATE KEY UPDATE
  76. Sort = VALUES (Sort)',
  77. $this->Table,
  78. implode(', ', $SQL)
  79. );
  80. $this->query_and_clear_cache($SQL);
  81. }
  82. }
  83. }