Closed (fixed)
Project:
Audio
Version:
5.x-2.x-dev
Component:
audio_playlist
Priority:
Critical
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
25 May 2008 at 19:31 UTC
Updated:
29 Oct 2008 at 08:01 UTC
1. Is there a way (function I could call) to count the number of audio files attached to a node (i.e. number of files in a playlist)?
2. I'd then like to use the result as the condition for an if statement in my template.php override to display the extended player for multiple files but switch to the slim player for a single file. Assuming #1 is possible, can anyone give me a clue as to the best way to accomplish #2?
My current theme override:
/**
* EXAMPLE THEME FUNCTION OVERRIDE TO DISPLAY ONE XSPF PLAYER
* Theme used if multiple files are attached
*/
function garland_audio_attach_list($nids, $teaser = FALSE) {
drupal_add_css(drupal_get_path('module', 'audio_attach') .'/audio_attach.css');
// generate an XSPF player for this playlist
$player = audio_get_players('name', variable_get('audio_feeds_default_player', 'xspf_extended'));
$playlist_url = url('node/' . arg(1) .'/xspf', NULL, NULL, TRUE);
$output .= "<strong>Audio samples:</strong><br>";
$output .= theme($player['theme_xspf'], $playlist_url);
$output .= "<br>";
foreach ($nids as $aid) {
$audio = node_load($aid);
$audio = node_prepare($audio, $teaser);
$title = $audio->status ? l($audio->title, 'node/' . $audio->nid, NULL, NULL, NULL, TRUE) : check_plain($audio->title);
$items[] = '<div class="title">'. $title .'</div>';
}
// removed individual players
// $output .= theme('item_list', $items, null, 'ol', array('class' => 'audio-attach-list'));
// commented above line to remove html playlist
return $output;
}
Comments
Comment #1
zirafa commentedComment #2
drewish commentedComment #3
anthonym commentedJust wanted to add my current code incorporating zirafa's answer in case it might assist someone else looking for a similar solution. It works well. Thanks.
Comment #4
anthonym commentedI need a little more info on the above, please. I'm now working with a separate template for the node type which includes the audio players as defined above. I have this in my node-type.tpl.php file, but it only partly works:
print garland_audio_attach_list($nids, $teaser = FALSE)I do get a player, but it appears on every node, whether or not there are audio files attached, and the switch I have configured to choose between the extended and slim players no longer works. Only the slim player gets displayed (although it does play multiple selections if they are in a playlist). I guess I need another way to count attached files in the if statement? Any ideas?
Comment #5
zirafa commentedYou'll have to give a little more detail about what you are trying to do. But my guess is that the variable $nids isn't getting set. Now that you are dealing with a node-[type].tpl.php file, you have to make sure the variables are getting sent to the tpl.php file properly. Often times this is done with a phptemplate_callback function. But you may already have the info you need...Try doing
print_r($node)in the tpl.php file to see if $node->audio_attach exists. Sending $node->audio_attach as the $nids argument would be the next step.Comment #6
anthonym commentedZirafa, thanks for the reply. That helped a lot. I'm not sure if this is what you meant, but I changed my node template line to:
print garland_audio_attach_list($node->audio_attach, $teaser = FALSE)which brought back the switching effect I was after, but the slim player was still appearing on all nodes. I'm guessing this was because (according to the devel module) the audio_attach array seemed to be present on all of my nodes even if the array was empty (i.e. no files attached). I solved this by wrapping the player generation/switching code in another if statement which checks to see if the array has anything in it first. I don't know how clean/efficient this is, but it's working so far. Included below for the record:
Comment #7
zirafa commentedCheck my post #1 which I revised to use !empty($nids) instead of is_array($nids). That might work better because !empty($nids) should evaluate to FALSE if $nids => array() (empty array). Or at least that's what http://php.net/empty says. With is_array it returns TRUE even if it is an empty array.
But the way you've done it works too.
Comment #8
drewish commentedComment #9
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.