integrateideas / cake3Themes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Installation

  • You can install this plugin into your CakePHP application using composer by running the following commands in the terminal.

  • composer config repositories.integrateideas vcs https://github.com/integrateideas/taskMaster

  • composer require "integrateideas/inspiniaTheme" : "dev-InspiniaTheme"

  • Then load the plugin by running

    bin/cake plugin load InspiniaTheme -b -r

    or by manually adding statement shown below to bootstrap.php:

    Plugin::load('InspiniaTheme', ['bootstrap' => true,'routes' => true]);

Usage

  • Create app_form.php in config and add this :

    '
    {{text}}
    ', 'checkbox' => '', 'checkboxFormGroup' => '{{label}}', 'checkboxWrapper' => '
    {{label}}
    ', 'dateWidget' => '{{year}}{{month}}{{day}}{{hour}}{{minute}}{{second}}{{meridian}}', 'error' => '
    {{content}}
    ', 'errorList' => '
      {{content}}
    ', 'errorItem' => '
      {{text}}
    ', 'file' => '', 'fieldset' => '{{content}}', 'formStart' => '
    ', 'formEnd' => '
    ', 'formGroup' => '{{label}}{{input}}', 'hiddenBlock' => '
    {{content}}
    ', 'input' => '
    ', 'inputSubmit' => '', 'inputContainer' => '
    {{content}}
    ', 'inputContainerError' => '
    {{content}}{{error}}
    ', 'label' => '{{text}}', 'nestingLabel' => '{{hidden}}{{input}}{{text}}', 'legend' => '{{text}}', 'multicheckboxTitle' => '{{text}}', 'multicheckboxWrapper' => '{{content}}', 'option' => '{{text}}', 'optgroup' => '{{content}}', 'select' => '
    {{content}}
    ', 'selectMultiple' => '
    {{content}}
    ', 'radio' => '', 'radioWrapper' => '{{label}}', 'textarea' => '<textarea name="{{name}}"{{attrs}}>{{value}}</textarea>', 'submitContainer' => '
    {{content}}
    ', ]; ?>
  • Then load it in src/View/AppView.php in initialize function :

    $this->loadHelper('Form', [ 'templates' => 'app_form', ]);

  • Then load this theme in src/Controller/AppController.php in beforeRender function:

    $this->viewBuilder()->theme('InspiniaTheme');

  • Create navigation.php file in config and create menu in it.

    If a menu has children, then the link for the menu must always be #

    All links must be in the form of ['controller' => 'ControllerName', 'action' =>'action name' ]

    Example: [ 'Users' => [ 'link' => '#', 'class' => 'fa-list-alt', 'children' => [ 'View All' => [ 'link' => [ 'controller' => 'Users', 'action' => 'index' ], ], 'Add' => [ 'link' => ['controller' => 'Users', 'action' => 'add'] ] ], ], 'Roles' => [ 'link' => ['controller' => 'Users', 'action' => 'index'], 'class' => 'fa-list-alt', ] ] ] ?>

  • Load navigation.php file in bootsrap.php if (file_exists(CONFIG . 'navigation.php')) { Configure::load('navigation'); }

  • Then in your AppController, add the below content in the related functions:

    public function beforRendor(Event $event){

    if($this->response->getStatusCode() == 200) { $user = $this->Auth->user(); $this->viewBuilder()->theme('InspiniaTheme'); $nav = $this->checkLink(Configure::read('NavigationMenu'), $user->role['name']); $this->set('sideNav',$nav['children']); } }

    If there is no Roles table in your Application, then set 'role_name' blank

    public function beforeFilter(Event $event) { $user = $this->Auth->user(); // pr($user); $sideNavData = ['id'=>$user['id'],'first_name' => $user['first_name'],'last_name' => $user['last_name'],'role_name' => $user['role']['name'],]; $this->set('sideNavData', $sideNavData); }

    public function beforeFilter(Event $event) { $user = $this->Auth->user(); // pr($user); $sideNavData = ['id'=>$user['id'],'first_name' => $user['first_name'],'last_name' => $user['last_name'],'role_name' => $user['role']['name'],]; $this->set('sideNavData', $sideNavData); }

    public function checkLink($nav = [], $role = false){ $currentLink = [ 'controller' => $this->request->params['controller'], 'action' => $this->request->params['action'] ]; $check = 0; foreach($nav as $key => &$value){

         Figure out active class
          if($value['link'] == '#'){
              $response = $this->checkLink($value['children'], $role);
              $value['children'] = $response['children'];
              $value['active'] = $response['active'];
          } else {
              $value['active'] = empty(array_diff($currentLink, $value['link'])) ? 1 : 0;
          }
          
          if(isset($value['active']) && $value['active']){
              $check = 1;
          }
          Figure out whether to show or not
          if($role){
              $show = 0;
              //role is not in show_to_roles
              if(empty($value['show_to_roles'])) {
                $show = 1;
              } elseif (in_array($role, $value['show_to_roles'])) {
                $show = 1;
              } 
              if($show){
                if(empty($value['hide_from_roles'])) {
                  $show = 1;
                } elseif (in_array($role, $value['hide_from_roles'])) {
                  $show = 0;
                }   
              }
              $value['show'] = $show;
          } else {
              $value['show'] = 1;
          }
      }
      return ['children' => $nav, 'active' => $check];
    

    }

About


Languages

Language:JavaScript 67.5%Language:CSS 29.7%Language:PHP 2.7%Language:HTML 0.1%