Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 46
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
LoopItem
0.00% covered (danger)
0.00%
0 / 46
0.00% covered (danger)
0.00%
0 / 5
182
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 checkVars
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
30
 addLoopItem
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
12
 getLoopItem
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
6
 deleteLoopItem
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace BuyerKiosk\DigitalSign;
4
5class LoopItem {
6
7    private $store;
8    private $storeDB;
9    private $log;
10    public $id;
11    public $startDate;
12    public $expireDate;
13    public $slideID;
14    public $position;
15    public $duration;
16    public $animation;
17    public $slideUploader;
18    public $scheduled;
19
20
21    public function __construct($store)
22    {
23        $this->store = $store;
24        $this->storeDB = dbConnectByName($this->store->getDbName());
25        $this->log = new \KLogger($_ENV['LOG_DIR']."digital_sign.log", \KLogger::DEBUG);
26        $this->animation = "fadeIn";
27    }
28    private function checkVars() {
29        if(!isset($this->slideID) || !isset($this->position) || !isset($this->duration) || !isset($this->slideUploader)) {
30            return false;
31        } else {
32            return true;
33        }
34    }
35
36    public function addLoopItem()
37    {
38        if(!$this->checkVars()) {
39            error_log("Error adding slide to loop: Missing variables");
40            return false;
41        }
42        $insert = $this->storeDB->prepare("INSERT INTO dsLoop (startDate, expireDate, slideID, position, duration, animation, slideUploader, scheduled) VALUES (:startDate, :expireDate, :slideID, :position, :duration, :animation, :slideUploader, :scheduled)");
43        $insert->bindParam(":startDate", $this->startDate);
44        $insert->bindParam(":expireDate", $this->expireDate);
45        $insert->bindParam(":slideID", $this->slideID);
46        $insert->bindParam(":position", $this->position);
47        $insert->bindParam(":duration", $this->duration);
48        $insert->bindParam(":animation", $this->animation);
49        $insert->bindParam(":slideUploader", $this->slideUploader);
50        $insert->bindParam(":scheduled", $this->scheduled);
51        if($insert->execute() === false) {
52            error_log("Error adding slide to loop: " . print_r($insert->errorInfo(), true));
53            return false;
54        } else {
55            $this->id = $this->storeDB->lastInsertId();
56            return true;
57        }
58    }
59
60    public function getLoopItem($id) {
61        $select = $this->storeDB->prepare("SELECT * FROM dsLoop WHERE id = :id");
62        $select->bindParam(":id", $id);
63        if($select->execute() === false) {
64            error_log("Error getting loop item: " . print_r($select->errorInfo(), true));
65            return false;
66        } else {
67            $result = $select->fetch();
68            $this->id = $result['id'];
69            $this->startDate = $result['startDate'];
70            $this->expireDate = $result['expireDate'];
71            $this->slideID = $result['slideID'];
72            $this->position = $result['position'];
73            $this->duration = $result['duration'];
74            $this->animation = $result['animation'];
75            $this->slideUploader = $result['slideUploader'];
76            $this->scheduled = $result['scheduled'];
77            return true;
78        }
79    }
80    public function deleteLoopItem($id) {
81        $delete = $this->storeDB->prepare("DELETE FROM dsLoop WHERE id = :id");
82        $delete->bindParam(":id", $id);
83        if($delete->execute() === false) {
84            error_log("Error deleting loop item: " . print_r($delete->errorInfo(), true));
85            return false;
86        } else {
87            return true;
88        }
89    }
90
91}