| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: audio.views.inc,v 1.5 2009/05/10 18:12:30 drewish Exp $ 3 4 // THIS IS THE UNPORTED LEGACY VIEWS CODE THAT'S JUST HERE FOR REFERENCE UNTIL 5 // IT CAN BE MOVED INTO views/audio.views.inc 6 7 function audio_views_tables() { 8 $players = array(); 9 foreach (audio_get_players('names') as $name => $player) { 10 $players[$name] = $player['title']; 11 } 12 13 $tables['audio'] = array( 14 'name' => 'audio', 15 'join' => array( 16 'left' => array( 17 'table' => 'node', 18 'field' => 'vid' 19 ), 20 'right' => array( 21 'field' => 'vid' 22 ) 23 ), 24 'fields' => array( 25 'file_size' => array( 26 'name' => t('Audio: File size'), 27 'handler' => 'views_handler_field_filesize', 28 'sortable' => TRUE, 29 'help' => t("This will display the audio file's size."), 30 ), 31 ), 32 ); 33 34 $numeric_tags = array('track', 'year'); 35 36 foreach (audio_get_tags_allowed() as $tag) { 37 $tables['audio_metadata_'. $tag] = array( 38 'name' => 'audio_metadata', 39 'join' => array( 40 'left' => array( 41 'table' => 'audio', 42 'field' => 'vid' 43 ), 44 'right' => array( 45 'field' => 'vid' 46 ), 47 'extra' => array( 48 'tag' => $tag 49 ), 50 ), 51 'fields' => array( 52 'value' => array( 53 'name' => t('Audio: Tag @tag', array('@tag' => $tag)), 54 'sortable' => TRUE, 55 'help' => t('This will display tag %tag values.', array('%tag' => $tag)), 56 ), 57 ), 58 'filters' => array( 59 'clean' => array( 60 'name' => t('Audio: Tag @tag', array('@tag' => $tag)), 61 'tag' => $tag, 62 'operator' => array('=' => 'Equals'), 63 'list' => 'audio_views_handler_filter_tags', 64 'list-type' => 'list', 65 'operator' => 'views_handler_operator_or', 66 'value-type' => 'array', 67 'help' => t('Filter by whether or not the audio is downloadable. '), 68 ), 69 ), 70 'sorts' => array( 71 'value' => array( 72 'name' => t('Audio: Tag @tag', array('@tag' => $tag)), 73 'help' => t('Sort audio nodes by tag %tag values.', array('%tag' => $tag)), 74 ), 75 ), 76 ); 77 78 // Use different handlers for numeric tags. 79 if (in_array($tag, $numeric_tags)) { 80 $tables["audio_metadata_$tag"]['sorts']['value']['handler'] = 'audio_views_sort_handler_numeric_tag'; 81 // Set notafield to TRUE so that our handler can add the field. 82 $tables["audio_metadata_$tag"]['fields']['value']['notafield'] = TRUE; 83 $tables["audio_metadata_$tag"]['fields']['value']['query_handler'] = 'audio_views_field_query_handler_numeric'; 84 } 85 } 86 87 return $tables; 88 } 89 90 /** 91 * 92 */ 93 function audio_views_handler_filter_tags($op, $field) { 94 $tags = array(); 95 $result = db_query(db_rewrite_sql("SELECT a.value, a.clean FROM {node} n INNER JOIN {audio_metadata} a ON n.vid = a.vid WHERE a.tag = '%s' ORDER BY a.value ASC"), $field['tag']); 96 while ($obj = db_fetch_object($result)) { 97 $tags[$obj->clean] = $obj->value; 98 } 99 return $tags; 100 } 101 102 /** 103 * Field sort handler to convert numeric values in string fiels for sorting. 104 * 105 * For more info on how this works see: http://blog.feedmarker.com/2006/02/01/how-to-do-natural-alpha-numeric-sort-in-mysql/ 106 */ 107 function audio_views_field_query_handler_numeric($fielddata, $fieldinfo, &$query) { 108 // This handler expects that the field will have 'notafield' => TRUE so that 109 // we can add in our field and not have worry about views overwriting it with 110 // the default. 111 $query->add_field($fielddata['field'] .' + 0', $fielddata['tablename'], $fielddata['queryname']); 112 } 113 114 /** 115 * Sort handler to convert numeric values in string fiels for sorting. 116 * 117 * For more info on how this works see: http://blog.feedmarker.com/2006/02/01/how-to-do-natural-alpha-numeric-sort-in-mysql/ 118 */ 119 function audio_views_sort_handler_numeric_tag($op, &$query, $sortinfo, $sort) { 120 // We go to a bunch of trouble here to make sure we're adding the same field 121 // as audio_views_field_query_handler_numeric() would so that views doesn't 122 // duplicate it. 123 $query->add_orderby('', $sort['field'] .' + 0', $sort['sortorder'], $sortinfo['table'] .'_'. $sortinfo['field']); 124 125 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |