/** * Check if individual ingredient is available inside a Fridge * @param Array $ingredient * @return Boolean */ public function lookForIngredient($ingredient) { for ($i = 0; $i < count($this->content); $i++) { $fridge_item = $this->content[$i]; $usebydate_obj = DateFunc::StringToDateObj($fridge_item['use-by']); // Returns false if expired.We don't cook expired one! if (!$this->checkExpiryDate($usebydate_obj)) { return false; } // Check the availability of the ingredient in the fridge // we compare the item, compare the unit and if amount is less or equal to available amount if ($ingredient['item'] == $fridge_item['item'] && (int) $ingredient['amount'] <= (int) $fridge_item['amount'] && $ingredient['unit'] == $fridge_item['unit']) { return true; } } return false; }
/** * More than one receipes so we need to choose one * We pick one whose's one of the ingredient has the smallest use by date. * Smallest use by means it will be the first to expire. * @return Array $closest_recpt */ public function getReceipeWithClosestUseBy() { $closest_useby_ts = strtotime(date("Y-n-j", PHP_INT_MAX)); $closest_recpt = null; $fridge = $this->fridge; // More than one receipes so we need to choose one // We pick one whose's one of the ingredient has the smallest use by date. // Smallest use by means it will be the first to expire. foreach ($this->tonight_recps as $rs) { $ingredients = $rs['ingredients']; foreach ($ingredients as $ing) { $dt_str = $fridge->obtainUsebyDate($ing['item']); $dt_obj = DateFunc::StringToDateObj($dt_str); if ($dt_obj->getTimestamp() <= $closest_useby_ts) { $closest_useby_ts = $dt_obj->getTimestamp(); $closest_recpt = $rs; } } } return $closest_recpt; }