Gazelle/sections/artist/add_similar.php

52 lines
1.9 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.');
}
$DB->query("SELECT ag.ArtistID FROM artists_group AS ag WHERE ag.Name LIKE '$Artist2Name'");
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-02-22 08:00:24 +00:00
$DB->query("SELECT
s1.SimilarID
2011-03-28 14:21:28 +00:00
FROM artists_similar AS s1
JOIN artists_similar AS s2 ON s1.SimilarID=s2.SimilarID
WHERE s1.ArtistID='$Artist1ID' AND s2.ArtistID='$Artist2ID'");
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
2011-03-28 14:21:28 +00:00
$DB->query("UPDATE artists_similar_scores SET Score=Score+200 WHERE SimilarID='$SimilarID'");
} else { // No, it doesn't exist - create it
$DB->query("INSERT INTO artists_similar_scores (Score) VALUES ('200')");
$SimilarID = $DB->inserted_id();
$DB->query("INSERT INTO artists_similar (ArtistID, SimilarID) VALUES ('$Artist1ID', '$SimilarID')");
$DB->query("INSERT INTO artists_similar (ArtistID, SimilarID) VALUES ('$Artist2ID', '$SimilarID')");
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
$DB->query("SELECT SimilarID FROM artists_similar_votes WHERE SimilarID='$SimilarID' AND UserID='$UserID' AND Way='up'");
2013-05-04 08:00:48 +00:00
if ($DB->record_count() == 0) {
2011-03-28 14:21:28 +00:00
$DB->query("INSERT INTO artists_similar_votes (SimilarID, UserID, way) VALUES ('$SimilarID', '$UserID', 'up')");
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
$Cache->delete('artist_'.$Artist1ID); // Delete artist cache
$Cache->delete('artist_'.$Artist2ID); // Delete artist cache
$Cache->delete('similar_positions_'.$Artist1ID); // Delete artist's similar map cache
$Cache->delete('similar_positions_'.$Artist2ID); // Delete artist's similar map cache
}
header('Location: '.$_SERVER['HTTP_REFERER']);
?>