public function signupAction() { $this->acl->checkPermission('is logged in'); $user = $this->auth->getLoggedInUser(); // Get conventions that are available for signup. $upcoming_cons = array(); $previous_cons = array(); $cons_raw = $this->em->createQuery('SELECT c FROM Entity\\Convention c WHERE (c.signup_enabled = 1 AND c.end_date >= :now) ORDER BY c.start_date ASC')->setParameter('now', gmdate('Y-m-d'))->getArrayResult(); foreach ($cons_raw as $row) { $row['range'] = Convention::getDateRange($row['start_date'], $row['end_date']); $upcoming_cons[$row['id']] = $row; } // Get conventions that the user has signed up for. $cons_signed_up = $this->em->createQuery('SELECT cs, c FROM Entity\\ConventionSignup cs JOIN cs.convention c WHERE (cs.user_id = :user_id) ORDER BY c.start_date DESC')->setParameter('user_id', $user->id)->getArrayResult(); foreach ($cons_signed_up as $row) { $con_id = $row['convention_id']; if (isset($upcoming_cons[$con_id])) { $upcoming_cons[$con_id]['signup'] = $row; } else { $con = $row['convention']; $con['range'] = Convention::getDateRange($con['start_date'], $con['end_date']); $previous_cons[$con_id] = $con; $previous_cons[$con_id]['signup'] = $row; } } $this->view->upcoming_cons = $upcoming_cons; $this->view->previous_cons = $previous_cons; }
public static function _runConventionPromotions(\Phalcon\DiInterface $di) { $news_items = array(); $em = $di->get('em'); // Pull all recent or upcoming conventions. $conventions_raw = $em->createQuery('SELECT c, ca FROM Entity\\Convention c LEFT JOIN c.archives ca WHERE (c.start_date BETWEEN :threshold_start AND :threshold_end) AND (c.image_url IS NOT NULL AND c.image_url != \'\') ORDER BY c.start_date DESC, ca.created_at DESC')->setParameter('threshold_start', date('Y-m-d', strtotime('-2 months')))->setParameter('threshold_end', date('Y-m-d', strtotime('+1 year')))->getArrayResult(); foreach ((array) $conventions_raw as $convention) { if (empty($convention['web_url'])) { continue; } $create_post = false; $start_date = $convention['start_date']->getTimestamp(); $end_date = $convention['end_date']->add(new \DateInterval('P1D'))->getTimestamp(); // Adjust for midnight. $post_item = array('id' => 'convention_' . $convention['id'], 'title' => $convention['name'], 'source' => 'convention', 'body' => '', 'image_url' => \PVL\Url::upload($convention['image_url']), 'web_url' => $convention['web_url'], 'layout' => 'vertical', 'tags' => array($convention['name'], 'Conventions'), 'sort_timestamp' => $start_date, 'display_timestamp' => $start_date); if ($start_date > time()) { // Pre-convention: Check for discount code promotion. if (!empty($convention['discount_code']) && $start_date >= time() + 86400 * 14) { $create_post = true; $convention_details = array(':convention' => $convention['name'], ':discount' => $convention['discount_code']); $post_title_raw = 'Register for :convention with Discount Code ":discount"'; $post_item['title'] = strtr($post_title_raw, $convention_details); $post_body_raw = 'Ponyville Live! is partnering with :convention to offer a special discount to our visitors. Visit the convention\'s registration page and enter discount code ":discount" to save on your registration!'; $post_item['body'] = strtr($post_body_raw, $convention_details); // More distant conventions sort lower on the list than closer ones. $time_diff = $start_date - time(); $post_item['sort_timestamp'] = time() - round($time_diff / 60); } } elseif ($start_date <= time() + 86400 * 7 && $end_date >= time()) { // Mid-convention: Check for live coverage. $coverage_types = array(Convention::COVERAGE_STREAMING => 'Ponyville Live! is streaming :convention live on the web! Check our web site for stream details, and check the convention\'s web site for official schedule updates and more information on the convention.', Convention::COVERAGE_FULL => 'Ponyville Live! will be providing full recording coverage of :convention. Check out the convention\'s web site for more information on the convention, and come back to our homepage for footage updates after the convention.', Convention::COVERAGE_PARTIAL => 'Ponyville Live! will be providing limited coverage of :convention. Check out the convention\'s web site for more information on the convention, and come back to our homepage for footage updates after the convention.'); if (isset($coverage_types[$convention['coverage_level']])) { $create_post = true; $convention_details = array(':convention' => $convention['name'], ':range' => Convention::getDateRange($convention['start_date'], $convention['end_date'])); $post_title_raw = ":convention\n:range"; $post_item['title'] = strtr($post_title_raw, $convention_details); $post_item['body'] = strtr($coverage_types[$convention['coverage_level']], $convention_details); $post_item['sort_timestamp'] = $end_date; } } if ($create_post) { $news_items[] = $post_item; } } return $news_items; }