/** * Controlller for manage matchs * it supports post and get methods * @param integer $id * @return multitype: */ public function actionManageMatchs($id) { $playGround = new PlayGround(); $model = $this->loadModel($id); $roundId = isset($_GET['roundId']) ? $_GET['roundId'] : 1; if (isset($_POST['MatchGame']) && $model->STATUS >= 4) { $matchArray = array(); if (isset($_POST['saveRound'])) { $matchArray = $_POST['MatchGame']; $success_message = ''; $warning_message = ''; $flagValidation = false; $matchs = array(); foreach ($matchArray as $match) { if (isset($match['ID']) && $match['ID'] > 0) { $dbMatch = MatchGame::model()->findByPk($match['ID']); } else { $dbMatch = new MatchGame(); } $dbMatch->scenario = 'register'; $dbMatch->attributes = $match; $dbMatch->TIME = $dbMatch->TIME == NULL ? NULL : date('Y-m-d H:i:s', strtotime(str_replace('/', '.', $dbMatch->TIME))); //& DateTime::createFromFormat('d/m/Y', $dbMatch->TIME)->format('Y-m-d'); /*Send to match validation*/ if ($dbMatch->validate()) { $dbMatch->STATUS = 2; $dbMatch->save(); $matchs[] = $dbMatch; } else { $matchs[] = $dbMatch; $flagValidation = true; } } if ($flagValidation) { /*Form validation*/ Yii::app()->user->setFlash('error', '<strong>Error. </strong>Revise las observaciones. '); $this->render('matchs', array('model' => $model, 'matchGames' => $matchs, 'playGround' => $playGround, 'roundId' => $roundId)); return; } else { Yii::app()->user->setFlash('success', '<strong>Listo. </strong>Guardado correctamente. '); } } else { if (isset($_POST['publishRound'])) { $matchArray = $_POST['MatchGame']; foreach ($matchArray as $match) { if (isset($match['ID']) && $match['ID'] > 0) { $dbMatch = MatchGame::model()->findByPk($match['ID']); $dbMatch->STATUS = 3; $dbMatch->save(); } } } } $this->redirect(array('manageMatchs', 'id' => $model->ID, 'roundId' => $roundId)); } if ($model->STATUS > 3 && count($model->matchGames) > 0) { $this->render('matchs', array('model' => $model, 'matchGames' => $model->matchGames, 'playGround' => $playGround, 'roundId' => $roundId)); } else { $toMatch = $this->generateMatchs($id); $this->render('matchs', array('model' => $model, 'matchGames' => $toMatch, 'playGround' => $playGround, 'roundId' => $roundId)); } }