| 1 |
<?php
|
| 2 |
//$Id$
|
| 3 |
/**
|
| 4 |
* Implementation of hook_views_tables
|
| 5 |
*
|
| 6 |
* @return
|
| 7 |
* array - Enables support in the video module for views integration
|
| 8 |
* porting to Drupal 6
|
| 9 |
* @author Heshan Wanigasooriya <heshan at heidisoft.com><heshanmw@gmail.com>
|
| 10 |
* @todo
|
| 11 |
**/
|
| 12 |
|
| 13 |
function video_views_tables() {
|
| 14 |
$tables['video'] = array(
|
| 15 |
'name' => 'video',
|
| 16 |
'join' => array(
|
| 17 |
'left' => array(
|
| 18 |
'table' => 'node',
|
| 19 |
'field' => 'vid'
|
| 20 |
),
|
| 21 |
'right' => array(
|
| 22 |
'field' => 'vid'
|
| 23 |
)
|
| 24 |
),
|
| 25 |
|
| 26 |
// Fields that can be inserted into a view
|
| 27 |
'fields' => array(
|
| 28 |
'play_counter' => array(
|
| 29 |
'name' => t('Video: Play count'),
|
| 30 |
'sortable' => true,
|
| 31 |
'help' => t('This will display the number of times this has been played.'),
|
| 32 |
),
|
| 33 |
'download_counter' => array(
|
| 34 |
'name' => t('Video: Download count'),
|
| 35 |
'sortable' => true,
|
| 36 |
'help' => t('This will display the number of times this has been downloaded.'),
|
| 37 |
),
|
| 38 |
'playtime_seconds' => array(
|
| 39 |
'name' => t('Video: Length'),
|
| 40 |
'handler' => 'video_views_handler_field_playtime_seconds',
|
| 41 |
'sortable' => true,
|
| 42 |
'help' => t('This will display the play length of the video.'),
|
| 43 |
),
|
| 44 |
'download_link' => array(
|
| 45 |
'name' => t('Video: Download link'),
|
| 46 |
'handler' => 'video_views_handler_field_download',
|
| 47 |
'notafield' => true,
|
| 48 |
'sortable' => false,
|
| 49 |
'help' => t('This will display a download link if the node allows it.'),
|
| 50 |
),
|
| 51 |
'play_link' => array(
|
| 52 |
'name' => t('Video: Play link'),
|
| 53 |
'handler' => 'video_views_handler_field_play',
|
| 54 |
'notafield' => true,
|
| 55 |
'sortable' => false,
|
| 56 |
'help' => t('This will display a play link if the node allows it.'),
|
| 57 |
),
|
| 58 |
'videox' => array(
|
| 59 |
'name' => t('Video: Width (x)'),
|
| 60 |
'sortable' => true,
|
| 61 |
'help' => t('This will display the width (x) of the video'),
|
| 62 |
),
|
| 63 |
'videoy' =>array(
|
| 64 |
'name' => t('Video: Height (y)'),
|
| 65 |
'sortable' => true,
|
| 66 |
'help' => t('This will display the height (y) of the video'),
|
| 67 |
),
|
| 68 |
),
|
| 69 |
'sorts' => array(
|
| 70 |
'play_counter' => array(
|
| 71 |
'name' => t('Video: Play count'),
|
| 72 |
'help' => t('Sort by the number of video plays.'),
|
| 73 |
),
|
| 74 |
'download_counter' => array(
|
| 75 |
'name' => t('Video: Download count'),
|
| 76 |
'help' => t('Sort by the number of video downloads.'),
|
| 77 |
),
|
| 78 |
'playtime_seconds' => array(
|
| 79 |
'name' => t('Video: Length'),
|
| 80 |
'help' => t('Sort by the video length.'),
|
| 81 |
)
|
| 82 |
)
|
| 83 |
);
|
| 84 |
|
| 85 |
// Add video_image support only if the video_image module is enabled
|
| 86 |
if (module_exists('video_image')) {
|
| 87 |
$tables['video']['fields']['video_image'] = array(
|
| 88 |
'name' => t('Video: Thumbnail'),
|
| 89 |
'notafield' => true,
|
| 90 |
'handler' => 'video_views_handler_field_video_image',
|
| 91 |
'sortable' => false,
|
| 92 |
'help' => t('This will display the thumbnail image for the video.'),
|
| 93 |
);
|
| 94 |
}
|
| 95 |
|
| 96 |
return $tables;
|
| 97 |
}
|
| 98 |
|
| 99 |
|
| 100 |
/**
|
| 101 |
* Provide a default view
|
| 102 |
*
|
| 103 |
* @return
|
| 104 |
array - of views
|
| 105 |
**/
|
| 106 |
function video_views_default_views() {
|
| 107 |
$views = array();
|
| 108 |
|
| 109 |
// recent video node activity view
|
| 110 |
$view = new stdClass();
|
| 111 |
$view->name = 'video_tracker';
|
| 112 |
$view->description = t('Shows all recent video activity (table format)');
|
| 113 |
$view->access = array ();
|
| 114 |
$view->view_args_php = '';
|
| 115 |
$view->page = TRUE;
|
| 116 |
$view->page_title = t('Recent video activity');
|
| 117 |
$view->page_header = '';
|
| 118 |
$view->page_header_format = '1';
|
| 119 |
$view->page_footer = '';
|
| 120 |
$view->page_footer_format = '1';
|
| 121 |
$view->page_empty = t('There is no recent video activity');
|
| 122 |
$view->page_empty_format = '1';
|
| 123 |
$view->page_type = 'table';
|
| 124 |
$view->url = 'video/tracker';
|
| 125 |
$view->use_pager = TRUE;
|
| 126 |
$view->nodes_per_page = '20';
|
| 127 |
$view->sort = array ();
|
| 128 |
$view->argument = array ();
|
| 129 |
$view->field = array (
|
| 130 |
array (
|
| 131 |
'tablename' => 'node',
|
| 132 |
'field' => 'title',
|
| 133 |
'label' => t('Title'),
|
| 134 |
'handler' => 'views_handler_field_nodelink',
|
| 135 |
'sortable' => '1',
|
| 136 |
),
|
| 137 |
array (
|
| 138 |
'tablename' => 'node',
|
| 139 |
'field' => 'changed',
|
| 140 |
'label' => t('Last Updated'),
|
| 141 |
'handler' => 'views_handler_field_date_small',
|
| 142 |
'sortable' => '1',
|
| 143 |
'defaultsort' => 'DESC',
|
| 144 |
),
|
| 145 |
array (
|
| 146 |
'tablename' => 'users',
|
| 147 |
'field' => 'name',
|
| 148 |
'label' => t('Author'),
|
| 149 |
),
|
| 150 |
array (
|
| 151 |
'tablename' => 'video',
|
| 152 |
'field' => 'video_image',
|
| 153 |
'label' => t('Preview / Play'),
|
| 154 |
),
|
| 155 |
);
|
| 156 |
$view->filter = array (
|
| 157 |
array (
|
| 158 |
'tablename' => 'node',
|
| 159 |
'field' => 'type',
|
| 160 |
'operator' => 'OR',
|
| 161 |
'options' => '',
|
| 162 |
'value' => array (
|
| 163 |
0 => 'video',
|
| 164 |
),
|
| 165 |
),
|
| 166 |
array (
|
| 167 |
'tablename' => 'node',
|
| 168 |
'field' => 'status',
|
| 169 |
'operator' => '=',
|
| 170 |
'options' => '',
|
| 171 |
'value' => '1',
|
| 172 |
),
|
| 173 |
);
|
| 174 |
$view->exposed_filter = array ();
|
| 175 |
$view->requires = array(node, users, video);
|
| 176 |
$views[$view->name] = $view;
|
| 177 |
|
| 178 |
return $views;
|
| 179 |
}
|
| 180 |
|
| 181 |
|
| 182 |
/**
|
| 183 |
* Handler to to render the "Download" link field
|
| 184 |
**/
|
| 185 |
function video_views_handler_field_download($fieldinfo, $fielddata, $value, $data) {
|
| 186 |
$nid = $data->nid;
|
| 187 |
return l(t('Download'), "node/$nid/download", array());
|
| 188 |
}
|
| 189 |
|
| 190 |
|
| 191 |
/**
|
| 192 |
* Handler to to render the "Play" link field
|
| 193 |
**/
|
| 194 |
function video_views_handler_field_play($fieldinfo, $fielddata, $value, $data) {
|
| 195 |
$nid = $data->nid;
|
| 196 |
return l(t('Play'), "node/$nid/play", array());
|
| 197 |
}
|
| 198 |
|
| 199 |
|
| 200 |
/**
|
| 201 |
* Handler to to render the correct playtime for the video in a field
|
| 202 |
**/
|
| 203 |
function video_views_handler_field_playtime_seconds($fieldinfo, $fielddata, $value, $data) {
|
| 204 |
$seconds = $value;
|
| 205 |
$hms = _video_sec2hms($seconds);
|
| 206 |
|
| 207 |
// Pad the minutes / seconds with a leading "0", if
|
| 208 |
// necessary
|
| 209 |
if ($hms['hours'] > 0) {
|
| 210 |
$hms['minutes'] = str_pad($hms['minutes'], 2, '0', STR_PAD_LEFT);
|
| 211 |
}
|
| 212 |
$hms['seconds'] = str_pad($hms['seconds'], 2, '0', STR_PAD_LEFT);
|
| 213 |
|
| 214 |
$out = '';
|
| 215 |
if ($hms['hours'] > 0) {
|
| 216 |
$out .= $hms['hours'].":";
|
| 217 |
}
|
| 218 |
$out .= $hms['minutes'].":".$hms['seconds'];
|
| 219 |
|
| 220 |
return t($out);
|
| 221 |
}
|
| 222 |
|
| 223 |
|
| 224 |
/**
|
| 225 |
* Handler to render the preview image associated with a video
|
| 226 |
**/
|
| 227 |
function video_views_handler_field_video_image($fieldinfo, $fielddata, $value, $data) {
|
| 228 |
$node = node_load($data->nid);
|
| 229 |
if($node->iid && $image = node_load($node->iid)) {
|
| 230 |
$output = theme('video_image_teaser', $image, $node);
|
| 231 |
}
|
| 232 |
return $output;
|
| 233 |
}
|