Ejemplo n.º 1
0
 public function actionGetPhotoInfoList($sn, $page = 1, $numPerPage = 50, $tagId = 0)
 {
     $start = ($page - 1) * $numPerPage;
     if ($tagId == 0) {
         $imageList = Image::find()->limit($numPerPage)->offset($start)->asArray()->all();
     } else {
         $imageList = Image::find()->leftJoin('image_tag', 'image.id = image_tag.imageId')->where(['image_tag.tagId' => $tagId])->limit($numPerPage)->offset($start)->asArray()->all();
     }
     $imageIdList = [];
     foreach ($imageList as $image) {
         $imageIdList[] = $image['id'];
     }
     //是否收藏
     $favoriteList = Favorite::find()->where(['isDelete' => 0, 'imageId' => $imageIdList])->asArray()->all();
     $favoriteMap = [];
     foreach ($favoriteList as $favorite) {
         $favoriteMap[$favorite['imageId']] = true;
     }
     $output = [];
     //更改链接
     foreach ($imageList as &$image) {
         $t = [];
         $t['id'] = $image['id'];
         $t['url'] = './image/' . Image::getUrlFromResizedFilePath($image['filePath']);
         //            $t['rawUrl'] = './rawImage/'.Image::getUrlFromRawFilePath($image['rawFilePath']);
         $t['thumbnailUrl'] = './image/' . Image::getUrlFromResizedFilePath($image['thumbnailFilePath']);
         $t['isFavorite'] = isset($favoriteMap[$image['id']]) ? true : false;
         $output[] = $t;
     }
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return ['sn' => $sn, 'data' => $output];
 }
    public function actionGetPhotoInfoList($sn, $page = 1, $numPerPage = 50)
    {
        $start = ($page - 1) * $numPerPage;
        $sql = <<<eof
        select image.*
        from image left join favorite on image.id = favorite.imageId
        where favorite.isDelete = 0
eof;
        $command = Yii::$app->db->createCommand($sql);
        $imageList = $command->queryAll();
        $output = [];
        //更改链接
        foreach ($imageList as &$image) {
            $t = [];
            $t['id'] = $image['id'];
            $t['url'] = './image/' . Image::getUrlFromResizedFilePath($image['filePath']);
            //            $t['rawUrl'] = './rawImage/'.Image::getUrlFromRawFilePath($image['rawFilePath']);
            $t['thumbnailUrl'] = './image/' . Image::getUrlFromResizedFilePath($image['thumbnailFilePath']);
            $t['isFavorite'] = true;
            $output[] = $t;
        }
        Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
        return ['sn' => $sn, 'data' => $output];
    }