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