本文整理汇总了PHP中Images::findFirst方法的典型用法代码示例。如果您正苦于以下问题:PHP Images::findFirst方法的具体用法?PHP Images::findFirst怎么用?PHP Images::findFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Images
的用法示例。
在下文中一共展示了Images::findFirst方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getImageInfo
/**
* 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;
}
示例2: function
$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();
}