/** * Load image info based on the id */ public function getImageInfo($id) { $image = Images::findFirst($id); if (!$image) { die('image not found!'); } $sql = 'select x, y, value, name as text FROM images_tags left join tags on images_tags.tag_id = tags.id WHERE confidence is null AND images_tags.image_id = ' . $id; $resultSet = $this->getDI()->get('db')->query($sql); $resultSet->setFetchMode(Phalcon\Db::FETCH_ASSOC); //Get tags $tags = $image->getTags()->toArray(); //Get imageTags $imageTags = $image->getImagesTags()->toArray(); $result = []; $result['image'] = $image; //Add tags $result['tags'] = $resultSet->fetchAll(); //Load additional information $additionalDataSql = 'select * from additional_image_info a WHERE a.filename = \'' . $image->filename . '\' LIMIT 1'; $resultSet2 = $this->getDI()->get('db')->query($additionalDataSql); $resultSet2->setFetchMode(Phalcon\Db::FETCH_ASSOC); $addData = $resultSet2->fetchAll(); //The data added depends on the type of information present if (isset($addData[0])) { $result['additional_info'] = $addData[0]; } else { $result['additional_info'] = []; $result['additional_info']['fotograf'] = null; } //Adds a default photographer if no name is given if ($result['additional_info']['fotograf'] == null || $result['additional_info']['fotograf'] == '' || $result['additional_info']['fotograf'] == '?') { $result['additional_info']['fotograf'] = 'DR'; } return $result; }
$app->get('/images/latest', function () use($app) { $url = $app->getDI()->get('imageLocation'); $sql = 'select distinct(images.id), CONCAT("' . $url . '",images.id,"_thumb.jpg") as url from images left join images_tags ON images.id = images_tags.image_id order by images_tags.created DESC limit 30'; $resultSet = $app->getDI()->get('db')->query($sql); $resultSet->setFetchMode(Phalcon\Db::FETCH_ASSOC); echo json_encode($resultSet->fetchAll()); }); /** * Set image tags */ $app->post('/image/metadata/{id:[0-9]+}', function ($id) use($app) { $request = new Phalcon\Http\Request(); $filter = new Phalcon\Filter(); $user = new Users(); $data = $request->getPost('tags', null, false); $image = Images::findFirst("id = '" . $id . "'"); $tags = []; /** * Save each tag * This is done by: * 1) Getting/creating the tag * 2) Creating an imageTag * 3) Saving the imageTag */ foreach ($data as $tagRow) { $name = $filter->sanitize($tagRow['name'], 'string'); //Get tag if it exists already $tag = Tags::findFirst("name = '" . $name . "' AND category_id = '" . $tagRow['category_id'] . "'"); if (!$tag) { $tag = new Tags(); }