示例#1
0
 public function store(Request $request, User $user, Album $album)
 {
     $like = new Like($request->all());
     $album->likeAlbum($like);
     flash('You like this album.', 'success');
     return back();
 }
 public function store(Request $request, Album $album)
 {
     $this->validate($request, ['comment' => 'required']);
     $comment = new Comment($request->all());
     $album->createComment($comment);
     flash('Your comment has been added.', 'success');
     return back();
 }
示例#3
0
 /**
  * 获取指定ID的节目内容描述
  *
  * @param string|integer    $album_id
  * @return array
  */
 private function obtainCurrentAlbumContent($album_id)
 {
     $album = new Album();
     $content = $album->getCurrentAlbumFullyDescribe(intval($album_id));
     // 将歌单列表反序列化后,加入到内容数组里
     $sheets_meta = $this->obtainSheetMeta($content);
     // 如果没有出现歌单详情,跳转到404界面
     if (empty($sheets_meta)) {
         return redirect('/index', 404);
     }
     return ['describe' => $content->toArray(), 'albums' => $sheets_meta];
 }
示例#4
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //Unguard
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     //Truncate
     Participant::truncate();
     //Event::truncate();
     Tag::truncate();
     Post::truncate();
     //Image::truncate();
     DB::statement('TRUNCATE `taggables`;');
     //DB::statement('TRUNCATE `imagables`;');
     DB::statement('TRUNCATE `participations`;');
     DB::statement('TRUNCATE `albumables`;');
     Event::reindex();
     Participant::reindex();
     User::reindex();
     Album::reindex();
     //Call
     $this->call(ParticipantTableSeeder::class);
     $this->call(EventTableSeeder::class);
     $this->call(TagTableSeeder::class);
     //Reguard
     Model::reguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
 }
 /**
  * TODO  Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $album = Album::with('songs')->find($id);
     /**
      *
      * display album name
      */
     echo '<strong>' . 'One to Many relationship' . '</strong>' . '<br>' . '<br>';
     echo 'Album Name:' . '<li>' . $album->name;
     echo '<br>';
     /**
      * Grab the songs for
      */
     echo '<br>';
     echo 'songs' . '<br>';
     foreach ($album->songs as $key => $value) {
         /**
          * display songs for each album
          */
         echo '<br>' . '<li>' . $value->name;
     }
     /**
      * Many to Many relationship
      * TODO Display album listeners
      */
     echo '<br>';
     echo '<br>';
     echo '<br>';
     echo '<strong>' . 'Many to Many relationship' . '</strong>' . '<br>';
     echo '<br>' . 'Album listeners' . '<br>';
     $album = Album::find($id);
     foreach ($album->listeners as $listeners) {
         echo '<li>' . $listeners->name;
     }
 }
示例#6
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]);
 }
示例#7
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(UploadImageRequest $request, $user)
 {
     if (!file_exists(public_path() . '/upload')) {
         mkdir(public_path() . '/upload');
     }
     if (!file_exists(public_path() . '/upload/images/')) {
         mkdir(public_path() . '/upload/images');
     }
     $id = Auth::user()->id;
     $auth = substr(md5(Auth::user()->id . Auth::user()->email), 0, 10);
     $resource = $request->except(['_token', 'image']);
     //dd($request->file('image'));
     if (!$request->get('album_id')) {
         $data_album = ['album_name' => 'Untitled', 'album_title' => 'Untitled album', 'user_id' => $id];
         if (!($album = Album::create($data_album))) {
             return redirect()->route('photo.create', $user)->withErrors('Unexpected error!');
         }
         $resource['album_id'] = $album->id;
     }
     if ($request->hasFile('image')) {
         $file = $request->file('image');
         $imageName = date('d-m-Y_h-i-s') . '_' . $id . '_' . $file->getClientOriginalName();
         $path = $this->path . '/' . $id . '_' . $auth;
         $destination = $path;
         $folder = public_path() . '/' . $path;
         if (!file_exists($folder)) {
             mkdir($folder);
         }
         $image = ['image_name' => $imageName, 'image_size' => $file->getSize(), 'user_id' => $id, 'fullsize_url' => $path . '/' . $imageName];
         if ($file->move($destination, $imageName) && Image::create(array_merge($resource, $image))) {
             return response()->json(['message' => 'Your photo has been upload!']);
         }
     }
     return response()->json(['message' => 'Unexpected errors']);
 }
示例#8
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'));
 }
 public function viewAlbumPics($id)
 {
     //showing the albums-details by its id
     $albums = Album::findOrFail($id);
     $photos = $albums->photos()->get();
     return view('admin.album-details', compact('albums', 'photos'));
 }
 public function run()
 {
     $albums = [['title' => 'Bruiloft 29/11', 'description' => '', 'seoble_type' => 'App\\Album', 'position' => [1, 2, 3, 4]], ['title' => 'Golf 22/10', 'description' => '', 'seoble_type' => 'App\\Album', 'position' => [1, 2, 3, 4]], ['title' => '', 'description' => '', 'seoble_type' => 'App\\Album', 'position' => [1, 2, 3, 4]], ['title' => '', 'description' => '', 'seoble_type' => 'App\\Album', 'position' => [1, 2, 3, 4]]];
     foreach ($albums as $album) {
         $a = Album::create(['position' => json_encode($album['position'])]);
         Seo::create(['title' => $album['title'], 'slug' => str_slug($album['title']), 'description' => $album['description'], 'seoble_type' => "App\\Album", 'seoble_id' => $a->id]);
     }
 }
示例#11
0
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function dashboard()
 {
     //
     $usercount = User::all()->count();
     $activecount = User::where('status', '=', 1)->count();
     $imagescount = Images::all()->count();
     $albumcount = Album::all()->count();
     return view('admin.dashboard')->with(['imagescount' => $imagescount, 'albumcount' => $albumcount, 'usercount' => $usercount, 'activeuser' => $activecount, 'fname' => 'Muhammad Adeel ']);
 }
示例#12
0
 public function getPhotos($album_id)
 {
     try {
         $photos = Album::find($album_id)->photos;
         return array('status' => 1, 'photos' => $photos, 'count' => $photos->count());
     } catch (Exception $exp) {
         return array('status' => 0);
     }
 }
示例#13
0
 public function createAlbum($name, $description, $cover, $user_id)
 {
     try {
         if (!Storage::disk('local')->exists($user_id)) {
             Storage::makeDirectory($user_id);
         }
         $cover_name = str_slug($name) . str_random(10) . '.jpg';
         $cover_make = Image::make($cover);
         Storage::put($user_id . '/' . $cover_name, $cover_make->stream());
         $newAlbum = new Album();
         $newAlbum->name = $name;
         $newAlbum->desc = $description;
         $newAlbum->user_id = $user_id;
         $newAlbum->cover = $cover_name;
         $newAlbum->save();
         return array('status' => 1);
     } catch (Exception $exp) {
         return array('status' => 0);
     }
 }
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     //
     view()->composer('_recent', function ($view) {
         $data = Images::leftJoin('albums', 'images.album_id', '=', 'albums.id')->leftJoin('users', 'images.user_id', '=', 'users.id')->select('images.*', 'albums.name as albumname', 'users.name as username')->limit(4)->where("images.status", "=", 'Public')->orderBy('images.id', 'desc')->get();
         $view->with("recent", $data);
     });
     view()->composer('_album', function ($view) {
         $data = Album::leftJoin('album_types', 'albums.albumtype_id', '=', 'album_types.id')->select('albums.*', 'album_types.name as typename')->orderBy('albums.id', 'desc')->get();
         $view->with("albums", $data);
     });
 }
示例#15
0
 public function run()
 {
     $users = [["id" => 1, "username" => "Torch", "first_name" => "Ján", "last_name" => "Krnáč", "password" => Hash::make('123456'), "admin" => 1, "email" => "*****@*****.**"]];
     $albums = [["id" => 1, "name" => "from posts", "albumable_id" => 1, "albumable_type" => "App\\User", "hash" => "abcde"]];
     if (!User::find(1)) {
         foreach ($users as $user) {
             User::create($user);
         }
         foreach ($albums as $album) {
             Album::create($album);
         }
     }
 }
示例#16
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;
 }
示例#17
0
 public function getAmaotoFlow()
 {
     $flow = new Collection();
     Music::orderByRaw('RAND()')->take(10)->get()->each(function ($item) use(&$flow) {
         /** @var Music $item */
         $flow->push(['type' => 'music', 'data' => $item->toArray()]);
     });
     Album::orderByRaw('RAND()')->take(10)->get()->each(function ($item) use(&$flow) {
         /** @var Album $item */
         $flow->push(['type' => 'album', 'data' => $item->toArray()]);
     });
     $result = $flow->shuffle();
     return $this->buildResponse(trans('api.system.get-amaoto-flow.success'), Tools::toArray($result));
 }
示例#18
0
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     Blade::directive('datetime', function ($expression) {
         return "<?php echo explode(' ', trim({$expression}, '()'))[0]; ?>";
     });
     Blade::directive('filesize', function ($expression) {
         return "<?php echo '[' . round({$expression} / 1024 / 1024, 2) . 'M]'; ?>";
     });
     Album::saved(function () {
         return response()->json('成功上传!');
     });
     Song::saved(function () {
         return response()->json('成功上传!');
     });
 }
示例#19
0
 public function upload(Request $request, $id)
 {
     $album = Album::findOrFail($id);
     $files = $request->file();
     $file = $files['files'][0];
     if (!$file->isValid()) {
         return new Response('Invalid Image ' . print_r($files, true), 400);
     }
     $destinationPath = app()->storagePath() . '/photos/';
     $file->move($destinationPath, $file->getFilename());
     $photo = Photo::create(['path' => $destinationPath . $file->getFilename(), 'name' => $file->getClientOriginalName(), 'album_id' => $album->id]);
     $photoArray = $photo->toArray();
     $photoArray['url'] = '/photo/' . $photo->id;
     $photo->makeThumbnail();
     return ['status' => 'done', 'files' => [$photoArray]];
 }
示例#20
0
 public function invitePost(Request $request)
 {
     /* @var $newUser /App/User */
     $newUser = User::create(['name' => $request->input('name'), 'email' => $request->input('email'), 'password' => 'temporary', 'is_admin' => 0]);
     if ($newUser->isValid()) {
         $album_ids = $request->input('albums', []);
         foreach ($album_ids as $album_id) {
             $newUser->albums()->attach($album_id);
         }
         $albums = Album::whereIn('id', $album_ids)->get();
         $token = base64_encode(sha1("{$newUser->id}_{$newUser->email}"));
         Mail::send('emails.invite', ['user' => $newUser, 'albums' => $albums, 'current' => $request->user(), 'token' => $token, 'domain' => $request->server('HTTP_HOST')], function ($m) use($newUser) {
             $m->to($newUser->email);
             $m->subject('Invitation');
         });
         return redirect('user/invite')->with('success', 'Invite sent.');
     } else {
         return redirect()->back()->withErrors($newUser->getErrors())->withInput();
     }
 }
示例#21
0
 public function postNotify(Request $request, $id)
 {
     /* @var $album \App\Album */
     $album = Album::findOrFail($id);
     $user_ids = $request->input('user', []);
     $subject = $request->input('subject', '');
     $message = $request->input('message', '');
     $emails_sent = 0;
     foreach ($user_ids as $user_id) {
         $user = User::find($user_id);
         if ($user) {
             $emails_sent++;
             Mail::raw($message, function ($m) use($user, $subject) {
                 $m->to($user->email);
                 $m->subject($subject);
             });
         }
     }
     return redirect('/albums')->with('success', "{$emails_sent} messages sent.");
 }
示例#22
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);
 }
 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);
     }
 }
示例#24
0
 public function getAlbumsWithPaginate(Request $request)
 {
     $perPage = $request->get('num');
     if (!is_numeric($perPage) || $perPage < 1 || $perPage > 30) {
         $perPage = 15;
     }
     $albums = Album::with(['musics' => function ($query) {
         $query->orderBy('track', 'asc');
     }])->orderBy('id', 'desc')->paginate($perPage);
     return $this->buildResponse(trans('api.album.paginate.success'), Tools::toArray($albums));
 }
示例#25
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  * @return Response
  */
 public function edit($id)
 {
     $tags = Tag::lists('name', 'id');
     $albums = Album::lists('name', 'id');
     $event = Event::findOrFail($id);
     $prices = $event->prices->toArray();
     $arr = array();
     foreach ($prices as $price) {
         $p = array();
         $p['name'] = $price['name'];
         $p['amount'] = $price['amount'];
         array_push($arr, $p);
     }
     $event['hiddenprice'] = json_encode($arr);
     $currencies = Currency::all();
     $event = $event->formatEvent();
     if ($event->banner_id == null) {
         $event['bannerid'] = '';
         $event['bannername'] = '';
     } else {
         $event['bannerid'] = $event->banner_id;
         $event['bannername'] = $event->banner->name;
     }
     if ($event->start == null) {
         $event['daterange'] = '';
     } else {
         $event['daterange'] = $event->start->format('d/m/Y H:s') . ' - ' . $event->end->format('d/m/Y H:s');
     }
     return view('admin.event.edit', compact('event', 'tags', 'albums', 'currencies'));
 }
示例#26
0
 public function destroy($id)
 {
     $album = Album::findOrFail($id);
     if (Gate::denies('album_authorize', $album)) {
         return "authorize fails";
     }
     foreach ($album->img as $albums) {
         File::delete(['uploads/' . $albums->name, 'uploads/thumbnails/' . 'thumbnail_' . $albums->name, 'uploads/' . $albums->thumbnail, 'uploads/thumbnails/' . $albums->thumbnail, 'uploads/' . $albums->thumbnail2, 'uploads/thumbnails/' . $albums->thumbnail2]);
     }
     Img::where('album_id', $album->id)->delete();
     Album::destroy($id);
     return redirect('/admin/albums/');
 }
示例#27
0
 /**
  * upload images.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function upload()
 {
     //
     $data = Album::lists('name', 'id');
     return view('image.upload', ['types' => $data]);
 }
示例#28
0
 /**
  * 获取以发布时间为准的节目列表
  *
  * @return array
  */
 private function obtainAlbumsOrderByPublished()
 {
     $albums = \App\Album::getFullyAlbumSheets();
     return is_null($albums) ? $this->emptyAlbums : $albums;
 }
 public function getForm($id)
 {
     $album = Album::find($id);
     return View::make('addimage')->with('album', $album);
 }
示例#30
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();
     }
 }