Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • DeleteBlock
  • DeleteOperation
  • EditBlock
  • Hooks
  • ManageBlock
  • Model
  • Module
  • PermissionsOperation
  • Role
  • SaveOperation
  1 <?php
  2 
  3 /*
  4  * This file is part of the Icybee package.
  5  *
  6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
  7  *
  8  * For the full copyright and license information, please view the LICENSE
  9  * file that was distributed with this source code.
 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      * Overrides the methods to create the "Visitor" and "User" roles.
 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             /* the model */
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 }
Autodoc API documentation generated by ApiGen 2.8.0