1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Users\Roles;
13
14 use ICanBoogie\ActiveRecord\RecordNotFound;
15 use ICanBoogie\I18n;
16 use ICanBoogie\Operation;
17 use ICanBoogie\Route;
18
19 use Brickrouge\Button;
20 use Brickrouge\Element;
21 use Brickrouge\Form;
22 use Brickrouge\Text;
23
24 class Module extends \Icybee\Module
25 {
26 const OPERATION_PERMISSIONS = 'permissions';
27
28 static public $levels = array
29 (
30 self::PERMISSION_NONE => 'none',
31 self::PERMISSION_ACCESS => 'access',
32 self::PERMISSION_CREATE => 'create',
33 self::PERMISSION_MAINTAIN => 'maintain',
34 self::PERMISSION_MANAGE => 'manage',
35 self::PERMISSION_ADMINISTER => 'administer'
36 );
37
38 39 40
41 public function install(\ICanBoogie\Errors $errors)
42 {
43 $rc = parent::install($errors);
44
45 if (!$rc)
46 {
47 return $rc;
48 }
49
50 $model = $this->model;
51
52 try
53 {
54 $this->model[1];
55 }
56 catch (RecordNotFound $e)
57 {
58 $role = Role::from
59 (
60 array
61 (
62 Role::NAME => I18n\t('Visitor')
63 ),
64
65 array($model)
66 );
67
68 $role->save();
69 }
70
71 try
72 {
73 $this->model[2];
74 }
75 catch (RecordNotFound $e)
76 {
77 $role = Role::from
78 (
79 array
80 (
81 Role::NAME => I18n\t('User')
82 ),
83
84 array($model)
85 );
86
87 $role->save();
88 }
89
90 return $rc;
91 }
92
93 public function is_installed(\ICanBoogie\Errors $errors)
94 {
95 if (!parent::is_installed($errors))
96 {
97 return false;
98 }
99
100 try
101 {
102 $this->model->find(array(1, 2));
103 }
104 catch (StatementInvalid $e)
105 {
106
107 }
108 catch (RecordNotFound $e)
109 {
110 if (!$e->records[1])
111 {
112 $errors[$this->id] = I18n\t('Visitor role is missing');
113 }
114
115 if (!$e->records[2])
116 {
117 $errors[$this->id] = I18n\t('User role is missing');
118 }
119 }
120
121 return !$errors->count();
122 }
123 }