setImport(array( 'panel.models.*', 'panel.components.*', )); } public function beforeControllerAction($controller, $action) { if(parent::beforeControllerAction($controller, $action)) { // this method is called before any module controller action is performed // you may place customized code here return true; } else return false; } /** * @return hash string. */ public static function encrypting($string="", $salt="") { $hash = Yii::app()->getModule('panel')->hash; if ($hash=="md5") return md5($string); if ($hash=="sha1") return sha1($string); if ($hash=='blowfish' && $salt=='') return crypt($string, Randomness::blowfishSalt()); if ($hash=='blowfish' && !empty($salt)) return crypt($string, $salt); else return hash($hash,$string); } /** * Return safe user data. * @param user id not required * @return user object or false */ static private $_users=array(); public static function user($id=0,$clearCache=false) { if (!$id&&!Yii::app()->user->isGuest) $id = Yii::app()->user->id; if ($id) { if (!isset(self::$_users[$id])||$clearCache) self::$_users[$id] = User::model()->with(array('profile'))->findbyPk($id); return self::$_users[$id]; } else return false; } /** * @var array * @desc Behaviors for models */ public $componentBehaviors=array(); public function getBehaviorsFor($componentName){ if (isset($this->componentBehaviors[$componentName])) { return $this->componentBehaviors[$componentName]; } else { return array(); } } }