-
Notifications
You must be signed in to change notification settings - Fork 0
/
recipe.class.php
40 lines (38 loc) · 934 Bytes
/
recipe.class.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
36
37
38
39
40
<?php
// Recipe class
class Recipe {
public $number;
public $name;
public $vegetarian;
public $ingredients;
public $calories;
public $cost;
public $time;
public $filename;
public $text;
public function __construct($number, $name, $vegetarian, $ingredients, $cost, $time, $filename, $text) {
$this->number = $number;
$this->name = $name;
$this->vegetarian = $vegetarian;
$this->ingredients = $ingredients;
$this->calCal();
$this->cost = $cost;
$this->time = $time;
$this->filename = $filename;
$this->text = $text;
}
// Calculate calories function
public function calCal() {
global $ingredient_list;
$total_calories = 0;
foreach ($this->ingredients as $amount) {
foreach ($ingredient_list as $calories) {
if ($amount[0] === $calories[0]) {
$total_calories += $amount[1] * $calories[1];
}
}
}
$this->calories = $total_calories;
}
}
?>