ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
Deck.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2016 Amstutz Timon <timon.amstutz@ilub.unibe.ch> Extended GPL, see docs/LICENSE */
4 
6 
9 
10 class Deck implements D\Deck
11 {
12  use ComponentHelper;
13 
17  protected $cards;
18 
22  protected $size;
28  public function __construct($cards, $size)
29  {
30  $classes = [\ILIAS\UI\Component\Card\Card::class];
31  $this->checkArgListElements("cards", $cards, $classes);
32  $this->checkArgIsElement("size", $size, self::$sizes, "size type");
33 
34  $this->cards = $cards;
35  $this->size = $size;
36  }
37 
41  public function withCards($cards)
42  {
43  $classes = [\ILIAS\UI\Component\Card\Card::class];
44  $this->checkArgListElements("sections", $cards, $classes);
45 
46  $clone = clone $this;
47  $clone->cards = $cards;
48  return $clone;
49  }
50 
54  public function getCards()
55  {
56  return $this->cards;
57  }
58 
62  public function withExtraSmallCardsSize()
63  {
64  return $this->withCardsSize(self::SIZE_XS);
65  }
66 
70  public function withSmallCardsSize()
71  {
72  return $this->withCardsSize(self::SIZE_S);
73  }
77  public function withNormalCardsSize()
78  {
79  return $this->withCardsSize(self::SIZE_M);
80  }
81 
85  public function withLargeCardsSize()
86  {
87  return $this->withCardsSize(self::SIZE_L);
88  }
89 
93  public function withExtraLargeCardsSize()
94  {
95  return $this->withCardsSize(self::SIZE_XL);
96  }
97 
101  public function withFullSizedCardsSize()
102  {
103  return $this->withCardsSize(self::SIZE_FULL);
104  }
105 
106  /***
107  * @param $size
108  * @return Deck
109  */
110  protected function withCardsSize($size)
111  {
112  $this->checkArgIsElement("size", $size, self::$sizes, "size type");
113 
114  $clone = clone $this;
115  $clone->size = $size;
116  return $clone;
117  }
118 
122  public function getCardsSize()
123  {
124  return $this->size;
125  }
126 
133  public function getCardsSizeSmallDisplays()
134  {
135  return $this->getCardsSizeForDisplaySize(self::SIZE_S);
136  }
137 
144  public function getCardsSizeForDisplaySize($display_size)
145  {
159  $sizes = [
160  self::SIZE_XS => [
161  self::SIZE_XS => 4,
162  self::SIZE_S => 2,
163  self::SIZE_M => 2,
164  self::SIZE_L => 1
165  ],
166  self::SIZE_S => [
167  self::SIZE_XS => 6,
168  self::SIZE_S => 3,
169  self::SIZE_M => 3,
170  self::SIZE_L => 2
171  ],
172  self::SIZE_M => [
173  self::SIZE_XS => 12,
174  self::SIZE_S => 6,
175  self::SIZE_M => 4,
176  self::SIZE_L => 3
177  ],
178  self::SIZE_L => [
179  self::SIZE_XS => 12,
180  self::SIZE_S => 6,
181  self::SIZE_M => 6,
182  self::SIZE_L => 4
183  ],
184  self::SIZE_XL => [
185  self::SIZE_XS => 12,
186  self::SIZE_S => 12,
187  self::SIZE_M => 6,
188  self::SIZE_L => 6
189  ],
190  self::SIZE_FULL => [
191  self::SIZE_XS => 12,
192  self::SIZE_S => 12,
193  self::SIZE_M => 12,
194  self::SIZE_L => 12
195  ],
196  ];
197 
198  return $sizes[$this->getCardsSize()][$display_size];
199  }
200 
201  private static $sizes = array(self::SIZE_FULL
202  , self::SIZE_XL
203  , self::SIZE_L
204  , self::SIZE_M
205  , self::SIZE_S
206  , self::SIZE_XS
207  );
208 }
checkArgIsElement($which, $value, $array, $name)
Throw an InvalidArgumentException if $value is not an element of array.
trait ComponentHelper
Provides common functionality for component implementations.
__construct($cards, $size)
Deck constructor.
Definition: Deck.php:28
checkArgListElements($which, array &$values, $classes)
Check every element of the list if it is an instance of one of the given classes. ...