Skip to content

Commit

Permalink
fixed flags in cardbox, trade page and recieved / send offers list
Browse files Browse the repository at this point in the history
  • Loading branch information
nekocari committed Oct 12, 2024
1 parent 3aaae6a commit 3593325
Show file tree
Hide file tree
Showing 20 changed files with 290 additions and 194 deletions.
2 changes: 1 addition & 1 deletion app/controllers/cardmanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CardmanagerController extends AppController {
public function cardmanager() {

$this->redirectNotLoggedIn();
$cardmanager = new Cardmanager($this->login()->getUser(),'join'); // if join runs slow, try using exists
$cardmanager = new Cardmanager($this->login()->getUser(),'exists'); // if exits runs slow, try using join

// a card status was selected and is valid then set as status
if(isset($_GET['status']) AND array_key_exists($_GET['status'], Card::getAcceptedStati())){
Expand Down
258 changes: 165 additions & 93 deletions app/models/card_flagged.php

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions app/models/card_status.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ public static function getByName($name) {
return parent::getByUniqueKey($name);
}

/**
* retuns all Elements from Database
* @param array $order_settings [fieldname=>direction]
* @param int $limit optional limit settings
* @return CardStatus[]
*/
public static function getAll($order_settings=['position'=>'ASC'],$limit=null){
return parent::getAll($order_settings, $limit);
}

/**
* retuns the status ment for new cards
* @return CardStatus
Expand Down
104 changes: 50 additions & 54 deletions app/models/cardmanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Cardmanager {
private static $accepted_query_styles = array('join','exists');
private $cards, $member, $member_id, $status, $status_id, $db, $query_style, $collections, $collection_decks, $viewer;

public function __construct($member,$query_style = 'join') {
public function __construct($member,$query_style = 'exists') {
$this->member = $member;
$this->member_id = $member->getId();
$this->db = DB::getInstance();
Expand Down Expand Up @@ -109,116 +109,112 @@ public function getCards($trade_locked=false) {
throw new ErrorException('status is invalid');
return null;
}

// unused --
//$status_id_new = CardStatus::getNew()->getId();


// str with ids of stati not tradeable to use in sql in
$status_id_collect = CardStatus::getCollect()->getId();
$status_ids_not_tradeable_str = 'NULL,';
$status_not_tradeable = CardStatus::getNotTradeable();
foreach($status_not_tradeable as $status_nt){
$status_ids_not_tradeable_str.= $status_nt->getId().',';
}
$status_ids_not_tradeable_str = substr($status_ids_not_tradeable_str,0,-1);

// str with ids of stati are tradeable to use in sql in
$status_ids_tradeable_str = 'NULL,';
$status_tradeable = CardStatus::getTradeable();
foreach($status_tradeable as $status_t){
$status_ids_tradeable_str.= $status_t->getId().',';
}
$status_ids_tradeable_str = substr($status_ids_tradeable_str,0,-1);

// sql partial - differenciate between tradeable an non tradeable cards
$join_partial = '';
$where_partial = '';
$join_partial_trades = '';
$where_partial_trades = '';
if(!$trade_locked){
$join_partial = "LEFT JOIN trades t ON (t.offered_card = c.id OR t.requested_card = c.id) AND t.status = 'new'";
$where_partial = "AND t.id IS NULL";
$join_partial_trades = "LEFT JOIN trades t ON (t.offered_card = c.id OR t.requested_card = c.id) AND t.status = 'new'";
$where_partial_trades = "AND t.id IS NULL";
}

// check if array element does already exist
// if not try to get the values from the Database
if(!isset($this->cards[$this->status_id][$trade_locked])){
$this->cards[$this->status_id][$trade_locked] = array();
$card_stati_not_tradeable = CardStatus::getNotTradeable();
$card_stati = CardStatus::getAll();
switch($this->query_style){
case 'exists':
$sql_not_tradeables = '';
foreach($card_stati_not_tradeable as $nt_status){
$sql_not_tradeables.= "
EXISTS (SELECT 1 FROM cards WHERE owner = c.owner and status_id = " . $nt_status->getId() . " and deck = c.deck) as status" . $nt_status->getId() . "_flag, ";
foreach($card_stati as $nt_status){
if(!$nt_status->isNew()){
$sql_not_tradeables.= "
EXISTS (SELECT 1 FROM cards WHERE owner = c.owner AND status_id = " . $nt_status->getId() . " AND deck = c.deck AND number = c.number) as in_status" . $nt_status->getId() . "_flag,
EXISTS (SELECT 1 FROM cards WHERE owner = c.owner AND status_id = " . $nt_status->getId() . " AND deck = c.deck) as status" . $nt_status->getId() . "_flag, ";
}
}
$sql = "SELECT c.*,
EXISTS (SELECT 1 FROM cards WHERE owner = c.owner and status_id = $status_id_collect and deck = c.deck) as collect_flag,
$sql_not_tradeables
EXISTS (SELECT 1 FROM decks_master WHERE member = c.owner and deck = c.deck) as mastered_flag,
EXISTS (SELECT 1 FROM members_wishlist WHERE member_id = c.owner and deck_id = c.deck) as wishlist_flag,
EXISTS (SELECT 1 FROM cards WHERE owner = c.owner and status_id = $status_id_collect and deck = c.deck AND number = c.number) as in_collect_flag,
EXISTS (SELECT 1 FROM cards WHERE owner = c.owner and status_id IN($status_ids_not_tradeable_str) and deck = c.deck) as not_tradeable_flag,
EXISTS (SELECT 1 FROM cards WHERE owner = c.owner and status_id IN($status_ids_not_tradeable_str) and deck = c.deck AND number = c.number) as in_not_tradeable_flag
FROM cards c $join_partial
FROM cards c
$join_partial_trades
LEFT JOIN decks d ON d.id = c.deck
WHERE c.owner = ".$this->member_id." AND c.status_id = '$this->status_id' $where_partial
WHERE c.owner = ".$this->member_id." AND c.status_id = '$this->status_id' $where_partial_trades
GROUP BY c.id
ORDER BY d.deckname ASC, c.number ASC";
break;
default:
$sql_in_not_tradeables = '';
$sql_not_tradeables = '';
default: // works also, but is usually slower
$sql_status_joins = '';
$sql_status_flag_fields = '';
foreach($card_stati as $nt_status){
if(!$nt_status->isNew()){
$sql_status_flag_fields.= "status" . $nt_status->getId() . ".flag as status" . $nt_status->getId() . "_flag, ";
$sql_status_flag_fields.= "in_status" . $nt_status->getId() . ".flag as in_status" . $nt_status->getId() . "_flag, ";
$sql_not_tradeables.= "
$sql_status_flag_fields.= "status" . $nt_status->getId() . ".flag as status" . $nt_status->getId() . "_flag, ";
$sql_status_flag_fields.= "in_status" . $nt_status->getId() . ".flag as in_status" . $nt_status->getId() . "_flag, ";
$sql_status_joins.= "
LEFT JOIN (SELECT DISTINCT deck, 1 as flag FROM cards WHERE owner = ".$this->member_id." AND status_id = " . $nt_status->getId() . " )
status" . $nt_status->getId() . " ON status" . $nt_status->getId() . ".deck = c.deck";
$sql_in_not_tradeables.= "
status" . $nt_status->getId() . " ON status" . $nt_status->getId() . ".deck = c.deck
LEFT JOIN (SELECT DISTINCT deck, number, status_id, 1 as flag FROM cards WHERE owner = ".$this->member_id." AND status_id = " . $nt_status->getId() . " )
in_status" . $nt_status->getId() . " ON in_status" . $nt_status->getId() . ".deck = c.deck AND in_status" . $nt_status->getId() . ".number = c.number ";
}}
}
}
$sql = "SELECT c.*,
$sql_status_flag_fields
collect.flag as collect_flag, in_collect.flag as in_collect_flag,
not_tradeable.flag as not_tradeable_flag,
in_not_tradeable.flag as in_not_tradeable_flag,
wishlist.flag as wishlist_flag, mastered.flag as mastered_flag
FROM cards c $join_partial
wishlist.flag as wishlist_flag,
mastered.flag as mastered_flag
FROM cards c
$join_partial_trades
LEFT JOIN decks d ON d.id = c.deck
LEFT JOIN (SELECT DISTINCT deck, 1 as flag FROM cards WHERE owner = ".$this->member_id." AND status_id = $status_id_collect)
collect ON collect.deck = c.deck
LEFT JOIN (SELECT DISTINCT deck, 1 as flag FROM cards WHERE owner = ".$this->member_id." AND status_id IN($status_ids_not_tradeable_str) )
not_tradeable ON not_tradeable.deck = c.deck
$sql_not_tradeables
$sql_status_joins
LEFT JOIN (SELECT DISTINCT deck_id, 1 as flag FROM members_wishlist WHERE member_id = ".$this->member_id.")
wishlist ON wishlist.deck_id = c.deck
LEFT JOIN (SELECT DISTINCT deck, 1 as flag FROM decks_master WHERE member = ".$this->member_id.")
mastered ON mastered.deck = c.deck
LEFT JOIN (SELECT DISTINCT deck, number, status_id, 1 as flag FROM cards WHERE owner = ".$this->member_id." AND status_id = $status_id_collect)
in_collect ON in_collect.deck = c.deck AND in_collect.number = c.number
LEFT JOIN (SELECT DISTINCT deck, number, status_id, 1 as flag FROM cards WHERE owner = ".$this->member_id." AND status_id IN($status_ids_not_tradeable_str) )
mastered ON mastered.deck = c.deck
LEFT JOIN (SELECT DISTINCT deck, 1 as flag FROM cards WHERE owner = ".$this->member_id." AND status_id IN($status_ids_not_tradeable_str) )
not_tradeable ON not_tradeable.deck = c.deck
LEFT JOIN (SELECT DISTINCT deck, number, status_id, 1 as flag FROM cards WHERE owner = ".$this->member_id." AND status_id IN($status_ids_not_tradeable_str) )
in_not_tradeable ON in_not_tradeable.deck = c.deck AND in_not_tradeable.number = c.number
$sql_in_not_tradeables
WHERE c.owner = ".$this->member_id." AND c.status_id = '$this->status_id' $where_partial
WHERE c.owner = ".$this->member_id." AND c.status_id = '$this->status_id' $where_partial_trades
GROUP BY c.id
ORDER BY d.deckname ASC, c.number ASC";
break;
}

//echo "<pre>$sql</pre>";
$req = $this->db->query($sql);
//echo $sql."<hr>";
foreach($req->fetchALL(PDO::FETCH_ASSOC) as $card_values){
$card = new CardFlagged();
$card->setPropValues($card_values);
//flags
foreach($card_stati as $nt_status){
// do not flag for status new
if(!$nt_status->isNew()){
if(isset($card_values['status'.$nt_status->getId().'_flag']) AND $card_values['status'.$nt_status->getId().'_flag'] == 1){
$card->setCustomFlagIds($nt_status->getId());
if(isset($card_values['status'.$nt_status->getId().'_flag']) AND $card_values['status'.$nt_status->getId().'_flag'] == 1){
// in case current status is for collections
if($nt_status->isCollections()){
$card->setPropValues(['collect_flag'=>1]);
}else{
$card->setCustomFlagIds($nt_status->getId());
}
}
if(isset($card_values['in_status'.$nt_status->getId().'_flag']) AND $card_values['in_status'.$nt_status->getId().'_flag'] == 1){
$card->setCustomInFlagIds($nt_status->getId());
// in case current status is for collections
if($nt_status->isCollections()){
$card->setPropValues(['in_collect_flag'=>1]);
}else{
$card->setCustomInFlagIds($nt_status->getId());
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/models/member.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function getTradeableCards($flag_for_member_id = NULL){
$group = 'general';
if($card->mastered()){ $group = 'mastered'; }
if($card->onWishlist() AND !$card->owned()){ $group = 'wishlist'; }
if($card->missingInKeep() AND !$card->owned()){ $group = 'keep'; }
if($card->missingInNotTradeable() AND !$card->owned()){ $group = 'keep'; }
if($card->missingInCollect() AND !$card->owned()){ $group = 'collect'; }
$this->tradeable_cards[$group][] = $card;
}
Expand Down
6 changes: 2 additions & 4 deletions app/models/trade.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ public function getOfferer() {
}
public function getOfferedCard() {
if(!$this->offered_card_obj instanceof CardFlagged){
$card = new CardFlagged();
$card->setPropValues(['id'=>$this->offered_card]);
$card = CardFlagged::getById($this->offered_card);
$this->offered_card_obj = $card->flag($this->recipient_id);
}
return $this->offered_card_obj;
Expand All @@ -270,8 +269,7 @@ public function getRecipient() {
}
public function getRequestedCard() {
if(!$this->requested_card_obj instanceof CardFlagged){
$card = new CardFlagged();
$card->setPropValues(['id'=>$this->requested_card]);
$card = CardFlagged::getById($this->requested_card);
$this->requested_card_obj = $card->flag($this->offerer_id);
}
return $this->requested_card_obj;
Expand Down
43 changes: 22 additions & 21 deletions app/views/de/login/cardmanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,34 @@
<?php echo $pagination; ?>

<div>
<?php foreach($cards as $card){

//var_dump($card);
?>
<div class="d-inline-block text-center m-1 card-cardmanager ">

<?php /*
$title_text = '';
if($card->onWishlist() AND !$card->deckInCollect() AND $card->missingInNotTradeable()){
// Auf Wunschliste und Deck noch nicht in Collect oder einer nicht tauschbaren Kategorie
$title_text = "Noch nicht in deiner Sammlung oder einer untauschbaren Kategorie";
echo " card-missing-wishlist";
}
if($card->missingInCollect()){
// wenn nicht in collect CSS Klasse einfügen
<?php foreach($cards as $card){ // loop through cards ?>
<div class="d-inline-block text-center m-1 card-cardmanager
<?php // ADD CSS CLASSES TO STYLE ELEMENT
// var for additional alt text
$title_text = '';
// deck is mastered
if($card->mastered()){
echo " card-mastered"; }
// card missing in collection
if($card->missingInCollect()){
echo " card-missing-collect"; }
if($card->mastered()){
echo " card-mastered"; }
foreach(CardStatus::getNotTradeable( ['position'=>'DESC']) as $nt_status){
if($card->missingIn($nt_status->getId())){
// deck on wishlist not missing in an untradeable category and is not part of collection
if($card->onWishlist() AND !$card->deckInCollect() AND !$card->deckInNotTradeable() ){
echo " card-missing-wishlist"; }
// card missing in an untrdeable category that is NOT collect
if($card->missingInNotTradeable() AND !$card->missingInCollect()){
echo " card-missing-keep"; }
// add class for untradeable category with highes position value,
// where card is missing in format "card-missing-status-[category ID]"
foreach(CardStatus::getNotTradeable( ['position'=>'DESC']) as $nt_status){
if($card->missingIn($nt_status->getId()) AND !$card->missingInCollect()){
$title_text = "Noch nicht in ".$nt_status->getName();
echo " card-missing-status-".$nt_status->getId();
echo " card-missing-keep";
break;
}
}
*/ ?>
?>
">

<div title="<?php echo $title_text; ?>">
<?php echo $card->getImageHtml(); ?>
Expand Down
2 changes: 1 addition & 1 deletion app/views/de/login/collectmanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<p class="text-center">
<?php foreach(Card::getAcceptedStatiObj() as $status){ ?>
<a class="btn btn-outline-secondary" href="<?php echo Routes::getUri('member_cardmanager')."?status=".$status->getId(); ?>"><?php echo strtoupper($status->getName()); ?></a>
<a class="btn btn-outline-dark" href="<?php echo Routes::getUri('member_cardmanager')."?status=".$status->getId(); ?>"><?php echo strtoupper($status->getName()); ?></a>
<?php } ?>
</p>

Expand Down
2 changes: 1 addition & 1 deletion app/views/de/member/profil/tradeable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</div>
<?php foreach($cat_elements as $card){ ?>
<div class="d-inline-block card-member-profil <?php
if($card->missingInKeep() AND !$card->owned()){ echo " card-missing-keep"; }
if($card->missingInNotTradeable() AND !$card->owned()){ echo " card-missing-keep"; }
if($card->missingInCollect() AND !$card->owned()){ echo " card-missing-collect"; }
if($card->onWishlist() AND !$card->owned()){ echo " card-missing-wishlist"; }
if($card->mastered()){ echo " card-mastered"; }
Expand Down
2 changes: 1 addition & 1 deletion app/views/de/templates/card_color_legend.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<small>
<span class="d-inline-block card-member-profil card-missing-keep">fehlend in nicht tauschbar</span>
<span class="d-inline-block card-member-profil card-missing-collect">fehlend in Sammlung</span>
<span class="d-inline-block card-member-profil card-missing-wishlist">fehlend für Wunschliste</span>
<span class="d-inline-block card-member-profil card-missing-wishlist">Deck auf Wunschliste</span>
<span class="d-inline-block card-member-profil card-mastered">Deck gemastert</span>
</small>
</div>
2 changes: 1 addition & 1 deletion app/views/de/trade/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<?php } foreach($g_cards as $card){ ?>
<option value="<?php echo $card->getId(); ?>" data-url="<?php echo $card->getImageUrl(); ?>">
<?php if($card->missingInCollect() AND !$card->owned()){ echo '&star; '; } ?>
<?php if($card->missingInKeep() AND !$card->owned()){ echo '&#11048; '; } ?>
<?php if($card->missingInNotTradeable() AND !$card->owned()){ echo '&#11048; '; } ?>
<?php if($card->onWishlist() AND !$card->owned()){ echo '&#9825; '; } ?>
<?php if($card->mastered()){ echo '&#10680; '; } ?>
<?php echo $card->getName(); if($card->getPossessionCounter() > 1){ echo ' ('.$card->getPossessionCounter().')'; } ?>
Expand Down
2 changes: 1 addition & 1 deletion app/views/de/trade/recieved.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<i class="fas fa-sync-alt h1"></i>
<div class="text-center d-inline-block">
<div class="d-inline-block card-member-profil <?php
if($trade->getOfferedCard()->missingInKeep() AND !$trade->getOfferedCard()->owned()){ echo " card-missing-keep"; }
if($trade->getOfferedCard()->missingInNotTradeable() AND !$trade->getOfferedCard()->owned()){ echo " card-missing-keep"; }
if($trade->getOfferedCard()->missingInCollect() AND !$trade->getOfferedCard()->owned()){ echo " card-missing-collect"; }
if($trade->getOfferedCard()->onWishlist()AND !$trade->getOfferedCard()->owned()){ echo " card-missing-wishlist"; }
if($trade->getOfferedCard()->mastered()){ echo " card-mastered"; } ?>">
Expand Down
Loading

0 comments on commit 3593325

Please sign in to comment.