private function getLastLocalisation($em, $id) {
$query = $em->createQuery("SELECT l1 FROM App\Entity\Localisation l1 WHERE l1.person = :person and l1.timestamp = (SELECT MAX(l2.timestamp) FROM App\Entity\Localisation l2 WHERE l2.person = l1.person)");
$query->setParameter('person', $id);
- return $query->getResult()[0];
+ $result = $query->getResult();
+ if (!empty($result)) {
+ return $result[0];
+ }
}
/**
return $this->PersonNotFound();
}
- return $person->getFriendsWithMe();
+ $friends_with_me = $person->getFriendsWithMe();
+
+ return $friends_with_me;
}
/**
$em->flush();
}
+ /**
+ * @Rest\Post(
+ * path = "/api/person/search",
+ * name = "search_person"
+ * )
+ * @Rest\View()
+ */
+ public function searchPerson(Request $request)
+ {
+ $em = $this->getDoctrine()->getManager();
+ $query = $em->createQuery("SELECT DISTINCT p FROM App\Entity\Person p WHERE
+ p.firstname LIKE :keyword or
+ p.lastname LIKE :keyword or
+ p.email LIKE :keyword");
+ $query->setParameter('keyword', '%'.$request->get('keyword').'%');
+ $persons = $query->getResult();
+
+ if (empty($persons)) {
+ return $this->PersonNotFound();
+ }
+
+ return $persons;
+ }
+
private function PersonNotFound() {
return View::create(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
}