keep magnet star history by add value field, update for distribution and reaction features

This commit is contained in:
ghost 2023-09-12 01:52:12 +03:00
parent 18f0c5d14e
commit 32884e1733
5 changed files with 16 additions and 49 deletions

View file

@ -1344,28 +1344,17 @@ class Database {
}
// Magnet star
public function addMagnetStar(int $magnetId, int $userId, int $timeAdded) : int {
public function addMagnetStar(int $magnetId, int $userId, bool $value, int $timeAdded) : int {
$this->_debug->query->insert->total++;
$query = $this->_db->prepare('INSERT INTO `magnetStar` SET `magnetId` = ?, `userId` = ?, `timeAdded` = ?');
$query = $this->_db->prepare('INSERT INTO `magnetStar` SET `magnetId` = ?, `userId` = ?, `value` = ?, `timeAdded` = ?');
$query->execute([$magnetId, $userId, $timeAdded]);
$query->execute([$magnetId, $userId, (int) $value, $timeAdded]);
return $this->_db->lastInsertId();
}
public function deleteMagnetStarByUserId(int $magnetId, int $userId) : int {
$this->_debug->query->delete->total++;
$query = $this->_db->prepare('DELETE FROM `magnetStar` WHERE `magnetId` = ? AND `userId` = ?');
$query->execute([$magnetId, $userId]);
return $query->rowCount();
}
public function findMagnetStarsTotalByMagnetId(int $magnetId) : int {
$this->_debug->query->select->total++;
@ -1388,26 +1377,15 @@ class Database {
return $query->fetch()->result;
}
public function findMagnetStarsTotal(int $magnetId, int $userId) : int {
public function findLastMagnetStarValue(int $magnetId, int $userId) : bool {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT COUNT(*) AS `result` FROM `magnetStar` WHERE `magnetId` = ? AND `userId` = ?');
$query = $this->_db->prepare('SELECT * FROM `magnetStar` WHERE `magnetId` = ? AND `userId` = ? ORDER BY `magnetStarId` DESC');
$query->execute([$magnetId, $userId]);
return $query->fetch()->result;
}
public function findMagnetStarByUserId(int $magnetId, int $userId) : int {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT * FROM `magnetStar` WHERE `magnetId` = ? AND `userId` = ?');
$query->execute([$magnetId, $userId]);
return $query->fetch();
return $query->rowCount() ? (bool) $query->fetch()->value : false;
}
// Magnet download