Ejemplo n.º 1
0
 /**
  * Store a newly created resource in storage.
  * POST /brewer
  *
  * @return Response
  */
 public function store()
 {
     if (Input::get('brewer_id')) {
         $brewer = Brewer::find(Input::get('brewer_id'));
     } else {
         $brewer = new Brewer();
     }
     $locality = Locality::find(Input::get('locality_id'));
     if (!$locality) {
         return Redirect::back()->withInput()->withMessage('Invalid Locality');
     }
     $brewer->name = Input::get('name');
     $brewer->url = Input::get('url');
     $brewer->locality_id = $locality->id;
     $brewer->save();
     if (Input::hasFile('logo')) {
         $f = Input::file('logo');
         //Change the image name: s<number_of_service>-<filename>.
         $filename = 'brewer-' . $brewer->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' => $brewer->id, 'beer_id' => NULL);
         if ($brewer->logoUrl()) {
             $brewer->logo()->fill($image)->save();
         } else {
             Image::create($image);
         }
     }
     return Redirect::to('/dashboard/brewers');
 }
Ejemplo n.º 2
0
 /**
  * returns the locality name including hierarchy
  * @return String
  */
 public function completeName()
 {
     $name = $this->name;
     if ($this->locality_id != null) {
         $name .= ", " . Locality::find($this->locality_id)->completeName();
     }
     return $name;
 }
Ejemplo n.º 3
0
 /**
  * Deletes the speified style
  * @param $id
  * @return mixed
  */
 public function deleteLocality($id)
 {
     if (!count(Locality::where('locality_id', $id))) {
         Locality::find($id)->delete();
         return Redirect::back()->withMessage('Locality deleted correctly');
     } else {
         return Redirect::back()->withMessage("Locality can't be deleted. Delete the child localities first");
     }
 }
Ejemplo n.º 4
0
 /**
  * return the country Locality Model Object of this brewer
  */
 public function country()
 {
     $locality = $this->locality;
     if (!$locality || $locality->type == "continent") {
         return null;
     }
     while ($locality->type != "country") {
         $locality = Locality::find($locality->locality_id);
     }
     return $locality;
 }
Ejemplo n.º 5
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]);
 }