Files
DBWT/M6/emensamobile/app/Models/Gericht.php
2024-01-19 16:59:27 +01:00

70 lines
1.8 KiB
PHP

<?php
namespace App\Models;
use Exception;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class Gericht extends Model {
protected $table = 'gericht';
protected $primaryKey = 'id';
public $incrementing = true;
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
}
}