M6 Abschluss

This commit is contained in:
S170H
2024-01-19 18:57:43 +01:00
parent 91856073e1
commit fcba35dc00
6 changed files with 128 additions and 26 deletions

View File

@@ -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()
{

View File

@@ -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;