Пример #1
0
 /**
  * Instantiates the ACL
  * @param \Lyra\Interfaces\Container $container
  */
 public function __construct(\Lyra\Interfaces\Container &$container)
 {
     $this->container = $container;
     \Profiler::setTime('ACL::constructor');
     // is the player logged in?
     $sessionModel = \App::getModel('Session');
     \Profiler::setTime('ACL::_construct SessionModel loaded');
     $playerModel = \App::getModel('Player');
     \Profiler::setTime('ACL::_construct playerModel loaded');
     if ($sessionModel->isLoggedIn()) {
         $this->setPlayer($playerModel->find($sessionModel->getPlayerId()));
         \Profiler::setTime('ACL::_construct setPlayer to Loggedin');
     } else {
         $this->setPlayer($playerModel->findGuest());
         \Profiler::setTime('ACL::_construct setPlayer as Guest');
     }
     // lookup in cache for roles
     if (\Config::get('cache.use') === true && isset($container['cache']['acl_player_' . $this->player['player_id'] . '_roles'])) {
         $roles = \Cache::get('acl_player_' . $this->player['player_id'] . '_roles');
         \Profiler::setTime('ACL::_construct CacheUse is true, set roles');
     } else {
         $roles = \App::getModel('PlayerRole')->findAllForPlayer($this->player['player_id']);
         \Profiler::setTime('ACL::_construct CacheUse is false, set roles');
         if (\Config::get('cache.use') === true) {
             $container['cache']['acl_player_' . $this->player['player_id'] . '_roles'] = $roles;
         }
     }
     $this->addRoles($roles);
     \Profiler::setTime('ACL::_construct addRoles');
     $container['acl'] = $this;
 }
Пример #2
0
 /**
  * Init Twig Environment
  */
 protected function initTwigEnv()
 {
     if (\App::adminTheme()) {
         $this->theme = $this->adminTheme;
     }
     $this->set('theme', $this->theme);
     $this->loader = new \Twig_Loader_Filesystem();
     $this->loader->addPath($this->themePath . $this->theme . '/');
     //$this->loader->addPath($this->themePath . $this->adminTheme . '/');
     $this->loadThemeTemplates();
     if (file_exists(\App::moduleDirectory() . '/templates/')) {
         $this->loader->addPath(\App::moduleDirectory() . '/templates/');
     }
     $this->loadModuleTemplates();
     //Create widget registry instance, who contains your widget
     $this->widgetRegistry = new WidgetRegistry();
     $this->twig = new \Twig_Environment($this->loader, array('debug' => true));
     $this->twig->addExtension(new \Twig_Extension_Debug());
     $this->getWidgets();
     // clear twig-cache
     $this->clearTwigCache();
 }
Пример #3
0
 /**
  * Serve the page
  * @return App
  */
 public function serve()
 {
     \View::initTwigEnv();
     \View::set('config', $this->getConfig());
     if (!defined('INSTALL')) {
         $menus = $this->getModel('Menu');
         \View::set('menu', $menus->getMenu());
         $player = \App::getModel('session');
         \View::set('loggedIn', $player->isLoggedIn());
         \Acl::setPlayer($player);
         $role = \Acl::getRoles();
         if (!empty($role)) {
             \View::set('playerRole', $role[0]->metadata['role_id']);
         }
     }
     if ($this->adminTheme) {
         \View::setTheme(\Config::get('site.adminTheme'));
     }
     if ($this->view->template == '') {
         \View::setTemplate($this->module . '.twig');
     }
     echo \View::render();
     return $this;
 }