FuelPHP Bin
<?php class Controller_Backend extends \Controller_Hybrid { public function before(){ parent::before(); if(!\Auth::check()){ $this->notify('Authentication Expired/Not Logged In','error','Log In Please'); throw new HttpNotAuthenticatedException(); } if(\Auth::get('group_id') == 5){ $this->institution = \Model_Auth::find(\Auth::get('id'))->institution; $this->get_cached(); } else { $this->institution = null; } } public function notify($text,$level,$title='',$ttl = 3){ \Event::register('notification',function() use ($text,$level,$title,$ttl){ return array( 'text'=>$text, 'level'=>$level, 'title'=>$title, 'ttl' => ($ttl != -1)?$ttl*1000:-1, ); }); } public function readable($text = false){ if($text == \Session::get('readable')){ return true; } $textStatistics = new DaveChild\TextStatistics\TextStatistics; $a = $textStatistics->automatedReadabilityIndex($text); if($a > 5){ \Session::set('readable',$text); return false; } else { return true; } } public function get_cached(){ $key = 'institution.'.$this->institution->id.'.'.\Auth::get('user_id').'.'.str_replace('/','.',\Uri::string()); try { $content = \Cache::get($key); $this->notify('Your Result Has been Cached','success','Cached Result'); return $content; } catch (\CacheNotFoundException $e) { return false; } } public function set_cached($data,$expire = 600){ if(\Auth::get('group_id') == 6){ return $data; } $key = 'institution.'.$this->institution->id.'.'.\Auth::get('user_id').'.'.str_replace('/','.',\Uri::string()); \Cache::set($key,$data,$expire); return $data; } public function post_purge_cache(){ if(\Auth::get('group_id') == 6){ \Cache::delete_all(); $this->notify('Global System Cache Purges','success','Cache Purged'); } if(\Auth::get('group_id') == 6){ \Cache::delete('institution.'.$this->institution->id); $this->notify('Cache of Institution:'.strtoupper($this->institution->name).' has been Purged','success','Cache Purged'); } } public function after($response) { if(\Input::method() == 'POST' || \Input::method() == 'DELETE'){ if(!is_array($response)){ $response = (array)$response; } } $data = $response; if(is_array($response)){ $data = array(); $data['data'] = $response; $data['notif'] = \Event::trigger('notification','','array'); } return parent::after($data); // not needed if you create your own response object } }