Last active
May 17, 2016 11:49
-
-
Save howtomakeaturn/fdf9258c2b2b66280a71f7e857ef4270 to your computer and use it in GitHub Desktop.
manual modeling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Dxchemistry\TraditionalChinese; | |
class Category | |
{ | |
private $id; | |
private $name; | |
private $subcategories; | |
function __construct($id, $name, $subcategories) | |
{ | |
$this->id = $id; | |
$this->name = $name; | |
$this->subcategories = $subcategories; | |
} | |
function getName() | |
{ | |
return $this->name; | |
} | |
function getSubcategories() | |
{ | |
return $this->subcategories; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Dxchemistry\TraditionalChinese; | |
class CategoryRepository | |
{ | |
private $map = [ | |
1 => '前處理藥劑', | |
2 => '染色加工藥劑', | |
3 => '後處理加工' | |
]; | |
function getAll() | |
{ | |
$result = []; | |
$result[] = $this->get(1); | |
$result[] = $this->get(2); | |
$result[] = $this->get(3); | |
return $result; | |
} | |
function get($id) | |
{ | |
$subcategories = []; | |
$sql = "select * from category2 where type = $id order by id"; | |
$data = mysql_query($sql); | |
while ($row = mysql_fetch_assoc($data)){ | |
$subcategories[] = $this->getSubcategory($row); | |
} | |
$category = new Category($id, $this->map[$id], $subcategories); | |
return $category; | |
} | |
private function getSubcategory($row) | |
{ | |
$products = []; | |
$id = $row['id']; | |
$sql = "select * from menu2 where type = $id order by weight"; | |
$data = mysql_query($sql); | |
while ($inner_row = mysql_fetch_assoc($data)){ | |
$products[] = new Product($inner_row['id'], $inner_row['name'], $inner_row['brief'], $inner_row['weight']); | |
} | |
$subcategory = new Subcategory($row['id'], $row['name'], $products); | |
return $subcategory; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Dxchemistry\TraditionalChinese; | |
class Product | |
{ | |
private $id; | |
private $name; | |
private $description; | |
private $weight; | |
function __construct($id, $name, $description, $weight) | |
{ | |
$this->id = $id; | |
$this->name = $name; | |
$this->description = $description; | |
$this->weight = $weight; | |
} | |
function getId() | |
{ | |
return $this->id; | |
} | |
function getName() | |
{ | |
return $this->name; | |
} | |
function getWeight() | |
{ | |
return $this->weight; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment