Example #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Requests\Backend\StoreCategoryRequest $request
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function update(Requests\Backend\StoreCategoryRequest $request, $id)
 {
     $category = Category::findOrFail($id);
     $this->authorize($category);
     $category->update($request->all());
     return redirect()->action('Backend\\CategoryController@show', [$category]);
 }
Example #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $user = auth()->check() ? auth()->user() : null;
     if (is_null($user)) {
         return redirect('/')->with('error', 'You need to be logged in');
     }
     if (!$user->can('break_upload_limit') && $user->videos()->newlyups()->count() >= 20) {
         return redirect()->back()->with('error', 'Uploadlimit reached')->withInput();
     }
     if (!$request->hasFile('file')) {
         return redirect()->back()->with('error', 'No file')->withInput();
     }
     $file = $request->file('file');
     if (!$file->isValid() || $file->getClientOriginalExtension() != 'webm' || $file->getMimeType() != 'video/webm') {
         return redirect()->back()->with('error', 'Invalid file');
     }
     if (!$user->can('break_max_filesize') && $file->getSize() > 30000000.0) {
         return redirect()->back()->with('error', 'File to big. Max 30MB')->withInput();
     }
     if (($v = Video::withTrashed()->where('hash', '=', sha1_file($file->getRealPath()))->first()) !== null) {
         return redirect($v->id)->with('error', 'Video already exists');
     }
     $file = $file->move(public_path() . '/b/', time() . '.webm');
     $hash = sha1_file($file->getRealPath());
     $video = new Video();
     $video->file = basename($file->getRealPath());
     $video->interpret = $request->get('interpret', null);
     $video->songtitle = $request->get('songtitle', null);
     $video->imgsource = $request->get('imgsource', null);
     $video->user()->associate($user);
     $video->category()->associate(Category::findOrFail($request->get('category')));
     $video->hash = $hash;
     $video->save();
     return redirect($video->id)->with('success', 'Upload successful');
 }
Example #3
0
 /**
  * Show the application dashboard to the user.
  *
  * @return Response
  */
 public function addCategory($category_id = null)
 {
     if ($category_id) {
         return view('admin.partials.add_category', ['category' => Category::findOrFail($category_id)]);
     } else {
         return view('admin.partials.add_category');
     }
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $category = Category::findOrFail($id);
     $paginator = $category->posts()->paginate(9);
     $posts = $paginator->getCollection();
     $data = fractal()->collection($posts)->transformWith(new PostTransformer())->includeUser()->includeCategories()->paginateWith(new IlluminatePaginatorAdapter($paginator))->toArray();
     return $this->respond($data);
 }
Example #5
0
 public function destroy(Request $request, $id)
 {
     try {
         $category = Category::findOrFail($id)->delete();
         session()->flash('flash_success', 'Delete successful!');
     } catch (ModelNotFoundException $e) {
         session()->flash('flash_error', 'Delete failed. The category you are trying to delete cannot be found.');
     }
     return redirect('/categories');
 }
Example #6
0
 /**
  * Displays category selection for a new request.
  *
  * @param null|int|string $categoryId
  *
  * @return \Illuminate\View\View
  */
 public function start($categoryId = null)
 {
     if (is_null($categoryId)) {
         $category = $this->category;
     } else {
         $category = $this->category->findOrFail($categoryId);
     }
     $categories = $this->presenter->tableCategories($this->inquiry, $category);
     return view('pages.inquiries.start', compact('categories'));
 }
 public function delete($id)
 {
     $id = intval($id);
     $category = Category::findOrFail($id);
     if ($category->delete()) {
         return Redirect::back()->withResult('delete succeed');
     } else {
         return Redirect::back()->withResult('delete failed');
     }
 }
Example #8
0
 /**
  * Display category videos
  *
  * @param  integer $id Category ID
  * @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse
  */
 public function category($id = false)
 {
     if ($id) {
         //we got an id, display the videos
         $selected_category = \App\Models\Category::findOrFail($id);
         $videos = $selected_category->videos;
         return view('partials.videos', compact('selected_category', 'videos'));
     }
     //don't display error message yet
     return redirect('/');
 }
 /**
  * Deletes the specified category.
  *
  * @param int|string $id
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($id)
 {
     $this->authorize('categories.destroy');
     $category = $this->category->findOrFail($id);
     if ($category->delete()) {
         flash()->success('Success!', 'Successfully deleted category.');
         return redirect()->route('inquiries.categories.index');
     }
     flash()->error('Error!', 'There was an issue deleting this category. Please try again.');
     return redirect()->route('inquiries.categories.index');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(StoreCategory $request, $id)
 {
     try {
         $category = Category::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         abort(404);
     }
     $category->update($request->all());
     $category->save();
     return redirect('categories')->with('alert-success', 'Название группы товаров обновлено');
 }
Example #11
0
 public function create($category = 0)
 {
     $category = intval($category);
     if ($category > 0) {
         $category = Category::findOrFail($category);
     }
     $categories = Category::roots()->get();
     $user = Auth::user();
     $states = Location::states()->first();
     $regions = $states->children()->first();
     $locations = $regions->children;
     return view('pages.task.create', compact('category', 'categories', 'user', 'locations'));
 }
Example #12
0
 public function trendingNews($category_id = -1)
 {
     /*
      * the news most visited
      */
     if ($category_id < 0) {
         $query = News::with('category');
     } else {
         $category = Category::findOrFail($category_id);
         $query = $category->news()->with('category');
     }
     $trendingNews = $query->where('status', 'active')->orderBy('visit', 'desc')->take(2)->get();
     return $this->parseNewsList($trendingNews);
 }
Example #13
0
 public function generateLessonWords($request, $user)
 {
     // Fetch the ids of learned words to be used in querying the words that have not been learned yet
     $lessonWords = Category::findOrFail($request->category_id)->words()->userUnlearnedWords($user)->orderBy(\DB::raw('RAND()'))->take(20)->get();
     $lessonWordsToInsert = [];
     foreach ($lessonWords as $lessonWord) {
         $lessonWordsToInsert[] = ['lesson_id' => $request->lesson_id, 'word_id' => $lessonWord->id, 'created_at' => date('Y-m-d H:i:s')];
     }
     try {
         Eloquent::insert($lessonWordsToInsert);
         return true;
     } catch (\Exception $e) {
         return false;
     }
 }
Example #14
0
 public function store(Request $request)
 {
     $availableQuestions = Category::findOrFail($request->category_id)->words()->userUnlearnedWords(auth()->user())->count();
     if ($availableQuestions < 20) {
         session()->flash('flash_error', 'There are not enough words left for your exam. Please try again later.');
         return redirect()->back();
     } else {
         try {
             $lesson = auth()->user()->lessons()->create(['category_id' => $request->category_id]);
         } catch (Exception $e) {
             session()->flash('flash_error', 'Your lesson could not be generated. Please try again later.');
             return redirect()->back();
         }
         // Route to LessonWordController to generate questions
         return redirect()->action('LessonWordController@create', ['lesson_id' => $lesson->id, 'category_id' => $lesson->category_id]);
     }
 }
Example #15
0
 public function game()
 {
     //game already running
     if (!empty(session('word'))) {
         $data = session()->all();
         return view('game')->with(['alphabet' => $this->alphabet, 'blank' => implode('', $data['blank']), 'category' => $data['category'], 'mistakes' => $data['mistakes'], 'points' => $data['points']]);
     } else {
         if (empty(session('cat_id'))) {
             return redirect('/');
         }
         $category = Category::findOrFail(session('cat_id'));
         $category->load('words');
         $word = $category->words->random()->name;
         $word = preg_split('//u', $word, -1, PREG_SPLIT_NO_EMPTY);
         $answer = implode('', $word);
         $blank = array_fill(0, count($word), '_');
         $points = session('points') == 0 ? 0 : session('points');
         session(['word' => $word, 'blank' => $blank, 'mistakes' => 0, 'category' => $category->name, 'points' => $points, 'answer' => $answer]);
         return view('game')->with(['alphabet' => $this->alphabet, 'blank' => implode('', $blank), 'category' => $category->name, 'mistakes' => 0, 'points' => $points]);
     }
 }
Example #16
0
 public function search(Request $request)
 {
     if (!empty($request->input('category'))) {
         $category = Category::findOrFail($request->input('category'));
     } else {
         $category = Category::first();
     }
     switch ($request->input('status')) {
         case 1:
             $words = $category->words()->userLearnedWords(auth()->user())->selectWords()->paginate(20);
             break;
         case 2:
             $words = $category->words()->userUnlearnedWords(auth()->user())->selectWords()->paginate(20);
             break;
         default:
             // Default is all words
             $words = $category->words()->selectWords()->paginate(20);
             break;
     }
     return view('words.home', ['words' => $words, 'categories' => $category->listCategories(), 'status' => $request->input('status'), 'category_id' => $category->id]);
 }
 public function subCategory(Request $request, $category, $format = '')
 {
     if ($format == '' && $request->ajax()) {
         $format = 'json';
     }
     $category = intval($category);
     if ($category == 0) {
         $categories = Category::roots()->get();
     } else {
         $category = Category::findOrFail($category);
         $categories = $category->children;
     }
     $categoriesTranslated = [];
     foreach ($categories as $c) {
         $t = ['title' => trans('categories.' . $c['title'] . '.title'), 'url' => trans('categories.' . $c['title'] . '.url'), 'id' => $c->id, 'pid' => $c->pid];
         $categoriesTranslated[] = $t;
     }
     if ($format = 'json') {
         return $categoriesTranslated;
     }
 }
 public function associateIdCategory($category, $advertisement)
 {
     return $advertisement->category()->associate(Category::findOrFail($category));
 }
Example #19
0
 /**
  * do edit data
  * @param mixed $request
  * @param int $id
  * @return redirect
  */
 public function update(Request $request, $id)
 {
     $messages = ['cate_name.required' => 'Category name is necessary!'];
     $this->validate($request, ['cate_name' => 'required'], $messages);
     $category = Category::findOrFail($id);
     $category->update($request->all());
     return redirect(route('admin.category.index'))->with('info', 'Updated Successfully~~');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     if (Request::ajax()) {
         $result['error'] = false;
         try {
             $cate = Category::findOrFail($id);
             $cate->delete();
             $result['error'] = false;
         } catch (Exception $e) {
             $result['error'] = true;
         }
         return response()->json($result);
     }
 }
 public function show($id)
 {
     $category = Category::findOrFail($id);
     return view('admin.pages.category.show', compact('category'));
 }
Example #22
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $category = Category::findOrFail($id);
     $category->delete();
     session()->flash('flash_message', 'Data Deleted!');
     return redirect('categories');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  *
  * @return Response
  */
 public function update($id, Request $request)
 {
     $this->validate($request, ['name' => 'required', 'description' => 'required', 'parent_id' => 'required']);
     $category = Category::findOrFail($id);
     $category->update($request->all());
     Session::flash('flash_message', 'Category updated!');
     return redirect('backoffice/categories');
 }
Example #24
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     if (!auth()->check()) {
         return response('Not logged in', 403);
     }
     $user = auth()->user();
     if (!$request->ajax()) {
         return response('Invalid request', 400);
     }
     $v = Video::findOrFail($id);
     if (!$user->can('edit_video') && $user->id != $v->user_id) {
         return response('Not enough permissions', 403);
     }
     if ($request->has('interpret')) {
         $v->interpret = $request->input('interpret');
         $v->tag($request->input('interpret'));
     }
     if ($request->has('songtitle')) {
         $v->songtitle = $request->input('songtitle');
         $v->tag($request->input('songtitle'));
     }
     if ($request->has('imgsource')) {
         $v->imgsource = $request->input('imgsource');
         $v->tag($request->input('imgsource'));
     }
     if ($request->has('category')) {
         $cat = Category::findOrFail($request->input('category'));
         $v->category()->associate($cat);
         $v->tag($cat->name);
         $v->tag($cat->shortname);
     }
     $v->save();
     $log = new ModeratorLog();
     $log->user()->associate($user);
     $log->type = 'edit';
     $log->target_type = 'video';
     $log->target_id = $v->id;
     $log->save();
     return $v;
 }
Example #25
0
 /**
  * @param Advertisement $advertisement
  * @param Request $request
  * @return mixed
  */
 public function index(Advertisement $advertisement, Request $request)
 {
     $ads = $advertisement::orderBy('top', 'desc')->orderBy('id', 'desc');
     $input = \Input::all();
     if ($request->input('search')) {
         $ads = $advertisement->where('text', 'LIKE', '%' . $request->input('search') . '%')->orderBy('top', 'desc')->orderBy('id', 'desc');
     }
     if ($request->input('category_id')) {
         if ($input['category_id'] != 'null') {
             $category = Category::findOrFail(\Input::get('category_id'));
             $ads = Advertisement::with('category')->where('category_id', '=', $category->id)->orderBy('top', 'desc')->orderBy('id', 'desc');
         }
     }
     if ($request->input('city_id')) {
         if ($input['city_id'] != 'null') {
             $city = Cities::findOrFail(\Input::get('city_id'));
             $ads = Advertisement::with('city')->where('city_id', '=', $city->id)->orderBy('top', 'desc')->orderBy('id', 'desc');
         }
     }
     if ($request->input('type_id')) {
         if ($input['type_id'] != 'null') {
             $type = AdType::findOrFail(\Input::get('type_id'));
             $ads = Advertisement::with('type')->where('type_id', '=', $type->id)->orderBy('top', 'desc')->orderBy('id', 'desc');
         }
     }
     if ($request->input('category_id') && $request->input('type_id')) {
         if ($input['category_id'] != 'null' && $input['type_id'] != 'null') {
             $category = Category::findOrFail(\Input::get('category_id'));
             $type = AdType::findOrFail(\Input::get('type_id'));
             $ads = Advertisement::with('category')->with('type')->where('category_id', '=', $category->id)->where('type_id', '=', $type->id)->orderBy('top', 'desc')->orderBy('id', 'desc');
         }
     }
     if ($request->input('city_id') && $request->input('category_id')) {
         if ($input['category_id'] != 'null' && $input['city_id'] != 'null') {
             $category = Category::findOrFail(\Input::get('category_id'));
             $city = Cities::findOrFail(\Input::get('city_id'));
             $ads = Advertisement::with('city')->with('category')->where('city_id', '=', $city->id)->where('category_id', '=', $category->id)->orderBy('top', 'desc')->orderBy('id', 'desc');
         }
     }
     if ($request->input('city_id') && $request->input('type_id')) {
         if ($input['city_id'] != 'null' && $input['type_id'] != 'null') {
             $city = Cities::findOrFail(\Input::get('city_id'));
             $type = AdType::findOrFail(\Input::get('type_id'));
             $ads = Advertisement::with('city')->with('type')->where('city_id', '=', $city->id)->where('type_id', '=', $type->id)->orderBy('top', 'desc')->orderBy('id', 'desc');
         }
     }
     if ($request->input('city_id') && $request->input('category_id') && $request->input('type_id')) {
         if ($input['category_id'] != 'null' && $input['city_id'] != 'null' && $input['type_id'] != 'null') {
             $category = Category::findOrFail(\Input::get('category_id'));
             $city = Cities::findOrFail(\Input::get('city_id'));
             $type = AdType::findOrFail(\Input::get('type_id'));
             $ads = Advertisement::with('city')->with('category')->with('type')->where('city_id', '=', $city->id)->where('category_id', '=', $category->id)->where('type_id', '=', $type->id)->orderBy('top', 'desc')->orderBy('id', 'desc');
         }
     }
     if ($_SERVER['HTTP_HOST'] == env('HOST')) {
         $ads = $ads->paginate(10);
     } else {
         $ads = $ads->paginate(20);
     }
     return View::make('welcome', compact('ads'))->with('input', \Input::all());
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  *
  * @return Response
  */
 public function show($id)
 {
     $category = Category::findOrFail($id);
     return view('frontoffice.categories.show', compact('category'));
 }
Example #27
0
 /**
  *
  * @param Request $request
  * @param Item $item
  * @return Response
  */
 public function update(Request $request, Item $item)
 {
     if ($request->has('updatingNextTimeForRecurringItem')) {
         $item = $this->itemsRepository->updateNextTimeForRecurringItem($item);
     } else {
         $data = array_compare($item->toArray(), $request->only(['priority', 'urgency', 'title', 'body', 'favourite', 'pinned', 'alarm', 'not_before', 'recurring_unit', 'recurring_frequency']));
         //So the recurring unit can be removed
         if ($request->get('recurring_unit') === 'none') {
             $data['recurring_unit'] = null;
         }
         //So the not before time can be removed
         if ($request->exists('not_before') && !$request->get('not_before')) {
             $data['not_before'] = null;
         }
         //So the recurring frequency can be removed
         if ($request->get('recurring_frequency') === '') {
             $data['recurring_frequency'] = null;
         }
         //So the alarm of an item can be removed
         if ($request->has('alarm') && !$request->get('alarm')) {
             $data['alarm'] = null;
         }
         //So the urgency of an item can be removed
         if ($request->has('urgency') && !$request->get('urgency')) {
             $data['urgency'] = null;
         }
         $item->update($data);
         if ($request->has('parent_id')) {
             //So the parent_id can be removed (so the item moves to the top-most level, home)
             if ($request->get('parent_id') === 'none') {
                 $item->parent()->dissociate();
             } else {
                 $item->parent()->associate(Item::findOrFail($request->get('parent_id')));
             }
             $item->save();
         }
         if ($request->has('category_id')) {
             $item->category()->associate(Category::findOrFail($request->get('category_id')));
             $item->save();
         }
         if ($request->has('moveItem')) {
             $this->itemsRepository->moveItem($request, $item);
         }
     }
     $item = $this->transform($this->createItem($item, new ItemTransformer()))['data'];
     return response($item, Response::HTTP_OK);
 }
 /**
  * Updates category attributes from form
  *
  * @param  Request              $request
  * @param  \App\Models\Category $category
  * @return View
  */
 public function update(EditCategoryRequest $request, Category $category)
 {
     // Set and save validated attributes
     $category->name = $request->input('name');
     $category->slug = $request->input('slug');
     $category->save();
     /**
      * If parent is set and if parent_id and category->id are not equal,
      * set parent category
      */
     $parentId = $request->input('parent_id');
     if (empty(trim($parentId))) {
         $category->makeRoot();
     } else {
         $parentCategory = Category::findOrFail($parentId);
         $category->makeChildOf($parentCategory);
     }
     return redirect(route('AdminCategoryIndex'));
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id, int $id2
  * @return \Illuminate\Http\Response
  */
 public function showSub($id, $id2)
 {
     $category = Category::findOrFail($id2);
     $events = Event::where("cancelled", 0)->where('publication_date', '<', strtotime(Carbon::now()))->where('category_id', $id2)->whereHas('presentations', function ($query) {
         $query->where('starts_at', '>', time());
     })->paginate(8);
     return view('external.subcategory', ["events" => $events, "category" => $category]);
 }
Example #30
0
 /**
  * Update the specified category in storage.
  *
  * @param  int $id
  * @return Response
  */
 public function update($id)
 {
     $category = Category::findOrFail($id);
     $category->update(Request::get());
     return Redirect::route('categories.index');
 }