private static function transformUpdate($out = NULL) { $returnOut = []; $linkeSpalte = []; $rechteSpalte = []; for ($i = 0; $i < count(Hersteller::getNames()); $i++) { array_push($linkeSpalte, Hersteller::getNames()[$i]); } if ($out !== NULL) { array_push($linkeSpalte, HTML::buildInput('hidden', 'id', $out->getId())); } else { array_push($linkeSpalte, ''); } if ($out !== NULL) { $dbWerte = json_decode(json_encode($out), true); } // überführe $dbWerte in rechte Spalte if ($out !== NULL) { $rechteSpalte[0] = HTML::buildInput('text', 'hersteller', $dbWerte['name'], NULL, 'name'); array_push($rechteSpalte, HTML::buildButton('OK', 'ok', 'updateHersteller', 'OK')); } else { $rechteSpalte[0] = HTML::buildInput('text', 'hersteller', '', NULL, 'name'); array_push($rechteSpalte, HTML::buildButton('OK', 'ok', 'insertHersteller', 'OK')); } $returnOut = HTML::buildFormularTable($linkeSpalte, $rechteSpalte); return $returnOut; }
public static function getById($id) { $pdo = DbConnect::connect(); $sql = "SELECT * from auto WHERE id=:id"; $stmt = $pdo->prepare($sql); $stmt->execute([':id' => $id]); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); return new Auto($rows[0]['name'], Hersteller::getById($rows[0]['hersteller_id']), $rows[0]['kennzeichen'], $rows[0]['id']); }
private static function transformUpdate($out = NULL) { $returnOut = []; $linkeSpalte = []; $rechteSpalte = []; for ($i = 0; $i < count(Auto::getNames()); $i++) { array_push($linkeSpalte, Auto::getNames()[$i]); } if ($out !== NULL) { array_push($linkeSpalte, HTML::buildInput('hidden', 'id', $out->getId())); } else { array_push($linkeSpalte, ''); } if ($out !== NULL) { $dbWerte = json_decode(json_encode($out), true); } // überführe $dbWerte in rechte Spalte // hersteller $options ertellen $options = []; $herst = Hersteller::getAll(); foreach ($herst as $hersteller) { $option = []; $option['value'] = $hersteller->getId(); $option['label'] = $hersteller->getName(); $options[$hersteller->getId()] = $option; if ($out !== NULL) { if ($out->getHersteller()->getId() == $hersteller->getId()) { $options[$hersteller->getId()]['selected'] = TRUE; } } } if ($out !== NULL) { array_push($rechteSpalte, HTML::buildDropDown('herstellerName', '1', $options, NULL, 'hersteller')); array_push($rechteSpalte, HTML::buildInput('text', 'autoName', $dbWerte['name'], NULL, 'autoName')); array_push($rechteSpalte, HTML::buildInput('text', 'kennzeichen', $dbWerte['kennzeichen'], NULL, 'kennzeichen')); array_push($rechteSpalte, HTML::buildButton('OK', 'ok', 'updateAuto', 'OK')); } else { array_push($rechteSpalte, HTML::buildDropDown('herstellerName', '1', $options, NULL, 'hersteller')); array_push($rechteSpalte, HTML::buildInput('text', 'autoName', '', NUll, 'autoName')); array_push($rechteSpalte, HTML::buildInput('text', 'kennzeichen', '', NULL, 'kennzeichen')); array_push($rechteSpalte, HTML::buildButton('OK', 'ok', 'insertAuto', 'OK')); } $returnOut = HTML::buildFormularTable($linkeSpalte, $rechteSpalte); return $returnOut; }
public static function doAction($action, $id) { switch ($action) { case 'showList': $out = Auto::getAll(); $out = self::transform($out); break; case 'showUpdate': $out = Auto::getById($id); $out = self::transformUpdate($out); break; case 'showInsert': $out = self::transformUpdate(); break; case 'update': $autoFiltered = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_MAGIC_QUOTES & FILTER_SANITIZE_SPECIAL_CHARS); $hersteller_idFiltered = filter_input(INPUT_POST, 'hersteller_id', FILTER_SANITIZE_MAGIC_QUOTES & FILTER_SANITIZE_SPECIAL_CHARS); $kennzeichenFiltered = filter_input(INPUT_POST, 'kennzeichen', FILTER_SANITIZE_MAGIC_QUOTES & FILTER_SANITIZE_SPECIAL_CHARS); $updateautoidFiltered = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT & FILTER_SANITIZE_SPECIAL_CHARS); $out = new Auto($autoFiltered, Hersteller::getById($hersteller_idFiltered), $kennzeichenFiltered, $updateautoidFiltered); $out = Auto::update($out); $out = Auto::getAll(); $out = self::transform($out); break; case 'insert': $autoFiltered = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_MAGIC_QUOTES & FILTER_SANITIZE_SPECIAL_CHARS); $hersteller_idFiltered = filter_input(INPUT_POST, 'hersteller_id', FILTER_SANITIZE_MAGIC_QUOTES & FILTER_SANITIZE_SPECIAL_CHARS); $kennzeichenFiltered = filter_input(INPUT_POST, 'kennzeichen', FILTER_SANITIZE_MAGIC_QUOTES & FILTER_SANITIZE_SPECIAL_CHARS); $out = new Auto($autoFiltered, Hersteller::getById($hersteller_idFiltered), $kennzeichenFiltered, NULL); $out = Auto::insert($out); $out = Auto::getAll(); $out = self::transform($out); break; case 'delete': $deleteautoidFiltered = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT & FILTER_SANITIZE_SPECIAL_CHARS); $out = $deleteautoidFiltered; $out = Auto::delete($out); $out = Auto::getAll(); $out = self::transform($out); break; default: break; } return $out; }