Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| BrandImporter | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| import | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BuyerKiosk\Sales; |
| 4 | |
| 5 | class BrandImporter extends \BuyerKiosk\Sales\Base { |
| 6 | private $csvFile; |
| 7 | |
| 8 | public function __construct($csvFilePath) { |
| 9 | parent::__construct(); |
| 10 | $this->csvFile = $csvFilePath; |
| 11 | } |
| 12 | |
| 13 | public function import() { |
| 14 | if (($handle = fopen($this->csvFile, "r")) !== FALSE) { |
| 15 | // Skip the header row |
| 16 | fgetcsv($handle, 1000, ","); |
| 17 | |
| 18 | $query = "INSERT INTO brands (id, name) VALUES (:id, :name) ON DUPLICATE KEY UPDATE name = :name"; |
| 19 | $stmt = $this->conn->prepare($query); |
| 20 | |
| 21 | while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { |
| 22 | $brandId = $data[0]; |
| 23 | $brandName = $data[1]; |
| 24 | |
| 25 | $stmt->bindParam(':id', $brandId); |
| 26 | $stmt->bindParam(':name', $brandName); |
| 27 | |
| 28 | $stmt->execute(); |
| 29 | } |
| 30 | |
| 31 | fclose($handle); |
| 32 | return true; |
| 33 | } |
| 34 | return false; |
| 35 | } |
| 36 | } |
| 37 |