Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 52
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
CustomerAlertController
0.00% covered (danger)
0.00%
0 / 52
0.00% covered (danger)
0.00%
0 / 6
210
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
 getAllCustomerAlerts
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 deleteAlert
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 getAlert
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
20
 updateAlert
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
20
 pageCustomerAlerts
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace BuyerKiosk\CustomerAlert\Controllers;
4
5use Symfony\Component\Validator\Constraints\DateTime;
6use BuyerKiosk\Core\Controllers\BaseController;
7
8class CustomerAlertController extends BaseController {
9    private $storeDB;
10    private $store;
11    private $log;
12
13    public function __construct($app, \Store $store)
14    {
15        parent::__construct($app);
16        $this->store = $store;
17        $this->log = new \KLogger($_ENV['LOG_DIR']."customerAlert.log", \KLogger::DEBUG);
18        $this->storeDB = dbConnectByName($store->getDbName());
19    }
20
21    public function getAllCustomerAlerts() {
22        $alertsArray = [];
23        $stmt = $this->storeDB->prepare("SELECT customerAlerts.id as id, customerAlerts.customerID as customerID, comment, class, customerAlerts.dateAdded as dateAdded, customers.firstName, customers.lastName, customers.phone, customers.driversLicense as driversLicense FROM customerAlerts JOIN customers ON customerAlerts.customerID = customers.customerID ORDER BY customerAlerts.dateAdded DESC");
24        $stmt->execute();
25        while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
26            $tempAlert = $row;
27            $date = new \DateTime($row['dateAdded'], new \DateTimeZone('UTC'));
28            $date->setTimezone(new \DateTimeZone($this->store->getTimeZone()));
29            $tempAlert['dateAddedPretty'] = $date->format("m/d/Y g:i a");
30            $tempAlert['phone'] = formatPhoneNumber($row['phone']);
31            $alertsArray[] = $tempAlert;
32        }
33        return $alertsArray;
34    }
35    public function deleteAlert($alertID) {
36        $stmt = $this->storeDB->prepare("DELETE FROM customerAlerts WHERE id = :alertID");
37        $stmt->bindValue(":alertID", $alertID);
38        if($stmt->execute()) {
39            return true;
40        }
41        return false;
42    }
43    public function getAlert($alertID) {
44        try {
45            $stmt = $this->storeDB->prepare("SELECT customerAlerts.id as id, customerAlerts.customerID as customerID, customerAlerts.type as type, comment, class, customerAlerts.dateAdded as dateAdded, customers.firstName as firstName, customers.lastName as lastName, customers.phone, customers.driversLicense as driversLicense FROM customerAlerts JOIN customers ON customerAlerts.customerID = customers.customerID WHERE customerAlerts.id = :alertID ORDER BY customerAlerts.dateAdded DESC");
46            $stmt->bindValue(":alertID", $alertID);
47            if($stmt->execute()) {
48                if($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
49                    return $row;
50                }
51            }
52        } catch (\PDOException $e) {
53            $this->log->LogError($e->getMessage());
54        }
55        return null;
56    }
57    public function updateAlert($json) {
58        if($json->class == "danger") {
59            $type = 1;
60        } else {
61            $type = 0;
62        }
63        try {
64            $stmt = $this->storeDB->prepare("UPDATE customerAlerts SET comment=:comment, type=:type, class=:class WHERE id=:alertID");
65            $stmt->bindValue(":alertID", $json->alertID);
66            $stmt->bindValue(":comment", $json->comment);
67            $stmt->bindValue(":type", $type);
68            $stmt->bindValue(":class", $json->class);
69            if($stmt->execute()) {
70                return true;
71            }
72        } catch (\PDOException $e) {
73            $this->log->LogError($e->getMessage());
74        }
75        return false;
76    }
77
78    public function pageCustomerAlerts()
79    {
80        $this->_app->render('customer/customer-alerts.html', [
81            'page' => [
82                'title' => "Customer Alerts",
83                'description' => "Manage your customer alerts",
84                'alerts' => $this->_app->alerts->getAndClearMessages(),
85                'active_page' => ""
86            ],
87            'groups' => $this->_app->user->getGroups(),
88            'customerAlerts' => $this->getAllCustomerAlerts(),
89            'store' => getStoreInfo($this->store)
90        ]);
91    }
92
93}