Ejemplo n.º 1
0
 public function add($em, $src = null)
 {
     $rsp = array();
     // Return error if $src is empty
     if (!isset($src)) {
         return array('success' => false, 'errorCode' => 'emptyField');
     }
     $configService = $this->getConfigService();
     $dateAgo = $this->getUtilityService()->getDateAgo($configService::EPISODE_DAY_MAX);
     // Check to see if the value is url (XML feed) or Youtube channel ID
     // If the input is a URL for XML Feed
     if (filter_var($src, FILTER_VALIDATE_URL)) {
         // Get data with SimplePie first
         $simplepie = new SimplePieService($src);
         $subscription = $simplepie->getSubscriptionArray();
         $episodes = $simplepie->getEpisodeCollection($dateAgo);
         //Check for empty fields
         // If the subscription array has any empty values try the ZetaService
         // Then fold the missing values together
         //			if(in_array("", array_merge($subscription, $episodes))){
         //				$rsp = $this->checkForEmptyFields( new ZetaXMLService(), $subscription, $episodes, $dateAgo);
         //				$subscription = $rsp['subscription'];
         //				$episodes = $rsp['episodes'];
         //			}
         $subscription = $this->createSubscriptionEntity(new Subscription(), $subscription, $src, $episodes[0]['src']);
         $em->persist($subscription);
         $em->flush($subscription);
         $episodeService = new EpisodeService();
         $episodes = $episodeService->buildBulkEpisodes($em, $episodes, $subscription);
         $rsp = array('subscription' => $this->getSubscriptionArray($subscription), 'episodes' => $episodes);
     } else {
         // Youtube
     }
     return $rsp;
 }
Ejemplo n.º 2
0
 /**
  * @depends testConstruct
  */
 public function testMakeEpisodeCollection(SimplePieService $rawData)
 {
     $lu = 1435546770000.0;
     $episodeCollection = $rawData->getEpisodeCollection($lu);
     $this->assertCount(2, $episodeCollection);
     $this->assertEquals('de5hbdhthdfg', $episodeCollection[0]['title']);
     $this->assertEquals('SSofj5DFH7d', $episodeCollection[0]['description']);
     $this->assertEquals('d9fk5m8', $episodeCollection[0]['src']);
     //        var_dump($episodeCollection);
 }
Ejemplo n.º 3
0
 /**
  * Iterates through each subscription gathering new episodes since last update array in the collection
  * @param doctrine entity manager, array of episode array data,
  * Subscription entity
  * @return Episode entity
  */
 public function gatherNewEpisodes($sr, $em)
 {
     // Collect all public subscriptions
     $subscriptions = $sr->findByPublic(true);
     $configService = $this->getConfigService();
     $fp = fopen($configService::FILES . 'last-update.txt', 'w+');
     $lastUpdateInt = (int) fgets($fp);
     fclose($fp);
     //print $lastUpdateInt;
     $subscriptionService = new SubscriptionService();
     $count = count($subscriptions);
     for ($i = 0; $i < $count; $i++) {
         // Get data with SimplePie first
         $simplepie = new SimplePieService($subscriptions[$i]->getSrc());
         $episodes = $simplepie->getEpisodeCollection($lastUpdateInt);
         //Check for empty fields
         // If the subscription array has any empty values try the ZetaService
         // Then fold the missing values together
         //			if (in_array("", $episodes)) {
         //				$rsp = $subscriptionService->checkForEmptyFields(new ZetaXMLService(), null, $episodes, $lastUpdateInt);
         //				$episodes = $rsp['episodes'];
         //			}
         $rsp = $this->buildBulkEpisodes($em, $episodes, $subscriptions[$i]);
         print count($rsp);
     }
     $currentDate = new \DateTime();
     //var_dump(new DateTime('now'));
     $newLastUpdate = strtotime($currentDate->format('Y-m-d H:i:s')) * 1000;
     //print $newLastUpdate;
     $fp = fopen($configService::FILES . 'last-update.txt', 'w+');
     fwrite($fp, $newLastUpdate);
     fclose($fp);
     return array("success" => true);
 }