-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ingredient.php
63 lines (53 loc) · 1.5 KB
/
Ingredient.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
class Recipe_Model_Ingredient extends Recipe_Model_GenericModel implements Zend_Acl_Resource_Interface
{
protected $_ownerUserId = null;
protected $_data = array();
public function getResourceId()
{
return 'ingredient';
}
/**
* Gather the ingredients for a recipe
*
* @param int $recipe_id
* @return array
*/
public function getIngredients( $recipe_id )
{
$select = $this->db->select()
->from(array('ri' => 'recipe_ingredients'))
->joinLeft(
array('i' => 'ingredients'),
'ri.ingredient_id = i.id',
array( 'name' => 'i.name')
)
->joinLeft(
array('m' => 'measurements'),
'ri.measurement_id = m.id',
array( 'measurement' => 'm.abbreviation')
)
->where('ri.recipe_id = ?', $recipe_id);
return $this->db->fetchAll($select);
}
/**
* Grab an ingredient for a recipe
*
* @param int $recipe_id
* @param int $ingredient_id
* @return array
*/
public function getIngredientForRecipe( $recipe_id, $ingredient_id )
{
$select = $this->db->select()
->from(array( 'ri' => 'recipe_ingredients'))
->joinLeft(array('i' => 'ingredients'), 'i.id = ri.ingredient_id', 'i.name')
->joinLeft(array('r' => 'recipes'), 'r.id = ri.recipe_id', 'r.user_id')
->joinLeft(array('m' => 'measurements'), 'm.id = ri.measurement_id', array('measurement' => 'm.name'))
->where('ri.recipe_id = ?', $recipe_id)
->where('ri.ingredient_id = ?', $ingredient_id);
$row = $this->db->fetchRow($select);
$this->dataMerge( $row );
return $row;
}
}