diff --git a/airtime_mvc/application/common/interface/Publish.php b/airtime_mvc/application/common/interface/Publish.php index 0a99314bf..0de672033 100644 --- a/airtime_mvc/application/common/interface/Publish.php +++ b/airtime_mvc/application/common/interface/Publish.php @@ -20,4 +20,17 @@ interface Publish { */ public function unpublish($fileId); + + /** + * Fetch the publication status for the file with the given ID + * + * @param int $fileId the ID of the file to check + * + * @return int 1 if the file has been published, + * 0 if the file has yet to be published, + * -1 if the file is in a pending state, + * 2 if the source is unreachable (disconnected) + */ + public function getPublishStatus($fileId); + } \ No newline at end of file diff --git a/airtime_mvc/application/services/PodcastEpisodeService.php b/airtime_mvc/application/services/PodcastEpisodeService.php index 9c3628505..56298e467 100644 --- a/airtime_mvc/application/services/PodcastEpisodeService.php +++ b/airtime_mvc/application/services/PodcastEpisodeService.php @@ -215,6 +215,22 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir ->delete(); } + /** + * Fetch the publication status for the file with the given ID + * + * @param int $fileId the ID of the file to check + * + * @return int 1 if the file has been published, + * 0 if the file has yet to be published, + * -1 if the file is in a pending state, + * 2 if the source is unreachable (disconnected) + */ + public function getPublishStatus($fileId) { + $stationPodcast = StationPodcastQuery::create() + ->findOneByDbPodcastId(Application_Model_Preference::getStationPodcastId()); + return (int) $stationPodcast->hasEpisodeForFile($fileId); + } + /** * @param $episodeId * @return array diff --git a/airtime_mvc/application/services/PublishService.php b/airtime_mvc/application/services/PublishService.php index 6ebb5b1c9..345ed1bf8 100644 --- a/airtime_mvc/application/services/PublishService.php +++ b/airtime_mvc/application/services/PublishService.php @@ -10,15 +10,6 @@ class Application_Service_PublishService { "station_podcast" => "My Podcast" ); - /** - * @var array map of arbitrary source names to functions that return - * their publication state (true = published) - */ - private static $SOURCE_FUNCTIONS = array( - "soundcloud" => "getSoundCloudPublishStatus", - "station_podcast" => "getStationPodcastPublishStatus" - ); - /** * Publish or remove the file with the given file ID from the services * specified in the request data (ie. SoundCloud, the station podcast) @@ -58,9 +49,8 @@ class Application_Service_PublishService { public static function getSourceLists($fileId) { $sources = array(); foreach (self::$SOURCES as $source => $label) { - $fn = self::$SOURCE_FUNCTIONS[$source]; - // Should be in a ternary but PHP doesn't play nice - $status = self::$fn($fileId); + $service = PublishServiceFactory::getService($source); + $status = $service->getPublishStatus($fileId); array_push($sources, array( "source" => $source, "label" => _($label), @@ -72,36 +62,23 @@ class Application_Service_PublishService { } /** - * Reflective accessor for SoundCloud publication status for the - * file with the given ID + * Given a cc_file identifier, check if the associated file has + * been published to any sources. * - * @param int $fileId the ID of the file to check + * @param int $fileId the cc_files identifier of the file to check * - * @return int 1 if the file has been published to SoundCloud, - * 0 if the file has yet to be published, - * -1 if the file is in a pending state + * @return bool true if the file has been published to any source, + * otherwise false */ - private static function getSoundCloudPublishStatus($fileId) { - $soundcloudService = new Application_Service_SoundcloudService(); - if (!$soundcloudService->hasAccessToken()) { return 2; } - return ($soundcloudService->referenceExists($fileId)); - } - - /** - * - * Reflective accessor for Station podcast publication status for the - * file with the given ID - * - * @param int $fileId the ID of the file to check - * - * @return int 1 if the file has been published to SoundCloud, - * 0 if the file has yet to be published, or -1 if the - * file is in a pending state - */ - private static function getStationPodcastPublishStatus($fileId) { - $stationPodcast = StationPodcastQuery::create() - ->findOneByDbPodcastId(Application_Model_Preference::getStationPodcastId()); - return (int) $stationPodcast->hasEpisodeForFile($fileId); + public static function isPublished($fileId) { + foreach (self::$SOURCES as $source => $label) { + $service = PublishServiceFactory::getService($source); + // 1: published or -1: pending + if (abs($service->getPublishStatus($fileId)) == 1) { + return true; + } + } + return false; } } diff --git a/airtime_mvc/application/services/SoundcloudService.php b/airtime_mvc/application/services/SoundcloudService.php index eff76cfe7..9e3c9e7d2 100644 --- a/airtime_mvc/application/services/SoundcloudService.php +++ b/airtime_mvc/application/services/SoundcloudService.php @@ -332,4 +332,18 @@ class Application_Service_SoundcloudService extends Application_Service_ThirdPar $this->delete($fileId); } + /** + * Fetch the publication status for the file with the given ID + * + * @param int $fileId the ID of the file to check + * + * @return int 1 if the file has been published, + * 0 if the file has yet to be published, + * -1 if the file is in a pending state, + * 2 if the source is unreachable (disconnected) + */ + public function getPublishStatus($fileId) { + if (!$this->hasAccessToken()) { return 2; } + return ($this->referenceExists($fileId)); + } } \ No newline at end of file diff --git a/airtime_mvc/application/services/StationPodcastService.php b/airtime_mvc/application/services/StationPodcastService.php deleted file mode 100644 index 0435b6d65..000000000 --- a/airtime_mvc/application/services/StationPodcastService.php +++ /dev/null @@ -1,6 +0,0 @@ -