Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 101
0.00% covered (danger)
0.00%
0 / 23
CRAP
0.00% covered (danger)
0.00%
0 / 1
EventProgress
0.00% covered (danger)
0.00%
0 / 101
0.00% covered (danger)
0.00%
0 / 23
702
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 create
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 getByEventId
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
12
 update
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
2
 updatePhase
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 incrementBinsPulled
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 incrementBinsOnFloor
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 incrementBinsStored
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 getOrCreate
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
6
 toArray
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
2
 getId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setId
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getEventId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setEventId
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getPhase
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setPhase
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getBinsPulled
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setBinsPulled
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getBinsOnFloor
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setBinsOnFloor
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getBinsStored
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setBinsStored
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getLastUpdated
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace BuyerKiosk\Backstock;
4
5class EventProgress extends Backstock
6{
7    public $id;
8    public $eventId;
9    public $phase;
10    public $binsPulled;
11    public $binsOnFloor;
12    public $binsStored;
13    public $lastUpdated;
14
15    public function __construct(\Store $store)
16    {
17        parent::__construct($store);
18    }
19
20    /**
21     * Create a new progress record
22     * @return $this
23     */
24    public function create()
25    {
26        $stmt = $this->storeDB->prepare("
27            INSERT INTO bsEvent_Progress (
28                eventId, phase, binsPulled, binsOnFloor, binsStored, lastUpdated
29            ) VALUES (
30                :eventId, :phase, :binsPulled, :binsOnFloor, :binsStored, NOW()
31            )
32        ");
33
34        $stmt->bindValue(":eventId", $this->eventId, \PDO::PARAM_INT);
35        $stmt->bindValue(":phase", $this->phase ?? 'upcoming');
36        $stmt->bindValue(":binsPulled", $this->binsPulled ?? 0, \PDO::PARAM_INT);
37        $stmt->bindValue(":binsOnFloor", $this->binsOnFloor ?? 0, \PDO::PARAM_INT);
38        $stmt->bindValue(":binsStored", $this->binsStored ?? 0, \PDO::PARAM_INT);
39
40        $stmt->execute();
41        $this->id = $this->storeDB->lastInsertId();
42        return $this;
43    }
44
45    /**
46     * Load progress by event ID
47     * @param int $eventId
48     * @return $this|null
49     */
50    public function getByEventId($eventId)
51    {
52        $stmt = $this->storeDB->prepare("
53            SELECT id, phase, binsPulled, binsOnFloor, binsStored, lastUpdated
54            FROM bsEvent_Progress
55            WHERE eventId = :eventId
56        ");
57        $stmt->bindValue(":eventId", $eventId, \PDO::PARAM_INT);
58
59        if ($stmt->execute()) {
60            $row = $stmt->fetch(\PDO::FETCH_ASSOC);
61            if ($row) {
62                $this->id = $row['id'];
63                $this->eventId = $eventId;
64                $this->phase = $row['phase'];
65                $this->binsPulled = $row['binsPulled'];
66                $this->binsOnFloor = $row['binsOnFloor'];
67                $this->binsStored = $row['binsStored'];
68                $this->lastUpdated = $row['lastUpdated'];
69                return $this;
70            }
71        }
72        return null;
73    }
74
75    /**
76     * Update existing progress record
77     * @return $this
78     */
79    public function update()
80    {
81        $stmt = $this->storeDB->prepare("
82            UPDATE bsEvent_Progress SET
83                phase = :phase,
84                binsPulled = :binsPulled,
85                binsOnFloor = :binsOnFloor,
86                binsStored = :binsStored,
87                lastUpdated = NOW()
88            WHERE id = :id
89        ");
90
91        $stmt->bindValue(":phase", $this->phase);
92        $stmt->bindValue(":binsPulled", $this->binsPulled, \PDO::PARAM_INT);
93        $stmt->bindValue(":binsOnFloor", $this->binsOnFloor, \PDO::PARAM_INT);
94        $stmt->bindValue(":binsStored", $this->binsStored, \PDO::PARAM_INT);
95        $stmt->bindValue(":id", $this->id, \PDO::PARAM_INT);
96
97        $stmt->execute();
98        return $this;
99    }
100
101    /**
102     * Update just the phase
103     * @param string $phase
104     * @return $this
105     */
106    public function updatePhase($phase)
107    {
108        $stmt = $this->storeDB->prepare("
109            UPDATE bsEvent_Progress SET
110                phase = :phase,
111                lastUpdated = NOW()
112            WHERE id = :id
113        ");
114
115        $stmt->bindValue(":phase", $phase);
116        $stmt->bindValue(":id", $this->id, \PDO::PARAM_INT);
117        $stmt->execute();
118
119        $this->phase = $phase;
120        return $this;
121    }
122
123    /**
124     * Increment bins pulled counter
125     * @param int $count
126     * @return $this
127     */
128    public function incrementBinsPulled($count = 1)
129    {
130        $stmt = $this->storeDB->prepare("
131            UPDATE bsEvent_Progress SET
132                binsPulled = binsPulled + :count,
133                lastUpdated = NOW()
134            WHERE id = :id
135        ");
136
137        $stmt->bindValue(":count", $count, \PDO::PARAM_INT);
138        $stmt->bindValue(":id", $this->id, \PDO::PARAM_INT);
139        $stmt->execute();
140
141        $this->binsPulled += $count;
142        return $this;
143    }
144
145    /**
146     * Increment bins on floor counter
147     * @param int $count
148     * @return $this
149     */
150    public function incrementBinsOnFloor($count = 1)
151    {
152        $stmt = $this->storeDB->prepare("
153            UPDATE bsEvent_Progress SET
154                binsOnFloor = binsOnFloor + :count,
155                lastUpdated = NOW()
156            WHERE id = :id
157        ");
158
159        $stmt->bindValue(":count", $count, \PDO::PARAM_INT);
160        $stmt->bindValue(":id", $this->id, \PDO::PARAM_INT);
161        $stmt->execute();
162
163        $this->binsOnFloor += $count;
164        return $this;
165    }
166
167    /**
168     * Increment bins stored counter
169     * @param int $count
170     * @return $this
171     */
172    public function incrementBinsStored($count = 1)
173    {
174        $stmt = $this->storeDB->prepare("
175            UPDATE bsEvent_Progress SET
176                binsStored = binsStored + :count,
177                lastUpdated = NOW()
178            WHERE id = :id
179        ");
180
181        $stmt->bindValue(":count", $count, \PDO::PARAM_INT);
182        $stmt->bindValue(":id", $this->id, \PDO::PARAM_INT);
183        $stmt->execute();
184
185        $this->binsStored += $count;
186        return $this;
187    }
188
189    /**
190     * Get existing progress or create new record
191     * @param int $eventId
192     * @return $this
193     */
194    public function getOrCreate($eventId)
195    {
196        $existing = $this->getByEventId($eventId);
197        if ($existing) {
198            return $existing;
199        }
200
201        // Create new progress record
202        $this->eventId = $eventId;
203        $this->phase = 'upcoming';
204        $this->binsPulled = 0;
205        $this->binsOnFloor = 0;
206        $this->binsStored = 0;
207        $this->create();
208
209        return $this;
210    }
211
212    /**
213     * Convert to array for JSON serialization
214     * @return array
215     */
216    public function toArray()
217    {
218        return [
219            'id' => $this->id,
220            'eventId' => $this->eventId,
221            'phase' => $this->phase,
222            'binsPulled' => $this->binsPulled,
223            'binsOnFloor' => $this->binsOnFloor,
224            'binsStored' => $this->binsStored,
225            'lastUpdated' => $this->lastUpdated
226        ];
227    }
228
229    /**
230     * @return int
231     */
232    public function getId()
233    {
234        return $this->id;
235    }
236
237    /**
238     * @param int $id
239     * @return $this
240     */
241    public function setId($id)
242    {
243        $this->id = $id;
244        return $this;
245    }
246
247    /**
248     * @return int
249     */
250    public function getEventId()
251    {
252        return $this->eventId;
253    }
254
255    /**
256     * @param int $eventId
257     * @return $this
258     */
259    public function setEventId($eventId)
260    {
261        $this->eventId = $eventId;
262        return $this;
263    }
264
265    /**
266     * @return string
267     */
268    public function getPhase()
269    {
270        return $this->phase;
271    }
272
273    /**
274     * @param string $phase
275     * @return $this
276     */
277    public function setPhase($phase)
278    {
279        $this->phase = $phase;
280        return $this;
281    }
282
283    /**
284     * @return int
285     */
286    public function getBinsPulled()
287    {
288        return $this->binsPulled;
289    }
290
291    /**
292     * @param int $binsPulled
293     * @return $this
294     */
295    public function setBinsPulled($binsPulled)
296    {
297        $this->binsPulled = $binsPulled;
298        return $this;
299    }
300
301    /**
302     * @return int
303     */
304    public function getBinsOnFloor()
305    {
306        return $this->binsOnFloor;
307    }
308
309    /**
310     * @param int $binsOnFloor
311     * @return $this
312     */
313    public function setBinsOnFloor($binsOnFloor)
314    {
315        $this->binsOnFloor = $binsOnFloor;
316        return $this;
317    }
318
319    /**
320     * @return int
321     */
322    public function getBinsStored()
323    {
324        return $this->binsStored;
325    }
326
327    /**
328     * @param int $binsStored
329     * @return $this
330     */
331    public function setBinsStored($binsStored)
332    {
333        $this->binsStored = $binsStored;
334        return $this;
335    }
336
337    /**
338     * @return string
339     */
340    public function getLastUpdated()
341    {
342        return $this->lastUpdated;
343    }
344}