/** * Updates an existing Confronto model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post())) { if ($model->empate == 1) { $model->vencedor = null; } $modelAposta = Aposta::find()->where(['=', 'id_confronto', $model->id])->all(); foreach ($modelAposta as $item) { if ($item->placar_casa == $model->placar_casa && $item->placar_visitante == $model->placar_visitante) { $modelRank = new Rank(); $modelRank->id_user = $item->id_user; $modelRank->data = date('Y-m-d H:i:s'); $modelRank->id_aposta = $item->id; $modelRank->id_ponto = 1; $modelRank->save(); } else { if ($model->vencedor != null) { if ($item->placar_casa > $item->placar_visitante && $model->vencedor == $model->id_time_casa) { $modelRank = new Rank(); $modelRank->id_user = $item->id_user; $modelRank->data = date('Y-m-d H:i:s'); $modelRank->id_aposta = $item->id; $modelRank->id_ponto = 2; $modelRank->save(); } else { if ($item->placar_casa < $item->placar_visitante && $model->vencedor == $model->id_time_visitante) { $modelRank = new Rank(); $modelRank->id_user = $item->id_user; $modelRank->data = date('Y-m-d H:i:s'); $modelRank->id_aposta = $item->id; $modelRank->id_ponto = 2; $modelRank->save(); } } } else { if ($item->placar_casa == $item->placar_visitante && $model->placar_casa == $model->placar_visitante) { $modelRank = new Rank(); $modelRank->id_user = $item->id_user; $modelRank->data = date('Y-m-d H:i:s'); $modelRank->id_aposta = $item->id; $modelRank->id_ponto = 2; $modelRank->save(); } } } } if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } }
public function actionGetapostas($id) { $this->layout = false; header('Content-type: application/json'); $arr = array(); $arrAposta = array(); $id_user = $id; if ($id_user != 0) { $aposta = Aposta::find()->where(['=', 'id_user', $id_user])->all(); } else { $aposta = Aposta::find()->all(); } foreach ($aposta as $item) { $dataHoje = strtotime(date("m/d/Y")); $dataExp = $item->data; array_push($arr, $item->id, $item->id_confronto, $item->id_user, $item->data, $item->placar_casa, $item->placar_visitante, ucfirst($item->idUser->username)); array_push($arrAposta, $arr); $arr = array(); } echo json_encode($arrAposta); }
public static function GetNumeroApostaVisitante($id) { $model = new Aposta(); $model = Aposta::find()->where(['=', 'id_confronto', $id])->all(); $conta = 0; foreach ($model as $item) { if ($item->placar_casa < $item->placar_visitante) { $conta = $conta + 1; } } return $conta; }
?> " /> <input type="hidden" id="data" name="data" value="<?php echo date("Y-m-d H:i:s"); ?> " /> </form> </div> <div id="verApostaDiv-<?php echo $data->id; ?> " class="panel-body verApostaDiv"> <?php $apostas = Aposta::find()->where(['=', 'id_confronto', $data->id])->orderBy(['data' => SORT_DESC])->all(); ?> <?php foreach ($apostas as $aposta) { ?> <div class="divApostas_<?php echo $aposta->id; ?> " style="padding: 0 0px 0px 2.5%;; margin: -30px 0 12px 0; text-align: right;width: 162px;"> <div class="" style="width: 30%;display: initial;"> <label> <?php echo ucfirst($aposta->idUser->username);
public static function GetErros($id) { $modelAposta = Rank::find()->where(['=', 'id_user', $id])->all(); $model = Aposta::find()->where(['=', 'id_user', $id])->all(); $total = 0; $totalAposta = 0; foreach ($modelAposta as $item) { $total = $total + 1; } foreach ($model as $item) { $totalAposta = $totalAposta + 1; } return $totalAposta - $total; }