1: <?php
2: /**
3: * Define the support items functions
4: *
5: * @since 1.3.0
6: *
7: * @package Simmer/Recipes/Items
8: */
9:
10: /**
11: * Get items for a specific recipe.
12: *
13: * @since 1.3.0
14: *
15: * @param int $recipe_id The recipe for which to get the items.
16: * @param array $args {
17: * Optional. The query parameters.
18: *
19: * @type string $type The item type to retrieve. Default: 'all'.
20: * @type bool|int $limit The number of items to get or false for no limit. Default: 'false'.
21: * @type bool|int $offset The number of items by which to offset the query or false for no
22: * offset. Default: 'false'.
23: * @type string $order The order in which to return the items. Default: 'ASC'. Accepts 'ASC' or 'DESC'.
24: * }
25: * @return array $items The retrieved items.
26: */
27: function simmer_get_recipe_items( $recipe_id, $args = array() ) {
28:
29: $items_api = new Simmer_Recipe_Items;
30:
31: $items = $items_api->get_items( $recipe_id, $args );
32:
33: return $items;
34: }
35:
36: /**
37: * Get a recipe item by its ID.
38: *
39: * @since 1.3.0
40: *
41: * @param int $item_id The ID of the desired item.
42: * @return object|bool $item The requested item or false on failure.
43: */
44: function simmer_get_recipe_item( $item_id ) {
45:
46: $items_api = new Simmer_Recipe_Items;
47:
48: $item = $items_api->get_item( $item_id );
49:
50: return $item;
51: }
52:
53: /**
54: * Add a recipe item to the database.
55: *
56: * @since 1.3.0
57: *
58: * @param int $recipe_id The ID of the recipe for which the item will be added.
59: * @param string $type The item type.
60: * @param int $order Optional. The item order number. Default: 0.
61: * @return int|bool $result The ID of the newly added item or false on failure.
62: */
63: function simmer_add_recipe_item( $recipe_id, $type, $order = 0 ) {
64:
65: $items_api = new Simmer_Recipe_Items;
66:
67: $item_id = $items_api->add_item( $recipe_id, $type, $order );
68:
69: return $item_id;
70: }
71:
72: /**
73: * Update an existing recipe item.
74: *
75: * @since 1.3.0
76: *
77: * @param int $item_id The ID of the item to update.
78: * @param array $args {
79: * The values to update. All values default to their existing database values.
80: *
81: * @type string $recipe_item_type The item type.
82: * @type int $recipe_id The ID of the associated recipe.
83: * @type int $recipe_item_order The item's order.
84: * }
85: * @return bool $result Whether the item was updated.
86: */
87: function simmer_update_recipe_item( $item_id, $args ) {
88:
89: $items_api = new Simmer_Recipe_Items;
90:
91: $result = $items_api->update_item( $item_id, $args );
92:
93: return $result;
94: }
95:
96: /**
97: * Delete an existing recipe item from the database.
98: *
99: * @since 1.3.0
100: *
101: * @param int $item_id The ID of the item to delete.
102: * @return bool $result Whether the item was deleted.
103: */
104: function simmer_delete_recipe_item( $item_id ) {
105:
106: $items_api = new Simmer_Recipe_Items;
107:
108: $result = $items_api->delete_item( $item_id );
109:
110: return $result;
111: }
112:
113: /**
114: * Get metadata for an item.
115: *
116: * @since 1.3.0
117: *
118: * @param int $item_id The item ID.
119: * @param string $meta_key Optional. The key of the metadata to retrieve. If left blank,
120: * all of the item's metadata will be returned in an array.
121: * @param bool $single Optional. Whether to return a single value or array of values. Default false.
122: * @return array|string|false $metadata Array of metadata, a single metadata value, or false on failure.
123: */
124: function simmer_get_recipe_item_meta( $item_id, $meta_key = '', $single = false ) {
125:
126: $item_meta_api = new Simmer_Recipe_Item_Meta;
127:
128: $metadata = $item_meta_api->get_item_meta( $item_id, $meta_key, $single );
129:
130: return $metadata;
131: }
132:
133: /**
134: * Add metadata to an item.
135: *
136: * @since 1.3.0
137: *
138: * @param int $item_id The item ID.
139: * @param string $meta_key The meta key to add.
140: * @param string $meta_value The meta value to add.
141: * @param bool $unique Optional. Whether the key should stay unique. When set to true,
142: * the custom field will not be added if the given key already exists
143: * among custom fields of the specified item.
144: * @return int|bool $result The new metadata's ID on success or false on failure.
145: */
146: function simmer_add_recipe_item_meta( $item_id, $meta_key, $meta_value, $unique = false ) {
147:
148: $item_meta_api = new Simmer_Recipe_Item_Meta;
149:
150: $result = $item_meta_api->add_item_meta( $item_id, $meta_key, $meta_value, $unique );
151:
152: return $result;
153: }
154:
155: /**
156: * Update an item's metadata.
157: *
158: * @since 1.3.0
159: *
160: * @param int $item_id The item ID.
161: * @param string $meta_key The key of the metadata to update.
162: * @param string $meta_value The new metadata value.
163: * @param string $prev_value Optional. The old value of the custom field you wish to change.
164: * This is to differentiate between several fields with the same key.
165: * If omitted, and there are multiple rows for this post and meta key,
166: * all meta values will be updated.
167: * @return int|bool $result True on success or false on failure. If the metadata being updated
168: * doesn't yet exist, it will be created and the new metadata's ID will
169: * be returned. If the specified value already exists, then nothing will
170: * be updated and false will be returned.
171: */
172: function simmer_update_recipe_item_meta( $item_id, $meta_key, $meta_value, $prev_value = '' ) {
173:
174: $item_meta_api = new Simmer_Recipe_Item_Meta;
175:
176: $result = $item_meta_api->update_item_meta( $item_id, $meta_key, $meta_value, $prev_value );
177:
178: return $result;
179: }
180:
181: /**
182: * Delete metadata from an item.
183: *
184: * @since 1.3.0
185: *
186: * @param int $item_id The item ID.
187: * @param string $meta_key The key of the metadata to delete.
188: * @param string $meta_value Optional. The value of the metadata you wish to delete. This is used
189: * to differentiate between several fields with the same key. If left blank,
190: * all fields with the given key will be deleted.
191: * @return bool $result True on success, false on failure.
192: */
193: function simmer_delete_recipe_item_meta( $item_id, $meta_key, $meta_value = '' ) {
194:
195: $item_meta_api = new Simmer_Recipe_Item_Meta;
196:
197: $result = $item_meta_api->delete_item_meta( $item_id, $meta_key, $meta_value );
198:
199: return $result;
200: }
201: