/** * Gets a list of dependants * * @return [EmployeeEntity] List of employee */ public function getDependants(EmployeeEntity $employee) { $dependant_mapper = new DependantMapper($this->db); $sql = "SELECT SSN FROM IsCareGiver WHERE Id = :id"; $stmt = $this->db->prepare($sql); $result = $stmt->execute(["id" => $employee->getId()]); $results = []; while ($row = $stmt->fetch()) { $results[] = $dependant_mapper->getDependantById($row['SSN']); } return $results; }
$data['SSN'] = filter_var($post_data['id'], FILTER_SANITIZE_STRING); $data['Name'] = filter_var($post_data['name'], FILTER_SANITIZE_STRING); $data['DateOfBirth'] = filter_var($post_data['dob'], FILTER_SANITIZE_STRING); $mapper = new DependantMapper($this->db); $dependant = $mapper->getDependantById($data['SSN']); $this->logger->info("POST Edit Dependant " . $dependant->getName()); $dependant->setName($data['Name']); $dependant->setDob($data['DateOfBirth']); $mapper->update($dependant); $response = $response->withRedirect("/index.php/dependants"); return $response; }); // Delete Dependant $app->get('/dependant/{id}/delete', function ($request, $response, $args) { $id = (int) $args['id']; $mapper = new DependantMapper($this->db); $dependant = $mapper->getDependantById($id); $this->logger->info("Deleting dependant " . $id); $mapper->delete($dependant); $response = $response->withRedirect("/index.php/dependants"); return $response; }); /**********************EMPLOYEE**********************/ // Employees $app->get('/employees', function ($request, $response, $args) { $this->logger->info("Employees page"); $employee_mapper = new EmployeeMapper($this->db); $employees = $employee_mapper->getEmployees(); return $this->renderer->render($response, 'employee/employees.phtml', [$args, "employees" => $employees]); }); // New Employee