ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
10class Deck implements D\Deck
11{
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
134 {
135 switch ($this->getCardsSize()) {
136 case self::SIZE_XS:
137 return 2;
138 case self::SIZE_S:
139 return 4;
140 case self::SIZE_M:
141 return 6;
142 case self::SIZE_L:
143 // no-break
144 case self::SIZE_XL:
145 // no-break
146 case self::SIZE_FULL:
147 return 12;
148 }
149 }
150
151 private static $sizes = array(self::SIZE_FULL
152 , self::SIZE_XL
153 , self::SIZE_L
154 , self::SIZE_M
155 , self::SIZE_S
156 , self::SIZE_XS
157 );
158}
An exception for terminatinating execution or to throw for unit testing.
__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.
trait ComponentHelper
Provides common functionality for component implementations.
checkArgIsElement($which, $value, $array, $name)
Throw an InvalidArgumentException if $value is not an element of array.