-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
module.php
67 lines (53 loc) · 2.01 KB
/
module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
class ReviewsModule extends OBFModule
{
public $name = 'Reviews';
public $description = 'Provide rating and comment functionality for media.';
public function callbacks()
{
}
public function install()
{
$this->db->query('CREATE TABLE IF NOT EXISTS `module_reviews_ratings` (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`media_id` int(10) UNSIGNED NOT NULL,
`name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`rating` tinyint(3) UNSIGNED NOT NULL,
`created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `media_id` (`media_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;');
$this->db->query('ALTER TABLE `module_reviews_ratings`
ADD CONSTRAINT `module_reviews_ratings_ibfk_1` FOREIGN KEY (`media_id`) REFERENCES `media` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;');
$this->db->query('CREATE TABLE IF NOT EXISTS `module_reviews_comments` (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`media_id` int(10) UNSIGNED NOT NULL,
`name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`comment` text NOT NULL,
`created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `media_id` (`media_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;');
$this->db->query('ALTER TABLE `module_reviews_comments`
ADD CONSTRAINT `module_reviews_comments_ibfk_1` FOREIGN KEY (`media_id`) REFERENCES `media` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;');
$this->db->insert('users_permissions', [
'category'=>'administration',
'description'=>'manage media reviews via api',
'name'=>'reviews_module'
]);
return true;
}
public function uninstall()
{
// remove permissions data for this module
$this->db->where('name','reviews_module');
$permission = $this->db->get_one('users_permissions');
$this->db->where('permission_id',$permission['id']);
$this->db->delete('users_permissions_to_groups');
$this->db->where('id',$permission['id']);
$this->db->delete('users_permissions');
return true;
}
}