예제 #1
0
 public function validate_style_id()
 {
     $errors = array();
     if (!is_integer($this->style_id) || !Style::find($this->style_id)) {
         $errors[] = "style does not exist";
     }
     return $errors;
 }
예제 #2
0
 public static function show_vars(&$vars, $id)
 {
     $vars['brewery'] = Brewery::find($vars['val']->brewery_id);
     $vars['style'] = Style::find($vars['val']->style_id);
     $ratings = Rating::find_by('beer_id', $id);
     if (count($ratings) > 0) {
         $sum = 0.0;
         foreach ($ratings as $r) {
             $sum += $r->rating;
         }
         $vars['average'] = $sum / count($ratings);
     }
     $vars['ratings'] = array();
     foreach ($ratings as $k => $v) {
         $vars['ratings'][] = array('rating' => $v, 'user' => User::find($v->user_id));
     }
 }
예제 #3
0
 public function searchElement($element_name, $text = null)
 {
     $html = "";
     $elements = [];
     $db_elements = DB::table($element_name)->where('name', 'like', "%" . $text . "%")->get();
     foreach ($db_elements as $db_element) {
         switch ($element_name) {
             case "beer":
                 $elements[] = Beer::find($db_element->id);
                 break;
             case "brewer":
                 $elements[] = Brewer::find($db_element->id);
                 break;
             case "locality":
                 $elements[] = Locality::find($db_element->id);
                 break;
             case "style":
                 $elements[] = Style::find($db_element->id);
                 break;
         }
     }
     foreach ($elements as $element) {
         $html .= '<li class="list-group-item clearfix">';
         if ($element_name == "locality" && $element->flag()) {
             $html .= '<img src="' . $element->flag()->path . '" style="height:15px">&nbsp;';
         } elseif ($element_name == "brewer" && $element->logo()) {
             $html .= '<img src="' . $element->logo()->path . '" style="height:15px">&nbsp;';
         }
         $html .= '<span>' . $element->name . '</span>' . '<div class="btn-group pull-right">';
         if ($element_name == "brewer" || $element_name == "beer") {
             $html .= '<a href="' . URL::to('/dashboard/' . $element_name . 's/edit/' . $element->id) . '">';
         }
         $html .= '<button type="button" class="btn btn-info" ';
         if ($element_name != "brewer" && $element_name == "beer") {
             $html .= 'onclick="editElement(' . $element->id . ')"';
         }
         $html .= '>Edit</button>';
         if ($element_name == "brewer" || $element_name == "beer") {
             $html .= '</a>';
         }
         $html .= '<a href="' . URL::to('/dashboard/' . $element_name . 's/delete/' . $element->id) . '"><button type="button" class="btn btn-danger">Delete</button></a>';
         $html .= '</div></li>';
     }
     return Response::json(['html' => $html]);
 }
예제 #4
0
 /**
  * Show the form for editing the specified style.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $style = Style::find($id);
     return View::make('styles.edit', compact('style'));
 }
예제 #5
0
 /**
  * Store a newly created resource in storage.
  * POST /beer
  *
  * @return Response
  */
 public function store()
 {
     if (Input::get('beer_id')) {
         $beer = Beer::find(Input::get('beer_id'));
         echo "already in db beer";
     } else {
         $beer = new Beer();
         echo "new beer!";
     }
     $brewers = [];
     for ($i = 1; $i <= Input::get('brewer-count'); $i++) {
         $brewer = Brewer::find(Input::get('brewer-' . $i . '_id'));
         if (!$brewer) {
             return Redirect::back()->withInput()->withMessage('Invalid Brewer ' . $i);
         }
         $brewers[] = $brewer->id;
     }
     $style = Style::find(Input::get('style_id'));
     if (!$style) {
         return Redirect::back()->withInput()->withMessage('Invalid Style');
     }
     $beer->name = Input::get('name');
     //$beer->brewer_id = $brewer->id;
     $beer->style_id = $style->id;
     $beer->ratebeer = Input::get('ratebeer_url');
     $beer->beeradvocate = Input::get('beeradvocate_url');
     $beer->album = Input::get('album');
     $beer->page = Input::get('page');
     $beer->position = Input::get('position');
     $beer->save();
     $beer->brewer()->sync($brewers);
     for ($i = 1; $i <= Input::get('sticker-count'); $i++) {
         if (Input::hasFile('sticker-' . $i)) {
             $f = Input::file('sticker-' . $i);
             //Change the image name: s<number_of_service>-<filename>.
             $filename = 'beerr-' . $beer->id . '-' . $f->getClientOriginalName();
             //Move it to our public folder
             $f->move(public_path() . '/upload/', $filename);
             //This is the path to show it on the web
             $complete_path = '/upload/' . $filename;
             //create the gallery
             $image = array('path' => $complete_path, 'brewer_id' => NULL, 'beer_id' => $beer->id);
             $img = Image::create($image);
             if (Input::get('sticker-' . $i . '_id') != null) {
                 $sticker = Sticker::find(Input::get('sticker-' . $i . '_id'));
                 $sticker->img_id = $img->id;
                 $sticker->type = "front";
                 //Input::get('sticker-'.$i.'_type');
                 $sticker->save();
             } else {
                 $sticker = Sticker::create(['beer_id' => $beer->id, 'image_id' => $img->id, 'type' => "front"]);
             }
             echo "Sticker created " . $sticker->id;
         } else {
             if (Input::file('sticker-' . $i)->isValid()) {
                 echo "IS F****N VALID";
             } else {
                 echo "IS F****N INVALID";
             }
             echo 'sticker-' . $i . " has no file";
             echo "<pre>" . print_r(Input::all(), 1) . "</pre>";
             exit;
         }
     }
     return Redirect::to('dashboard/beers');
 }
예제 #6
0
 /**
  * Deletes the speified style
  * @param $id
  * @return mixed
  */
 public function deleteStyle($id)
 {
     Style::find($id)->delete();
     return Redirect::back();
 }