hanze/lollipop

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

Course.php (1361B) download


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