public function viewAction() { // Sociel Gaming $app = $this->getApplication(); $option = $this->getCurrentOptionValue(); $current_game = new Socialgaming_Model_Game(); $current_game->findCurrent($app->getId()); if (!$current_game->getId()) { $current_game->findDefault(); } list($start, $end) = $current_game->getFromDateToDate(); $log = new LoyaltyCard_Model_Customer_Log(); $customers = $log->getBestCustomers($app->getId(), $start->toString('y-MM-dd HH:mm:ss'), $end->toString('y-MM-dd HH:mm:ss'), false); $team_leader = $customers->current(); $customers->removeCurrent(); $this->loadPartials($this->getFullActionName('_') . '_l' . $this->_layout_id, false); $this->getLayout()->getPartial('content')->setCurrentGame($current_game)->setTeamLeader($team_leader)->setCustomers($customers); $html = array('html' => $this->getLayout()->render()); if ($url = $option->getBackgroundImageUrl()) { $html['background_image_url'] = $url; } $html['use_homepage_background_image'] = (int) $option->getUseHomepageBackgroundImage() && !$option->getHasBackgroundImage(); $html['title'] = $option->getTabbarName(); $this->getLayout()->setHtml(Zend_Json::encode($html)); }
public function stopcurrentgameAction() { if ($datas = $this->getRequest()->isXmlHttpRequest()) { $game = new Socialgaming_Model_Game(); $current_game = new Socialgaming_Model_Game(); $current_game->findCurrent($this->getSession()->getAdminId()); try { if (!$current_game->getId()) { throw new Exception('Une erreur est survenue lors de la sauvegarde'); } $message = ''; // Met à jour la date de fin du jeu en cours if ($current_game->getEndAt()) { $current_game->setData('end_at', null); } else { $current_game->setEndAt(); $message = 'Votre jeu se terminera le ' . $current_game->getFormattedEndAt('dd/MM/yyyy'); } $current_game->save(); $html = array('success_message' => 'Sauvegarde effectuée avec succès.<br />' . $message, 'message_button' => 0, 'message_loader' => 0, 'message_timeout' => 3); } catch (Exception $e) { $html = array('message' => $e->getMessage()); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } return $this; }
public function editpostAction() { if ($datas = $this->getRequest()->getPost()) { $html = array(); $datas['value_id'] = $this->getCurrentOptionValue()->getId(); $game = new Socialgaming_Model_Game(); $current_game = new Socialgaming_Model_Game(); $current_game->findCurrent($this->getCurrentOptionValue()->getId()); $next_game = new Socialgaming_Model_Game(); $next_game->findNext($this->getCurrentOptionValue()->getId()); try { // Sauvegarde le jeu if ($current_game->getId()) { $next_game->setData($datas)->save(); // Si le jeu n'a pas de date de fin if (!$current_game->getEndAt()) { // Met à jour la date de fin du jeu en cours $current_game->setEndAt()->save(); } } else { $current_game->setData($datas)->save(); } $html = array('success' => 1, 'success_message' => $this->_('Game successfully saved'), 'message_button' => 0, 'message_timeout' => 3, 'message_loader' => 1); } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }
public function findallAction() { if ($this->getRequest()->getParam('value_id')) { // Social Gaming $application = $this->getApplication(); $option = $this->getCurrentOptionValue(); $offset = $this->getRequest()->getParam('offset', 0); $current_game = new Socialgaming_Model_Game(); $current_game->findCurrent($option->getId()); if (!$current_game->getId()) { $current_game->findDefault(); } list($start, $end) = $current_game->getFromDateToDate(); $log = new LoyaltyCard_Model_Customer_Log(); $customers = $log->getBestCustomers($application->getId(), $start->toString('y-MM-dd HH:mm:ss'), $end->toString('y-MM-dd HH:mm:ss'), false, $offset); $team_leader = $customers->current(); $customers->removeCurrent(); $data = array("icon_url" => $this->_getColorizedImage($option->getIconId(), $application->getBlock('background')->getColor()), "game" => array("period" => strtoupper($current_game->getGamePeriodLabel())), "team_leader" => array(), "collection" => array()); if ($team_leader) { $data["team_leader"] = array("id" => $team_leader->getId(), "image_url" => $team_leader->getImageLink(), "name" => $team_leader->getFirstname() . ' ' . mb_substr($team_leader->getLastname(), 0, 1, "UTF-8") . '.', "number_of_points" => $this->_('%s point%s', $team_leader->getNumberOfPoints(), $team_leader->getNumberOfPoints() > 1 ? 's' : '')); } if ($customers->count()) { foreach ($customers as $customer) { $data["collection"][] = array("id" => $customer->getId(), "image_url" => $customer->getImageLink(), "name" => $customer->getFirstname() . ' ' . mb_substr($customer->getLastname(), 0, 1, "UTF-8") . '.', "number_of_points" => $this->_('%s point%s', $customer->getNumberOfPoints(), $customer->getNumberOfPoints() > 1 ? 's' : '')); } } $data['page_title'] = $option->getTabbarName(); $this->_sendHtml($data); } }