The feeding log system allows employees to record when and how animals are fed, track compliance with nutrition plans, and monitor feeding patterns over time. All feeding operations require the animal_feeding-assign permission.
View all feeding logs with nutrition plan comparison:
public function start(){ $feedingModel = new FeedingLog(); $animalModel = new AnimalFull(); $feedings = $feedingModel->getAll(); $animals = $animalModel->getAll(); include_once __DIR__ . '/../views/feeding/start.php';}
The query joins with nutrition plans to show planned vs. actual:
public function getAll() { $sql = "SELECT fl.*, ag.animal_name, af.nutrition_id, n.food_type AS plan_food_type, n.food_qtty AS plan_food_qtty, n.nutrition_type, u.username AS fed_by_username FROM feeding_logs fl JOIN animal_full af ON fl.animal_f_id = af.id_full_animal JOIN animal_general ag ON af.animal_g_id = ag.id_animal_g LEFT JOIN nutrition n ON af.nutrition_id = n.id_nutrition LEFT JOIN users u ON fl.user_id = u.id_user ORDER BY fl.food_date DESC"; $stmt = $this->db->prepare($sql); $stmt->execute(); return $stmt->fetchAll(PDO::FETCH_OBJ);}
// User ID is automatically captured from session$userId = $_SESSION['user']['id_user'] ?? null;// Saved in feeding log$feedingModel->create($animalFullId, $foodType, $foodQty, $userId, $foodDate);
SELECT fl.*, ag.animal_name, u.username AS fed_by_usernameFROM feeding_logs flJOIN animal_full af ON fl.animal_f_id = af.id_full_animalJOIN animal_general ag ON af.animal_g_id = ag.id_animal_gLEFT JOIN users u ON fl.user_id = u.id_userWHERE fl.user_id = :employee_idORDER BY fl.food_date DESC
public function getLastFeeding($animalFullId) { $sql = "SELECT fl.*, ag.animal_name, af.nutrition_id, n.food_type AS plan_food_type, n.food_qtty AS plan_food_qtty, n.nutrition_type, u.username AS fed_by_username FROM feeding_logs fl JOIN animal_full af ON fl.animal_f_id = af.id_full_animal JOIN animal_general ag ON af.animal_g_id = ag.id_animal_g LEFT JOIN nutrition n ON af.nutrition_id = n.id_nutrition LEFT JOIN users u ON fl.user_id = u.id_user WHERE fl.animal_f_id = :animal_id ORDER BY fl.food_date DESC LIMIT 1"; $stmt = $this->db->prepare($sql); $stmt->execute([':animal_id' => $animalFullId]); return $stmt->fetch(PDO::FETCH_OBJ);}
This is useful for:
Checking when an animal was last fed
Ensuring animals aren’t overfed or underfed
Alerting if too much time has passed since last feeding
Feeding logs are related to veterinary health reports:
// When viewing an animal's health report$report = $reportModel->getById($reportId);$feedings = $feedingModel->getByAnimalId($report->id_full_animal);// Veterinarians can see:// 1. Health state over time// 2. Feeding compliance during that period// 3. Correlation between feeding and health