<?php
/**
* IrsaComponent
*
* @package
* @author portalbook
* @copyright saleh
* @version 6/6/2011 5:13:57 AM
* @access public
*/
class IrsaComponent extends Component
{
public $Controller;
public $components = array('Session');
public function initialize($Controller)
{
$this->Controller = $Controller;
if(isset( $this->Controller->request->params['prefix']) ) {
$this->prefix = $this->Controller->request->params['prefix'];
}
Configure::load('Irsa/'.$this->prefix);
$this->initConfig($Controller);
}
public function initConfig($Controller) {
if ( $this->config('Irsa.theme') ) {
$Controller->viewClass = $this->config('Irsa.viewClass');
$Controller->theme = $this->config('Irsa.theme');
}
if ( $this->config('Irsa.Langs.default') ) {
Configure::write('Config.language', $this->config('Irsa.Langs.default') );
}
}
public function beforeRender($controller){
$this->pageTitle();
}
/**
* IrsaComponent::IsAdmin()
* Check Prefix Is Admin
* @return true/false
*/
function IsAdmin()
{
if ( isset( $this->Controller->request->params['prefix'] ) )
{
if ($this->Controller->request->params['prefix'] == 'admin' || $this->Controller->request->params['admin'] )
{
return true;
}
}
return false;
}
public function config($key ) {
return Configure::read($key);
}
/**
* IrsaComponent::AdminHelper()
*
* @return void
*/
function AdminHelper()
{
//$this->Controller->helpers[]= 'Irsa.Irsa';
// $this->Controller->helpers[]= 'Irsa.Layout';
$this->Controller->helpers[]= 'Paginator';
// $this->Controller->helpers[]= 'Irsa.IMenu';
// $this->Controller->helpers[]= 'Irsa.Sections';
// $this->Controller->helpers[]= 'Irsa.ShortCute';
return;
}
/**
* AppController::IrsaFlassRedirect()
*
* @param mixed $msg
* @param mixed $url
* @param string $type [E,I,S,W]
* @return void
*/
public function IrsaFlashRedirect( $msg , $url , $type = 'I' ) {
$CssType = array( 'E' => 'error' , 'I' => 'info' , 'S' => 'success' , 'W' => 'warning');
$this->Session->setFlash( $msg , 'flash/inline' , array( 'class' => $CssType[$type] ) );
$this->Controller->redirect($url);
}
public function IrsaFlash( $msg , $type = 'I' ) {
$CssType = array( 'E' => 'error' , 'I' => 'info' , 'S' => 'success' , 'W' => 'warning');
$this->Session->setFlash( $msg , 'flash/inline' , array( 'class' => $CssType[$type] ) );
}
public function pageTitle()
{
$title = array();
$title[] = (empty($this->Controller->controllerTitle)) ? $this->Controller->name : $this->Controller->controllerTitle ;
$title[] = (empty($this->Controller->actionTitle)) ? $this->Controller->action : $this->Controller->actionTitle;
if(!empty($title)){
$title = implode(' - ',$title);
$title = $this->config('Irsa.title').' > '.$title ;
}
else
$title = $this->config('Irsa.title');
return $this->Controller->set('title_for_layout',$title);
}
}