/** * Handle form action */ protected function formAction() { switch ($this->s->action) { case 'create': $actions = array('players' => $this->vars['player'], 'actions' => $this->vars['action'], 'values' => $this->vars['value']); $spot = new PokerSpot($this->vars['title'], $this->vars['button'], $this->vars['stack_p1'], $this->vars['stack_p2'], explode(',', preg_replace('/\\s+/', '', $this->vars['range_p1'])), explode(',', preg_replace('/\\s+/', '', $this->vars['range_p2']))); if ($spot->save()) { $raise = 1; if (is_array($this->vars['player']) && count($this->vars['player']) > 0) { //$players = array_reverse($this->vars['player'], true); foreach ($this->vars['player'] as $key => $value) { if (!isset($own[$value])) { $own[$value] = $value == $this->vars['button'] ? 0.5 : 1; } if ($this->vars['action'][$key] == 'raise') { $params = array('value' => $this->vars['value'][$key], 'rel_value' => $this->vars['value'][$key] - $raise, 'own_value' => $this->vars['value'][$key] - $own[$value]); $own[$value] = $this->vars['value'][$key]; $raise = $this->vars['value'][$key]; } elseif ($this->vars['action'][$key] == 'call') { $params = array('value' => $this->vars['value'][$key]); } else { $params = array(); } $action = new SpotAction($spot, $this->vars['action'][$key], $params, $value); $action->save(); } } Error::addMessage('Der Spot wurde erfolgreich angelegt!'); $this->form['reload'] = array('poker' => array('poker_spot' => 'spots')); return true; } //*/ break; case 'update': $spot = PokerSpot::getInstance($this->s->element); $spot->title = $this->vars['title']; $spot->button = $this->vars['button']; $spot->stacks = array($this->vars['stack_p1'], $this->vars['stack_p2']); $spot->ranges = array(explode(',', preg_replace('/\\s+/', '', $this->vars['range_p1'])), explode(',', preg_replace('/\\s+/', '', $this->vars['range_p2']))); if ($spot->save()) { if (is_array($spot->actions)) { foreach ($spot->actions as $action) { $action->delete(); } } $raise = 1; if (is_array($this->vars['player']) && count($this->vars['player']) > 0) { foreach ($this->vars['player'] as $key => $value) { if (!isset($own[$value])) { $own[$value] = $value == $this->vars['button'] ? 0.5 : 1; } if ($this->vars['action'][$key] == 'raise') { $params = array('value' => $this->vars['value'][$key], 'rel_value' => $this->vars['value'][$key] - $raise, 'own_value' => $this->vars['value'][$key] - $own[$value]); $own[$value] = $this->vars['value'][$key]; $raise = $this->vars['value'][$key]; } elseif ($this->vars['action'][$key] == 'call') { $params = array('value' => $this->vars['value'][$key]); } else { $params = array(); } $action = new SpotAction($spot, $this->vars['action'][$key], $params, $value); $action->save(); } } Error::addMessage('Die Änderungen wurden erfolgreich gespeichert!'); $this->form['reload'] = array('poker' => array('poker_spot' => 'spots')); return true; } break; case 'delete': $spot = PokerSpot::getInstance($this->s->element); /* if (is_object($spot->game)) { Error::addError('Der Spot kann nicht gelöscht werden (Spiel ist noch aktiv)!'); return false; }//*/ if ($spot->delete()) { Error::addMessage('Der Spot wurde erfolgreich gelöscht!'); $this->form['reload'] = array('poker' => array('poker_spot' => 'spots')); return true; } break; case 'reload': echo $this->listSpots(); break; } return false; }