dataArray=[]; $this->index=0; } public function delete($id){ for ($i=0;$idataArray);$i++){ if ($this->dataArray[$i]->getId()==$id){ array_splice($this->dataArray, $i, 1); } } } public function displayAll(){ for ($i=0;$idataArray);$i++){ echo $this->dataArray[$i]->displayInfo(); } } } class BackpackList extends BaseList{ public function add($name, $vendor, $category, $price, $properties){ $id=++$this->index; $nb = new Backpack($id, $name,$vendor, $category, $price, $properties); array_push($this->dataArray,$nb); return $id; } public function edit($id, $name, $vendor, $category, $price, $properties){ for ($i=0;$idataArray);$i++){ if ($this->dataArray[$i]->getId()==$id){ $this->dataArray[$i]->edit($name, $vendor, $category, $price, $properties); } } } } class Backpack{ private $id; private $name; private $vendor; private $category; private $price; private $properties; public function __construct($id, $name, $vendor, $category, $price, $properties){ $this->id=$id; $this->name=$name; $this->vendor=$vendor; $this->category=$category; $this->price=$price; $this->properties=$properties; } public function getId(){ return $this->id; } public function edit($name, $vendor, $category,$price, $properties){ $this->name=$name; $this->vendor=$vendor; $this->category=$category; $this->price=$price; $this->properties=$properties; } private function displayProperties(){ $result='Характеристики:
'; foreach($this->properties as $key => $value) { $result.= $key . ": " . $value; $result.= "
"; } return $result; } public function displayInfo(){ return $this->id.". ".$this->vendor." ".$this->name."
Ціна: ".$this->price."
Категорія: ".$this->category."
". $this->displayProperties(); } public function __destruct(){ echo ""; } } class CategoryList extends BaseList{ public function add($name){ $id=++$this->index; $nc = new Category($id, $name); array_push($this->dataArray,$nc); return $id; } public function edit($id, $name){ for ($i=0;$idataArray);$i++){ if ($this->dataArray[$i]->getId()==$id){ $this->dataArray[$i]->edit($name); } } } } class Category{ private $id; private $name; public function __construct($id, $name){ $this->id=$id; $this->name=$name; } public function displayInfo(){ return $this->id.". ".$this->name."
"; } public function getId(){ return $this->id; } public function edit($name){ $this->name=$name; } public function __destruct(){ echo ""; } } class PropertyList extends BaseList{ public function add($name, $units){ $id=++$this->index; $np = new Property($id, $name, $units); array_push($this->dataArray,$np); return $id; } public function edit($id, $name, $units){ for ($i=0;$idataArray);$i++){ if ($this->dataArray[$i]->getId()==$id){ $this->dataArray[$i]->edit($name, $units); } } } } class Property{ private $id; private $name; private $units; public function __construct($id, $name,$units){ $this->id=$id; $this->name=$name; $this->units=$units; } public function getId(){ return $this->id; } public function edit($name,$units){ $this->name=$name; $this->units=$units; } public function displayInfo(){ return $this->id.". ".$this->name." (".$this->units.")
"; } public function __destruct(){ echo ""; } } $cl= new CategoryList(); $cl->add('Міські рюкзаки'); $cl->add('Похідні рюкзаки'); $cl->displayAll(); echo '
'; $pl= new PropertyList(); $pl->add('Вага','кг'); $pl->add('Об\'єм','л'); $pl->displayAll(); echo '
'; $bl= new BackpackList(); $bl->add('Flare', 'Osprey','Міські рюкзаки', '999',['Вага'=>'1.1','Об\'єм'=>'20']); $bl->add('Kestrel', 'Osprey','Похідні рюкзаки', '1999',['Вага'=>'1.6','Об\'єм'=>'65']); $bl->displayAll(); echo '
'; $bl->edit(2,'Kestrel', 'Osprey','Похідні рюкзаки', '2999',['Вага'=>'1.6','Об\'єм'=>'65']); $bl->displayAll(); ?>