Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class BannersController extends BaseController {
- /**
- * Banner Repository
- *
- * @var Banner
- */
- protected $banner;
- public function __construct(Banner $banner) {
- $this->banner = $banner;
- }
- /**
- * Display a listing of the resource.
- *
- * @return Response
- */
- public function index() {
- $banners = $this->banner->all();
- return View::make('banners.index', compact('banners'));
- }
- /**
- * Show the form for creating a new resource.
- *
- * @return Response
- */
- public function create() {
- $sectionList = Section::getList();
- $banner = new Banner;
- return View::make('banners.create')->with(compact('sectionList', 'banner'));
- }
- /**
- * Store a newly created resource in storage.
- *
- * @return Response
- */
- public function store() {
- $input = array_except(Input::all(), array('_method', 'q'));
- $destinationPath = '/tmp';
- if (Input::hasFile('image')) {
- $extension = Input::file('image')->getClientOriginalExtension();
- $name = Input::file('image')->getClientOriginalName();
- $fileName = $name; //.'.'.$extension;
- Input::file('image')->move($destinationPath, $fileName);
- $input['image'] = $destinationPath . DIRECTORY_SEPARATOR . $fileName;
- } else {
- }
- if (empty($input['current'])) {
- $input['current'] = 0;
- }
- $validation = Validator::make($input, Banner::$rules);
- if ($validation->passes()) {
- $this->banner->create($input);
- return Redirect::route('banners.index');
- }
- return Redirect::route('banners.create')
- ->withInput()
- ->withErrors($validation)
- ->with('message', 'There were validation errors.');
- }
- /**
- * Display the specified resource.
- *
- * @param int $id
- * @return Response
- */
- public function show($id) {
- $banner = $this->banner->findOrFail($id);
- return View::make('banners.show', compact('banner'));
- }
- /**
- * Show the form for editing the specified resource.
- *
- * @param int $id
- * @return Response
- */
- public function edit($id) {
- $banner = $this->banner->find($id);
- if (is_null($banner)) {
- return Redirect::route('banners.index');
- }
- $sectionList = Section::getList();
- return View::make('banners.edit', compact('banner', 'sectionList'));
- }
- /**
- * Update the specified resource in storage.
- *
- * @param int $id
- * @return Response
- */
- public function update($id) {
- $input = array_except(Input::all(), array('_method', 'q'));
- $destinationPath = '/tmp';
- if (Input::hasFile('image')) {
- $extension = Input::file('image')->getClientOriginalExtension();
- $name = Input::file('image')->getClientOriginalName();
- $fileName = $name; //.'.'.$extension;
- Input::file('image')->move($destinationPath, $fileName);
- $input['image'] = $destinationPath . DIRECTORY_SEPARATOR . $fileName;
- } else {
- unset($input['image']);
- }
- if (empty($input['current'])) {
- $input['current'] = 0;
- }
- $validation = Validator::make($input, Banner::$rules);
- if ($validation->passes()) {
- $banner = $this->banner->find($id);
- $banner->update($input);
- return Redirect::route('banners.show', $id);
- }
- return Redirect::route('banners.edit', $id)
- ->withInput()
- ->withErrors($validation)
- ->with('message', 'There were validation errors.');
- }
- /**
- * Remove the specified resource from storage.
- *
- * @param int $id
- * @return Response
- */
- public function destroy($id) {
- $this->banner->find($id)->delete();
- return Redirect::route('banners.index');
- }
- // otros
- /**
- * Show the report for the specified resource.
- *
- * @param int $id
- * @return Response
- */
- public function report($id, $month = null, $year = null) {
- if (is_null($month)) {
- $month = date('m');
- }
- if (is_null($year)) {
- $year = date('Y');
- }
- $banner = $this->banner->find($id);
- if (is_null($banner)) {
- return Redirect::route('banners.index');
- }
- return View::make('banners.report', compact('banner', 'month', 'year'));
- }
- /**
- * Actualizar los banners según el día y la fecha que tengan
- */
- public function getUpdate() {
- $banners = Banner::all();
- foreach ($banners as $banner) {
- $banner->current = $banner->isCurrent();
- $banner->save();
- }
- $banners = Banner::all();
- Session::flash('message', 'Banners actualizados!');
- return Redirect::route('banners.index');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement