/** * Retrieve all the images. * * /images - get all images or * /images?tag=someTag - get all images that have specific tag */ function index_get() { header('Access-Control-Allow-Origin: *'); $tag = $this->get('tag'); $imageModel = new ImageModel($this->db); if ($tag != null) { $images = $imageModel->getImagesWithTag($tag); } else { $images = $imageModel->getImages(); } // To make the newest first // TODO: Make the database query do it instead $images = array_reverse($images); $imagesJson = array(); foreach ($images as $image) { $imagesJson[] = $image->serialize(); } if (empty($imagesJson)) { $this->response(error('No images found.', 404), 404); } else { $this->response($imagesJson); } }