public function actionEvents()
 {
     $data = array('knights' => null, 'events' => array());
     $app_rules_level = AppRulesLevel::model()->findAll(array('index' => 'level'));
     //Load knight
     //$data['knights']= Knights::model()->with( array('knightsEventsLasts'=>array('order'=>'knightsEventsLasts.date DESC', 'limit'=>Yii::app()->params['events']['event_last']['maximum']  )) )->find( 't.name=:name ', array(':name'=>$_GET['sir']) );
     $events_list = KnightsEventsLast::model()->findKnightEventLast($this->knight->id, Yii::app()->params['events']['event_last']['maximum']);
     Yii::trace('[CHARACTER][actionEvents] START actionEvents');
     if ($events_list) {
         //Load knights_status template
         //$data['knights_status_template'] = $this->renderFile(  Yii::app()->basePath.'/views/character/knights_status.php', array('knight'=>$data['knights']), true );
         //Para cada evento cargamos los datos de ese evento.
         foreach ($events_list as $event) {
             //Check type event.
             switch ($event->type) {
                 //Combate
                 case KnightsEvents::TYPE_COMBAT:
                     //Search combat
                     $combat = Combats::model()->with(array('fromKnight', 'toKnight', array('rounds' => array('order' => 'rounds.number DESC'))))->find('t.id=:id', array(':id' => $event->identificator));
                     //Make status html
                     switch ($combat->status) {
                         case Combats::STATUS_PENDING:
                             Yii::trace('[CHARACTER][actionEvents] COMBATE PENDIENTE');
                             //Check if knights are enable for combat
                             if ($combat->fromKnight->status == Knights::STATUS_ENABLE && $combat->toKnight->status == Knights::STATUS_ENABLE) {
                                 $combatStatusHtml = $this->renderFile(Yii::app()->basePath . '/views/character/event_type_combat_status_pending.php', array('combat' => &$combat), true);
                                 //Check why can not combat
                             } else {
                                 //Check if somebudy is at combat
                                 if ($combat->fromKnight->status == Knights::STATUS_AT_COMBAT || $combat->toKnight->status == Knights::STATUS_AT_COMBAT) {
                                     $combatStatusHtml = $this->renderFile(Yii::app()->basePath . '/views/character/event_type_combat_status_enable_but_somebody_is_at_combat.php', array('combat' => &$combat), true);
                                     //Check if somebody is at working
                                 } elseif ($combat->fromKnight->status == Knights::STATUS_AT_WORK || $combat->toKnight->status == Knights::STATUS_AT_WORK) {
                                     $combatStatusHtml = $this->renderFile(Yii::app()->basePath . '/views/character/event_type_combat_status_enable_but_somebody_is_at_work.php', array('combat' => &$combat), true);
                                 } elseif ($combat->fromKnight->status == Knights::STATUS_WITHOUT_EQUIPMENT || $combat->toKnight->status == Knights::STATUS_WITHOUT_EQUIPMENT) {
                                     $combatStatusHtml = $this->renderFile(Yii::app()->basePath . '/views/character/event_type_combat_status_enable_but_somebody_is_without_equipment.php', array('combat' => &$combat), true);
                                 }
                             }
                             break;
                         case Combats::STATUS_ENABLE:
                             $combatStatusHtml = $this->renderFile(Yii::app()->basePath . '/views/character/event_type_combat_status_enable.php', array('combat' => &$combat), true);
                             /*
                              //In first round
                             if( count($combat->rounds)==1 ){
                             $combatStatusHtml = $this->renderFile( Yii::app()->basePath.'/views/character/event_type_combat_status_enable_accepted_challenge.php', array('combat'=>&$combat ), true );
                             	
                             }else{
                             //Several rounds
                             $combatStatusHtml = $this->renderFile( Yii::app()->basePath.'/views/character/event_type_combat_status_enable.php', array('combat'=>&$combat ), true );
                             }
                             */
                             break;
                         case Combats::STATUS_FINISHED:
                             if ($combat->result == Combats::RESULT_REJECT) {
                                 $combatStatusHtml = $this->renderFile(Yii::app()->basePath . '/views/character/event_type_combat_status_finished_result_reject.php', array('combat' => &$combat), true);
                             } else {
                                 $combatStatusHtml = $this->renderFile(Yii::app()->basePath . '/views/character/event_type_combat_status_enable.php', array('combat' => &$combat), true);
                             }
                             break;
                     }
                     array_push($data['events'], $this->renderFile(Yii::app()->basePath . '/views/character/event_type_combat.php', array('combat' => &$combat, 'combatStatusHtml' => $combatStatusHtml), true));
                     break;
                     //Evolucion de un personaje
                 //Evolucion de un personaje
                 case KnightsEvents::TYPE_KNIGHTS_EVOLUTION:
                     $knightsEventsData = array('knight' => &$data['knights'], 'evolution' => KnightsEvolution::model()->findByPk($event->identificator));
                     array_push($data['events'], $this->renderFile(Yii::app()->basePath . '/views/character/event_type_knights_evolution.php', $knightsEventsData, true));
                     break;
                 case KnightsEvents::TYPE_JOB:
                     $knightsEventsData = array('knight' => &$data['knights'], 'job' => Jobs::model()->findByPk($event->identificator), 'app_rules_level' => &$app_rules_level);
                     array_push($data['events'], $this->renderFile(Yii::app()->basePath . '/views/character/event_type_job.php', $knightsEventsData, true));
                 default:
                     //Nothing to do here. for example if is void
             }
         }
         //Display
         $this->render('events', $data);
     } else {
         $data['message'] = 'El caballero buscado no existe.';
         if ($error = Yii::app()->errorHandler->error) {
             $this->render('error', $error);
         }
     }
 }
 /**
  * Retrieves old last event of knight
  * @param unknown_type $knight_id
  */
 public static function getOldLastEvent($knight_id)
 {
     return KnightsEventsLast::model()->find(array('condition' => 'knights_id = :knights_id', 'params' => array(':knights_id' => $knight_id), 'order' => 'date ASC', 'limit' => '1'));
 }