Update of exercises
parent
29d5d9cf5d
commit
84f5411563
|
@ -1,6 +1,6 @@
|
|||
# Filmdatenbank mit PHP
|
||||
|
||||
📆 **Fällig: 10.12.2023** 📆
|
||||
📆 **Fällig: 10.12.2023** 📆 [Musterlösung](solution/)
|
||||
|
||||
Ziel dieser Übung ist es, die Filmdatenbank aus der letzten Übung in einer reinen PHP-Variante zu erstellen. Dies bedeutet, dass kein clientseitiges Skripting zum Einsatz kommt, sondern nur HTML, CSS und PHP. Auf JavaScript sollen Sie bewusst verzichten, um später die beiden Optionen vergleichen zu können.
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
class Film {
|
||||
public string $titel;
|
||||
public string $regisseur;
|
||||
public int $produktionsjahr;
|
||||
public int $laufzeit;
|
||||
public int $altersfreigabe;
|
||||
|
||||
function __construct(string $titel, string $regisseur,
|
||||
int $produktionsjahr, int $laufzeit, int $altersfreigabe) {
|
||||
$this->altersfreigabe = $altersfreigabe;
|
||||
$this->laufzeit = $laufzeit;
|
||||
$this->produktionsjahr = $produktionsjahr;
|
||||
$this->regisseur = $regisseur;
|
||||
$this->titel = $titel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $other Film
|
||||
* @return bool
|
||||
*/
|
||||
function equals(Film $other) : bool {
|
||||
if (gettype($other) != gettype($this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $other->titel == $this->titel
|
||||
&& $other->regisseur == $this->regisseur
|
||||
&& $other->produktionsjahr == $this->produktionsjahr
|
||||
&& $other->laufzeit == $this->laufzeit
|
||||
&& $other->altersfreigabe == $this->altersfreigabe;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,164 @@
|
|||
<?php
|
||||
require_once("Film.php");
|
||||
|
||||
session_start();
|
||||
|
||||
if (isset($_REQUEST["reset"])) {
|
||||
unset($_SESSION["filme"]);
|
||||
unset($_SESSION["sort"]);
|
||||
}
|
||||
|
||||
$lieblingsfilme = $_SESSION["filme"];
|
||||
|
||||
if (!isset($lieblingsfilme)) {
|
||||
$lieblingsfilme = [
|
||||
new Film("Pulp Fiction", "Quentin Tarantino", 1994, 148, 16),
|
||||
new Film("Inglourious Basterds", "Quentin Tarantino", 2009, 148, 16),
|
||||
new Film("Reservoir Dogs", "Quentin Tarantino", 1992, 100, 18),
|
||||
new Film("Blade Runner", "Ridley Scott", 1982, 117, 16) ];
|
||||
$_SESSION["filme"] = $lieblingsfilme;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST["delete"])) {
|
||||
$index = $_REQUEST["delete"];
|
||||
array_splice($lieblingsfilme, $index, 1);
|
||||
$_SESSION["filme"] = $lieblingsfilme;
|
||||
}
|
||||
elseif (isset($_REQUEST["save"])) {
|
||||
$film = new Film(
|
||||
$_REQUEST["titel"],
|
||||
$_REQUEST["regisseur"],
|
||||
(int) $_REQUEST["jahr"],
|
||||
(int) $_REQUEST["spielzeit"],
|
||||
(int) $_REQUEST["fsk"]);
|
||||
$lieblingsfilme[] = $film;
|
||||
$_SESSION["filme"] = $lieblingsfilme;
|
||||
}
|
||||
elseif (isset($_REQUEST["sort"])) {
|
||||
$kriterium = $_REQUEST["sort"];
|
||||
$_SESSION["sort"] = $kriterium;
|
||||
}
|
||||
|
||||
if (!isset($kriterium)) {
|
||||
$kriterium = $_SESSION["sort"];
|
||||
|
||||
if (!isset($kriterium)) {
|
||||
$kriterium = "titel";
|
||||
$_SESSION["sort"] = $kriterium;
|
||||
|
||||
}
|
||||
}
|
||||
uasort($lieblingsfilme, 'cmp');
|
||||
$_SESSION["filme"] = $lieblingsfilme;
|
||||
|
||||
function cmp($a, $b) {
|
||||
|
||||
global $kriterium;
|
||||
|
||||
if ($a->equals($b)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($kriterium == 'titel') {
|
||||
return $a->titel > $b->titel ? 1 : -1;
|
||||
}
|
||||
elseif ($kriterium == 'regisseur') {
|
||||
return $a->regisseur > $b->regisseur ? 1 : -1;
|
||||
}
|
||||
elseif ($kriterium == 'jahr') {
|
||||
return $a->produktionsjahr > $b->produktionsjahr ? 1 : -1;
|
||||
}
|
||||
elseif ($kriterium == 'spielzeit') {
|
||||
return $a->laufzeit > $b->laufzeit ? 1 : -1;
|
||||
}
|
||||
elseif ($kriterium == 'fsk') {
|
||||
return $a->altersfreigabe > $b->altersfreigabe ? 1 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
function showTable($filme) {
|
||||
|
||||
print('<table id="filmtable">' . "\n");
|
||||
print('<tr>' . "\n");
|
||||
print('<th>#</th>' . "\n");
|
||||
print('<th><button name="sort" value="titel">Titel</button></th>' . "\n");
|
||||
print('<th><button name="sort" value="regisseur">Regisseur</button></th>' . "\n");
|
||||
print('<th><button name="sort" value="jahr">Jahr</button></th>' . "\n");
|
||||
print('<th><button name="sort" value="spielzeit">Spielzeit</button></th>' . "\n");
|
||||
print('<th><button name="sort" value="fsk">FSK</button></th>' . "\n");
|
||||
print('<th> </th>' . "\n");
|
||||
print('</tr>' . "\n");
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach ($filme as $film) {
|
||||
$count = $i + 1;
|
||||
print("<tr><td>$count</td>" . "\n");
|
||||
print("<td>$film->titel</td>" . "\n");
|
||||
print("<td>$film->regisseur</td>" . "\n");
|
||||
print("<td>$film->produktionsjahr</td>" . "\n");
|
||||
print("<td>$film->laufzeit</td>" . "\n");
|
||||
print("<td>$film->altersfreigabe</td>" . "\n");
|
||||
print("<td><button name='delete' value='$i'>Löschen</button></td>" . "\n");
|
||||
print("</tr>");
|
||||
$i++;
|
||||
}
|
||||
print('</table>');
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
||||
<title>Filmdatenbank</title>
|
||||
<meta charset="UTF-8">
|
||||
<style>
|
||||
table, td, tr, th {
|
||||
border: 1px solid;
|
||||
border-color: #d3d3d3;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Filmdatenbank</h1>
|
||||
|
||||
<form method="POST">
|
||||
|
||||
<?php
|
||||
showTable($lieblingsfilme);
|
||||
?>
|
||||
|
||||
<h2>Eingabe eines neuen Films</h2>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Titel</th>
|
||||
<td><input type="text" name="titel"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Regisseur</th>
|
||||
<td><input type="text" name="regisseur"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Jahr</th>
|
||||
<td><input type="text" size="4" name="jahr"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Spielzeit</th>
|
||||
<td><input type="text" size="4" name="spielzeit"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>FSK</th>
|
||||
<td><input type="text" size="2" name="fsk"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<button type="submit" name="save">Speichern</button>
|
||||
<br>
|
||||
<br>
|
||||
<button type="submit" name="reset">Session löschen</button>
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -16,5 +16,5 @@ Hier finden Sie die wöchentlichen Assignments für die Vorlesung Webbasierte Sy
|
|||
| 2. | 16.10.2023 | [Styling der Fanseite mit CSS](Assignment_002/readme.md) | **22.10.2023** | |
|
||||
| 3. | 23.10.2023 | [Fanseite responsive machen](Assignment_003/readme.md) | **05.11.2023** | |
|
||||
| 4. | 06.11.2023 | [Interaktive Filmdatenbank](Assignment_004/readme.md) | **19.11.2023** | [✅](Assignment_004/solution/) |
|
||||
| 5. | 27.11.2023 | [Filmdatenbank mit PHP](Assignment_005/readme.md) | **10.12.2023** | |
|
||||
| 5. | 27.11.2023 | [Filmdatenbank mit PHP](Assignment_005/readme.md) | **10.12.2023** | [✅](Assignment_005/solution/) |
|
||||
| 6. | 11.12.2023 | [Filmdatenbank mit PHP und Twig](Assignment_006/readme.md) | **17.12.2023** | |
|
||||
|
|
Loading…
Reference in New Issue