/** * 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; }
/** * read the object information from the db */ private function load($id) { $db = new DB(); $sql = "SELECT *\n FROM poker_spots AS ps\n LEFT JOIN poker_actions AS pa ON pa.idspot = ps.idspot\n WHERE ps.idspot = '{$id}'\n ORDER BY pa.idaction ASC"; $result = $db->query($sql); if ($result->length() > 0) { // general information $this->info = array('title' => $result->title, 'button' => $result->button, 'stacks' => array($result->p1_stack, $result->p2_stack), 'ranges' => array(unserialize($result->p1_range), unserialize($result->p2_range))); // action log $actions = array(); if ($result->idaction != '') { do { $actions[] = SpotAction::getInstance($result->idaction); } while ($result->next()); } $this->info['actions'] = $actions; $this->id = $id; return true; } return false; }