public function latestAction() { try { $latest_shows = Podcast::fetchLatest(); $return = array(); foreach ((array) $latest_shows as $show_info) { $return_row = Podcast::api($show_info['record'], FALSE); foreach ((array) $show_info['episodes'] as $ep_row) { $return_row['episodes'][] = PodcastEpisode::api($ep_row); } $return[] = $return_row; } return $this->returnSuccess($return); } catch (\Exception $e) { return $this->returnError($e->getMessage()); } }
/** * Send notifications for new podcast episodes. * * @param \Phalcon\DiInterface $di * @throws \DF\Exception */ public static function _runPodcastEpisodes(\Phalcon\DiInterface $di, $force = false) { $em = $di->get('em'); $start_threshold = time() - 86400 * 7; $end_threshold = time(); $podcast_episodes = $em->createQuery('SELECT pe, p FROM Entity\\PodcastEpisode pe JOIN pe.podcast p WHERE pe.timestamp BETWEEN :start AND :end AND pe.is_notified = 0 AND pe.is_active = 1 AND p.is_approved = 1 ORDER BY pe.timestamp DESC')->setParameter('start', $start_threshold)->setParameter('end', $end_threshold)->setMaxResults(1)->execute(); if ($podcast_episodes) { $episode = $podcast_episodes[0]; $podcast = $episode->podcast; $podcast_name = $podcast->name; if ($podcast->is_adult) { $podcast_name = '[18+] ' . $podcast_name; } $title = \DF\Utilities::truncateText($episode->title, 110 - strlen($podcast_name) - 6); $tweet = $podcast_name . ': "' . $title . '"'; PvlNode::push('podcast.new_episode', array('episode' => PodcastEpisode::api($episode), 'podcast' => Podcast::api($podcast, false))); $image_url = NULL; if ($podcast->banner_url) { $image_url = \PVL\Service\AmazonS3::path($podcast->banner_url); } // Special handling of podcast YT videos. if (stristr($episode->web_url, 'youtube.com') !== false) { $image_url = NULL; } self::notify($tweet, $episode->getLocalUrl('twitter'), $image_url); // Set all episodes of the same podcast to be notified, to prevent spam. $em->createQuery('UPDATE Entity\\PodcastEpisode pe SET pe.is_notified=1 WHERE pe.podcast_id = :podcast_id')->setParameter('podcast_id', $podcast->id)->execute(); } }