Пример #1
0
 /**
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function home()
 {
     //only for the album of Guido
     $album = Album::where('id', 2)->first();
     $photos = $album->photos()->sortTake();
     return view('home.index', compact('album', 'photos'));
 }
Пример #2
0
 public function homepage()
 {
     $album_latsed = Album::where('published_at', '<', date("Y-m-d h:i:s"))->where('display_id', 0)->orderBy('id', 'desc')->take(8)->get();
     $Video_latsed = Video::where('published_at', '<', date("Y-m-d h:i:s"))->orderBy('id', 'desc')->take(8)->get();
     $banner = Album::where('display_id', 2)->get();
     return view('welcome', ['album_latsed' => $album_latsed, 'video_latsed' => $Video_latsed, 'banners' => $banner]);
 }
Пример #3
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($slug)
 {
     $albums = Album::where('slug', $slug)->first();
     //$photos = Photo::paginate(1);
     $photos = $albums->photos()->paginate(2);
     $photos->setPath('');
     return view('albums.show', compact('albums', 'photos'));
 }
Пример #4
0
 public function getAlbumById($id = 0)
 {
     /** @var Album $album */
     $album = Album::where('id', $id)->first();
     if (!$album) {
         throw new AppException(AppException::ALBUM_NOT_FOUND);
     }
     return $this->buildResponse(trans('api.album.get.success'), Tools::toArray($album));
 }
 public function changeCoverPhoto($user, UpdateCoverPhotoRequest $request)
 {
     if ($request->hasFile('image')) {
         $file = $request->file('image');
         $album = Album::where(['album_name' => 'Cover photos', 'user_id' => $this->user->id])->get()->first();
         if (count($album)) {
             $albumId = $album->id;
         } else {
             if ($newAlbum = Album::create(['album_name' => 'Cover photos', 'album_title' => 'Cover photos', 'album_description' => '', 'user_id' => $this->user->id])) {
                 $albumId = $newAlbum->id;
             } else {
                 return response('Unexpected error!', 422);
             }
         }
         $destination = public_path() . '/upload/images/' . $this->user->id . '_' . $this->folder . '/cover';
         if (!file_exists(public_path() . '/upload/images/' . $this->user->id . '_' . $this->folder)) {
             mkdir(public_path() . '/upload/images/' . $this->user->id . '_' . $this->folder);
         }
         if (!file_exists($destination)) {
             mkdir($destination);
         }
         $imageName = date('d-m-Y_h-i-s') . '_' . $this->user->id . '_' . $file->getClientOriginalName();
         $imageUrl = 'upload/images/' . $this->user->id . '_' . $this->folder . '/cover/' . $imageName;
         $imageArr = ['image_name' => $imageName, 'fullsize_url' => $imageUrl, 'image_size' => $file->getSize(), 'image_caption' => '', 'user_id' => $this->user->id, 'album_id' => $albumId, 'make_as_cover_photo' => 1];
         $changeImage = Image::find($this->hasCoverPhoto($this->user->id));
         if (!is_null($changeImage)) {
             $changeImage->make_as_cover_photo = 0;
             $changeImage->save();
         }
         if ($file->move($destination, $imageName) && Image::create($imageArr)) {
             $data['errors'] = 0;
             $data['msg'] = 'Your cover photo has been change!';
             $data['imageUrl'] = url($imageUrl);
             return json_encode($data);
         }
         return response('Unexpected error while changging your cover photo!', 422);
     }
 }
Пример #6
0
 public function doUploadMusic(Guard $guard, Request $request)
 {
     if ($guard->guest()) {
         throw new AppException(AppException::NEED_SIGN_IN);
     }
     $uploadedFile = $request->file('file');
     if (!$uploadedFile) {
         throw new FileUploadException(FileUploadException::UploadFail);
     }
     if (!$uploadedFile->isValid()) {
         throw new FileUploadException(FileUploadException::UploadFailWithError, ['error' => $uploadedFile->getErrorMessage()]);
     }
     //        $chunkSize   = $request->get('_chunkSize');
     //        $chunkNumber = $request->get('_chunkNumber');
     $totalSize = $request->get('_totalSize');
     $uniName = $request->has('uniName') ? $guard->id() . '-' . md5($request->get('uniName')) : $guard->id() . '-' . md5($uploadedFile->getClientOriginalName() . '-' . $uploadedFile->getClientMimeType());
     $filePath = FileManager::rebuildChunkFile($uploadedFile->getRealPath(), $uniName, $totalSize);
     if ($filePath == false) {
         return $this->buildResponse(trans('api.music.upload.continue'));
     }
     $fileName = $request->get('filename');
     if (!$fileName) {
         $fileName = $uploadedFile->getClientOriginalName();
     }
     /** @var User $user */
     $user = $guard->user();
     $music = FileManager::UploadMusic($filePath, $fileName, $user);
     if ($request->has('albumId')) {
         $id = $request->get('albumId');
         /** @var Album $album */
         $album = Album::where('id', $id)->first();
         if (!$album) {
             throw new AppException(AppException::ALBUM_NOT_FOUND);
         }
         $album->musics()->attach($music);
     }
     return $this->buildResponse(trans('api.music.upload.success'), $music);
 }
Пример #7
0
 public function albums($id = 1)
 {
     $albums = Album::where('published_at', '<', date("Y-m-d h:i:s"))->where('display_id', 0)->orderBy('id', 'desc')->paginate($perPage = 10, $columns = ['*'], $pageName = 'page', $page = $id);
     return view('album.index', ['albums' => $albums]);
 }
Пример #8
0
 public static function edit($action, array $data, $id)
 {
     $goods = self::find($id);
     if ($action == 'edit') {
         $rows = Album::where('pid', $id)->get();
         $srcNum = Album::where('pid', $id)->count();
         $path = 'uploads';
         $files = Upload::fileUpload($path);
         $uploadNum = count($files);
         if ($uploadNum < $srcNum) {
             $i = 0;
             foreach ($files as $file) {
                 $array = ['album_path' => $file['name']];
                 unlink("uploads/" . $rows[$i]->album_path);
                 $rows[$i]->update($array);
                 $i++;
             }
             for ($j = $i; $j < $srcNum; $j++) {
                 $rows[$j]->delete();
                 unlink("uploads/" . $rows[$j]->album_path);
             }
         } elseif ($uploadNum == $srcNum) {
             $i = 0;
             foreach ($files as $file) {
                 $updateArr = ['album_path' => $file['name']];
                 unlink("uploads/" . $rows[$i]->album_path);
                 $rows[$i]->update($updateArr);
                 $i++;
             }
         } elseif ($uploadNum > $srcNum) {
             $i = 0;
             foreach ($rows as $row) {
                 $updateArr = array('album_path' => $files[$i]['name']);
                 unlink("uploads/" . $row->album_path);
                 $row->update($updateArr);
                 $i++;
             }
             for ($j = $i; $j < $uploadNum; $j++) {
                 $insertArr = array('pid' => $id, 'album_path' => $files[$j]['name']);
                 Album::create($insertArr);
             }
         }
         if ($goods->update($data)) {
             return self::success(['pro_id' => $id]);
         }
         return self::fail();
     } elseif ($action == 'delete') {
         if (self::where('id', $id)->delete()) {
             foreach (Album::where('pid', $id)->get() as $row) {
                 unlink("uploads/" . $row->album_path);
             }
             Album::where('pid', $id)->delete();
             Comments::where('pro_id', $id)->delete();
             return self::success();
         }
         return self::fail();
     }
 }
Пример #9
0
 /**
  * Authorize the upload action of a picture album
  * see the route list for details
  *
  * @param $model
  * @param $model_id
  * @param $id
  *
  * @return bool
  */
 private function _authorize($model, $model_id, $id)
 {
     switch ($model) {
         case 'user':
             if ($id != 'new') {
                 $this->album = Album::where('id', $id)->first();
                 session(['album_id' => null]);
             } else {
                 if (session('album_id') && session('album_id') != null) {
                     $this->album = Album::where('id', session('album_id'))->first();
                 } else {
                     $this->makeNewAlbum();
                     Auth::user()->albums()->save($this->album);
                     $this->album->update(['user_id' => Auth::id()]);
                 }
             }
             break;
         case 'article':
             $this->article = Article::whereId($id)->first();
             if (!($this->album = Album::where('albumable_id', $id)->get()->first())) {
                 $this->makeNewAlbum();
                 $this->article->albums()->save($this->album);
             }
             break;
         case 'profession':
             $this->profession = Profession::whereId($id)->first();
             if (!($this->album = Album::where('albumable_id', $id)->get()->first())) {
                 $this->makeNewAlbum();
                 $this->profession->albums()->save($this->album);
             }
             break;
         case 'site':
             $this->site = Site::whereId($model_id)->first();
             if (!($this->album = Album::where('id', $id)->first())) {
                 if (!$this->site->albums->last()) {
                     $this->makeNewAlbum();
                     $this->site->albums()->save($this->site);
                 }
             }
             break;
         case 'classified':
             $this->classified = Classified::whereId($id)->first();
             if (!($this->classified = Album::where('albumable_id', $id)->get()->first())) {
                 $this->makeNewAlbum();
                 $this->classified->albums()->save($this->album);
             }
             break;
     }
     //session(['album_id' => $this->album->id]);
     return true;
 }
Пример #10
0
 public function getAlbums(Request $request)
 {
     $query = $request->all()['q'];
     $albums = Album::where('name', 'LIKE', '%' . $query . '%')->orderBy('id', 'desc')->get();
     return $albums;
 }
Пример #11
0
 /**
  * Remove the specified album from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     //
     $isdelete = Album::where('id', $id)->delete();
     return redirect('/album/list')->with('status', "Album Removed  Successfully");
 }
Пример #12
0
 public function banner($id = 1)
 {
     $banners = Album::where("display_id", 2)->orderBy('id', 'desc')->paginate($perPage = 20, $columns = ['*'], $pageName = 'page', $page = $id);
     return view('admin.displays.banner', ["banners" => $banners]);
 }
Пример #13
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($user, $id)
 {
     $album = Album::where(['id' => $id, 'user_id' => $user]);
     $is_del = true;
     if (count($album->get()->toArray())) {
         $images = Album::find($id);
         if (count($images) > 0) {
             $images = $images->images()->get()->toArray();
             foreach ($images as $image) {
                 $comment_img = Comment_image::where('image_id', $image['id']);
                 if (count($comment_img->get()->toArray())) {
                     if (false == $comment_img->delete()) {
                         $is_del = false;
                     }
                 }
                 if (false == unlink(public_path() . '/' . $image['fullsize_url']) || false == Image::destroy($image['id'])) {
                     $is_del = false;
                     break;
                 }
             }
         }
         $album_id = $album->get()->first()->id;
         $comment = Comment_album::where('album_id', $album_id);
         if (count($comment->get()->toArray())) {
             if (false == $comment->delete()) {
                 $is_del = false;
             }
         }
         if ($album->delete() && true == $is_del) {
             return redirect()->route('album.index', $user)->with(['message' => 'Album has been delete.']);
         }
     }
     return redirect()->route('album.index', $user)->withErrors('Can not delete album.');
 }
Пример #14
0
 /**
  * Get the secret variable saved into $album->settings
  *
  * @param $id
  *
  * @return mixed
  */
 public function getSecret($id)
 {
     $settings = Album::where('id', $id)->pluck('settings')->first();
     return $settings['secret'];
 }