PermissionUser.php (1522B) download
1<?php
2
3namespace Model {
4 class PermissionUser extends \Lollipop\DatabaseObject
5 {
6 public static function get_table(): string
7 {
8 return "permission_user";
9 }
10
11 public static function get_primary(): string
12 {
13 return 'email';
14 }
15 public static function get_schema(): string
16 {
17 return "panda";
18 }
19 public function add_permissions(User $user): bool
20 {
21 if(array_key_exists('permissions', $_POST)) {
22 foreach($_POST['permissions'] as $permission) {
23 $this->{$user->get_primary()} = $user->{$user->get_primary()};
24 $this->id_permission = $permission;
25 $this->add();
26 }
27 return true;
28 }
29 return false;
30 }
31 public function update_permissions(User $user): bool
32 {
33 foreach($this->db->all_where(PermissionUser::class, [$this->get_primary() => $_POST[$this->get_primary()]]) as $permission) {
34 $permission->delete();
35 }
36 if(array_key_exists('permissions', $_POST)) {
37 foreach($_POST['permissions'] as $permission) {
38 $this->{$user->get_primary()} = $user->{$user->get_primary()};
39 $this->id_permission = $permission;
40 $this->add();
41 }
42 return true;
43 }
44 return false;
45 }
46 }
47}