hanze/lollipop

Model/Exam.php in master
Repositories | Summary | Log | Files

Exam.php (1351B) download


 1<?php
 2
 3namespace Model {
 4    use Lollipop\Utils;
 5
 6    class Exam extends \Lollipop\DatabaseObject
 7    {
 8        public static function get_table(): string
 9        {
10            return "exam";
11        }
12
13        public static function get_primary(): string
14        {
15            return "id";
16        }
17        public static function get_schema(): string
18        {
19            return "lollipop";
20        }
21        public function add_exam(): bool
22        {
23            $missing_fields = Utils::missing_fields($this->notNullable());
24            if(sizeof($missing_fields) == 0) {
25                foreach($_POST as $key => $post) {
26                    if(in_array($key, $this->get_col_names_no_ai())) {
27                        $this->{$key} = $post;
28                    }
29                }
30                return $this->add();
31            }
32            return false;
33        }
34        public function update_exam(): bool
35        {
36            $missing_fields = Utils::missing_fields($this->notNullable());
37            if(sizeof($missing_fields) == 0) {
38                foreach($_POST as $key => $post) {
39                    if(in_array($key, $this->get_column_names())) {
40                        $this->{$key} = $post;
41                    }
42                }
43                return $this->save();
44            }
45            return false;
46        }
47    }
48}