View Single Post
  #3  
Old 25th May 2019, 08:32
darkalchemy darkalchemy is offline
Administrator
 
Join Date: Dec 2017
United States
Posts: 101
Default
I don't check whether the torrent is being seeded, but whether the torrent has been snatched. You can change this easily enough to peers if desired. In my opinion what the user wants to know is if they have snatched that particular torrent before, sometimes its difficult to remember.

I can't give you an exact change to your query, since you haven't posted it. But, what I do in my code is add a left join to the snatched column and then a select from that like this
Code:
LEFT JOIN snatched AS s on s.torrentid = t.id AND s.userid = $CURUSER['id']
and the select
Code:
IF(s.to_go IS NOT NULL, (t.size - s.to_go) / t.size, -1) AS to_go
Please escape the $CURUSER['id'] however your code does it.
Now you have the coloumn to_go available.
When you loop through the query to display the data, if to_go == -1 then the user has not snatched the torrent. If to_go = 100 then the have completed the torrent and if its anything else, then they have snatched it but not completed it. Then you simply adjust the color of the seeders to match what you want to show.

In my code, I have a column specifically for completed/snatched but I also use FluentPDO in that query and its a searchable column This is that portion of my query.
Code:
if (isset($_GET['unsnatched']) && $_GET['unsnatched'] == 1) {
    $count = $count->where('s.to_go IS NULL')
                   ->leftJoin('snatched AS s on s.torrentid = t.id AND s.userid = ?', $CURUSER['id']);
    $select = $select->select('IF(s.to_go IS NOT NULL, (t.size - s.to_go) / t.size, -1) AS to_go')
                     ->leftJoin('snatched AS s on s.torrentid = t.id AND s.userid = ?', $CURUSER['id'])
                     ->having('to_go = -1');
    $addparam .= 'unsnatched=1&';
} else {
    $select = $select->select('IF(s.to_go IS NOT NULL, (t.size - s.to_go) / t.size, -1) AS to_go')
                     ->leftJoin('snatched AS s on s.torrentid = t.id AND s.userid = ?', $CURUSER['id']);
}
I hope that can get something useful from this.
Reply With Quote
The Following User Says Thank You to darkalchemy For This Useful Post:
papad (26th May 2019)