Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 41
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
Link
0.00% covered (danger)
0.00%
0 / 41
0.00% covered (danger)
0.00%
0 / 7
462
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 get
0.00% covered (danger)
0.00%
0 / 13
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
6
 delete
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
 isValid
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
90
 setID
0.00% covered (danger)
0.00%
0 / 1
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
1<?php
2namespace BuyerKiosk\CustomerSurvey;
3
4class Link {
5    private $id;
6    private $db;
7    public $name;
8    public $url;
9    public $active;
10    public $link;
11
12    public function __construct(\Store $store, $db = null) {
13        if(isset($db)) {
14            $this->db = $db;
15        } else {
16            $this->db = dbConnectByName($store->getDbName());
17        }
18    }
19
20    public function get($id) {
21        try {
22            $stmt = $this->db->prepare("SELECT *, COUNT(*) as rowCount FROM surveyLinks WHERE id = :id");
23            $stmt->bindValue(":id", $id);
24            $stmt->execute();
25            $row = $stmt->fetch(\PDO::FETCH_ASSOC);
26            if($row['rowCount'] > 0) {
27                $this->id = $row['id'];
28                $this->name = $row['name'];
29                $this->url = $row['link'];
30                $this->active = $row['active'];
31                return true;
32            } else {
33                return false;
34            }
35        } catch (\PDOException $e) {
36            return false;
37        }
38    }
39
40    public function update() {
41        try {
42            $stmt = $this->db->prepare("UPDATE surveyLinks SET name=:name, link=:link, active=:active WHERE id = :id");
43            $stmt->bindValue(":id", $this->id);
44            $stmt->bindValue(":name", $this->name);
45            $stmt->bindValue(":link", $this->url);
46            $stmt->bindValue(":active", $this->active);
47            $stmt->execute();
48            return true;
49        } catch (\PDOException $e) {
50            return false;
51        }
52    }
53
54    public function delete() {
55        try {
56            $stmt = $this->db->prepare("DELETE FROM surveyLinks WHERE id = :id");
57            $stmt->bindValue(":id",$this->id);
58            if($stmt->execute()) {
59                return true;
60            }
61        } catch (\PDOException $e) {
62            return false;
63        }
64        return false;
65    }
66
67    public function isValid() {
68        if(!isset($this->name) || !strlen($this->name) > 0 || !is_string($this->name)) {
69            return false;
70        }
71        if(!isset($this->url) || !strlen($this->url) > 6 || !is_string($this->url)) {
72            return false;
73        }
74        if(!isset($this->active) || !is_int($this->active)) {
75            return false;
76        }
77        return true;
78    }
79
80    public function setID($id) {
81        $this->id = $id;
82    }
83    public function getID() {
84        return $this->id;
85    }
86}