public static function addOpinionInDataBase($stars, $description, $idUser, $idShelter) { if (Shelter::isShelterExistInDataBase($idShelter)) { $db = DbManager::getPDO(); $query = "INSERT INTO Opinion(stars, description, idUser, idShelter) " . "VALUES (" . $stars . ", '" . $description . "'," . $idUser . "," . $idShelter . ")"; return $db->exec($query) >= 0; } else { return "Unknown shelter"; } }
public static function getAllShelters() { $db = DbManager::getPDO(); $query = "SELECT * FROM Shelter;"; $res = $db->query($query)->fetchAll(); for ($i = 0; $i < count($res); $i++) { $shelter = Shelter::getShelterArrayFromFetch($res[$i]); $listShelters[$shelter['idShelter']] = $shelter; } return $listShelters; }
<?php require_once 'models/Opinion.php'; $shelter = new Shelter($_POST['idShelter']); $listOpinions = $shelter->getOpinions(); echo json_encode($listOpinions);
<?php require_once 'models/Shelter.php'; $shelter = new Shelter($_POST['idShelter']); $addResult = $shelter->addAnimal($_POST['idAnimal']); if (gettype($addResult) === "string") { $response = ['success' => false, 'error' => $addResult]; } else { $response = ['success' => $addResult]; } echo json_encode($response);
<?php require_once 'models/Shelter.php'; $shelter = new Shelter($_POST['idShelter']); $listAnimals = $shelter->getAnimals(); echo json_encode($listAnimals);
public function followShelter($idShelter) { if (Shelter::isShelterExistInDataBase($idShelter)) { $db = DbManager::getPDO(); $query = "INSERT INTO FollowShelter(idUser, idShelter) VALUES (" . $this->idUser . "," . $idShelter . ")"; return $db->exec($query) >= 0; } else { return "Unknown shelter"; } }
<?php require_once 'models/Shelter.php'; $addResult = Shelter::addShelterInDataBase($_POST['name'], $_POST['phone'], $_POST['description'], $_POST['email'], $_POST['operationalHours'], $_POST['street'], $_POST['zipcode'], $_POST['city'], $_POST['latitude'], $_POST['longitude']); echo json_encode(['success' => $addResult]);
<?php require_once 'models/Shelter.php'; $shelter = new Shelter($_POST['idShelter']); $user = new User($_POST['nickname']); $result = $shelter->addManager($user->getId()); echo json_encode(["success" => $result]);
<?php require_once 'models/Shelter.php'; $shelter = new Shelter($_POST['idShelter']); $user = new User($_POST['nickname']); $result = $shelter->addAdministrator($user->getId()); echo json_encode(["success" => $result]);
<?php require_once 'models/Shelter.php'; $listShelters = Shelter::getAllShelters(); echo json_encode($listShelters);