21600, * 'recalled/' => 86400 * ); * * $cacheAction can also be set to a strtotime() compatible string. This * marks all the actions in the controller for view caching. * * @var mixed * @access public */ var $cacheAction = array('view/' => 3600); /** * Holds pagination defaults for controller actions. The keys that can be included * in this array are: 'conditions', 'fields', 'order', 'limit', 'page', and 'recursive', * similar to the parameters of Model->findAll(). * * @var array * @access public */ var $paginate = array('order'=>array('ArtistProfile.display_name' => 'asc'), 'limit' => 50); /** * Cake automatically calls this after the controller action is run, but before the view is * rendered. Overridden in subclasses. Here, we are using it to generate the Article-specific * menu links in the backend. * * @access public */ function beforeFilter() { $this->admin_menu = array( 'Browse' => '/admin/artists/index', 'New Artist' => '/admin/artists/add', 'Needs Attention' => '/admin/artists/attend', 'Missing Purchase Links' => '/admin/artists/missing_links', 'Has Purchase Links' => '/admin/artists/has_links', ); parent::beforeFilter(); } /** * Checks to see if data has been POSTed, and performs a search of the artists_profiles table for * the data submitted. This function is used by the AJAX widget that allow users to specify * content associations. Used by the artist profile selection widget. * * @see /app/webroot/js/admin/artistProfileWidgetController.js * @see /app/webroot/js/admin.js (line 56) */ function browse() { if(!empty($this->data)) { //so we can paginate, save the search criteria from the form in a session variable $this->Session->write($this->name.'.search', $this->data['Search']); } elseif($this->Session->check($this->name.'.search')) { //if there's no POST data, check the session and see if it's been saved $search = $this->Session->read($this->name.'.search'); if ($search) { $this->data['Search'] = $search; } } //generate the search criteria for the query $search = $this->generateFilters(); $filters = array(); if(isset($search)) { $filters = $search; $this->Session->write($this->name.'.search', $filters); } //query the database $this->ArtistProfile->unbindAll(); $artists = $this->paginate('ArtistProfile',$filters); $this->set('artists', $artists); //send it to the AJAX view if ($this->RequestHandler->isAjax()) { $this->viewPath = 'artists'.DS.'js'; } } /** * Generates an index page for the artists index, and allows users to search * by letter or by entering a search term. Keyword searches return matching * artist names and album titles. * * @param string $letter * A single alphabetic character. If specified, all artists that start with * that letter are found. * * @todo at some point we need to figure out how to get paginated results for two separate queries into the view */ function index($letter = null) { $this->pageTitle = "Artist Index"; $this->sidebar = "wpgu"; if ((!$letter) && (!isset($_POST['artistSearch']))) { $this->redirect('/artists/index/A'); } elseif (isset($_POST['artistSearch'])) { $this->pageTitle = "Artist Index: Search"; $findMe = $_POST['artistSearch']; $artistProfiles = $this->ArtistProfile->simpleSearch($findMe); $conditions = array(); /* $this->ArtistProfile->unbindAll(array('hasMany' => array('ArtistAlbum'))); $artCond= array(); $artCond['or'][] = 'ArtistProfile.name LIKE "%'.$findMe.'%"'; $artCond['or'][] = 'ArtistProfile.display_name LIKE "%'.$findMe.'%"'; $results = $this->paginate($artCond); $this->set('artistResults', $results); $this->ArtistProfile->ArtistAlbum->unbindAll(array('belongsTo' => array('ArtistProfile'))); $albumCond = array(); $albumCond[] = 'ArtistAlbum.name LIKE "%'.$findMe.'%"'; $results2 = $this->paginate('ArtistAlbum', $albumCond); $this->set('albumResults', $results2); */ $this->set('results', $artistProfiles); $this->set('search', 1); } else { if ($letter == 'local') { $this->pageTitle = 'Artist Index: Local Artists'; $conditions = array('local' => true); $this->set('letter', 'Local Artists'); } else { $this->pageTitle = "Artist Index: ".$letter; $conditions = array('`ArtistProfile`.`name` LIKE "'.$letter.'%"'); $this->set('letter', $letter); } } $this->ArtistProfile->unbindAll(array('hasMany' => array('ArtistMetadatum'))); $this->set('artistProfiles', $this->ArtistProfile->findAll($conditions,null, "name ASC")); } /** * Displays an individual artist record for the frontend of the site, with associated information. * * @param mixed $artist * The slug string or ID number of an artist record * */ function view($artist) { $this->sidebar = 'wpgu'; if (is_numeric($artist)) { $art = $this->ArtistProfile->findById($artist); $this->redirect(array($art['ArtistProfile']['slug']), null, true); } if(!$artist) { $this->Session->setFlash('Invalid Artist.'); $this->redirect(array('action'=>'index'), null, true); } // Fetch the Artist profile, Albums for this Artist, and the tracks of that Album $this->ArtistProfile->recursive = 2; $this->ArtistProfile->unbindAll(array('hasMany' => array('ArtistAlbum', 'ArtistMetadatum'), 'hasAndBelongsToMany' => array('Media', 'Article'))); $this->ArtistProfile->ArtistAlbum->unbindAll(array('hasAndBelongsToMany' => array('Comment'), 'belongsTo' => array('Media'))); $this->ArtistProfile->ArtistAlbum->ArtistAlbumsComments->bindModel(array('belongsTo' => array('Comment'))); $this->ArtistProfile->Article->unbindAll(array('hasOne' => array('Content'))); $this->ArtistProfile->Media->unbindAll(); $profile = $this->ArtistProfile->findBySlug($artist); //if the function was called with the requestAction() function, return the results //of the query at this point and stop, instead of rendering the view if(isset($this->params['requested'])) { return $profile; } //find the events... we'll need to do a little work to get the upcoming dates right $fetch_events = $this->ArtistProfile->ArtistProfilesCalendarEvents->findAll(array('artist_profile_id' => $profile['ArtistProfile']['id']), 'calendar_event_id'); $event_ids = Set::extract($fetch_events, '{n}.ArtistProfilesCalendarEvents.calendar_event_id'); unset($fetch_ids); $this->ArtistProfile->CalendarEvent->unbindAll(array('belongsTo' => array('DirectoryListing','PrimaryCategory'), 'hasMany' => array('CalendarEventInstance'))); $this->ArtistProfile->CalendarEvent->CalendarEventInstance->recursive = 1; $upcoming_events = $this->ArtistProfile->CalendarEvent->CalendarEventInstance->findAll(array('CalendarEventInstance.calendar_event_id' => $event_ids, 'timestamp > '.mktime())); $event_ids = Set::extract($upcoming_events,'{n}.CalendarEventInstance.calendar_event_id'); $events = $this->ArtistProfile->CalendarEvent->findAll(array('CalendarEvent.id' => $event_ids, 'CalendarEvent.moderated' => 1)); //fetch the date and time of the next upcoming occurence of each event if(!empty($events)) { $count = 0; foreach($events as $event) { $upcoming = array(); foreach($event['CalendarEventInstance'] as $day) { if($day['id'] >= mktime()) { $upcoming[] = $day['timestamp']; } } $events[$count]['Next']['date'] = null; if(!empty($upcoming)) { $events[$count]['Next']['date'] = min($upcoming); } $count++; } //sort the events into chronological order $size = count($events); for($i = 0; $i < $size; $i++) { for($j = 0; $j < $size; $j++) { if($events[$i]['Next']['date'] < $events[$j]['Next']['date']) { $hold = $events[$i]; $events[$i] = $events[$j]; $events[$j] = $hold; } } } } $this->set('events', $events); if (!$profile) { $this->cakeError('error404', array($this->params['url'])); } $this->pageTitle = $profile['ArtistProfile']['display_name']; $this->set('profile', $profile); $this->set('last_played', $this->ArtistProfile->lastPlayed($profile['ArtistProfile']['id'])); } /** * Pulls limited artist information (only bio and primary media) for a given * artist. Used by the LMA views. * * @param mixed $artist * The slug string or ID number of an artist record * */ function viewbio($artist) { $this->sidebar = 'wpgu'; if (is_numeric($artist)) { $art = $this->ArtistProfile->findById($artist); $this->redirect(array($art['ArtistProfile']['slug']), null, true); } if(!$artist) { $this->Session->setFlash('Invalid Artist.'); $this->redirect(array('action'=>'index'), null, true); } //$this->ArtistProfile->unbindAll(array('hasMany' => array('ArtistAlbum', 'ArtistMetadatum'), 'hasAndBelongsToMany' => array('Media', 'Article'))); $this->ArtistProfile->unbindAll(array('belongsTo' => array('PrimaryMedia'))); $profile = $this->ArtistProfile->findBySlug($artist); //if the function was called with the requestAction() function, return the results //of the query at this point and stop, instead of rendering the view if(isset($this->params['requested'])) { return $profile; } $this->set('artist', $profile); } /** * Pulls album records and associated information for the site frontend. * * @param int $id * The ID number of an artist album record * */ function view_album($id = null) { if(!$id) { $this->Session->setFlash('Invalid Artist Album.'); $this->redirect(array('action'=>'index'), null, true); } $this->ArtistProfile->ArtistAlbum->recursive = 2; $this->ArtistProfile->unbindAll(array('hasMany' => array('ArtistAlbum', 'ArtistMetadatum'))); $album = $this->ArtistProfile->ArtistAlbum->read(null, $id); $this->set('album', $album); //filter out unapproved comments so they don't get counted and format output for the comments element $this->ArtistProfile->ArtistAlbum->ArtistAlbumsComments->recursive = 2; $this->ArtistProfile->ArtistAlbum->ArtistAlbumsComments->bindModel(array('belongsTo' => array('Comment'))); $albumComments = $this->ArtistProfile->ArtistAlbum->ArtistAlbumsComments->findAll(array('artist_album_id' => $id)); $comments = array(); foreach($albumComments as $comment) { if($comment['Comment']['approved'] == 1) { $comment['Comment']['rating'] = $comment['ArtistAlbumsComments']['rating']; $comments[] = $comment['Comment']; } } $this->set('comments', $comments); $this->pageTitle = $album['ArtistProfile']['display_name']." : ".$album['ArtistAlbum']['name']; } /******************* * Admin Functions *******************/ /** * Generates a searchable index of artist profile listings in the backend */ function admin_index() { $this->imcAuth->lock(array('reporter','producer','buzzEditor','dj', 'wpguManager','directory','calendar')); if(!$this->RequestHandler->isAjax()) { $this->admin_title = "Browse Artists"; $this->layout = "admin"; // clear the session on first page visit $this->Session->del($this->name.'.search'); } if(!empty($this->data)) { $this->Session->write($this->name.'.search', $this->data['Search']); } elseif($this->Session->check($this->name.'.search')) { $search = $this->Session->read($this->name.'.search'); if ($search) { $this->data['Search'] = $search; } } $search = $this->generateFilters(); $filters = array(); if(isset($search)) { $filters = $search; $this->Session->write($this->name.'.search', $filters); } $profiles = $this->paginate(null,$filters); $this->set('artistProfiles', $profiles); if($this->RequestHandler->isAjax()) { $this->layout = 'ajax'; $this->viewPath = 'elements'.DS.'admin'.DS.'artists'; $this->render('paging'); } } /** * Creates a new artist profile listing. */ function admin_add() { $this->imcAuth->lock(array('reporter','producer','dj', 'wpguManager')); $this->layout = "admin"; $this->admin_title = "Create Artist"; $populate = ($this->data['ArtistProfile']['auto_populate'] == 1) ? true : false; unset($this->data['ArtistProfile']['auto_populate']); if(!empty($this->data)) { $cond = array(); $cond['or'] = array(); $cond['or'][] = '`name` LIKE CONVERT( _utf8 \'%'.$this->data['ArtistProfile']['name'].'%\' USING latin1 )'; $cond['or'][] = '`alternate_names` LIKE CONVERT( _utf8 \'%'.$this->data['ArtistProfile']['name'].'%\' USING latin1 )'; //let's make sure we're not inserting a duplicate profile $check = $this->ArtistProfile->findAll($cond); if($check && !isset($this->data['ArtistProfile']['ok'])) { $this->set('check', $check); } else { //if it checks out, save it if ($artist = $this->ArtistProfile->createArtist($this->data['ArtistProfile'],$populate)) { $this->Session->setFlash('The Artist Profile has been saved'); $this->redirect(array('action'=>'edit',$artist['ArtistProfile']['id']), null, true); } else { $this->Session->setFlash('The Artist Profile could not be saved. Please, try again.'); } } } } /** * Adds a new album to an existing artist profile. */ function admin_add_album($artist_profile_id = null) { $this->imcAuth->lock(array('reporter','producer','dj', 'wpguManager')); $this->layout = "admin"; $this->admin_title = "Create Album"; $this->admin_menu['Add Album'] = '/admin/artists/add_album/'.$artist_profile_id; if(!$artist_profile_id) { $this->Session->setFlash('Invalid Artist Profile ID'); $this->redirect(array('action'=>'index'), null, true); } $this->set('artist_profile_id', $artist_profile_id); if(!empty($this->data)) { $data = $this->data; if($data['ArtistAlbum']['amazon_link'] == '') { $data['ArtistAlbum']['amazon_link'] = null; } if($data['ArtistAlbum']['itunes_link'] == '') { $data['ArtistAlbum']['itunes_link'] = null; } if($data['ArtistAlbum']['media_id'] == '') { $data['ArtistAlbum']['media_id'] = null; } $user = $this->imcAuth->getUser(); if($user) { $data['ArtistAlbum']['updater_id'] = $user['User']['id']; } //save the basic album info if($this->ArtistProfile->ArtistAlbum->save($data['ArtistAlbum'])) { $getID = $this->ArtistProfile->ArtistAlbum->getLastInsertId(); //save album tracks if(!empty($data['ArtistTrack'])) { foreach($data['ArtistTrack'] as $track) { $track['id'] = null; $track['artist_album_id'] = $getID; $this->ArtistProfile->ArtistAlbum->ArtistTrack->save($track); //while we're at it, let's check the playlists and see if the track we just added/updated been played on WPGU $playlists = $this->Playlist->findAll(array('artist_profile_id = '. $artist_profile_id, 'track LIKE "%'.$track['title'].'%"', 'artist_track_id IS NULL')); if(!empty($playlists)) { $getTrackID = $this->ArtistProfile->ArtistAlbum->ArtistTrack->getLastInsertId(); foreach($playlists as $playlist) { $playlist['Playlist']['artist_track_id'] = $getTrackID; $this->Playlist->save($playlist); } } } } $this->Session->setFlash('The Artist Album has been saved'); $this->redirect(array('action'=>'edit_album/'.$getID), null, true); } else { $this->Session->setFlash('The Artist Album could not be saved. Please, try again.'); } } } /** * Administrator editing of an artist profile * * @param int $id * The ID number of an artist profile record * */ function admin_edit($id = null) { $this->imcAuth->lock(array('reporter','producer','dj', 'wpguManager')); $this->layout = "admin"; $this->admin_menu['Edit Artist'] = '/admin/artists/edit/'.$id; if(!$id) { $this->Session->setFlash('Invalid Artist Profile'); $this->redirect(array('action'=>'index'), null, true); } $this->ArtistProfile->recursive = 2; $this->ArtistProfile->unbindAll(array('belongsTo' => array('PrimaryMedia'), 'hasMany' => array('ArtistAlbum', 'ArtistMetadatum'), 'hasAndBelongsToMany' => array('Media'))); $profile = $this->ArtistProfile->find(array('ArtistProfile.id' => $id)); $this->admin_title = "Edit Artist: ".$profile['ArtistProfile']['name']; $this->set('profile', $profile); if(!empty($this->data)) { //print_r($this->data);die; $data = $this->data; //remove the auto-created flag, since, theoretically, there should be some real info in the profile now $data['ArtistProfile']['auto_created'] = 0; if($this->ArtistProfile->save($data)) { //save any metadata on the form $meta_ids = array(); if(isset($this->data['ArtistMetadatum'])) { foreach($this->data['ArtistMetadatum'] as $meta) { if(!isset($meta['id'])) { $meta['id'] = null; } $meta['artist_profile_id'] = $id; //if it's a link make sure it includes the http:// if(isset($meta['category'])) { if($meta['category'] == 'links') { $check = strstr($meta['value'], 'http://'); if(!$check) { $meta['value'] = 'http://'.$meta['value']; } } } $this->ArtistProfile->ArtistMetadatum->save($meta); if(!isset($meta['id'])) { $meta['id'] = $this->ArtistProfile->ArtistMetadatum->getLastInsertId(); } $meta_ids[] = $meta['id']; } } if(isset($this->data['ArtistSoundsLike'])) { foreach($this->data['ArtistSoundsLike'] as $key => $value) { $meta['id'] = null; $meta['artist_profile_id'] = $id; $meta['category'] = 'sounds_like'; if($key != '') { if($key == 'value') { $meta['key'] = 0; $meta['value'] = $value; } else { $meta['key'] = $value['key']; $meta['value'] = $value['value']; } $this->ArtistProfile->ArtistMetadatum->save($meta); } $meta['id'] = $this->ArtistProfile->ArtistMetadatum->getLastInsertId(); $meta_ids[] = $meta['id']; } } //check to see if any old metadata are to be removed $check_meta = $this->ArtistProfile->ArtistMetadatum->findAll(array('artist_profile_id' => $this->data['ArtistProfile']['id']), 'ArtistMetadatum.id'); $check_ids = Set::extract($check_meta, '{n}.ArtistMetadatum.id'); foreach($check_ids as $check) { if(!in_array($check, $meta_ids)) { $this->ArtistProfile->ArtistMetadatum->delete($check); } } $this->Session->setFlash('The Artist Profile saved'); $this->redirect('/admin/artists/edit/'.$id); } else { $this->Session->setFlash('The Artist Profile could not be saved. Please, try again.'); } } $this->data = $profile; $this->set('last_played', $this->ArtistProfile->lastPlayed($id)); $this->set('genre_options', array('Indie' => 'Indie', 'Rock' => 'Rock', 'Pop Rock' => 'Pop Rock', 'Folk' => 'Folk', 'Hip-Hop' => 'Hip-Hop', 'Electronica' => 'Electronica', 'Punk' => 'Punk', 'Dance' => 'Dance', 'Lo-Fi' => 'Lo-Fi', 'Hardcore Ska' => 'Hardcore Ska', 'Alternative' => 'Alternative', 'New Wave' => 'New Wave', 'Surf' => 'Surf')); $new_albums = $this->ArtistProfile->findUpdates($profile['ArtistProfile']); $have = array(); foreach($profile['ArtistAlbum'] as $check) { $have[] = $check['name']; } foreach($new_albums as $i => $new_album) { if(in_array($new_album, $have)) { unset($new_albums[$i]); } } $this->set('new_albums', $new_albums); } /** * Administrator editing of album data and track listing * * @param int $album_id * The ID number of an artist album record * */ function admin_edit_album($album_id = null) { $this->imcAuth->lock(array('reporter','producer','dj', 'wpguManager')); $this->layout = "admin"; if(!$album_id) { $this->Session->setFlash('Invalid Artist Profile'); $this->redirect(array('action'=>'index'), null, true); } if(!empty($this->data)) { $data = $this->data; if($data['ArtistAlbum']['amazon_link'] == '') { $data['ArtistAlbum']['amazon_link'] = null; } if($data['ArtistAlbum']['itunes_link'] == '') { $data['ArtistAlbum']['itunes_link'] = null; } $data['ArtistAlbum']['amazon_link'] = $this->sanitize_link($data['ArtistAlbum']['amazon_link']); $data['ArtistAlbum']['itunes_link'] = $this->sanitize_link($data['ArtistAlbum']['itunes_link']); $user = $this->imcAuth->getUser(); if($user) { $data['ArtistAlbum']['updater_id'] = $user['User']['id']; } if (empty($data['ArtistAlbum']['media_id'])) { unset($data['ArtistAlbum']['media_id']); } if (empty($data['ArtistAlbum']['release_year'])) { unset($data['ArtistAlbum']['release_year']); } if($this->ArtistProfile->ArtistAlbum->save($data)) { //save any track info on the form $track_ids = array(); if(isset($data['ArtistTrack'])) { foreach($data['ArtistTrack'] as $track) { if(!isset($track['id'])) { $track['id'] = null; } $track['artist_album_id'] = $album_id; $this->ArtistProfile->ArtistAlbum->ArtistTrack->save($track); if(!$track['id']) { $track['id'] = $this->ArtistProfile->ArtistAlbum->ArtistTrack->getLastInsertId(); } $track_ids[] = $track['id']; //while we're at it, let's check the playlists and see if the track we just added/updated been played on WPGU $conditions = array(); $conditions['and'][] = array('track' => 'LIKE %'.$track['title'].'%'); $conditions['or'] = array(array('artist_profile_id' => $data['ArtistAlbum']['artist_profile_id']), array('artist' => 'LIKE %'.$data['ArtistProfile']['name'].'%'), array('artist' => 'LIKE %'.$data['ArtistProfile']['display_name'].'%'), array('artist' => 'LIKE %'.$data['ArtistProfile']['alternate_names'].'%') ); $this->Playlist->unbindAll(); $playlists = $this->Playlist->findAll($conditions); if(!empty($playlists)) { if($track['id'] == '') { $getTrackID = $this->ArtistProfile->ArtistAlbum->ArtistTrack->getLastInsertId(); } else { $getTrackID = $track['id']; } foreach($playlists as $playlist) { $playlist['Playlist']['artist_track_id'] = $getTrackID; if(empty($playlist['Playlist']['artist_profile_id'])) { $playlist['Playlist']['artist_profile_id'] = $data['ArtistAlbum']['artist_profile_id']; } $this->Playlist->save($playlist); } } } } //check to see if any old tracks are to be removed $check_tracks = $this->ArtistProfile->ArtistAlbum->ArtistTrack->findAll(array('artist_album_id' => $this->data['ArtistAlbum']['id']), 'ArtistTrack.id'); $check_ids = Set::extract($check_tracks, '{n}.ArtistTrack.id'); foreach($check_ids as $check) { if(!in_array($check, $track_ids)) { $this->ArtistProfile->ArtistAlbum->ArtistTrack->delete($check); } } //save any metadata on the form if(isset($data['ArtistMetadatum'])) { foreach($data['ArtistMetadatum'] as $link) { if($link['value'] != '') { if($link['id'] == '') { $link['id'] = null; } $link['artist_profile_id'] = $data['ArtistAlbum']['artist_profile_id']; $this->ArtistProfile->ArtistMetadatum->save($link); } else { //if the record exists, but the field has been cleared out by the user, delete the record if($link['id'] != '') { $this->ArtistProfile->ArtistMetadatum->del($link['id']); } } } } $this->Session->setFlash('The Artist Album saved'); $this->redirect(array('action'=>'edit_album/'.$data['ArtistAlbum']['id']), null, true); } else { $this->Session->setFlash('The Artist Album could not be saved. Please, try again.'); $this->redirect(array('action'=>'edit_album/'.$data['ArtistAlbum']['id']), null, true); } } if (empty($this->data)) { $this->data = $this->ArtistProfile->ArtistAlbum->find(array('ArtistAlbum.id' => $album_id)); $this->admin_title = "Edit Album: ".$this->data['ArtistAlbum']['name']; } } /** * Saves the checked values of the "new albums" form embeded in the /admin/artists/edit form */ function admin_add_updates() { if(empty($this->data)) { return false; } $data = $this->data; $artist = $data['ArtistAlbum']['artist_name']; foreach($data['NewAlbum'] as $album) { if($album['add']) { //fetch the track listing from lastFM $details = $this->ArtistProfile->findAlbumDetails($artist, $album['name']); if(!empty($details)) { $details['ArtistAlbum']['id'] = null; $details['ArtistAlbum']['artist_profile_id'] = $data['ArtistAlbum']['artist_profile_id']; //debug($details);die; $this->ArtistProfile->ArtistAlbum->save($details); $album_id = $this->ArtistProfile->ArtistAlbum->getLastInsertId(); foreach($details['ArtistTrack'] as $track) { $track['artist_album_id'] = $album_id; $this->ArtistProfile->ArtistAlbum->ArtistTrack->save($track); } } } } $this->redirect('/admin/artists/edit/'.$data['ArtistAlbum']['artist_profile_id']); } /** * Delete an entire artist profile * * @param int $id * The ID number of an artist profile record * */ function admin_delete($id = null) { $this->imcAuth->lock(array('reporter','producer','dj', 'wpguManager')); if(!$id) { $this->Session->setFlash('Invalid id for Artist Profile'); $this->redirect(array('action'=>'index'), null, true); } if($this->ArtistProfile->del($id)) { //log the fact that a deletion has just occurred $session = $this->Session->read('imcAuth.secret'); if($session) { $log = array(); $log['id'] = null; $log['model'] = 'ArtistProfile'; $log['model_id'] = $id; $log['user_id'] = $session['User']['id']; $log['action'] = 'delete'; $this->LogEntry->save($log); } $this->Session->setFlash('Artist Profile #'.$id.' deleted'); $this->redirect(array('action'=>'index'), null, true); } } /** * Admin view of and entire artist profile... required by the Add Artist javascript widget * * @param int $id * The ID number of an artist profile record * */ function admin_view($id = null) { $this->imcAuth->lock(array('reporter','producer','buzzEditor','dj', 'wpguManager','directory','calendar')); $this->layout = "admin"; if(!$id) { $this->Session->setFlash('Invalid Artist Profile.'); $this->redirect(array('action'=>'index'), null, true); } $this->ArtistProfile->recursive = 2; $profile = $this->ArtistProfile->read(null, $id); $this->admin_title = "View Artist: ".$profile['ArtistProfile']['name']; $this->set('profile', $profile); $this->set('last_played', $this->ArtistProfile->lastPlayed($id)); $tracks = $this->ArtistProfile->ArtistAlbum->ArtistTrack->findAll(array('artist_profile_id' => $id), null, 'rating desc'); $high_track = array(); if($tracks) { $high_track = $tracks[0]; } $this->set('high_track', $high_track); } /** * Delete individual associated profile information stored in the ArtistProfileMetadatum, * ArtistAlbum, or ArtistTrack models * * @param string $model * The name of the model the information belongs to * * @param int $artist_profile_id * The ID of the artist profile the information is associated with * * @param int $meta_id * The ID of the associated information * */ //delete individual profile information stored in metadata, albums, or tracks function admin_info_delete($model = null, $artist_profile_id = null, $meta_id = null) { $this->imcAuth->lock(array('reporter','producer','dj', 'wpguManager')); if(!$model || !$meta_id || !$artist_profile_id) { $this->Session->setFlash('Invalid id for Profile information'); $this->redirect(array('action' => 'index'), null, true); } else { //log the fact that a deletion has just occurred $session = $this->Session->read('imcAuth.secret'); if($session) { $log = array(); $log['id'] = null; $log['model'] = $model; $log['model_id'] = $meta_id; $log['user_id'] = $session['User']['id']; $log['action'] = 'delete'; $this->LogEntry->save($log); } if($model == 'ArtistProfile') { if($this->ArtistProfile->del($meta_id)) { $this->Session->setFlash('Artist deleted'); $this->redirect('/admin/artists/index'); } } elseif($model == 'ArtistAlbum') { if($this->ArtistProfile->ArtistAlbum->del($meta_id)) { $this->Session->setFlash('Album deleted'); $this->redirect('/admin/artists/edit/'.$artist_profile_id); } } elseif($model == 'ArtistTrack') { $track = $this->ArtistProfile->ArtistAlbum->ArtistTrack->find(array('ArtistTrack.id' => $meta_id)); if($this->ArtistProfile->ArtistAlbum->ArtistTrack->del($meta_id)) { $this->Session->setFlash('Track deleted'); $this->redirect('/admin/artists/edit_album/'.$track['ArtistTrack']['artist_album_id']); } } elseif($model == 'ArtistMetadatum') { if($this->ArtistProfile->ArtistMetadatum->del($meta_id)) { $this->Session->setFlash('Track deleted'); $this->redirect('/admin/artists/edit/'.$artist_profile_id); } } else { $this->Session->setFlash('Invalid model'); } } } /** * Filters for incomplete artist profile records (ones that were auto-generated * using info from LastFM) and paginates the results */ function admin_attend() { $this->imcAuth->lock(array('reporter','producer','dj', 'wpguManager')); if(!$this->RequestHandler->isAjax()) { $this->admin_title = "Needs Attention"; $this->layout = "admin"; // clear the session on first page visit $this->Session->del($this->name.'.search'); } if(!empty($this->data)) { $this->Session->write($this->name.'.search', $this->data['Search']); } elseif($this->Session->check($this->name.'.search')) { $search = $this->Session->read($this->name.'.search'); if ($search) { $this->data['Search'] = $search; } } $search = $this->generateFilters(); $filters = array(); if(isset($search)) { $filters = $search; $this->Session->write($this->name.'.search', $filters); } $profiles = $this->paginate(array('auto_created' => 1, $filters)); $this->set('artistProfiles', $profiles); if($this->RequestHandler->isAjax()) { $this->viewPath = 'elements'.DS.'admin'.DS.'artists'; $this->render('paging'); } } /** * Filteres for artist albums lacking itunes/amazon purchase links and paginates the results */ function admin_missing_links($filter = null) { $this->imcAuth->lock(array('reporter','producer','dj', 'wpguManager')); $this->admin_title = "Missing Purchase Links"; $this->layout = "admin"; $this->ArtistProfile->ArtistAlbum->unbindAll(array('belongsTo' => array('ArtistProfile')),false); $conditions['or'][] = 'ArtistAlbum.amazon_link IS NULL'; $conditions['or'][] = 'ArtistAlbum.itunes_link IS NULL'; //if requested, don't return auto-generated/unedited profiles if($filter) { $conditions['and']['ArtistProfile.auto_created'] = false; $this->set('filter', true); } $albums = $this->paginate($this->ArtistProfile->ArtistAlbum, $conditions); $this->set('albums', $albums); } /** * Filters for albums that have at least one itunes/amazon purchase link */ function admin_has_links() { $this->imcAuth->lock(array('reporter','producer','dj', 'wpguManager')); $this->admin_title = "Has Purchase Links"; $this->layout = "admin"; $this->ArtistProfile->ArtistAlbum->unbindAll(array('belongsTo' => array('ArtistProfile')),false); $conditions['or'][] = 'ArtistAlbum.amazon_link IS NOT NULL'; $conditions['or'][] = 'ArtistAlbum.itunes_link IS NOT NULL'; $albums = $this->paginate($this->ArtistProfile->ArtistAlbum, $conditions); $this->set('albums', $albums); } /** * Displays matching results for the text entered into a search field. Used by the * backend related artist profiles widget. */ function autocomplete() { $this->ArtistProfile->unbindAll(); if(isset($this->data['SoundsLike']['value'])) { $find_me = $this->data['SoundsLike']['value']; } else { foreach($this->data['SoundsLike'] as $value) { $find_me = $value['value']; } } //debug($find_me);die; $this->set('soundslikes', $this->ArtistProfile->findAll( "name LIKE '%{$find_me}%'") ); $this->layout = "ajax"; } /** * Displays matching results for the text entered into a search field. Used by the SongLists controller * in place of Troy's ridiculously complex auto complete widget that can be displayed multiple times on a page */ function simpleautocomplete() { $find_me = ''; $this->ArtistProfile->unbindAll(); if(isset($this->data['SongListEntry']['artist_name'])) { $find_me = $this->data['SongListEntry']['artist_name']; } else { //if there are multiple autocomplete fields, the stucture of $this->data['ArtistProfile'] is slightly different //We just need the loop because the key for the array varies foreach($this->data['SongListEntry'] as $value) { $find_me = $value['artist_name']; } } $this->set('soundslikes', $this->ArtistProfile->findAll( "name LIKE '%{$find_me}%'") ); $this->layout = "ajax"; } /** * Displays a preview of user-selected results from the autocomplete function. */ function artistPreview($model,$id = null) { $this->ArtistProfile->unbindAll(); $this->set('model',$model); if (!$id) { $this->set('soundslike',false); } else { $this->set('soundslike',$this->ArtistProfile->find(array('ArtistProfile.id' => $id))); } } /** * Retrieves and renders as XML a list of uploaded audio files associated with * an artist profile. Used to generate the XML playlist for the embedded audio player. * * @param int $id * The ID number of an artist profile record * */ function get_audio($id) { $this->layout = null; if(!$id) { return false; } $this->ArtistProfile->ArtistsMedia->bindModel(array('belongsTo' => array('Media'))); $tracks = $this->ArtistProfile->ArtistsMedia->findAll(array('ArtistsMedia.artist_profile_id' => $id, 'Media.type LIKE "%audio%"')); $this->set('tracks', $tracks); } /** * Cleans itunes/amazon purchase links of any additional HTML code before inserting * into the database. Used by the add/edit functions. * * returns string $link */ private function sanitize_link($link) { if (strpos($link,'href=') !== false) { preg_match('/href="([^"]*)"/',$link,$matches); if (isset($matches[1])) { return $matches[1]; } } $position = strpos($link,'http'); if($position != 0) { $link = substr($link,$position); } $position = strpos($link,'"'); if($position != 0) { $link = substr($link,0,$position); } $link = str_replace(array('"','>'),'',strip_tags($link)); return $link; } /** * Generates an array of search filters for the backend's artist profile search fields. * * returns array $conditions */ private function generateFilters() { $conditions = array(); if (!empty($this->data['Search']['value'])) { $text = array(); $text[] = "ArtistProfile.name LIKE \"%".$this->data['Search']['value']."%\""; //$text[] = "ArtistTrack.title LIKE \"%".$this->data['Search']['value']."%\""; //$text[] = "ArtistAlbum.name LIKE \"%".$this->data['Search']['value']."%\""; $conditions['or'] = $text; } if(!empty($this->data['Search']['local']) && $this->data['Search']['local']) { $conditions['and']['ArtistProfile.local'] = 1; } if(!empty($this->data['Search']['or']) || !empty($this->data['Search']['and'])) { $conditions = $this->data['Search']; } return $conditions; } } ?>