This is the goal: Extending the
schedulermodule
tobe able to view a countdown until a node is published orunpublished. Countdown meaning "How many time units until the nodeis published or unpublished". This would be the perfect job for theviews module. Scheduler already exposes its publish_on andunpublish_on fields for use with views.
Defining the supported views version in filescheduler.module
<?php
function
scheduler_views_api
(){
$info
[
'api'
]=
2
;
return
$info
;
}
?>
Defining the table and fields in filescheduler.views.inc:
<?php
function scheduler_views_data(){
$tables['scheduler']['table']['group']= t('Scheduler');
//how is the scheduler table linked to the nodes
$tables['scheduler']['table']['join']['node']= array(
'left_field' => 'nid',
'field' => 'nid',
);
//description of the fields (table columns)
$tables['scheduler']['publish_on']= array(
'title' => t('Publishon'),
'help' => t('Date/timeon which the article will be automaticallypublished'),
'field' =>array(
'handler' => 'views_handler_field_date',
'clicksortable' => TRUE,
),
'filter' =>array(
'handler' => 'views_handler_filter_date',
'label' => t('Publishon'),
),
'sort' =>array(
'handler' => 'views_handler_sort_date',
),
);
$tables['scheduler']['unpublish_on']= array(
'title' => t('Unpublishon'),
'help' => t('Date/timeon which the article will be automaticallyunpublished'),
'field' =>array(
'handler' => 'views_handler_field_date',
'clicksortable' => TRUE,
),
'filter' =>array(
'handler' => 'views_handler_filter_date',
'label' => t('Unpublishon'),
),
'sort' =>array(
'handler' => 'views_handler_sort_date',
),
);
return $tables;
}
?>
Since we just exposed existing DB fields we only needed to definehow the scheduler table is to be joined with the node table. Fordisplaying the values we could rely on a predefined handler fordate values (views_handler_field_date
).That is the code that we need to build upon.
What we need now is a custom handler because there is no predefinedhandler for our purpose. At first we need to define the field.Let's start with a simple second count down:
<?php
$tables['scheduler']['publish_countdown']= array(
'title' => t('Publishcountdown'),
'help' => t('Timeuntil the article will be automaticallypublished'),
'field' =>array(
'handler' => 'scheduler_handler_field_scheduler_countdown',
'clicksortable' => FALSE,
'timestamp_field' => 'publish_on',
),
);
?>