Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
112 lines (89 sloc) 2.94 KB
<?php
class ReleaseController extends DrupalDefaultEntityController{
public function save($release) {
drupal_write_record('bandcamp_release', $release);
field_attach_insert('release', $release);
module_invoke_all('entity_insert', 'release', $release);
return $release;
}
/**
* Validation and formatting of release record for insertion into db
*/
public function validate($release) {
if(!is_numeric($release->album_id)) {
return false;
}
try {
field_attach_validate('release', $release);
}
catch(FieldValidationException $e) {
watchdog_exception('bandcamp', $e);
// let the calling function act on the exception
throw $e;
return false;
}
return true;
}
public function prepare($raw_release, $band) {
$downloadable = 0;
if(isset($raw_release->downloadable)) {
$downloadable = $raw_release->downloadable;
}
$artist = $band->band_name;
if($raw_release->artist) {
$artist = check_plain($raw_release->artist);
}
$about = '';
if(isset($raw_release->about)) {
$about = $raw_release->about;
}
$release = array(
'title' => check_plain($raw_release->title),
'album_id' => $raw_release->album_id,
'bid' => $band->bid,
'bandcamp_large_art_url' => array('und' => array(array(
'url' => $raw_release->large_art_url,
'title' => '',
))),
'bandcamp_small_art_url' => array('und'=> array(array(
'url' => $raw_release->small_art_url,
'title' => '',
))),
'bandcamp_downloadable' => array('und' => array(array('value' => $downloadable))),
'bandcamp_release_date' => array('und' => array(array(
'value' => date('Y-m-d H:m:s', $raw_release->release_date),
'value2' => '',
'timezone' => 'utc',
))),
'bandcamp_release_url' => array('und' => array(array(
'url' => $raw_release->url,
'title' => t($raw_release->title . ' bandcamp URL'),
))),
'bandcamp_release_url' => array('und' => array(array(
'url' => $raw_release->url,
'title' => t($raw_release->title . ' bandcamp URL'),
))),
'bandcamp_artist' => array('und' => array(array('value' => $artist))),
'bandcamp_about' => array('und' => array(array('value' => $about))),
);
$release = (object) $release;
return $release;
}
/**
* Set variables for release for theming
*/
function view($release, $band) {
$url = '';
$artist = check_plain($band->band_name);
if(isset($release->bandcamp_release_url['und'][0]['url'])) {
$url = $release->bandcamp_release_url['und'][0]['url'];
}
$release->url = $url;
$release->art_url = $release->bandcamp_small_art_url['und'][0]['url'];
$release->artist = $artist;
if(isset($release->bandcamp_artist['und'][0]['value'])) {
$release->artist = $release->bandcamp_artist['und'][0]['safe_value'];
}
return $release;
}
}