/**
  * Store a newly created resource in storage.
  *
  * @param  CreatePostRequest $request
  * @return Response
  */
 public function store(CreatePostRequest $request, $category_id)
 {
     // save post
     $post = new Post();
     $post->fill($request->all());
     $post->category_id = $category_id;
     $post->save();
     // if have attachment, create the attachment record
     if ($request->hasFile('attachment')) {
         // generate filename based on UUID
         $filename = Uuid::generate();
         $extension = $request->file('attachment')->getClientOriginalExtension();
         $fullfilename = $filename . '.' . $extension;
         // store the file
         Image::make($request->file('attachment')->getRealPath())->resize(null, 640, function ($constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         })->save(public_path() . '/attachments/' . $fullfilename);
         // attachment record
         $attachment = new Attachment();
         $attachment->post_id = $post->id;
         $attachment->original_filename = $request->file('attachment')->getClientOriginalName();
         $attachment->filename = $fullfilename;
         $attachment->mime = $request->file('attachment')->getMimeType();
         $attachment->save();
     }
     return redirect('category/' . $category_id . '/posts');
 }
Пример #2
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     if ($id) {
         $attachment = new Attachment();
         $attachment->showAttachment($id);
     } else {
         return Redirect::back()->withErrors(['Attachment code not indicated.']);
     }
 }
Пример #3
0
 public function addLogo($file)
 {
     $imageName = $this->id . '-' . time() . '.' . $file->getClientOriginalExtension();
     $attachment = new Attachment();
     $attachment->type = 'image';
     $attachment->file_src = 'images/uploads/branches/' . $imageName;
     $attachment->filename = $imageName;
     $attachment->save();
     $file->move(base_path() . '/public/images/uploads/branches', $imageName);
     $this->pictures()->save($attachment);
 }
Пример #4
0
 public function addBackgroundImage($file)
 {
     $imageName = $this->id . '-' . time() . '.' . $file->getClientOriginalExtension();
     $attachment = new Attachment();
     $attachment->type = 'image';
     $attachment->file_src = 'images/uploads/dockets/' . $imageName;
     $attachment->filename = $imageName;
     $attachment->save();
     $file->move(base_path() . '/public/images/uploads/dockets', $imageName);
     $this->pictures()->save($attachment);
     $this->pictures()->first()->resize(1000, 2000);
     $this->pictures()->first()->saveDimensions();
 }
Пример #5
0
 public function destroy(Attachment $attachment)
 {
     if (!Helper::getMode()) {
         return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
     }
     if ($attachment->user_id != Auth::user()->id && !Entrust::hasRole('admin')) {
         return redirect()->back()->withErrors(config('constants.INVALID_LINK'));
     }
     $belongs_to = $attachment->belongs_to;
     File::delete('uploads/attachment_files/' . $attachment->file);
     $attachment->delete($id);
     $activity = 'Deleted a file on a ' . $belongs_to;
     Activity::log($activity);
     return redirect()->back()->withSuccess(config('constants.DELETED'));
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $generator = \Faker\Factory::create('vi_VN');
     $articleCategories = ['Thị trường nhà đất', 'Dự án căn hộ', 'Đầu tư căn hộ', 'Lời khuyên'];
     //, 'Vị trí bài viết', 'Slideshow chính', 'Trang chủ', 'Slideshow footer'];
     $articleCategoryPositionArticles = null;
     foreach ($articleCategories as $key => $value) {
         $articleCategory = ArticleCategory::create(['key' => Common::createKeyURL($value), 'parent_id' => is_null($articleCategoryPositionArticles) ? 0 : $articleCategoryPositionArticles->id, 'priority' => $key, 'is_publish' => 1, 'created_by' => 'vankhoektcn', 'updated_by' => 'vankhoektcn']);
         ArticleCategoryTranslation::create(['article_category_id' => $articleCategory->id, 'locale' => 'vi', 'name' => $value, 'summary' => $value, 'meta_description' => $value, 'meta_keywords' => $value]);
         if ($value == 'Vị trí bài viết') {
             $articleCategoryPositionArticles = $articleCategory;
         }
     }
     $articles = ['Giới Thiệu', 'Tuyển Dụng', 'Tài Khoản Giao Dịch'];
     foreach ($articles as $key => $value) {
         $article = Article::create(['key' => Common::createKeyURL($value), 'priority' => $key, 'is_publish' => 1, 'created_by' => 'vankhoektcn', 'updated_by' => 'vankhoektcn']);
         ArticleTranslation::create(['article_id' => $article->id, 'locale' => 'vi', 'name' => $value, 'summary' => $generator->text($maxNbChars = 200), 'content' => $generator->realText($maxNbChars = 1000, $indexSize = 2), 'meta_description' => $generator->text($maxNbChars = 200), 'meta_keywords' => $generator->text($maxNbChars = 200)]);
     }
     $categories = ArticleCategory::where('parent_id', '=', 0)->lists('id');
     $categories2 = ArticleCategory::where('parent_id', '<>', 0)->lists('id');
     for ($i = 0; $i < 3; $i++) {
         $name = $generator->sentence($nbWords = 6);
         $key = Common::createKeyURL($name);
         $article = Article::create(['key' => $key, 'priority' => $i, 'is_publish' => 1, 'created_by' => 'vankhoektcn', 'updated_by' => 'vankhoektcn']);
         ArticleTranslation::create(['article_id' => $article->id, 'locale' => 'vi', 'name' => $name, 'summary' => $generator->text($maxNbChars = 200), 'content' => $generator->text, 'meta_description' => $generator->text($maxNbChars = 200), 'meta_keywords' => $generator->text($maxNbChars = 200)]);
         Attachment::create(['entry_id' => $article->id, 'table_name' => 'articles', 'path' => '/uploads/notfound.jpg', 'priority' => 0, 'is_publish' => 1]);
         $article->categories()->attach($categories->random());
         //$article->categories()->attach($categories2->random());
     }
 }
Пример #7
0
 /**
  * @param $aid
  * @return \Response
  * @throws \Exception
  */
 public function loadAudio($aid)
 {
     $attachment = Attachment::findOrFail($aid);
     $response = Vk::call('audio.getById', ['audios' => $attachment->external_id]);
     $audio = reset($response['response']);
     return response()->json(['url' => $audio['url']]);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $generator = \Faker\Factory::create('vi_VN');
     $articleCategories = ['Thông tin', 'Bài viết nỗi bật'];
     foreach ($articleCategories as $key => $value) {
         $articleCategory = ArticleCategory::create(['key' => Common::createKeyURL($value), 'parent_id' => 0, 'priority' => 0, 'is_publish' => 1, 'created_by' => 'phantsang', 'updated_by' => 'phantsang']);
         ArticleCategoryTranslation::create(['article_category_id' => $articleCategory->id, 'locale' => 'vi', 'name' => $value, 'summary' => $value, 'meta_description' => $value, 'meta_keywords' => $value]);
     }
     $articles = ['Giới thiệu', 'Dịch vụ của chúng tôi', 'Tại sao chọn chúng tôi'];
     foreach ($articles as $key => $item) {
         $article = Article::create(['key' => Common::createKeyURL($item), 'priority' => 0, 'is_publish' => 1, 'created_by' => 'phantsang', 'updated_by' => 'phantsang']);
         ArticleTranslation::create(['article_id' => $article->id, 'locale' => 'vi', 'name' => $item, 'summary' => $generator->text($maxNbChars = 200), 'content' => $generator->text, 'meta_description' => $generator->text($maxNbChars = 200), 'meta_keywords' => $generator->text($maxNbChars = 200)]);
         Attachment::create(['entry_id' => $article->id, 'table_name' => 'articles', 'path' => '/uploads/notfound.jpg', 'priority' => 0, 'is_publish' => 1]);
     }
     // BÀI VIẾT THÔNG TIN
     $articleCategory = ArticleCategory::findByKey('thong-tin')->first()->id;
     if (!is_null($articleCategory) && count($articleCategory) > 0) {
         for ($i = 0; $i < 10; $i++) {
             $name = $generator->sentence($nbWords = 6);
             $article = Article::create(['key' => Common::createKeyURL($name), 'priority' => 0, 'is_publish' => 1, 'created_by' => 'phantsang', 'updated_by' => 'phantsang']);
             ArticleTranslation::create(['article_id' => $article->id, 'locale' => 'vi', 'name' => $name, 'summary' => $generator->text($maxNbChars = 200), 'content' => $generator->text, 'meta_description' => $generator->text($maxNbChars = 200), 'meta_keywords' => $generator->text($maxNbChars = 200)]);
             /*
             Attachment::create([
             	'entry_id' => $article->id,
             	'table_name' => 'articles',
             	//'path' => $generator->imageUrl($width = 780, $height = 546),
             	'path' => '/uploads/notfound.jpg',
             	'priority' => 0,
             	'is_publish' => 1
             ]);
             */
             $article->categories()->attach($articleCategory);
         }
     }
 }
Пример #9
0
 public function addAttachment($file)
 {
     $imageName = 'comment-' . $this->id . '-' . time() . '.' . $file->getClientOriginalExtension();
     $filetype = strtolower($file->getClientOriginalExtension());
     $attachment = new Attachment();
     if ($filetype == 'jpg' || $filetype == 'jpeg' || $filetype == 'png' || $filetype == 'gif') {
         $attachment->type = 'image';
     } else {
         $attachment->type = 'other';
     }
     $attachment->file_src = 'images/uploads/attachments/' . $imageName;
     $attachment->filename = $imageName;
     $attachment->save();
     $file->move(base_path() . '/public/images/uploads/attachments', $imageName);
     $this->attachments()->save($attachment);
 }
Пример #10
0
 public function handle(LoanWasCreated $event)
 {
     $docs = Requireddocument::where('loantype_id', $event->loan->loan_type_id)->get();
     foreach ($docs as $doc) {
         Attachment::create(['loan_id' => $event->loan->id, 'title' => $doc->document]);
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $generator = \Faker\Factory::create('vi_VN');
     $value = 'Banner Chính 1';
     $navigation = Navigation::create(['key' => Common::createKeyURL($value), 'navigation_category_id' => 1, 'priority' => 0, 'is_publish' => 1, 'created_by' => 'phantsang', 'updated_by' => 'phantsang']);
     NavigationTranslation::create(['navigation_id' => $navigation->id, 'locale' => 'vi', 'name' => $value, 'summary' => $value]);
     Attachment::create(['entry_id' => $navigation->id, 'table_name' => 'navigations', 'path' => $generator->imageUrl($width = 1269, $height = 820), 'priority' => 0, 'is_publish' => 1]);
 }
Пример #12
0
 public function destroy($employeeId, $attachmentId)
 {
     $attachment = Attachment::findOrFail($attachmentId);
     //TODO::doesnt work for some reason
     \File::delete($attachment->location);
     $attachment->delete();
     return redirect()->to('/hr/employee/' . $employeeId);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $generator = \Faker\Factory::create('vi_VN');
     $name = 'Giới thiệu';
     $article = Article::create(['key' => Common::createKeyURL($name), 'priority' => 0, 'is_publish' => 1, 'created_by' => 'phantsang', 'updated_by' => 'phantsang']);
     ArticleTranslation::create(['article_id' => $article->id, 'locale' => 'vi', 'name' => $name, 'summary' => $generator->text($maxNbChars = 200), 'content' => $generator->text, 'meta_description' => $generator->text($maxNbChars = 200), 'meta_keywords' => $generator->text($maxNbChars = 200)]);
     Attachment::create(['entry_id' => $article->id, 'table_name' => 'articles', 'path' => '/uploads/notfound.jpg', 'priority' => 0, 'is_publish' => 1]);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $generator = \Faker\Factory::create('vi_VN');
     for ($i = 0; $i < 10; $i++) {
         $name = $generator->sentence($nbWords = 6);
         $product = Product::create(['key' => Common::createKeyURL($name), 'code' => $generator->unique()->randomDigit, 'producer_id' => 0, 'origin' => $generator->sentence($nbWords = 2), 'unit' => $generator->word, 'price' => $generator->randomFloat($nbMaxDecimals = NULL, $min = 0, $max = NULL), 'discount' => $generator->numberBetween($min = 0, $max = 100), 'priority' => 0, 'is_publish' => 1, 'created_by' => 'phantsang', 'updated_by' => 'phantsang']);
         ProductTranslation::create(['product_id' => $product->id, 'locale' => 'vi', 'name' => $name, 'summary' => $generator->text($maxNbChars = 200), 'content' => $generator->text, 'meta_description' => $generator->text($maxNbChars = 200), 'meta_keywords' => $generator->text($maxNbChars = 200)]);
         Attachment::create(['entry_id' => $product->id, 'table_name' => 'products', 'path' => '/uploads/notfound.jpg', 'priority' => 0, 'is_publish' => 1]);
     }
 }
Пример #15
0
 /**
  * Show the application dashboard.
  *
  * @return \Illuminate\Http\Response
  */
 public function index($name)
 {
     $page = Page::where('name', 'LIKE', $name)->first();
     $section = Section::where('id', 'LIKE', $page->section_id)->first();
     $articles = Article::where('page_id', 'LIKE', $page->id)->orderBy('publish_time', 'desc')->get();
     $articles_attachments = [];
     foreach ($articles as $article) {
         $articles_attachments[$article->id] = Attachment::where('article_id', 'LIKE', $article->id)->get();
     }
     return view('page.index', ['page' => $page, 'section' => $section, 'articles' => $articles, 'articles_attachments' => $articles_attachments]);
 }
Пример #16
0
 public function update($id)
 {
     // save updated
     $record = $this->records->find($id);
     if (!$record) {
         Attachment::create(Input::all());
         return $this->respond($record);
     }
     $record->fill(Input::all())->save();
     return $this->respond($record);
 }
 public function run()
 {
     DB::table('attachments')->delete();
     Attachment::create(['loan_id' => 1, 'user_id' => 3, 'status' => 'uploaded', 'title' => "Driver's License", 'filename' => 'driversLicense.pdf', 'path' => '2015_1/driversLicense.pdf', 'filetype' => 'pdf', 'original_filename' => 'Stark Drivers License', 'description' => '', 'date_requested' => '2015-06-30', 'date_received' => '2015-07-15']);
     Attachment::create(['loan_id' => 1, 'title' => "CPA Financials", 'filetype' => 'pdf', 'date_requested' => '2015-06-30']);
     Attachment::create(['loan_id' => 1, 'user_id' => 3, 'status' => 'uploaded', 'title' => "Equipment Inventory", 'filename' => 'equipmentList.pdf', 'path' => '2015_1/equipmentList.pdf', 'filetype' => 'pdf', 'original_filename' => 'Equipment Inventory', 'date_requested' => '2015-06-30', 'date_received' => '2015-07-04']);
     Attachment::create(['loan_id' => 1, 'title' => "FSA Information", 'filetype' => 'pdf', 'date_requested' => '2015-06-30']);
     Attachment::create(['loan_id' => 1, 'title' => "Crop Insurance APH Database", 'filetype' => 'xlsx', 'date_requested' => '2015-06-30']);
     Attachment::create(['loan_id' => 2, 'user_id' => 3, 'status' => 'uploaded', 'title' => "Driver's License", 'filename' => 'driversLicense.pdf', 'path' => '2015_2/driversLicense.pdf', 'filetype' => 'pdf', 'original_filename' => 'Murdock Drivers License', 'description' => '', 'date_requested' => '2015-06-30', 'date_received' => '2015-07-15']);
     Attachment::create(['loan_id' => 2, 'title' => "CPA Financials", 'filetype' => 'pdf', 'date_requested' => '2015-06-30']);
     Attachment::create(['loan_id' => 2, 'user_id' => 3, 'status' => 'uploaded', 'title' => "Equipment Inventory", 'filename' => 'equipmentInventory.pdf', 'path' => '2015_2/equipmentInventory.pdf', 'filetype' => 'pdf', 'original_filename' => 'Equipment Inventory', 'date_requested' => '2015-06-30', 'date_received' => '2015-07-04']);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param \Illuminate\Http\Request $request
  * @param  int                     $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request, $id)
 {
     $attachment = \App\Attachment::findOrFail($id);
     $path = attachment_path($attachment->name);
     if (\File::exists($path)) {
         \File::delete($path);
     }
     $attachment->delete();
     if ($request->ajax()) {
         return response()->json('', 204);
     }
     flash()->success(trans('forum.deleted'));
     return back();
 }
Пример #19
0
 /**
  * Store a newly created resource in storage.
  *
  * @param \App\Http\Requests\ArticlesRequest $request
  * @return \Illuminate\Http\Response
  */
 public function store(ArticlesRequest $request)
 {
     $payload = array_merge($request->except('_token'), ['notification' => $request->has('notification')]);
     $article = $request->user()->articles()->create($payload);
     $article->tags()->sync($request->input('tags'));
     if ($request->has('attachments')) {
         $attachments = \App\Attachment::whereIn('id', $request->input('attachments'))->get();
         $attachments->each(function ($attachment) use($article) {
             $attachment->article()->associate($article);
             $attachment->save();
         });
     }
     flash()->success(trans('forum.created'));
     return redirect(route('articles.index'));
 }
Пример #20
0
 /**
  * Store a newly created resource in storage.
  *
  * @param \App\Http\Requests\ArticlesRequest $request
  * @return \Illuminate\Http\Response
  */
 public function store(ArticlesRequest $request)
 {
     $payload = array_merge($request->except('_token'), ['notification' => $request->has('notification')]);
     $article = $request->user()->articles()->create($payload);
     $article->tags()->sync($request->input('tags'));
     if ($request->has('attachments')) {
         $attachments = \App\Attachment::whereIn('id', $request->input('attachments'))->get();
         $attachments->each(function ($attachment) use($article) {
             $attachment->article()->associate($article);
             $attachment->save();
         });
     }
     event(new ModelChanged(['articles', 'tags']));
     return $this->respondCreated($article);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $generator = \Faker\Factory::create('vi_VN');
     $value = 'Banner Chính 1';
     $navigation = Navigation::create(['key' => Common::createKeyURL($value), 'navigation_category_id' => 1, 'priority' => 0, 'is_publish' => 1, 'created_by' => 'phantsang', 'updated_by' => 'phantsang']);
     NavigationTranslation::create(['navigation_id' => $navigation->id, 'locale' => 'vi', 'name' => $value, 'summary' => $value]);
     Attachment::create(['entry_id' => $navigation->id, 'table_name' => 'navigations', 'path' => $generator->imageUrl($width = 1269, $height = 820), 'priority' => 0, 'is_publish' => 1]);
     // BANNER SOCIAL
     $navigationCategory = NavigationCategory::findByKey('banner-social')->first()->id;
     for ($i = 1; $i <= 3; $i++) {
         $navigation_name = $generator->sentence($nbWords = 6);
         $navigation = Navigation::create(['key' => Common::createKeyURL($navigation_name), 'navigation_category_id' => $navigationCategory, 'priority' => $i, 'is_publish' => 1, 'created_by' => 'phantsang', 'updated_by' => 'phantsang']);
         NavigationTranslation::create(['navigation_id' => $navigation->id, 'locale' => 'vi', 'name' => $navigation_name, 'summary' => $generator->text($maxNbChars = 50), 'content' => '']);
         Attachment::create(['entry_id' => $navigation->id, 'table_name' => 'navigations', 'path' => '/uploads/social' . $i . '.png', 'priority' => 0, 'is_publish' => 1]);
     }
 }
 public function destroy(Request $request)
 {
     $attachmentId = $request->get('key');
     $filePath = $request->get('path');
     DB::transaction(function () use($attachmentId) {
         $user = Auth::user();
         $attachment = Attachment::findOrFail($attachmentId);
         $attachment->updated_by = $user->name;
         $attachment->deleted_by = $user->name;
         $attachment->save();
         $filePath = $attachment->path;
         // soft delete
         $attachment->delete();
     });
     if (!is_null($filePath)) {
         Storage::disk('image')->delete(str_replace('/uploads/', '', $filePath));
     }
 }
Пример #23
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show(Request $request)
 {
     $filename = $request->route('file');
     $post = $request->route('post');
     $path = '../storage/app/images/uploads/';
     $filepath = $path . $post . '/' . $filename;
     $find = Attachment::where('update_id', $post)->where('filename', $filename);
     if ($find->count()) {
         $file_ext = $find->first()->type;
         if (file_exists($filepath)) {
             $file_size = filesize($filepath);
             $file = @fopen($filepath, "rb");
             if ($file) {
                 // set the headers, prevent caching
                 header("Pragma: public");
                 header("Expires: -1");
                 header("Cache-Control: public, must-revalidate, post-check=0, pre-check=0");
                 header("Content-Disposition: attachment; filename=\"{$filename}\"");
                 // set the mime type based on extension, add yours if needed.
                 $ctype = "application/octet-stream";
                 header("Content-Type: " . $ctype);
                 header("Content-Length: {$file_size}");
                 set_time_limit(0);
                 while (!feof($file)) {
                     print @fread($file, 1024 * 8);
                     ob_flush();
                     flush();
                     if (connection_status() != 0) {
                         @fclose($file);
                         exit;
                     }
                 }
                 // file save was a success
                 @fclose($file);
                 exit;
             } else {
                 // file couldn't be opened
                 header("HTTP/1.0 500 Internal Server Error");
                 exit;
             }
         }
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request, $ticket)
 {
     $this->validate($request, ['response' => 'required']);
     $response = TicketResponse::create(['user_id' => $this->my_id, 'response' => $request->response, 'source' => 'web', 'ticket_id' => $ticket]);
     if (isset($request->attachments)) {
         foreach ($request->attachments as $attachment) {
             // Check that the directory exists
             $uploadPath = storage_path() . '/attachments/' . $ticket;
             $fs = new Filesystem();
             if (!$fs->isDirectory($uploadPath)) {
                 // Create the directory
                 $fs->makeDirectory($uploadPath);
             }
             $attachment->move($uploadPath, $attachment->getClientOriginalName());
             $_attachment = Attachment::create(['user_id' => $this->my_id, 'name' => $attachment->getClientOriginalName(), 'ticket_response_id' => $response->id]);
         }
     }
     $_ticket = Ticket::where('id', $ticket)->first();
     Ticket::where('id', $ticket)->update(['status_id' => $request->status]);
     $this->dispatch(new EmailUpdatedTicket($_ticket, $response));
     return redirect('/ticket-response/' . $ticket);
 }
Пример #25
0
 /**
  * @param array $data
  * @return Attachment|\Illuminate\Database\Eloquent\Model|null|static
  */
 protected static function __getAttachment(array $data = [])
 {
     $atatch = null;
     $whereParam = ['external_id' => $data['id'], 'type' => $data['type']];
     switch ($data['type']) {
         case 'link':
             $url = $data['srcs']['url'];
             $url = str_replace('/', '\\\\/', $url);
             $attach = Attachment::where('srcs', 'like', '%' . $url . '%')->where('type', $data['type'])->first();
             if (is_null($attach)) {
                 $attach = new Attachment($whereParam);
             }
             break;
         default:
             $attach = Attachment::firstOrNew($whereParam);
             break;
     }
     return $attach;
 }
 public function update($id, Request $request)
 {
     $validator = Validator::make($request->all(), ['title' => 'required | min:3', 'headline' => 'sometimes|min:3', 'body' => 'sometimes | min:3', 'attachments' => 'required', 'published' => 'required|date', 'expires' => 'sometimes|after:' . $request->published]);
     if ($validator->passes()) {
         $post = Update::withTrashed()->find($id);
         $post->title = $request->title;
         $post->content = $request->body;
         $post->published_on = $request->published;
         $post->headline = $request->headline;
         if (isset($request->expires)) {
             $post->expires_on = $request->expires;
         }
         $post->category_id = $request->category;
         if ($post->save()) {
             if ($request->delete) {
                 foreach ($request->delete as $deletion) {
                     $attachment = Attachment::find($deletion);
                     $attachment->delete();
                 }
             }
             $request->featured = $request->featured == '' ? null : $request->featured;
             $post->featured = $request->featured;
             $post->save();
             if ($request->destroy) {
                 $post->delete();
             } else {
                 if (!is_null($post->deleted_at)) {
                     $post->restore();
                 }
             }
             $files = $request->file('attachments');
             if (count($files)) {
                 if (!is_dir($this->upload_dir . $post->id)) {
                     mkdir($this->upload_dir . $post->id);
                 }
                 $success = true;
                 foreach ($files as $file) {
                     if (!is_null($file) && $file->isValid()) {
                         if ($file->move($this->upload_dir . $post->id, $file->getClientOriginalName())) {
                             $attachment = new Attachment();
                             $attachment->filename = $file->getClientOriginalName();
                             $attachment->size = $file->getClientSize();
                             $attachment->update_id = $post->id;
                             $attachment->type = pathinfo($this->upload_dir . $post->id . '/' . $file->getClientOriginalName(), PATHINFO_EXTENSION);
                             $attachment->save();
                         } else {
                             $success = false;
                         }
                     }
                 }
                 if ($success) {
                     return redirect('about/galleries/' . $post->id . '/edit');
                 }
             }
             return redirect('about/galleries');
         } else {
             return 'Error';
         }
     } else {
         return redirect('about/galleries/' . $post->id . '/edit')->withInput();
     }
 }
Пример #27
0
 /**
  * @param array $attachmentsRaw
  * @return array
  */
 public function __attachmentsPost($attachmentsRaw)
 {
     $attachments = [];
     $videoIds = [];
     $albumIds = [];
     $attachmentsRaw = array_map(function ($attachmentRaw) use(&$videoIds, &$albumIds) {
         $id = null;
         $title = '';
         $description = '';
         $srcs = '';
         $date = null;
         $access_key = '';
         switch ($attachmentRaw['type']) {
             case 'photo':
                 $id = sprintf('%s_%s', $attachmentRaw['photo']['owner_id'], $attachmentRaw['photo']['pid']);
                 $access_key = $attachmentRaw['photo']['access_key'];
                 $date = $attachmentRaw['photo']['created'];
                 $description = $attachmentRaw['photo']['text'];
                 $srcs = ['src' => $attachmentRaw['photo']['src'], 'src_big' => $attachmentRaw['photo']['src_big']];
                 break;
             case 'video':
                 $id = sprintf('%s_%s', $attachmentRaw['video']['owner_id'], $attachmentRaw['video']['vid']);
                 $access_key = $attachmentRaw['video']['access_key'];
                 $date = $attachmentRaw['video']['date'];
                 $title = $attachmentRaw['video']['title'];
                 $description = $attachmentRaw['video']['description'];
                 $srcs = ['image' => $attachmentRaw['video']['image'], 'image_big' => $attachmentRaw['video']['image_big']];
                 array_push($videoIds, $id . '_' . $access_key);
                 break;
             case 'audio':
                 $id = sprintf('%s_%s', $attachmentRaw['audio']['owner_id'], $attachmentRaw['audio']['aid']);
                 $title = $attachmentRaw['audio']['artist'];
                 $description = $attachmentRaw['audio']['title'];
                 $srcs = ['url' => $attachmentRaw['audio']['url'], 'duration' => $attachmentRaw['audio']['duration']];
                 break;
             case 'album':
                 $id = sprintf('%s_%s', $attachmentRaw['album']['owner_id'], $attachmentRaw['album']['aid']);
                 $title = $attachmentRaw['album']['title'];
                 $description = $attachmentRaw['album']['description'];
                 $date = $attachmentRaw['album']['created'];
                 $srcs = ['updated' => $attachmentRaw['album']['updated'], 'thumb' => ['src' => $attachmentRaw['album']['thumb']['src'], 'src_big' => $attachmentRaw['album']['thumb']['src_big']]];
                 array_push($albumIds, $id);
                 break;
         }
         if (is_null($id)) {
             return null;
         }
         return ['id' => $id, 'type' => $attachmentRaw['type'], 'title' => $title, 'description' => $description, 'date' => $date, 'srcs' => $srcs, 'access_key' => $access_key];
     }, $attachmentsRaw);
     if (sizeof($videoIds) > 0) {
         $videosResponse = Vk::call('video.get', ['videos' => implode(',', $videoIds)]);
         $videos = array_slice($videosResponse['response'], 1);
         foreach ($videos as $video) {
             $id = $video['owner_id'] . '_' . $video['vid'];
             $index = array_search($id, array_column($attachmentsRaw, 'id'));
             if (is_bool($index) && $index === false) {
                 continue;
             }
             $attachmentsRaw[$index]['srcs']['player'] = $video['player'];
         }
     }
     if (sizeof($albumIds) > 0) {
         foreach ($albumIds as $albumId) {
             $part = explode('_', $albumId);
             $owner_id = $part[0];
             $album_id = $part[1];
             $index = array_search($albumId, array_column($attachmentsRaw, 'id'));
             if (is_bool($index) && $index === false) {
                 continue;
             }
             $photosResponse = Vk::call('photos.get', ['owner_id' => $owner_id, 'album_id' => $album_id]);
             $photos = array_slice($photosResponse['response'], 1);
             $normalizePhotos = [];
             foreach ($photos as $photo) {
                 $normalizePhotos[] = ['external_id' => $photo['owner_id'] . '_' . $photo['pid'], 'srcs' => ['src' => $photo['src'], 'src_big' => $photo['src_big']], 'description' => $photo['text']];
             }
             $attachmentsRaw[$index]['photos'] = $normalizePhotos;
         }
     }
     $attachments = array_map(function ($attachmentRaw) {
         if (is_null($attachmentRaw)) {
             return null;
         }
         $attachmentRaw['external_id'] = $attachmentRaw['id'];
         unset($attachmentRaw['id']);
         $attachment = Attachment::firstOrNew(['external_id' => $attachmentRaw['external_id'], 'type' => $attachmentRaw['type']]);
         $attachment->access_key = $attachmentRaw['access_key'];
         $attachment->title = $attachmentRaw['title'];
         $attachment->description = $attachmentRaw['description'];
         $attachment->srcs = $attachmentRaw['srcs'];
         $attachment->save();
         if ($attachmentRaw['type'] === 'album' && isset($attachmentRaw['photos']) && sizeof($attachmentRaw['photos']) > 0) {
             $photoIds = [];
             foreach ($attachmentRaw['photos'] as $photo) {
                 $attachmentPhoto = Attachment::firstOrNew(['external_id' => $photo['external_id']]);
                 $attachmentPhoto->description = $photo['description'];
                 $attachmentPhoto->srcs = $photo['srcs'];
                 $attachmentPhoto->save();
                 array_push($photoIds, $attachmentPhoto->id);
             }
             if (sizeof($photoIds) > 0) {
                 $attachment->childs()->sync($photoIds, false);
             }
         }
         return $attachment->id;
     }, $attachmentsRaw);
     $attachments = array_filter($attachments, function ($attachment) {
         return !is_null($attachment);
     });
     return $attachments;
 }
Пример #28
0
 public function uploadFile(Request $request)
 {
     // copy($_FILES['file']['tmp_name'], '/files/'.$_FILES['file']['name']);
     $file = $request->file('file');
     $file->move('uploads/files/' . $request->name, $_FILES['file']['name']);
     $array = array('filelink' => asset('uploads/files/' . $request->name . '/' . $_FILES['file']['name']), 'filename' => $_FILES['file']['name']);
     $attachment = new Attachment();
     $attachment->name = $request->name;
     $attachment->file = $_FILES['file']['name'];
     $attachment->type = 'pdf';
     $attachment->save();
     echo stripslashes(json_encode($array));
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     // validate request
     $validateProductColor = Validator::make($request->get('ProductColor'), ProductColor::$rules);
     $validationMessages = [];
     foreach ($request->get('ProductColorTranslation') as $key => $value) {
         $validateProductColorTranslation = Validator::make($value, ProductColorTranslation::$rules);
         if ($validateProductColorTranslation->fails()) {
             $validationMessages = array_merge_recursive($validationMessages, $validateProductColorTranslation->messages()->toArray());
         }
     }
     if ($validateProductColor->fails() or count($validationMessages) > 0) {
         $validationMessages = array_merge_recursive($validateProductColor->messages()->toArray(), $validationMessages);
         return redirect()->back()->withErrors($validationMessages)->withInput();
     }
     // get all languages
     $languages = Language::all();
     // find language default
     $languageDefault = $languages->where('is_key_language', 1)->first();
     if (is_null($languageDefault)) {
         $languageDefault = $languages->first();
     }
     // sure execute success, if not success rollback
     DB::transaction(function () use($request, $id, $languageDefault) {
         $user = $request->user();
         // insert ProductColor
         $productColor = ProductColor::findOrFail($id);
         $productColor->key = Common::createKeyURL($request->input('ProductColorTranslation.' . $languageDefault->code . '.name'));
         $productColor->parent_id = $request->input('ProductColor.parent_id');
         $productColor->priority = $request->input('ProductColor.priority');
         $productColor->is_publish = $request->input('ProductColor.is_publish');
         $productColor->created_by = $user->name;
         $productColor->updated_by = $user->name;
         $productColor->save();
         // save attachments
         // only insert or delete, not update
         if ($request->input('ProductColor.attachments') != "") {
             $currentAttachments = $productColor->attachments->lists('id');
             $requestAttachments = explode(',', $request->input('ProductColor.attachments'));
             $attachments = [];
             $keepAttachments = [];
             foreach ($requestAttachments as $key => $value) {
                 if (strpos($value, '|') === false) {
                     array_push($attachments, new Attachment(['entry_id' => $productColor->id, 'table_name' => 'product_colors', 'path' => $value, 'priority' => 0, 'is_publish' => 1]));
                 } else {
                     $attachmentId = explode('|', $value)[0];
                     array_push($keepAttachments, $attachmentId);
                 }
             }
             if (count($attachments) > 0) {
                 $productColor->attachments()->saveMany($attachments);
             }
             // delete attachments
             foreach ($currentAttachments as $key => $value) {
                 if (!in_array($value, $keepAttachments)) {
                     Attachment::findOrFail($value)->delete();
                 }
             }
         }
         // save data languages
         foreach ($request->get('ProductColorTranslation') as $locale => $value) {
             $productColor->translateOrNew($locale)->name = $request->input('ProductColorTranslation.' . $locale . '.name');
             $productColor->translateOrNew($locale)->summary = $request->input('ProductColorTranslation.' . $locale . '.summary');
             $productColor->translateOrNew($locale)->meta_description = $request->input('ProductColorTranslation.' . $locale . '.meta_description');
             $productColor->translateOrNew($locale)->meta_keywords = $request->input('ProductColorTranslation.' . $locale . '.meta_keywords');
         }
         $productColor->save();
     });
     return redirect()->route('admin.productcolors.index');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // Liên kết slider chính trang chủ
     $navigationCategories_homepage_id = NavigationCategory::findByKey('banner-trang-chu')->first()->id;
     $home_main_navigation_name = ['Khuyến mại sốc đầu xuân mới 2016', 'Cloud VPS siêu tiết kiệm', 'Tăng tốc website với CDN'];
     $home_main_navigation_summary = ['Khuyến mại sốc đầu xuân mới 2016', 'Cloud VPS siêu tiết kiệm', 'Tăng tốc website với CDN'];
     $home_main_navigation_content_templates = ['home_page_tinh-tien-theo-gio.html', 'home_page_khoi-tao-cuc-nhanh.html', 'home_page_chong-ddos.html'];
     $home_banner_navigation_attachments = ['/uploads/banner1.jpg', '/uploads/banner2.jpg', '/uploads/banner3.jpg'];
     foreach ($home_main_navigation_name as $key => $name) {
         $navigation = Navigation::create(['key' => Common::createKeyURL($name), 'navigation_category_id' => $navigationCategories_homepage_id, 'priority' => $key, 'is_publish' => 1, 'created_by' => 'vankhoektcn', 'updated_by' => 'vankhoektcn']);
         NavigationTranslation::create(['navigation_id' => $navigation->id, 'locale' => 'vi', 'name' => $name, 'summary' => $home_main_navigation_summary[$key]]);
         Attachment::create(['entry_id' => $navigation->id, 'table_name' => 'navigations', 'path' => $home_banner_navigation_attachments[$key], 'priority' => $key, 'is_publish' => 1]);
     }
     // Liên kết slider customer trang chủ
     $navigationCategories_customer_id = NavigationCategory::findByKey('khach-hang-tieu-bieu')->first()->id;
     $home_customer_navigation_name = ['VietDesigner', 'MKO', '24h', 'CGV', 'Ygame'];
     $home_customer_navigation_attachments = ['/frontend/img/vietdesigner.png', '/frontend/img/MKO.png', '/frontend/img/24h.png', '/frontend/img/CGV.png', '/frontend/img/ygame.png'];
     $home_customer_navigation_content = ['<img alt="" src="/frontend/img/vietdesigner.png">', '<img alt="" src="/frontend/img/MKO.png">', '<img alt="" src="/frontend/img/24h.png">', '<img alt="" src="/frontend/img/CGV.png">', '<img alt="" src="/frontend/img/ygame.png">'];
     foreach ($home_customer_navigation_name as $key => $name) {
         $navigation = Navigation::create(['key' => Common::createKeyURL($name), 'navigation_category_id' => $navigationCategories_customer_id, 'priority' => $key, 'is_publish' => 1, 'created_by' => 'vankhoektcn', 'updated_by' => 'vankhoektcn']);
         NavigationTranslation::create(['navigation_id' => $navigation->id, 'locale' => 'vi', 'name' => $name, 'summary' => '', 'content' => $home_customer_navigation_content[$key]]);
         Attachment::create(['entry_id' => $navigation->id, 'table_name' => 'navigations', 'path' => $home_customer_navigation_attachments[$key], 'priority' => $key, 'is_publish' => 1]);
     }
     // Liên kết slider chính trang MÁY CHỦ VPS
     $vps_service_navigationCategories_id = NavigationCategory::findByKey('banner-may-chu')->first()->id;
     $vps_service_navigation_name = ['Tính Tiền Theo Giờ', 'Khởi Tạo Cực Nhanh', 'Chống DDos', 'Dễ dàng & Linh hoạt'];
     $vps_service_navigation_summary = ['Dùng bao nhiêu, trả bấy nhiêu', 'Máy chủ sẵn sàng sau 30s', 'An toàn là trên hết', 'Tất cả đều có thể thao tác trên website'];
     $vps_service_navigation_content_templates = ['vps_service_tinh-tien-theo-gio.html', 'vps_service_khoi-tao-cuc-nhanh.html', 'vps_service_chong-ddos.html', 'vps_service_de-dang-linh-hoat.html'];
     foreach ($vps_service_navigation_name as $key => $name) {
         $navigation = Navigation::create(['key' => Common::createKeyURL($name), 'navigation_category_id' => $vps_service_navigationCategories_id, 'priority' => $key, 'is_publish' => 1, 'created_by' => 'vankhoektcn', 'updated_by' => 'vankhoektcn']);
         NavigationTranslation::create(['navigation_id' => $navigation->id, 'locale' => 'vi', 'name' => $name, 'summary' => $vps_service_navigation_summary[$key], 'content' => file_get_contents(base_path() . '\\public\\templates\\navigations\\' . $vps_service_navigation_content_templates[$key])]);
     }
     // Liên kết slider chính trang EMAIL SERVER
     $email_server_navigationCategories_id = NavigationCategory::findByKey('banner-email-server')->first()->id;
     $email_server_navigation_name = ['Nâng tầm doanh nghiệp', 'An toàn và linh hoạt', 'Dễ dàng thanh toán', 'Dual Xeon 5620'];
     $email_server_navigation_summary = ['Cloudone mang tới bạn dịch vụ E-mail chuyên nghiệp', 'Sử dụng an toàn và linh hoạt', 'Thanh toán linh hoạt, dễ dàng và tiện ích', 'Dual Xeon 5620 summary'];
     $email_server_navigation_content_templates = ['email_server_slider_1.html', 'email_server_slider_2.html', 'email_server_slider_3.html', 'email_server_slider_4.html'];
     foreach ($email_server_navigation_name as $key => $name) {
         $navigation = Navigation::create(['key' => Common::createKeyURL($name), 'navigation_category_id' => $email_server_navigationCategories_id, 'priority' => $key, 'is_publish' => 1, 'created_by' => 'vankhoektcn', 'updated_by' => 'vankhoektcn']);
         NavigationTranslation::create(['navigation_id' => $navigation->id, 'locale' => 'vi', 'name' => $name, 'summary' => $email_server_navigation_summary[$key], 'content' => file_get_contents(base_path() . '\\public\\templates\\navigations\\' . $email_server_navigation_content_templates[$key])]);
     }
     // Liên kết slider chính trang DỊCH VỤ HOSTING
     $hosting_service_navigationCategories_id = NavigationCategory::findByKey('banner-hosting')->first()->id;
     $hosting_service_navigation_name = ['WEB Hosting', 'Hệ thống máy chủ hiện đại, ổn định', 'Thanh toán tiện lợi', 'Thân thiện'];
     $hosting_service_navigation_summary = ['Quản lý 1 cách đơn giản trên web', 'Chi phí hợp lý, gói dịch vụ linh hoạt', 'Thanh toán linh hoạt, dẽ dàng và tiện ích', 'Hệ thống quản lý thân thiện, dễ sử dụng'];
     $hosting_service_navigation_content_templates = ['hosting_service_slider_1.html', 'hosting_service_slider_2.html', 'hosting_service_slider_3.html', 'hosting_service_slider_4.html'];
     foreach ($hosting_service_navigation_name as $key => $name) {
         $navigation = Navigation::create(['key' => Common::createKeyURL($name), 'navigation_category_id' => $hosting_service_navigationCategories_id, 'priority' => $key, 'is_publish' => 1, 'created_by' => 'vankhoektcn', 'updated_by' => 'vankhoektcn']);
         NavigationTranslation::create(['navigation_id' => $navigation->id, 'locale' => 'vi', 'name' => $name, 'summary' => $hosting_service_navigation_summary[$key], 'content' => file_get_contents(base_path() . '\\public\\templates\\navigations\\' . $hosting_service_navigation_content_templates[$key])]);
     }
     // Liên kết slider chính trang DỊCH VỤ DOMAIN
     $domain_service_navigationCategories_id = NavigationCategory::findByKey('banner-ten-mien')->first()->id;
     $domain_service_navigation_name = ['Lựa chọn đơn giản', 'Domain Slider 2', 'Domain Slider 3', 'Domain Slider 4'];
     $domain_service_navigation_summary = ['Đăng ký nhanh gọn, chuyển đổi đơn giản', 'Slider 2 summary', 'Slider 3 summary', 'Slider 4 summary'];
     $domain_service_navigation_content_templates = ['domain_service_slider_1.html', 'domain_service_slider_2.html', 'domain_service_slider_3.html', 'domain_service_slider_4.html'];
     foreach ($domain_service_navigation_name as $key => $name) {
         $navigation = Navigation::create(['key' => Common::createKeyURL($name), 'navigation_category_id' => $domain_service_navigationCategories_id, 'priority' => $key, 'is_publish' => 1, 'created_by' => 'vankhoektcn', 'updated_by' => 'vankhoektcn']);
         NavigationTranslation::create(['navigation_id' => $navigation->id, 'locale' => 'vi', 'name' => $name, 'summary' => $domain_service_navigation_summary[$key], 'content' => file_get_contents(base_path() . '\\public\\templates\\navigations\\' . $domain_service_navigation_content_templates[$key])]);
     }
     // Liên kết slider chính trang DỊCH VỤ CDN
     $cdn_service_navigationCategories_id = NavigationCategory::findByKey('banner-cdn')->first()->id;
     $cdn_service_navigation_name = ['CDN System', 'CDN, xu thế mới', 'Siêu tốc', 'Cdn Slider 4'];
     $cdn_service_navigation_summary = ['Slider 1 summary', 'Slider 2 summary', 'Thiết lập nhanh chóng, dễ dàng và an toàn', 'Slider 4 summary'];
     $cdn_service_navigation_content_templates = ['cdn_service_slider_1.html', 'cdn_service_slider_2.html', 'cdn_service_slider_3.html', 'cdn_service_slider_4.html'];
     foreach ($cdn_service_navigation_name as $key => $name) {
         $navigation = Navigation::create(['key' => Common::createKeyURL($name), 'navigation_category_id' => $cdn_service_navigationCategories_id, 'priority' => $key, 'is_publish' => 1, 'created_by' => 'vankhoektcn', 'updated_by' => 'vankhoektcn']);
         NavigationTranslation::create(['navigation_id' => $navigation->id, 'locale' => 'vi', 'name' => $name, 'summary' => $cdn_service_navigation_summary[$key], 'content' => file_get_contents(base_path() . '\\public\\templates\\navigations\\' . $cdn_service_navigation_content_templates[$key])]);
     }
     // Liên kết slider chính trang DỊCH VỤ WEBSITE
     $website_service_navigationCategories_id = NavigationCategory::findByKey('banner-website')->first()->id;
     $website_service_navigation_name = ['Hiện đại, Nhanh chóng, tiện lợi', 'An toàn, linh hoạt', 'Thanh toán linh hoạt, dẽ dàng và tiện ích', 'Website Slider 4'];
     $website_service_navigation_summary = ['Hiện đại, Nhanh chóng, tiện lợi', 'Sử dụng an toàn và linh hoạt', 'Thanh toán linh hoạt, dẽ dàng và tiện ích', 'Website Slider 4 summary'];
     $website_service_navigation_content_templates = ['website_service_slider_1.html', 'website_service_slider_2.html', 'website_service_slider_3.html', 'website_service_slider_4.html'];
     foreach ($website_service_navigation_name as $key => $name) {
         $navigation = Navigation::create(['key' => Common::createKeyURL($name), 'navigation_category_id' => $website_service_navigationCategories_id, 'priority' => $key, 'is_publish' => 1, 'created_by' => 'vankhoektcn', 'updated_by' => 'vankhoektcn']);
         NavigationTranslation::create(['navigation_id' => $navigation->id, 'locale' => 'vi', 'name' => $name, 'summary' => $website_service_navigation_summary[$key], 'content' => file_get_contents(base_path() . '\\public\\templates\\navigations\\' . $website_service_navigation_content_templates[$key])]);
     }
     // Liên kết slider chính landingpage
     $navigationCategories_landingpage_id = NavigationCategory::findByKey('banner-landing-page')->first()->id;
     $home_main_navigation_name = ['VPS Tính Tiền Theo Giờ Landing Page', 'Chúc mừng năm mới 2016 Landing Page', 'Tiện ích vượt trội Landing Page', 'Dễ dàng & Linh hoạt Landing Page'];
     $home_main_navigation_summary = ['Dùng bao nhiêu, trả bấy nhiêu', 'Dich vụ ưu đãi, chất lượng đầu năm', 'Dịch vụ chuyên nghiệp', 'Tất cả đều có thể thao tác trên website'];
     $home_main_navigation_content_templates = ['home_page_tinh-tien-theo-gio.html', 'home_page_khoi-tao-cuc-nhanh.html', 'home_page_chong-ddos.html', 'home_page_de-dang-linh-hoat.html'];
     foreach ($home_main_navigation_name as $key => $name) {
         $navigation = Navigation::create(['key' => Common::createKeyURL($name), 'navigation_category_id' => $navigationCategories_landingpage_id, 'priority' => $key, 'is_publish' => 1, 'created_by' => 'vankhoektcn', 'updated_by' => 'vankhoektcn']);
         NavigationTranslation::create(['navigation_id' => $navigation->id, 'locale' => 'vi', 'name' => $name, 'summary' => $home_main_navigation_summary[$key], 'content' => file_get_contents(base_path() . '\\public\\templates\\navigations\\' . $home_main_navigation_content_templates[$key])]);
     }
 }