Gazelle/sections/artist/add_similar.php

71 lines
2.0 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
authorize();
$UserID = $LoggedUser['ID'];
$Artist1ID = db_string($_POST['artistid']);
$Artist2Name = db_string($_POST['artistname']);
2013-05-04 08:00:48 +00:00
if (!is_number($Artist1ID)) {
2011-03-28 14:21:28 +00:00
error(0);
}
2013-05-04 08:00:48 +00:00
if (empty($Artist2Name)) {
2011-03-28 14:21:28 +00:00
error('Blank artist name.');
}
2013-07-12 08:00:46 +00:00
$DB->query("
SELECT ag.ArtistID
FROM artists_group AS ag
WHERE ag.Name LIKE '$Artist2Name'");
2011-03-28 14:21:28 +00:00
list($Artist2ID) = $DB->next_record();
2013-05-04 08:00:48 +00:00
if (!empty($Artist2ID)) { // artist was found in the database
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
// Let's see if there's already a similar artists field for these two
2013-07-12 08:00:46 +00:00
$DB->query("
SELECT s1.SimilarID
2011-03-28 14:21:28 +00:00
FROM artists_similar AS s1
2013-07-12 08:00:46 +00:00
JOIN artists_similar AS s2 ON s1.SimilarID = s2.SimilarID
WHERE s1.ArtistID = '$Artist1ID'
AND s2.ArtistID = '$Artist2ID'");
2011-03-28 14:21:28 +00:00
list($SimilarID) = $DB->next_record();
2013-02-22 08:00:24 +00:00
2013-05-04 08:00:48 +00:00
if ($SimilarID) { // The similar artists field already exists, just update the score
2013-07-12 08:00:46 +00:00
$DB->query("
UPDATE artists_similar_scores
SET Score = Score + 200
WHERE SimilarID = '$SimilarID'");
2011-03-28 14:21:28 +00:00
} else { // No, it doesn't exist - create it
2013-07-12 08:00:46 +00:00
$DB->query("
INSERT INTO artists_similar_scores (Score)
VALUES ('200')");
2011-03-28 14:21:28 +00:00
$SimilarID = $DB->inserted_id();
2013-07-12 08:00:46 +00:00
$DB->query("
INSERT INTO artists_similar (ArtistID, SimilarID)
VALUES ('$Artist1ID', '$SimilarID')");
$DB->query("
INSERT INTO artists_similar (ArtistID, SimilarID)
VALUES ('$Artist2ID', '$SimilarID')");
2011-03-28 14:21:28 +00:00
}
2013-02-22 08:00:24 +00:00
2013-07-12 08:00:46 +00:00
$DB->query("
SELECT SimilarID
FROM artists_similar_votes
WHERE SimilarID = '$SimilarID'
AND UserID = '$UserID'
AND Way = 'up'");
2013-07-10 00:08:53 +00:00
if (!$DB->has_results()) {
2013-07-12 08:00:46 +00:00
$DB->query("
INSERT INTO artists_similar_votes (SimilarID, UserID, way)
VALUES ('$SimilarID', '$UserID', 'up')");
2011-03-28 14:21:28 +00:00
}
2013-02-22 08:00:24 +00:00
2013-07-12 08:00:46 +00:00
$Cache->delete_value("artist_$Artist1ID"); // Delete artist cache
$Cache->delete_value("artist_$Artist2ID"); // Delete artist cache
$Cache->delete_value("similar_positions_$Artist1ID"); // Delete artist's similar map cache
$Cache->delete_value("similar_positions_$Artist2ID"); // Delete artist's similar map cache
2011-03-28 14:21:28 +00:00
}
header('Location: '.$_SERVER['HTTP_REFERER']);
?>