/** * The add action */ public function addAction() { $auth = $this->session->get('auth'); if ($auth) { $this->_bc->add('Add', 'awards/add'); $allEpisodes = Episodes::find(array('order' => 'air_date DESC')); $allUsers = Users::find(array('order' => 'username')); $allPlayers = Players::find(array('order' => 'active DESC, name')); $this->view->setVar('users', $allUsers); $this->view->setVar('episodes', $allEpisodes); $this->view->setVar('players', $allPlayers); if ($this->request->isPost()) { $datetime = date('Y-m-d H:i:s'); $award = new Awards(); $award->userId = $this->request->getPost('user_id', 'int'); $award->episodeId = $this->request->getPost('episode_id', 'int'); $award->playerId = $this->request->getPost('player_id', 'int'); $award->award = $this->request->getPost('award', 'int'); if (!$award->save()) { foreach ($award->getMessages() as $message) { $this->flash->error((string) $message); } } else { $this->view->disable(); $this->flash->success('Award created successfully'); $this->invalidateCache(); $this->response->redirect('awards/'); } } } }
/** * The index action */ public function indexAction() { $data[] = array('id' => '-1', 'number' => 'All'); $episodes = Episodes::find(array('order' => 'airDate DESC')); foreach ($episodes as $episode) { $data[] = array('id' => $episode->id, 'number' => $episode->number); } $this->view->setVar('episodes', json_encode($data)); }
/** * get Action */ public function getAction() { $this->view->setRenderLevel(View::LEVEL_LAYOUT); $data = ''; $results = $this->cache->get($this->getCacheHash('model')); if (!$results) { $episodes = Episodes::find(); if (count($episodes) > 0) { foreach ($episodes as $episode) { $data[] = array('id' => $episode->id, 'number' => substr("0000" . $episode->number, -3), 'air_date' => $episode->air_date, 'outcome' => $this->translateOutcome($episode->outcome), 'summary' => $episode->summary); } } $results = json_encode(array('results' => $data)); $this->cache->save($this->getCacheHash('model'), $results); } echo $results; }