2015-10-28 23:54:30 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Application_Service_PublishService {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array map of arbitrary source names to descriptive labels
|
|
|
|
*/
|
|
|
|
private static $SOURCES = array(
|
|
|
|
"soundcloud" => SOUNDCLOUD,
|
2015-11-03 22:23:17 +01:00
|
|
|
"station_podcast" => "Station Podcast"
|
2015-10-28 23:54:30 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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)
|
|
|
|
*
|
|
|
|
* @param int $fileId ID of the file to be published
|
|
|
|
* @param array $data request data containing what services to publish to
|
|
|
|
*/
|
|
|
|
public static function publish($fileId, $data) {
|
|
|
|
foreach ($data as $k => $v) {
|
|
|
|
$service = PublishServiceFactory::getService($k);
|
2015-10-29 18:09:50 +01:00
|
|
|
$service->$v($fileId);
|
2015-10-28 23:54:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For the file with the given ID, check external sources and generate
|
|
|
|
* an array of source states and labels.
|
|
|
|
*
|
|
|
|
* Sources to which the file has been published should be passed back in a
|
|
|
|
* "published" array, while sources to which the file has not been published
|
|
|
|
* should be passed back in a "toPublish" array.
|
|
|
|
*
|
|
|
|
* @param int $fileId the ID of the file to check
|
|
|
|
*
|
|
|
|
* @return array array containing published and toPublish arrays. Has the form
|
|
|
|
* [
|
|
|
|
* "toPublish" => [
|
|
|
|
* "source" => "label",
|
|
|
|
* ...
|
|
|
|
* ]
|
|
|
|
* "published" => [
|
|
|
|
* "source" => "label",
|
|
|
|
* ...
|
|
|
|
* ]
|
|
|
|
* ]
|
|
|
|
*/
|
|
|
|
public static function getSourceLists($fileId) {
|
|
|
|
$publishSources = $publishedSources = array();
|
|
|
|
foreach (self::$SOURCES as $source => $label) {
|
|
|
|
$fn = self::$SOURCE_FUNCTIONS[$source];
|
|
|
|
// Should be in a ternary but PHP doesn't play nice
|
|
|
|
if (self::$fn($fileId)) {
|
|
|
|
$publishedSources[$source] = _($label);
|
|
|
|
} else {
|
|
|
|
$publishSources[$source] = _($label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return array(
|
|
|
|
"toPublish" => $publishSources,
|
|
|
|
"published" => $publishedSources
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-10-30 21:10:16 +01:00
|
|
|
/**
|
2015-10-28 23:54:30 +01:00
|
|
|
* Reflective accessor for SoundCloud publication status for the
|
|
|
|
* file with the given ID
|
|
|
|
*
|
|
|
|
* @param int $fileId the ID of the file to check
|
|
|
|
*
|
|
|
|
* @return bool true if the file has been published to SoundCloud,
|
|
|
|
* otherwise false
|
|
|
|
*/
|
|
|
|
private static function getSoundCloudPublishStatus($fileId) {
|
|
|
|
$soundcloudService = new Application_Service_SoundcloudService();
|
2015-10-30 21:10:16 +01:00
|
|
|
return ($soundcloudService->referenceExists($fileId));
|
2015-10-28 23:54:30 +01:00
|
|
|
}
|
|
|
|
|
2015-10-30 21:10:16 +01:00
|
|
|
/**
|
|
|
|
*
|
2015-10-28 23:54:30 +01:00
|
|
|
* 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 bool true if the file has been published to the Station podcast,
|
|
|
|
* otherwise false
|
|
|
|
*/
|
|
|
|
private static function getStationPodcastPublishStatus($fileId) {
|
|
|
|
$stationPodcast = StationPodcastQuery::create()
|
|
|
|
->findOneByDbPodcastId(Application_Model_Preference::getStationPodcastId());
|
|
|
|
return $stationPodcast->hasEpisodeForFile($fileId);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|