-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComputerCase.php
35 lines (33 loc) · 883 Bytes
/
ComputerCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
class ComputerCase {
public $name;
public $price;
public function __construct($name, $price) {
$this->name = $name;
$this->price = $price;
}
function getCaseInformation($limitPrice) {
// get ComputerCase has closest price
$rows = array_map ( 'str_getcsv', file ( 'data/computer/Case.csv' ) );
$header = array_shift ( $rows );
$csv = array ();
$data = array ();
$caseData = array ();
foreach ( $rows as $row ) {
$csv [] = array_combine ( $header, $row );
}
foreach ( $csv as $caseData ) {
$value = floatval ( $caseData ['Price'] );
if ($value <= $limitPrice && $value > 0) {
array_push ( $data, $caseData );
}
}
$sort = new sort();
$sort->sortArray ( $data, 'Price' );
$name = $data [0] ['Name'];
$price = $data [0] ['Price'];
$psuName = $data [0] ['Watt'];
return new ComputerCase ( $name, $price, $psuName );
}
}
?>