diff --git a/M6/emensa/config/db.php b/M6/emensa/config/db.php index 636415f..3d013ac 100644 --- a/M6/emensa/config/db.php +++ b/M6/emensa/config/db.php @@ -2,7 +2,7 @@ return [ 'host' => 'localhost', // 'localhost' or '127.0.0.1' 'user' => 'root', // '' - 'password' => 'admin', // '' + 'password' => 'wm#32', // '' 'database' => 'emensawerbeseite', // optionally: set port below if it differs from the default 3306 // 'port' => 13306 // !! this is not your webserver port, but the mariadb port diff --git a/M6/emensamobile/app/Http/Controllers/MainController.php b/M6/emensamobile/app/Http/Controllers/MainController.php index 7954615..811e913 100644 --- a/M6/emensamobile/app/Http/Controllers/MainController.php +++ b/M6/emensamobile/app/Http/Controllers/MainController.php @@ -54,6 +54,20 @@ class MainController extends BaseController if ($data["gerichtid"] != null) { + $gericht = Gerichte::query()->find($data["gerichtid"]); + $gerichtName = $gericht->getGerichtName(); + $bildname = $gericht->getBildname(); + + + return view('main.bewertung', [ + "gerichtName" => $gerichtName, + "bildname" => $bildname, + "data" => $data, + 'url' => 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}" + ]); + + + /* $gericht = new Gerichte(); $g = $gericht->db_gericht_bewertung($data["gerichtid"]); @@ -62,6 +76,7 @@ class MainController extends BaseController "data" => $data, 'url' => 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}" ]); + */ } if($data["hervorheben"]!=null){ @@ -97,10 +112,16 @@ class MainController extends BaseController $bemerkung = $data["bemerkung"] ?? NULL; $benutzer = session("benutzer_id",0); + bewertungen::query()->firstOrCreate( + [ + 'ersteller_id' => $benutzer, + 'gericht_id' => $id, + 'bemerkung' => $bemerkung, + 'sterne' => $sterne + ] + ); $b = new bewertungen(); - $check = $b->bewerten($benutzer,$id,$sterne, $bemerkung); - $bewertungen = $b->bewertungen(); return redirect('/bewertung'); } @@ -117,20 +138,20 @@ class MainController extends BaseController ]); } - $b = new bewertungen(); if($rd->isMethod("get")) { $data = $rd; if ($data["loschen"] != null) { - $check = $b->loschen($data["loschen"]); + + bewertungen::destroy($data["loschen"]); + //$b->delete(); return redirect('/meinebewertungen'); } } - - + $b = new bewertungen(); $meine = $b->meine_bewertungen($benutzer_id); return view('main.meine_bewertungen', [ diff --git a/M6/emensamobile/app/Models/Gerichte.php b/M6/emensamobile/app/Models/Gerichte.php index 4727259..0da2235 100644 --- a/M6/emensamobile/app/Models/Gerichte.php +++ b/M6/emensamobile/app/Models/Gerichte.php @@ -11,9 +11,67 @@ use Illuminate\Support\Facades\Session; class Gerichte extends Model { + protected $table = 'gericht'; + protected $primaryKey = 'id'; + public $incrementing = true; use HasFactory; + function getPreisIntern(){ + return $this->formatPreis($this->attributes['preisintern']); + } + + function getPreisExtern(){ + return $this->formatPreis($this->attributes['preisextern']); + } + + private function formatPreis($unformatted){ + return number_format($unformatted, 2, ','); + } + + function getBildname(){ + return $this->attributes['bildname']; + } + + function getGerichtName(){ + return $this->attributes['name']; + } + + function setVegetarischAttribut($value){ + if ($value == 1 || $value == 0){ + $this->attributes['vegetarisch'] = $value; + return; + } + + $parsed = $this->parse_wahrheitswert($value) ; + $this->attributes['vegetarisch'] = $parsed; + } + + function setVeganAttribut($value){ + if ($value == 1 || $value == 0){ + $this->attributes['vegan'] = $value; + return; + } + + $parsed = $this->parse_wahrheitswert($value) ; + $this->attributes['vegetarisch'] = $parsed; + } + + private function parse_wahrheitswert($value){ + $value = strtolower(str_replace(" ", "", $value)); + + if ($value == "yes" || $value == "ja"){ + return 1; + } + elseif ($value == "no" || $value == "nein"){ + return 0; + } + else{ + trigger_error("Could not parse value"); + } + // Wenn versucht wird das in die Datenbank zu schreiben sollte es eine Fehlermeldung geben + } + function db_gericht_select_karte() { diff --git a/M6/emensamobile/app/Models/bewertungen.php b/M6/emensamobile/app/Models/bewertungen.php index f28e3e0..ebf66bc 100644 --- a/M6/emensamobile/app/Models/bewertungen.php +++ b/M6/emensamobile/app/Models/bewertungen.php @@ -10,6 +10,21 @@ use Illuminate\Support\Facades\Session; class bewertungen extends Model { + protected $table = 'bewertungen'; + protected $primaryKey = 'id'; + public $incrementing = true; + protected $attributes = [ + 'hervorgehoben' => 0 + ]; + public $fillable = [ + 'ersteller_id', + 'gericht_id', + 'bemerkung', + 'sterne', + 'hervorgehoben' + ]; + + public $timestamps = false; use HasFactory; function bewerten(int $ersteller, int $gericht, int $sterne, string $bemerkung){ @@ -77,8 +92,13 @@ class bewertungen extends Model return 0; } - $sql = "UPDATE bewertungen SET hervorgehoben =1 WHERE id =" .$id; - DB::update($sql); + $this->query()->updateOrCreate( + ['id'=>$id], + ['hervorgehoben' => 1] + ); + + // $sql = "UPDATE bewertungen SET hervorgehoben =1 WHERE id =" .$id; + // DB::update($sql); return 1; @@ -90,8 +110,13 @@ class bewertungen extends Model return 0; } - $sql = "UPDATE bewertungen SET hervorgehoben =0 WHERE id =" .$id; - DB::update($sql); + $this->query()->updateOrCreate( + ['id'=>$id], + ['hervorgehoben' => 0] + ); + + // $sql = "UPDATE bewertungen SET hervorgehoben =0 WHERE id =" .$id; + // DB::update($sql); return 1; diff --git a/M6/emensamobile/resources/views/main/bewertung.blade.php b/M6/emensamobile/resources/views/main/bewertung.blade.php index 46f2b3e..ef87737 100644 --- a/M6/emensamobile/resources/views/main/bewertung.blade.php +++ b/M6/emensamobile/resources/views/main/bewertung.blade.php @@ -39,11 +39,8 @@ @if(isset($admin)) @endif - @if(isset($gericht)) + @if(isset($gerichtName, $bildname)) bildname; if ($bildname == Null) { $bildname = "00_image_missing.jpg"; @@ -53,15 +50,15 @@ ?> -
-
+
+
-
-
- Bild vom Gericht -
-
-

{{$gericht->name}}

+
+
+ Bild vom Gericht +
+
+

{{$gerichtName}}

diff --git a/M6/emensamobile/resources/views/main/index.blade.php b/M6/emensamobile/resources/views/main/index.blade.php index a544c54..81821e4 100644 --- a/M6/emensamobile/resources/views/main/index.blade.php +++ b/M6/emensamobile/resources/views/main/index.blade.php @@ -76,10 +76,11 @@ foreach ($result_sql_gerichte as $row_gerichte) { - $preisintern = number_format($row_gerichte->preisintern, 2, ',', '.'); - $preisextern = number_format($row_gerichte->preisextern, 2, ',', '.'); + $gericht = App\Models\Gerichte::query()->find($row_gerichte->id); + $preisintern = $gericht->getPreisIntern(); + $preisextern = $gericht->getPreisExtern(); - $bildname = $row_gerichte->bildname; + $bildname = $gericht->getBildname(); if ($bildname == Null) { $bildname = "00_image_missing.jpg";