Page 1 of 1

Move all card from different location back to deck

Posted: 16 September 2020, 00:13
by Ilmion
I have multiple locations for cards in my deck and I would like to move all the card from all the location back to the deck.
I'm lucky that all those cards are of the same type, so this seem to be working well

Code: Select all

$distributedCards = array_map(function($card){ return $card['id']; }, $this->maptiles_deck->getCardsOfType( 'mapTiles' ));
$this->maptiles_deck->moveCards($distributedCards , 'maptiles_deck');
But for getCardsOfType, it it written in the wiki as "rarely use". Is there a better way ? Would there be a way if all the card where of a different type ?

Re: Move all card from different location back to deck

Posted: 16 September 2020, 04:24
by Mosty Mostacho
You can use

Code: Select all

getCardsInLocation($location, $location_arg = null, $order_by = null)
documented here: http://en.doc.boardgamearena.com/index. ... formations

Of course, use the array of locations you need to get them from.

Having said that, why not just?

Code: Select all

self::DbQuery("UPDATE `deck` SET `card_location` = 'deck'");
That is more efficient. Considering the slowness of the Studio server, efficiency should not be negligible. If you care too much about readability, just create a new class (possible extending Deck) and create the corresponding method.

Re: Move all card from different location back to deck

Posted: 16 September 2020, 12:45
by Ilmion
You get my idea about readability but also it is much cleaner (IMHO) if we always use the deck object to manipulate the deck. That is why I was hesitant to directly query the database, but I really like the idea of extending the deck object.

Re: Move all card from different location back to deck

Posted: 16 September 2020, 13:57
by Ilmion
I've found it !!
In the wiki in the hearts "example" :

Code: Select all

// This is a new hand: let's gather all cards from everywhere in the deck:
$this->cards->moveAllCardsInLocation( null, "deck" );
I'll try and update the definition of moveAllCardsInLocation.