Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
TextLog
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 3
30
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
2
 setDates
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getTextLog
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace BuyerKiosk\Core;
4
5class TextLog extends Store {
6    public $textLogArray;
7    private $db;
8    private $dateStart;
9    private $dateEnd;
10
11    public function __construct($typeNum) {
12        parent::__construct();
13        $this->createStore($typeNum);
14        $this->db = dbConnectByName($this->getDbName());
15    }
16    public function setDates($dateStart, $dateEnd) {
17        $this->dateStart = getDateRange($dateStart);
18        $this->dateEnd = getDateRange($dateEnd);
19    }
20    public function getTextLog() {
21        $log = new \KLogger($_ENV['LOG_DIR']."dev_log.txt",\KLogger::DEBUG);
22        $queryText = "  SELECT texts.timestamp, texts.customerID, customers.firstName, customers.lastName, customers.phone, CEIL(ROUND((UNIX_TIMESTAMP(timestamp)/texts.customerID)*100000)/100000) as combined FROM
23                                     texts
24                                     INNER JOIN customers ON texts.customerID = customers.customerID
25                                     WHERE texts.timestamp BETWEEN '".$this->dateStart['dateStart']->format("Y-m-d H:i:s")."' AND '".$this->dateEnd['dateEnd']->format("Y-m-d H:i:s")."' AND type = 0 GROUP BY combined ORDER BY texts.id DESC
26                                  ";
27
28
29        $log->LogDebug($queryText);
30        $textLogArray = [];
31        $query = $this->db->query($queryText);
32        $count = 0;
33        if($query) {
34            while ($row = $query->fetch(\PDO::FETCH_ASSOC)) {
35                $tempLogItem = [];
36                $time = new \DateTime($row['timestamp'], new \DateTimeZone('UTC'));
37                $time->setTimezone(new \DateTimeZone($this->getTimeZone()));
38                $phone = $row['phone'];
39                $phone = "(" . substr($phone, 0, 3) . ") " . substr($phone, 3, 3) . "-" . substr($phone, 6, 4);
40                $tempLogItem['time'] = $time->format("Y, M jS  g:i a");
41                $tempLogItem['id'] = $row['customerID'];
42                $tempLogItem['name'] = $row['firstName'] . " " . $row['lastName'];
43                $tempLogItem['phone'] = $phone;
44                $textLogArray[] = $tempLogItem;
45            }
46        }
47        $query = $this->db->query("SELECT count(id) as textCount FROM (SELECT CEIL(ROUND((UNIX_TIMESTAMP(timestamp)/customerID)*100000)/100000) as combined, id, timestamp, customerID FROM texts WHERE timestamp BETWEEN '".$this->dateStart['dateStart']->format("Y-m-d H:i:s")."' AND '".$this->dateEnd['dateEnd']->format("Y-m-d H:i:s")."' GROUP BY combined ORDER BY id DESC) as B");
48        $row = $query->fetch(\PDO::FETCH_ASSOC);
49        $count = (int)$row['textCount'];
50        return array('count' => $count, 'logItems' => $textLogArray);
51    }
52}