lollipop

A PHP-framework
Log | Files | Refs

commit 294b50809b4783c9a62ab922e319040ae7ac1334
parent 2f644893700f9ff0eb356f8115ec35f3e2f0c790
Author: Friedel Schön <[email protected]>
Date:   Sun, 25 Jun 2023 21:36:50 +0200

Merge branch 'master' of https://github.com/friedelschoen/lollipop

Diffstat:
MLollipop/DatabaseObject.php | 14+++++++-------
MLollipop/Router.php | 4++--
MLollipop/SQLDatabase.php | 2+-
MLollipop/Utils.php | 4++--
Mrouting/user.php | 9++++++++-
5 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/Lollipop/DatabaseObject.php b/Lollipop/DatabaseObject.php @@ -26,7 +26,7 @@ namespace Lollipop { abstract public static function get_primary(): string; abstract public static function get_table(): string; abstract public static function get_schema(): string; - + /// setData is to bulk-set the row instead of one-for-one public function setData($data) { @@ -73,7 +73,7 @@ namespace Lollipop { $this->data = $result->fetch_assoc(); return true; } - + /// select row by id (and key is $this->primary_key()) public function load(string $id): bool { @@ -160,7 +160,7 @@ namespace Lollipop { return false; } } - + /// deletes the row public function delete() { @@ -215,7 +215,7 @@ namespace Lollipop { } return $col_names; } - + /// get column names of table public function get_column_names(): array { @@ -236,7 +236,7 @@ namespace Lollipop { } return $column_names; } - + /// get column names without auto-increments public function get_col_names_no_ai(): array { @@ -258,7 +258,7 @@ namespace Lollipop { } return $column_names; } - + /// get auto-incremented columns public function get_col_names_ai(): array { @@ -280,7 +280,7 @@ namespace Lollipop { } return $column_names; } - + /// get column infos public function get_col_info(): array { diff --git a/Lollipop/Router.php b/Lollipop/Router.php @@ -55,7 +55,7 @@ namespace Lollipop { return true; } - /// add route + /// add route /// $func can be a path to an template or a function which returns the path to an template and modifies $vars public function addRoute(string|array $method, string $match, string|callable $func) { @@ -70,7 +70,7 @@ namespace Lollipop { ); } - /// final routing + /// final routing public function route(string $base = null) { $this->path = $_SERVER["REQUEST_URI"]; diff --git a/Lollipop/SQLDatabase.php b/Lollipop/SQLDatabase.php @@ -87,7 +87,7 @@ namespace Lollipop { } return $objects; } - + public function getDateRange(string $table_name, array $query, $order) { if($query == null) { diff --git a/Lollipop/Utils.php b/Lollipop/Utils.php @@ -1,7 +1,7 @@ <?php namespace Lollipop{ - + /// this class is a collection of utilities class Utils { @@ -16,7 +16,7 @@ namespace Lollipop{ } return $missing; } - + public static function missing_fields_sans_pw($not_nullable) { $missing = []; diff --git a/routing/user.php b/routing/user.php @@ -90,16 +90,23 @@ $user_delete = function (&$vars) { $user_page = function (&$vars) { global $db; $user = $db->get(Model\User::class); + $exam = $db->get(Model\Exam::class); $user->load($vars['primary_key']); $data = $user->getData(); if(in_array(3, $_SESSION['user_permissions'])) { foreach($data as $key => $d) { $vars['user_data'] .= "<p>your $key = $d<p><br>"; } - } elseif($vars['primary'] == $_SESSION['email']) { + } elseif($vars['primary_key'] == $_SESSION['email']) { foreach($data as $key => $d) { $vars['user_data'] .= "<p>your $key = $d<p><br>"; } + $vars['user_data'] .= "<h1>your grades</h1><br>"; + foreach($db->all_where(Model\Grade::class, ['email' => $vars['primary_key']]) as $grade) { + $exam->load($grade->exam); + $exam_name =$exam->name; + $vars['user_data'] .= "<p>your grade for $exam_name = $grade->grade </p><br>"; + } } return "views/user_page.html"; };