M6 Nr3 4)-6)
This commit is contained in:
65
M6/emensamobile/app/Models/Gericht.php
Normal file
65
M6/emensamobile/app/Models/Gericht.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?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 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
|
||||
}
|
||||
}
|
||||
@@ -9,14 +9,9 @@ use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
|
||||
class Gerichte extends Model
|
||||
{
|
||||
class Gerichte extends Model {
|
||||
use HasFactory;
|
||||
|
||||
|
||||
|
||||
function db_gericht_select_karte()
|
||||
{
|
||||
function db_gericht_select_karte(){
|
||||
try {
|
||||
|
||||
$sql_gerichte = "SELECT * FROM gericht ORDER BY RAND() LIMIT 5";
|
||||
|
||||
@@ -50,7 +50,7 @@ return [
|
||||
'port' => env('DB_PORT', '3306'),
|
||||
'database' => env('DB_DATABASE', 'emensawerbeseite'),
|
||||
'username' => env('DB_USERNAME', 'root'),
|
||||
'password' => env('DB_PASSWORD', 'admin'),
|
||||
'password' => env('DB_PASSWORD', 'wm#32'),
|
||||
'unix_socket' => env('DB_SOCKET', ''),
|
||||
'charset' => 'utf8mb4',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
@extends("layouts.main_layout", ['title' => "E-Mensa"])
|
||||
<?php use Illuminate\Support\Facades\Session; ?>
|
||||
<?php
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
?>
|
||||
|
||||
@section("header")
|
||||
<link rel="stylesheet" href="/css/style.css">
|
||||
@@ -48,7 +51,6 @@
|
||||
|
||||
@section("gerichte")
|
||||
|
||||
|
||||
@if (isset($data['error']))
|
||||
<h1>Es gab ein Problem mit der Datenbankverbindung</h1>
|
||||
<p>Fehlermeldung</p>
|
||||
@@ -68,11 +70,15 @@
|
||||
|
||||
|
||||
foreach ($result_sql_gerichte as $row_gerichte) {
|
||||
$gericht = \App\Models\Gericht::query()->find($row_gerichte->id);
|
||||
$preisintern = $gericht->getPreisIntern();
|
||||
$preisextern = $gericht->getPreisExtern();
|
||||
$bildname = $gericht->getBildname();
|
||||
|
||||
$preisintern = number_format($row_gerichte->preisintern, 2, ',', '.');
|
||||
$preisextern = number_format($row_gerichte->preisextern, 2, ',', '.');
|
||||
// $preisintern = number_format($row_gerichte->preisintern, 2, ',', '.');
|
||||
// $preisextern = number_format($row_gerichte->preisextern, 2, ',', '.');
|
||||
// $bildname = $row_gerichte->bildname;
|
||||
|
||||
$bildname = $row_gerichte->bildname;
|
||||
|
||||
if ($bildname == Null) {
|
||||
$bildname = "00_image_missing.jpg";
|
||||
|
||||
Reference in New Issue
Block a user