/**
  * Manages MatchGame 
  * @param unknown $id
  */
 public function actionManage($id)
 {
     $MATCH_TYPE = 3;
     $ACTIVE = 1;
     $STATUS_EVALUANDO = 5;
     $model = $this->loadModel($id);
     if (isset($_POST['MatchResult'])) {
         $matchResultArray = array();
         $matchResultArray = $_POST['MatchResult'];
         foreach ($matchResultArray as $matchResult) {
             if (isset($matchResult['MATCH_ID']) && $matchResult['MATCH_ID'] > 0 && isset($matchResult['RESULT_ID']) && $matchResult['RESULT_ID'] > 0) {
                 $dbMatchResult = MatchResult::model()->findByPk(array('RESULT_ID' => $matchResult['RESULT_ID'], 'MATCH_ID' => $matchResult['MATCH_ID']));
             } else {
                 throw new CHttpException(400, 'The requested page does not exist.');
                 // confirm http estatus code = 400 Bad Request
             }
             if ($dbMatchResult === null) {
                 $dbMatchResult = new MatchResult();
             }
             $dbMatchResult->attributes = $matchResult;
             $dbMatchResult->save();
         }
         $model->STATUS = $STATUS_EVALUANDO;
         $model->save();
         $this->redirect(array('tournament/manageResults', 'id' => $dbMatchResult->mATCH->TOURNAMENT_ID, 'roundId' => $dbMatchResult->mATCH->GROUP));
     }
     $currentResults = $model->matchResults;
     $catResult = new CatResult();
     $catResult->TYPE_RESULT = $MATCH_TYPE;
     $catResult->ACTIVE = $ACTIVE;
     $catResults = array();
     $catResults = $catResult->search()->getData();
     $matchResults = array();
     foreach ($catResults as $_catResult) {
         $matchResult = MatchResult::model()->findByPk(array('RESULT_ID' => $_catResult->ID, 'MATCH_ID' => $id));
         if ($matchResult === null) {
             $matchResult = new MatchResult();
             $matchResult->MATCH_ID = $id;
             $matchResult->RESULT_ID = $_catResult->ID;
         }
         $matchResults[] = $matchResult;
     }
     $this->render('manage', array('model' => $model, 'matchResults' => $matchResults));
 }