Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 64
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
Slide
0.00% covered (danger)
0.00%
0 / 64
0.00% covered (danger)
0.00%
0 / 6
182
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
2
 checkRequiredFields
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
20
 save
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 insert
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
6
 update
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
2
 getByID
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace BuyerKiosk\DigitalSign;
4class Slide
5{
6
7    public $id;
8    public $slideName;
9    public $fileName;
10    public $enabled;
11    public $type;
12    public $embed;
13    public $slideID;
14    public $videoDuration;
15    private $store;
16    public $animation;
17    public $thumbName;
18    public $duration;
19    public $position;
20    public $slideUploader;
21    public $enableWaitTime;
22    public $scheduled;
23    public $startDate;
24    public $expireDate;
25
26
27
28    public function __construct(\Store $store)
29    {
30        $this->id = null;
31        $this->slideName = null;
32        $this->fileName = null;
33        $this->enabled = null;
34        $this->type = null;
35        $this->animation = null;
36        $this->embed = null;
37        $this->videoDuration = null;
38        $this->store = $store;
39    }
40    public function checkRequiredFields() {
41        if(!isset($this->slideName) || !isset($this->fileName) || !isset($this->type)) {
42            error_log("Slide Name: " . $this->slideName);
43            error_log("File Name: " . $this->fileName);
44            error_log("Type: " . $this->type);
45            return false;
46        } else {
47            return true;
48        }
49    }
50
51    public function save() {
52        if(!$this->checkRequiredFields()) {
53            return false;
54        }
55        if($this->id == null) {
56            return $this->insert();
57        } else {
58            return $this->update();
59        }
60    }
61    public function insert() {
62        try{
63            $db = dbConnectByName($this->store->getDbName());
64            $db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
65            $db->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
66            $query = $db->prepare("INSERT INTO dsSlides (slideName, fileName, enabled, type, embed, videoDuration) VALUES (:slideName, :fileName, :enabled, :type, :embed, :videoDuration)");
67            $query->bindParam(":slideName", $this->slideName);
68            $query->bindParam(":fileName", $this->fileName);
69            $query->bindValue(":enabled", 1);
70            $query->bindParam(":type", $this->type);
71            $query->bindParam(":embed", $this->embed);
72            $query->bindParam(":videoDuration", $this->videoDuration);
73            $query->execute();
74            $this->id = $db->lastInsertId();
75            return true;
76        } catch(\PDOException $e) {
77            error_log($e->getMessage());
78            return false;
79        }
80
81    }
82    public function update() {
83        $db = dbConnectByName($this->store->getDbName());
84        $db->beginTransaction();
85        $query = $db->prepare("UPDATE dsSlides SET slideName = :slideName, fileName = :fileName, enabled = :enabled, type = :type, embed = :embed, videoDuration = :videoDuration WHERE id = :id");
86        $query->bindParam(":slideName", $this->slideName);
87        $query->bindParam(":fileName", $this->fileName);
88        $query->bindParam(":enabled", $this->enabled);
89        $query->bindParam(":type", $this->type);
90        $query->bindParam(":embed", $this->embed);
91        $query->bindParam(":videoDuration", $this->videoDuration);
92        $query->bindParam(":id", $this->id);
93        $query->execute();
94        $db->commit();
95        return true;
96    }
97    public function getByID($id) {
98        $db = dbConnectByName($this->store->getDbName());
99        $query = $db->prepare("SELECT * FROM dsSlides WHERE id = :id");
100        $query->bindParam(":id", $id);
101        $query->execute();
102        $result = $query->fetch(\PDO::FETCH_ASSOC);
103        if($result) {
104            $this->id = $result['id'];
105            $this->slideName = $result['slideName'];
106            $this->fileName = $result['fileName'];
107            $this->enabled = $result['enabled'];
108            $this->type = $result['type'];
109            $this->embed = $result['embed'];
110            $this->videoDuration = $result['videoDuration'];
111            return true;
112        } else {
113            return false;
114        }
115    }
116
117
118
119}