public function save() { $petOwner = new PetOwner(); $petOwner->setUsername(Session::get('username')); $petOwner->setEmail(Session::get('email')); $petOwner->setPassword(Session::get('password')); $petFactory = new PetFactory(Session::get('planet'), $_POST['kind']); $pet = $petFactory->createPet(); // Usar transação DAO::on('PetOwner')->save($petOwner); // DAO::on('Pet')->insert($pet); header('Location: ' . URL . 'login/run'); }
public function findById(int $id) { $data = $this->select("SELECT pet_id, age, hunger, stress, \n\t\t\talive, planet, kind FROM pet AS p\n\t\t\tLEFT JOIN pet_planet AS pp ON pp.pet_planet_id = p.pet_planet_id \n\t\t\tLEFT JOIN pet_kind AS pk ON pk.pet_kind_id = p.pet_kind_id \n\t\t\tWHERE p.pet_id = :id limit 1", [':id' => $id])[0]; $petFactory = new PetFactory($data['planet'], $data['kind']); $pet = $petFactory->createPet(); $pet->setId($data['pet_id']); $pet->setName('Little Dolly'); $pet->setAge($data['age']); $pet->setHunger($data['hunger']); $pet->setStress($data['stress']); if ($data['alive'] != 1) { $pet->die(); } return $pet; }