diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..6a74bfd --- /dev/null +++ b/README.txt @@ -0,0 +1,14 @@ +README file for the cma_airing_report module for Drupal 7.x. + +This module upon installation will create a view, airing_distribution_report, with 3 displays: + +1. Distribution Report + This view has a custom header that will show distribution reports that filter by the views exposed date filter. + +2. Data Export + This display allows the results from teh Distribuation report to be downloaded. Note: I wouldn't recommend downloading more than 6 months at a time. + +3. Refresh Show Runtimes + This view will allow one to refresh the runtime for a Show via a Bulk Operations. If a show has multiple airing results, the show will only be resaved once. + +This module also provides a menu page: admin/airings/manage/reports that has links to both the Distribution Report and the Refresh Show Runtimes page. diff --git a/cma_airing_report.info b/cma_airing_report.info new file mode 100644 index 0000000..e7d0ad2 --- /dev/null +++ b/cma_airing_report.info @@ -0,0 +1,9 @@ +name = Community Media Advanced Airing Report +package = Community Media Advanced +description = "Helper functions for airing reports" +version 7.x-1.0 + +core = 7.x + +dependencies[] = cm_airing + diff --git a/cma_airing_report.info~ b/cma_airing_report.info~ new file mode 100644 index 0000000..b3ee076 --- /dev/null +++ b/cma_airing_report.info~ @@ -0,0 +1,8 @@ +name = Community Media Advanced Airing Report +package = Community Media Advanced +description = "Helper functions for airing reports" + +core = 7.x + +dependencies[] = cm_airing + diff --git a/cma_airing_report.install b/cma_airing_report.install new file mode 100644 index 0000000..c80743d --- /dev/null +++ b/cma_airing_report.install @@ -0,0 +1,91 @@ + 'reservations_resource_node', + 'index_name' => 'rateperhour', + 'fields' => array('reservations_rate_per_hour')); + + $args[] = array('table_name' => 'reservations_reservation', + 'index_name' => 'status', + 'fields' => array('reservations_reservation_status')); + + $args[] = array('table_name' => 'reservations_reservation_detail', + 'index_name' => 'vidnid', + 'fields' => array("vid","nid")); + + $args[] = array('table_name' => 'reservations_resource_node', + 'index_name' => 'vidrateperhour', + 'fields' => array('vid','reservations_rate_per_hour')); + + foreach ($args as $index) { + $sql = "show index from {" . $index['table_name']. + "} where Key_name = :index_name"; + + $query_args = array(':index_name' => $index['index_name']); + + $results = db_query($sql, $query_args); + + $index_exists = FALSE; + while ($result = $results->fetchObject()) { + $index_exists = TRUE; + break; + } + if ($index_exists) { + continue; + } + $sql = "ALTER TABLE {" . $index['table_name']."} ADD INDEX " . + $index['index_name'] ." ("; + + $is_first = TRUE; + $counter = 0; + $query_args = array(); + foreach($index['fields'] as $field) { + if ($is_first) { + $is_first= FALSE; + } + else { + $sql .= ","; + } + $counter ++; + $sql .= $field; + } + $sql .= ")"; + db_query($sql); + + } +} + +/** + * Implements hook_uninstall(). + */ +function cma_airing_report_uninstall() { + /* + $sql = "ALTER TABLE reservations_resource_node ADD INDEX rateperhour + (reservations_rate_per_hour)"; + db_query($sql); + + $sql = "ALTER TABLE reservations_reservation ADD INDEX status + (reservations_reservation_status)"; + db_query($sql); + + $sql = "ALTER TABLE reservations_reservation_detail ADD INDEX vidnid + (vid,nid)"; + db_query($sql); + + $sql = "ALTER TABLE reservations_resource_node ADD INDEX vidrateperhour + (vid,reservations_rate_per_hour)"; + + */ +} \ No newline at end of file diff --git a/cma_airing_report.module b/cma_airing_report.module new file mode 100644 index 0000000..812e9c4 --- /dev/null +++ b/cma_airing_report.module @@ -0,0 +1,1225 @@ + 3, + 'path' => + drupal_get_path('module', + 'cma_airing_report').'/inc' + ); +} + +function cma_airing_report_menu() { + $items = array(); + + $items['admin/airings/manage/reports'] = + array( + 'title' => t('Airing Reports'), + 'page callback' => 'cma_airing_report_menu_page', + 'access arguments' => array('view cm_airing entities'), + 'type' => MENU_NORMAL_ITEM, + ); + + return $items; +} + +function cma_airing_report_menu_page() { + $ret = ""; + $ret .= ""; + + return $ret; +} + +function cma_airing_report_distribution_fields() { + return + array( + array('name' => 'airing_project_ref', + 'postfix' => '_target_id', + 'entity' => 'airing', + 'table' => 'aproj', + 'report' => TRUE, + 'ids' => array(1532, 6563, 6564, 6565), + 'children' => array('is_show_premiere_date', 'airing_channel'), + ), + array('name' => 'airing_project_ref', + 'report_only' => TRUE, + 'report' => TRUE, + 'postfix' => ' live_source', + 'ids' => array(1532, 6563, 6564, 6565), + 'children' => array('is_show_premiere_date', 'live_source', + 'airing_channel'), + + ), + + array('name' => 'airing_show_ref', + 'postfix' => '_target_id', + 'entity' => 'airing', + 'table' => 'ashow', + 'report' => FALSE, + ), + array('name' => 'airing_channel', + 'postfix' => '_tid', + 'entity' => 'airing', + 'table' => 'ch', + 'report' => TRUE, + ), + array('name' => 'airing_date', + 'postfix' => '_value', + 'entity' => 'airing', + 'table' => 'adate', + 'report' => FALSE, + ), + array('name' => 'is_show_premiere_date', + 'postfix' => '_value', + 'entity' => 'airing', + 'table' => 'ashow_premiere', + 'report' => TRUE, + 'children' => array('airing_channel'), + ), + array('name' => 'is_show_premiere_date', + 'report_only' => TRUE, + 'report' => TRUE, + 'postfix' => ' government_channel', + 'ids' => array(1532, 6563, 6564, 6565), + 'children' => array('airing_channel'), + + ), + array('name' => 'is_show_premiere_date', + 'report_only' => TRUE, + 'report' => TRUE, + 'postfix' => ' pcm_facilities', + 'children' => array('pcm_facilities', 'airing_channel'), + ), + array('name' => 'is_show_premiere_date', + 'report_only' => TRUE, + 'report' => TRUE, + 'postfix' => ' pbcore_genres', + 'children' => array('pbcore_genres'), + ), + array('name' => 'is_show_premiere_date', + 'report_only' => TRUE, + 'report' => TRUE, + 'postfix' => ' live_source', + 'children' => array('live_source'), + ), + array('name' => 'is_show_premiere_date', + 'report_only' => TRUE, + 'report' => TRUE, + 'postfix' => ' pcm_facilities live_source', + 'children' => array('pcm_facilities', 'live_source', + 'airing_channel'), + ), + array('name' => 'is_show_premiere_date', + 'report_only' => TRUE, + 'report' => TRUE, + 'postfix' => ' produced_where', + 'children' => array('produced_where', 'airing_channel'), + ), + array('name' => 'is_show_premiere_date', + 'report_only' => TRUE, + 'report' => TRUE, + 'postfix' => ' produced_where live_source', + 'children' => array('produced_where', 'live_source', + 'airing_channel'), + ), + array('name' => 'is_show_premiere_date', + 'report_only' => TRUE, + 'report' => TRUE, + 'postfix' => ' produced_city', + 'children' => array('produced_city', 'airing_channel'), + ), + array('name' => 'is_show_premiere_date', + 'report_only' => TRUE, + 'report' => TRUE, + 'postfix' => ' produced_city live_source', + 'children' => array('produced_city', 'live_source', + 'airing_channel'), + ), + + array('name' => 'is_show_simul_premiere', + 'postfix' => '_value', + 'entity' => 'airing', + 'table' => 'ashow_simul', + 'report' => TRUE, + ), + + array('name' => 'live_source', + 'postfix' => '_value', + 'entity' => 'airing', + 'table' => 'lsource', + 'report' => TRUE, + 'children' => array(), + ), + + array('name' => 'live_source', + 'report_only' => TRUE, + 'report' => TRUE, + 'postfix' => ' airing_channel', + 'children' => array('airing_channel'), + ), + array('name' => 'live_source', + 'report_only' => TRUE, + 'report' => TRUE, + 'postfix' => ' produced_where airing_channel', + 'children' => array('produced_where', 'airing_channel'), + ), + array('name' => 'live_source', + 'report_only' => TRUE, + 'report' => TRUE, + 'postfix' => ' pcm_facilities airing_channel', + 'children' => array('pcm_facilities', 'airing_channel'), + + ), + array('name' => 'live_source', + 'report_only' => TRUE, + 'report' => TRUE, + 'postfix' => ' produced_city airing_channel', + 'children' => array('produced_city', 'airing_channel'), + ), + + array('name' => 'pbcore_genres', + 'postfix' => '_tid', + 'entity' => 'show', + 'table' => 'spbg', + 'report' => TRUE, + 'children' => array('is_show_premiere_date'), + ), + array('name' => 'premier_date', + 'postfix' => '_value', + 'entity' => 'show', + 'table' => 'pd', + 'report' => TRUE, + ), + array('name' => 'produced_where', + 'postfix' => '_value', + 'entity' => 'show', + 'table' => 'pw', + 'report' => TRUE, + 'children' => array('airing_channel'), + ), + array('name' => 'produced_city', + 'postfix' => '_value', + 'entity' => 'show', + 'table' => 'city', + 'report' => TRUE, + 'children' => array('airing_channel'), + ), + array('name' => 'pcm_facilities', + 'postfix' => '_value', + 'entity' => 'show', + 'table' => 'facil', + 'report' => TRUE, + 'children' => array('airing_channel'), + ), + + array('name' => 'produced_where', + 'report_only' => TRUE, + 'report' => TRUE, + 'postfix' => ' live_source', + 'children' => array('is_show_premiere_date', 'live_source', + 'airing_channel'), + ), + array('name' => 'produced_city', + 'report_only' => TRUE, + 'report' => TRUE, + 'postfix' => ' live_source', + 'children' => array('is_show_premiere_date', 'live_source', + 'airing_channel'), + ), + array('name' => 'pcm_facilities', + 'report_only' => TRUE, + 'report' => TRUE, + 'postfix' => ' live_source', + 'children' => array('is_show_premiere_date', 'live_source', + 'airing_channel'), + ), + + array('name' => 'runtime', + 'postfix' => '_value', + 'entity' => 'show', + 'table' => 'rt', + 'report' => FALSE, + ), + array('name' => 'pbcore_genres', + 'postfix' => '_tid', + 'entity' => 'project', + 'table' => 'ppbg', + 'report' => FALSE, + ), + + ); + +} +/** + * Initializes a sum for report totals + */ +function cma_airing_report_initialize_sum($sum) { + if (isset($sum)) { + return $sum; + } + return 0; +} + +/** + * Initializes an array for sub report + */ +function cma_airing_report_initialize_array($array) { + if (isset($array)) { + return $array; + } + return array(); +} +/** + * Provides the header for admin/airings/reports/distribution + */ +function cma_airing_report_distribution_header() { + $view = views_get_current_view(); + $count_query = $view->build_info['count_query']; + $exposed_input = $view->exposed_input; + + $query_args = $count_query->getArguments(); + $fields = cma_airing_report_distribution_fields(); + + $sql = 'SELECT '; + $is_first = TRUE; + foreach($fields as $field_info) { + if (isset($field_info['report_only']) && $field_info['report_only']) { + continue; + } + if (!$is_first) { + $sql .= ', '; + } + $sql .= $field_info['table'] . '.field_' . $field_info['name'] . + $field_info['postfix'] .' as ' . $field_info['name']; + + $is_first = FALSE; + } + + $sql .= ' FROM cm_airing airing '; + + foreach($fields as $field_info) { + if (isset($field_info['report_only']) && $field_info['report_only']) { + continue; + } + if ($field_info['entity'] == 'airing') { + $sql .= + 'LEFT JOIN field_data_field_' . $field_info['name'] . ' ' . + $field_info['table'] . ' ON airing.airing_id=' . $field_info['table']. + '.entity_id'; + } + else if ($field_info['entity'] == 'show') { + $sql .= + 'LEFT JOIN field_data_field_' . $field_info['name'] . ' ' . + $field_info['table'] . + ' ON ashow.field_airing_show_ref_target_id=' . + $field_info['table'] . '.entity_id'; + } + else if ($field_info['entity'] == 'project') { + $sql .= + 'LEFT JOIN field_data_field_' . $field_info['name'] . ' ' . + $field_info['table'] . + ' ON aproj.field_airing_project_ref_target_id=' . + $field_info['table'] . '.entity_id'; + } + $sql .= ' '; + } + + $start =$query_args[':field_data_field_airing_date_field_airing_date_value']; + $end = $query_args[':field_data_field_airing_date_field_airing_date_value1']; + $sql .= " WHERE adate.field_airing_date_value >= '$start'"; + $sql .= " AND adate.field_airing_date_value <= '$end'"; + + $results = db_query($sql); + $counter = 0; + + $report = array(); + $limit = 0; + + while($result = $results->fetchObject()) { + $report['count'] = cma_airing_report_initialize_sum($report['count']); + $report['time'] = cma_airing_report_initialize_sum($report['time']); + $report['count']++; + $report['time'] += $result->runtime; + + foreach($fields as $field_info) { + if ($field_info['report']) { + if (isset($field_info['ids']) && $field_info['ids']) { + $has_right_id = FALSE; + foreach($field_info['ids'] as $id) { + if ($id == $result->airing_project_ref) { + $has_right_id = TRUE; + break; + } + } + if (!$has_right_id) { + continue; + } + } + $name = $field_info['name']; + $value = $result->{$name}; + + if (isset($field_info['report_only']) && $field_info['report_only']) { + $name .= $field_info['postfix']; + } + + $value = ($value == '') ? -1 : $value; + $child = $grandchild = $ggchild = NULL; + if (isset($field_info['children'])) { + $child = array_shift($field_info['children']); + if ($child) { + $grandchild = array_shift($field_info['children']); + } + if ($grandchild) { + $ggchild = array_shift($field_info['children']); + } + } + + $report[$name] = cma_airing_report_initialize_array($report[$name]); + + $report[$name]['count'] = + cma_airing_report_initialize_sum($report[$name]['count']); + + $report[$name]['time'] = + cma_airing_report_initialize_sum($report[$name]['time']); + + $report[$name]['count']++; + $report[$name]['time'] += $result->runtime; + + $report[$name][$value] = + cma_airing_report_initialize_array($report[$name][$value]); + + $report[$name][$value]['count'] = + cma_airing_report_initialize_sum($report[$name][$value]['count']); + + $report[$name][$value]['time'] = + cma_airing_report_initialize_sum($report[$name][$value]['time']); + + $report[$name][$value]['count']++; + $report[$name][$value]['time'] += $result->runtime; + + if ($child) { + $cvalue = $result->{$child}; + $cvalue = ($cvalue == '') ? -1 : $cvalue; + $report[$name][$value][$child] = + cma_airing_report_initialize_array($report[$name][$value] + [$child]); + + $report[$name][$value][$child]['count'] = + cma_airing_report_initialize_sum($report[$name][$value] + [$child]['count']); + + $report[$name][$value][$child]['time'] = + cma_airing_report_initialize_sum($report[$name][$value][$child] + ['time']); + + $report[$name][$value][$child]['count']++; + $report[$name][$value][$child]['time'] += $result->runtime; + + $report[$name][$value][$child][$cvalue] = + cma_airing_report_initialize_array($report[$name][$value] + [$child][$cvalue]); + + $report[$name][$value][$child][$cvalue]['count'] = + cma_airing_report_initialize_sum($report[$name][$value] + [$child][$cvalue]['count']); + + $report[$name][$value][$child][$cvalue]['time'] = + cma_airing_report_initialize_sum($report[$name][$value][$child] + [$cvalue]['time']); + + $report[$name][$value][$child][$cvalue]['count']++; + $report[$name][$value][$child][$cvalue]['time'] += $result->runtime; + + } + if ($grandchild) { + $gvalue = $result->{$grandchild}; + $gvalue = ($gvalue == '') ? -1 : $gvalue; + $report[$name][$value][$child][$cvalue][$grandchild] = + cma_airing_report_initialize_array($report[$name][$value] + [$child][$cvalue][$grandchild]); + + $report[$name][$value][$child][$cvalue][$grandchild]['count'] = + cma_airing_report_initialize_sum($report[$name][$value] + [$child][$cvalue][$grandchild] + ['count']); + + $report[$name][$value][$child][$cvalue][$grandchild]['time'] = + cma_airing_report_initialize_sum($report[$name][$value][$child] + [$cvalue][$grandchild] + ['time']); + + $report[$name][$value][$child][$cvalue][$grandchild]['count']++; + $report[$name][$value][$child][$cvalue][$grandchild]['time'] += + $result->runtime; + + $report[$name][$value][$child][$cvalue][$grandchild][$gvalue] = + cma_airing_report_initialize_array($report[$name][$value] + [$child][$cvalue][$grandchild] + [$gvalue]); + + $report[$name][$value][$child][$cvalue][$grandchild][$gvalue] + ['count'] = + cma_airing_report_initialize_sum($report[$name][$value] + [$child][$cvalue][$grandchild] + [$gvalue]['count']); + + $report[$name][$value][$child][$cvalue][$grandchild] + [$gvalue]['time'] = + cma_airing_report_initialize_sum($report[$name][$value][$child] + [$cvalue][$grandchild] + [$gvalue]['time']); + + $report[$name][$value][$child][$cvalue][$grandchild][$gvalue] + ['count']++; + $report[$name][$value][$child][$cvalue][$grandchild][$gvalue]['time'] + += $result->runtime; + + } + + if ($ggchild) { + + $ggvalue = $result->{$ggchild}; + $ggvalue = ($ggvalue == '') ? -1 : $ggvalue; + $report[$name][$value][$child][$cvalue][$grandchild][$gvalue] + [$ggchild] = + cma_airing_report_initialize_array($report[$name][$value] + [$child][$cvalue][$grandchild] + [$gvalue][$ggchild]); + + $report[$name][$value][$child][$cvalue][$grandchild][$gvalue] + [$ggchild]['count'] = + cma_airing_report_initialize_sum($report[$name][$value] + [$child][$cvalue][$grandchild] + [$gvalue][$ggchild] + ['count']); + + $report[$name][$value][$child][$cvalue][$grandchild][$gvalue] + [$ggchild]['time'] = + cma_airing_report_initialize_sum($report[$name][$value][$child] + [$cvalue][$grandchild][$gvalue] + [$ggchild] + ['time']); + + $report[$name][$value][$child][$cvalue][$grandchild][$gvalue] + [$ggchild]['count']++; + $report[$name][$value][$child][$cvalue][$grandchild][$gvalue] + [$ggchild]['time'] += + $result->runtime; + + $report[$name][$value][$child][$cvalue][$grandchild][$gvalue] + [$ggchild][$ggvalue] = + cma_airing_report_initialize_array($report[$name][$value][$child] + [$cvalue][$grandchild][$gvalue] + [$ggchild][$ggvalue]); + + $report[$name][$value][$child][$cvalue][$grandchild][$gvalue] + [$ggchild][$ggvalue]['count'] = + cma_airing_report_initialize_sum($report[$name][$value] + [$child][$cvalue][$grandchild] + [$gvalue][$ggchild][$ggvalue] + ['count']); + + $report[$name][$value][$child][$cvalue][$grandchild] + [$gvalue]['time'] = + cma_airing_report_initialize_sum($report[$name][$value][$child] + [$cvalue][$grandchild] + [$gvalue][$ggchild][$ggvalue] + ['time']); + + $report[$name][$value][$child][$cvalue][$grandchild][$gvalue] + [$ggchild][$ggvalue] + ['count']++; + $report[$name][$value][$child][$cvalue][$grandchild][$gvalue] + [$ggchild][$ggvalue]['time'] + += $result->runtime; + + } + } + } + $limit ++; + if ($limit > 100000) { + break; + } + } + $ret = ''; + + $tree = taxonomy_get_tree(12); + $channels = array(); + foreach($tree as $term) { + $channels[$term->tid] = $term->name; + } + asort($channels); + + $tree = taxonomy_get_tree(3); + $genres = array(); + foreach($tree as $term) { + $term = taxonomy_term_load($term->tid); + $custom_name = + cma_airing_report_get_single_field_value($term, + 'field_pbcore_custom_name'); + + if ($custom_name) { + $name = $custom_name; + } + else { + $name = $term->name; + } + + + if (isset($report['pbcore_genres'][$term->tid])) { + $genres[$term->tid] = $name; + } + } + asort($genres); + + $all_fields = field_info_fields(); + + $values= list_allowed_values($all_fields["field_live_source"]); + foreach($values as $id=>$value) { + if (isset($report['live_source'][$id])) { + $live_sources[$id] = $value; + } + } + asort($live_sources); + + ///////////////////////////////////////////////////////////////////////// + //TOTAL PREMIERES AND REPEATS BY CHANNEL + $args = array( + 'title' => "TOTAL SHOW PREMIERES AND REPEATS BY CHANNEL", + 'categories' => array('First Run Shows', 'Repeat Shows'), + 'pname' => 'is_show_premiere_date', + 'pvalues' => array(1,0), + 'cname' => 'airing_channel', + 'type' => 'count', + 'cvalue' => NULL, + 'gname' => NULL, + 'gvalue' => NULL, + 'ggname' => NULL, + 'ggvalues' => NULL, + ); + + $ret .= cma_airing_sub_report($args, $report, $channels); + + ///////////////////////////////////////////////////////////////////////// + //RUNTIMES FOR PREMIERES AND REPEATS RUNTIMES BY CHANNEL + $args = array( + 'title' => + "RUNTIMES FOR PREMIERES AND REPEATS RUNTIMES BY CHANNEL", + 'categories' => array('First Run Show Runtime', + 'Repeat Show Runtime'), + 'pname' => 'is_show_premiere_date', + 'pvalues' => array(1,0), + 'type' => 'time', + 'cname' => 'airing_channel', + 'cvalue' => NULL, + 'gname' => NULL, + 'gvalue' => NULL, + 'ggname' => NULL, + 'ggvalues' => NULL, + ); + + $ret .= cma_airing_sub_report($args, $report, $channels); + ///////////////////////////////////////////////////////////////////////// + $name = "Genres"; + $pname = 'is_show_premiere_date'; + $pvalues = array(1,0); + $cname = 'pbcore_genres'; + $cvalue = NULL; + $gname = NULL; + $gvalue = NULL; + $ggname = NULL; + $ggvalue = NULL; + + $type = 'count'; + $title = "TOTAL PREMIERES BY " . strtoupper($name); + $report_name = $pname . ' ' . $cname; + $categories = array('First Run Shows', 'Repeat Shows'); + + $args = + array('title' => $title, 'categories' => $categories, + 'pname' => $report_name, 'pvalues' => $pvalues, 'cname' => $cname, + 'cvalue' => $cvalue, 'gname' => $gname, 'gvalue' => $gvalue, + 'ggname' => $ggname,'ggvalue' => $ggvalue, 'type' => $type); + $ret .= cma_airing_sub_report($args, $report, $channels, $genres); + + $args['title'] = "RUNTIME FOR PREMIERES BY " . strtoupper($name); + $args['type'] = 'time'; + $args['categories'] = array('Runtime for First Run Shows', + 'Runtime for Repeat Shows'); + + + $ret .= cma_airing_sub_report($args, $report, $channels, $genres); + ///////////////////////////////////////////////////////////////////////// + //TOTAL AREA PREMIERES AND REPEATS BY CHANNEL + $args = array( + 'title' => + "TOTAL OPSIG PRODUCED PREMIERES AND REPEATS BY CHANNEL", + 'categories' => array('First Run OpSig Produced Through OpSig', + 'Repeat Shows Produced Through OpSig'), + 'pname' => 'is_show_premiere_date pcm_facilities', + 'pvalues' => array(1,0), + 'cname' => 'pcm_facilities', + 'cvalue' => 1, + 'gname' => 'airing_channel', + 'gcvalues' => NULL, + 'ggname' => NULL, + 'ggvalue' => NULL, + 'type' => 'count', + ); + + $ret .= cma_airing_sub_report($args, $report, $channels); + + ///////////////////////////////////////////////////////////////////////// + //RUNTIME FOR OPSIG PRODUCED PREMIERES AND REPEATS BY CHANNEL", + $args = array( + 'title' => + "RUNTIME FOR OPSIG PRODUCED PREMIERES AND REPEATS BY CHANNEL", + 'categories' => + array('Runtime for First Run Produced Through OpSig', + 'Runtime for Repeat Shows Produced Through OpSig'), + 'pname' => 'is_show_premiere_date pcm_facilities', + 'pvalues' => array(1,0), + 'cname' => 'pcm_facilities', + 'cvalue' => 1, + 'gname' => 'airing_channel', + 'gcvalues' => NULL, + 'ggname' => NULL, + 'ggvalue' => NULL, + 'type' => 'time', + ); + + $ret .= cma_airing_sub_report($args, $report, $channels); + + ///////////////////////////////////////////////////////////////////////// + //TOTAL METROPOLITAN AREA PREMIERES AND REPEATS BY CHANNEL", + $args = array( + 'title' => + "TOTAL METROPOLITAN AREA PREMIERES AND REPEATS BY CHANNEL", + 'categories' => array('First Run Shows made in Metro Area', + 'Repeat Shows made in Metro Area'), + 'pname' => 'is_show_premiere_date produced_where', + 'pvalues' => array(1,0), + 'cname' => 'produced_where', + 'cvalue' => 1, + 'gname' => 'airing_channel', + 'gcvalues' => NULL, + 'ggname' => NULL, + 'ggvalue' => NULL, + 'type' => 'count', + ); + + $ret .= cma_airing_sub_report($args, $report, $channels); + + ///////////////////////////////////////////////////////////////////////// + //RUNTIME FOR METROPOLITAN AREA PREMIERES AND REPEATS BY CHANNEL", + $args = array( + 'title' => "RUNTIME FOR METROPOLITAN AREA PREMIERES AND " . + "REPEATS BY CHANNEL", + 'categories' => + array('Runtime for First Run made in Metro Area', + 'Runtime for Repeat Shows made in Metro Area'), + 'pname' => 'is_show_premiere_date produced_where', + 'pvalues' => array(1,0), + 'cname' => 'produced_where', + 'cvalue' => 1, + 'gname' => 'airing_channel', + 'gcvalues' => NULL, + 'ggname' => NULL, + 'ggvalue' => NULL, + 'type' => 'time', + ); + + $ret .= cma_airing_sub_report($args, $report, $channels); + + ///////////////////////////////////////////////////////////////////////// + $name = "City of Portland"; + $pname = 'is_show_premiere_date'; + $pvalues = array(1,0); + $cname = 'produced_city'; + $cvalue = 1; + $gname = 'airing_channel'; + $gvalue = NULL; + $ggname = NULL; + $ggvalue = NULL; + + $type = 'count'; + $title = "TOTAL " . strtoupper($name) ." PREMIERES AND REPEATS BY CHANNEL"; + $report_name = $pname . ' ' . $cname; + $categories = + array('First Run Shows made in ' . $name, 'Repeat Shows made in ' . $name); + + $args = + array('title' => $title, 'categories' => $categories, + 'pname' => $report_name, 'pvalues' => $pvalues, 'cname' => $cname, + 'cvalue' => $cvalue, 'gname' => $gname, 'gvalue' => $gvalue, + 'ggname' => $ggname,'ggvalue' => $ggvalue, 'type' => $type); + + $ret .= cma_airing_sub_report($args, $report, $channels); + + $args['title'] = "RUNTIME FOR " . strtoupper($name) . + " PREMIERES AND REPEATS BY CHANNEL"; + $args['type'] = 'time'; + $args['categories'] = array('Runtime for First Run Shows made in ' . $name, + 'Runtime for Repeat Shows made in ' . $name); + + + $ret .= cma_airing_sub_report($args, $report, $channels); + + ///////////////////////////////////////////////////////////////////////// + $name = "Outside of Metro Area"; + $pname = 'is_show_premiere_date'; + $pvalues = array(1,0); + $cname = 'produced_where'; + $cvalue = 0; + $gname = 'airing_channel'; + $gvalue = NULL; + $ggname = NULL; + $ggvalue = NULL; + + $type = 'count'; + $title = "TOTAL " . strtoupper($name) ." PREMIERES AND REPEATS BY CHANNEL"; + $report_name = $pname . ' ' . $cname; + $categories = + array('First Run Shows made in ' . $name, 'Repeat Shows made in ' . $name); + + $args = + array('title' => $title, 'categories' => $categories, + 'pname' => $report_name, 'pvalues' => $pvalues, 'cname' => $cname, + 'cvalue' => $cvalue, 'gname' => $gname, 'gvalue' => $gvalue, + 'ggname' => $ggname,'ggvalue' => $ggvalue, 'type' => $type); + + $ret .= cma_airing_sub_report($args, $report, $channels); + + $args['title'] = "RUNTIME FOR " . strtoupper($name) . + " PREMIERES AND REPEATS BY CHANNEL"; + $args['type'] = 'time'; + $args['categories'] = array('Runtime for First Run Shows made in ' . $name, + 'Runtime for Repeat Shows made in ' . $name); + + + $ret .= cma_airing_sub_report($args, $report, $channels); + + ///////////////////////////////////////////////////////////////////////// + $name = "Live Sources"; + $pname = 'is_show_premiere_date'; + $pvalues = array(1,0); + $cname = 'live_source'; + $cvalue = NULL; + $gname = NULL; + $gvalue = NULL; + $ggname = NULL; + $ggvalue = NULL; + + $type = 'count'; + $title = "TOTAL PREMIERES BY " . strtoupper($name); + $report_name = $pname . ' ' . $cname; + $categories = array('First Run Shows'); + + $args = + array('title' => $title, 'categories' => $categories, + 'pname' => $report_name, 'pvalues' => $pvalues, 'cname' => $cname, + 'cvalue' => $cvalue, 'gname' => $gname, 'gvalue' => $gvalue, + 'ggname' => $ggname,'ggvalue' => $ggvalue, 'type' => $type); + $ret .= cma_airing_sub_report($args, $report, $channels, NULL,$live_sources); + + $args['title'] = "RUNTIME FOR PREMIERES BY " . strtoupper($name); + $args['type'] = 'time'; + $args['categories'] = array('Runtime for First Run Shows'); + + + $ret .= cma_airing_sub_report($args, $report, $channels, NULL,$live_sources); + + ///////////////////////////////////////////////////////////////////////// + $name = "Live Sources By Channel"; + $pname = 'live_source'; + $pvalues = array_keys($live_sources); + $cname = 'airing_channel'; + $cvalue = NULL; + $gname = NULL; + $gvalue = NULL; + $ggname = NULL; + $ggvalue = NULL; + $categories = $live_sources; + + $type = 'count'; + $title = "TOTAL AIRINGS FOR " . strtoupper($name); + $report_name = $pname . ' ' . $cname; + + $args = + array('title' => $title, 'categories' => $categories, + 'pname' => $report_name, 'pvalues' => $pvalues, 'cname' => $cname, + 'cvalue' => $cvalue, 'gname' => $gname, 'gvalue' => $gvalue, + 'ggname' => $ggname,'ggvalue' => $ggvalue, 'type' => $type); + $ret .= cma_airing_sub_report($args, $report, $channels); + + $args['type'] = 'time'; + $args['title'] = "RUNTIME FOR AIRINGS FOR " . strtoupper($name); + + $ret .= cma_airing_sub_report($args, $report, $channels); + + ///////////////////////////////////////////////////////////////////////// + $name = "Live Sources In OpSig Facilities By Channel"; + $pname = 'live_source'; + $pvalues = array_keys($live_sources); + $cname = 'pcm_facilities'; + $cvalue = 1; + $gname = 'airing_channel'; + $gvalue = NULL; + $ggname = NULL; + $ggvalue = NULL; + $categories = $live_sources; + + $type = 'count'; + $title = "TOTAL AIRINGS FOR " . strtoupper($name); + $report_name = $pname . ' ' . $cname; + if ($gname) { + $report_name .= ' ' . $gname; + } + + $args = + array('title' => $title, 'categories' => $categories, + 'pname' => $report_name, 'pvalues' => $pvalues, 'cname' => $cname, + 'cvalue' => $cvalue, 'gname' => $gname, 'gvalue' => $gvalue, + 'ggname' => $ggname,'ggvalue' => $ggvalue, 'type' => $type); + $ret .= cma_airing_sub_report($args, $report, $channels); + + $args['type'] = 'time'; + $args['title'] = "RUNTIME FOR AIRINGS FOR " . strtoupper($name); + + $ret .= cma_airing_sub_report($args, $report, $channels); + + + ///////////////////////////////////////////////////////////////////////// + $name = "Live Sources In Portland City By Channel"; + $pname = 'live_source'; + $pvalues = array_keys($live_sources); + $cname = 'produced_city'; + $cvalue = 1; + $gname = 'airing_channel'; + $gvalue = NULL; + $ggname = NULL; + $ggvalue = NULL; + $categories = $live_sources; + + $type = 'count'; + $title = "TOTAL AIRINGS FOR " . strtoupper($name); + $report_name = $pname . ' ' . $cname; + if ($gname) { + $report_name .= ' ' . $gname; + } + + $args = + array('title' => $title, 'categories' => $categories, + 'pname' => $report_name, 'pvalues' => $pvalues, 'cname' => $cname, + 'cvalue' => $cvalue, 'gname' => $gname, 'gvalue' => $gvalue, + 'ggname' => $ggname,'ggvalue' => $ggvalue, 'type' => $type); + $ret .= cma_airing_sub_report($args, $report, $channels); + + $args['type'] = 'time'; + $args['title'] = "RUNTIME FOR AIRINGS FOR " . strtoupper($name); + + $ret .= cma_airing_sub_report($args, $report, $channels); + ///////////////////////////////////////////////////////////////////////// + $name = "Live Sources In Metro Area By Channel"; + $pname = 'live_source'; + $pvalues = array_keys($live_sources); + $cname = 'produced_where'; + $cvalue = 1; + $gname = 'airing_channel'; + $gvalue = NULL; + $ggname = NULL; + $ggvalue = NULL; + $categories = $live_sources; + + $type = 'count'; + $title = "TOTAL AIRINGS FOR " . strtoupper($name); + $report_name = $pname . ' ' . $cname; + if ($gname) { + $report_name .= ' ' . $gname; + } + + $args = + array('title' => $title, 'categories' => $categories, + 'pname' => $report_name, 'pvalues' => $pvalues, 'cname' => $cname, + 'cvalue' => $cvalue, 'gname' => $gname, 'gvalue' => $gvalue, + 'ggname' => $ggname,'ggvalue' => $ggvalue, 'type' => $type); + $ret .= cma_airing_sub_report($args, $report, $channels); + + $args['type'] = 'time'; + $args['title'] = "RUNTIME FOR AIRINGS FOR " . strtoupper($name); + + $ret .= cma_airing_sub_report($args, $report, $channels); + ///////////////////////////////////////////////////////////////////////// + $name = "Live Sources Outside Metro Area By Channel"; + $pname = 'live_source'; + $pvalues = array_keys($live_sources); + $cname = 'produced_where'; + $cvalue = 0; + $gname = 'airing_channel'; + $gvalue = NULL; + $ggname = NULL; + $ggvalue = NULL; + $categories = $live_sources; + + $type = 'count'; + $title = "TOTAL AIRINGS FOR " . strtoupper($name); + $report_name = $pname . ' ' . $cname; + if ($gname) { + $report_name .= ' ' . $gname; + } + + $args = + array('title' => $title, 'categories' => $categories, + 'pname' => $report_name, 'pvalues' => $pvalues, 'cname' => $cname, + 'cvalue' => $cvalue, 'gname' => $gname, 'gvalue' => $gvalue, + 'ggname' => $ggname,'ggvalue' => $ggvalue, 'type' => $type); + $ret .= cma_airing_sub_report($args, $report, $channels); + + $args['type'] = 'time'; + $args['title'] = "RUNTIME FOR AIRINGS FOR " . strtoupper($name); + + $ret .= cma_airing_sub_report($args, $report, $channels); + + ///////////////////////////////////////////////////////////////////////// + $name = "City Council Meeting By Channel"; + $pname = 'is_show_premiere_date'; + $pvalues = array(1,0); + $cname = 'airing_channel'; + $cvalue = 0; + $gname = NULL; + $gvalue = NULL; + $ggname = NULL; + $ggvalue = NULL; + $categories = + array('First Run City Council Shows', + 'Repeat Run City Council Shows'); + + $type = 'count'; + $title = "TOTAL AIRINGS FOR " . strtoupper($name); + + $report_name = $pname . ' government_channel'; + + if ($gname) { + $report_name .= ' ' . $gname; + } + + $args = + array('title' => $title, 'categories' => $categories, + 'pname' => $report_name, 'pvalues' => $pvalues, 'cname' => $cname, + 'cvalue' => $cvalue, 'gname' => $gname, 'gvalue' => $gvalue, + 'ggname' => $ggname,'ggvalue' => $ggvalue, 'type' => $type); + $ret .= cma_airing_sub_report($args, $report, $channels); + + $args['type'] = 'time'; + $args['title'] = "RUNTIME FOR AIRINGS FOR " . strtoupper($name); + $args['categories'] = array('Runtime For First Run City Council Shows', + 'Runtime For Repeat Run City Council Shows'); + + + $ret .= cma_airing_sub_report($args, $report, $channels); + + /////////////////////////////////////////////////////////////////////// + //dsm($report, 'Raw Data Reports'); + return $ret; + +} + +/** + * Function builds a sub report table + */ +function cma_airing_sub_report($args, $report, $channels, $genres = NULL, + $live_sources = NULL) { + $type = $args['type']; + $pname = $args['pname'];//name of parent, or highest level + $cname = $args['cname'];//name of child, or second highest level + $gname = $args['gname'];//name of grandchild, or third highest level + $ggname = $args['ggname'];//name of great-grandchild, or the lowest level + $cvalue = $args['cvalue']; + $gvalue = $args['gvalue']; + $ggvalue = $args['ggvalue']; + + $ret = "

" . $args['title'] . "

"; + $ret .= ""; + + if ($genres) { + $columns = $genres; + } + else if ($live_sources) { + $columns = $live_sources; + } + else { + $columns = $channels; + } + foreach ($columns as $id => $name) { + $ret .= ""; + } + $ret .= ""; + $ret .= ""; + + $index = 0; + $column_total = array(); + //LOOP OVER TEH CATEGORIES OUTPUTTING A SINGLE ROW FOR EACH + foreach ($args['categories'] as $category) { + $pvalue = $args['pvalues'][$index]; + $index ++; + $ret .= ""; + + //ITERATE OVER EACH COLUMN, OUTPUTTING A SINGLE AMOUNT FOR EACH + $total = 0; + + foreach ($columns as $id => $name) { + $column_total[$id] = isset($column_total[$id]) ? $column_total[$id] : + 0; + if ($ggname) { + $amount = $report[$pname][$pvalue][$cname][$cvalue][$gname][$gvalue] + [$ggname][$id][$type]; + } + else if ($gname) { + $amount = $report[$pname][$pvalue][$cname][$cvalue][$gname][$id] + [$type]; + } + else if ($cname) { + $amount = $report[$pname][$pvalue][$cname][$id][$type]; + } + $amount = $amount ? $amount : 0; + $total += $amount; + $column_total[$id] += $amount; + $amount = ($type == 'time') ? cma_airing_report_hms($amount) : $amount; + $ret .= ""; + } + + $total = ($type == 'time') ? cma_airing_report_hms($total) : $total; + $ret .= ""; + } + + $ret .= ""; + $total = 0; + foreach ($columns as $id => $name) { + $amount = $column_total[$id]; + $amount = $amount ? $amount : 0; + $total += $amount; + $amount = ($type == 'time') ? cma_airing_report_hms($amount) : $amount; + + $ret .= ""; + } + $total = $total ? $total : 0; + $total = ($type == 'time') ? cma_airing_report_hms($total) : $total; + $ret .= ""; + $ret .= "
Category".$name."Total
".$category."" . $amount . "". $total . "
Totals".$amount."".$total."
"; + + return $ret; +} +/** + * Function returns hours minutes seconds for unixtimestamps + */ +function cma_airing_report_hms($seconds) { + if (!$seconds) { + return '00:00:00'; + } + $hours = floor($seconds / 3600); + $minutes = floor(($seconds / 60) % 60); + $seconds = $seconds % 60; + + if ($seconds < 10) { + $seconds = '0'.$seconds; + } + if ($minutes < 10) { + $minutes = '0'.$minutes; + } + + return "$hours:$minutes:$seconds"; +} + + +/** + * Implementation of hook_action_info(). + */ +function cma_airing_report_action_info() { + + $action = + array( + 'cma_airing_report_resave_show_nodes' => + array( + 'label' => t("Update runtimes for the Airing's Show"), + 'type' => 'airing', + 'configurable' => FALSE, + 'triggers' => array('any'), + 'behavior' => array('delete_property'), + ), + + ); + + return $action; +} + +/** + *Bulk operations action for updating the Airing's Show's runtime + */ +function cma_airing_report_resave_show_nodes(&$airing, + $context = array()) { + global $count; + global $shows; + + $count = isset($count) ? $count : 0; + $shows = isset($shows) ? $shows : array(); + $count ++; + + $show_nid = cma_airing_report_get_single_field_value($airing, + 'field_airing_show_ref', + 'target_id'); + + if (!$shows[$show_nid]) { + $shows[$show_nid] = $show_nid; + $show = node_load($show_nid); + + //fetch the cc show to see if there is a runtime over there + $cc_show_id = + cma_airing_report_get_single_field_value($show, + 'field_cablecast_show_id', + 'value'); + + $cc_show = $cc_show_id ? + cablecast_api_server_query('GetShowInformation', + array('ShowID'=> + $cc_show_id)) : NULL; + + $cc_show = ($cc_show && isset($cc_show->GetShowInformationResult)) ? + $cc_show->GetShowInformationResult : NULL; + + $runtime = $cc_show ? $cc_show->TotalSeconds : 0; + if ($runtime) { + $show->field_runtime[LANGUAGE_NONE][0]['value'] = $runtime; + node_save($show); + } + } + +} + + +/** + * Helper function to get a single value off of a entity + */ +function cma_airing_report_get_single_field_value($entity, $field_name, + $index = 'value') { + if (isset($entity->{$field_name})) { + $field = $entity->{$field_name}; + if (isset($field[LANGUAGE_NONE]) && + isset($field[LANGUAGE_NONE][0]) && + isset($field[LANGUAGE_NONE][0][$index])) { + return $field[LANGUAGE_NONE][0][$index]; + } + } + return NULL; +} diff --git a/inc/cma_airing_report.views.inc b/inc/cma_airing_report.views.inc new file mode 100644 index 0000000..4071468 --- /dev/null +++ b/inc/cma_airing_report.views.inc @@ -0,0 +1,317 @@ +name = 'airing_distribution_report'; + $view->description = ''; + $view->tag = 'default'; + $view->base_table = 'cm_airing'; + $view->human_name = 'Airing Distribution Report'; + $view->core = 7; + $view->api_version = '3.0'; + $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ + + /* Display: Master */ + $handler = $view->new_display('default', 'Master', 'default'); + $handler->display->display_options['title'] = 'Airing Distribution Report'; + $handler->display->display_options['use_more_always'] = FALSE; + $handler->display->display_options['access']['type'] = 'none'; + $handler->display->display_options['cache']['type'] = 'none'; + $handler->display->display_options['query']['type'] = 'views_query'; + $handler->display->display_options['exposed_form']['type'] = 'basic'; + $handler->display->display_options['pager']['type'] = 'full'; + $handler->display->display_options['pager']['options']['items_per_page'] = '100'; + $handler->display->display_options['style_plugin'] = 'table'; + $handler->display->display_options['style_options']['columns'] = array( + 'airing_id' => 'airing_id', + ); + $handler->display->display_options['style_options']['default'] = '-1'; + $handler->display->display_options['style_options']['info'] = array( + 'airing_id' => array( + 'sortable' => 0, + 'default_sort_order' => 'asc', + 'align' => '', + 'separator' => '', + 'empty_column' => 0, + ), + ); + /* Relationship: Entity Reference: Referenced Entity */ + $handler->display->display_options['relationships']['field_airing_show_ref_target_id']['id'] = 'field_airing_show_ref_target_id'; + $handler->display->display_options['relationships']['field_airing_show_ref_target_id']['table'] = 'field_data_field_airing_show_ref'; + $handler->display->display_options['relationships']['field_airing_show_ref_target_id']['field'] = 'field_airing_show_ref_target_id'; + /* Field: Airing: Date */ + $handler->display->display_options['fields']['field_airing_date']['id'] = 'field_airing_date'; + $handler->display->display_options['fields']['field_airing_date']['table'] = 'field_data_field_airing_date'; + $handler->display->display_options['fields']['field_airing_date']['field'] = 'field_airing_date'; + $handler->display->display_options['fields']['field_airing_date']['settings'] = array( + 'format_type' => 'short', + 'fromto' => 'both', + 'multiple_number' => '', + 'multiple_from' => '', + 'multiple_to' => '', + 'show_repeat_rule' => 'show', + ); + /* Field: Airing: Title */ + $handler->display->display_options['fields']['field_airing_title']['id'] = 'field_airing_title'; + $handler->display->display_options['fields']['field_airing_title']['table'] = 'field_data_field_airing_title'; + $handler->display->display_options['fields']['field_airing_title']['field'] = 'field_airing_title'; + /* Field: Airing: Cablecast Airing ID */ + $handler->display->display_options['fields']['field_cablecast_airing_id']['id'] = 'field_cablecast_airing_id'; + $handler->display->display_options['fields']['field_cablecast_airing_id']['table'] = 'field_data_field_cablecast_airing_id'; + $handler->display->display_options['fields']['field_cablecast_airing_id']['field'] = 'field_cablecast_airing_id'; + $handler->display->display_options['fields']['field_cablecast_airing_id']['settings'] = array( + 'thousand_separator' => '', + 'prefix_suffix' => 1, + ); + /* Field: Airing: Project */ + $handler->display->display_options['fields']['field_airing_project_ref']['id'] = 'field_airing_project_ref'; + $handler->display->display_options['fields']['field_airing_project_ref']['table'] = 'field_data_field_airing_project_ref'; + $handler->display->display_options['fields']['field_airing_project_ref']['field'] = 'field_airing_project_ref'; + $handler->display->display_options['fields']['field_airing_project_ref']['settings'] = array( + 'link' => 0, + ); + /* Field: Airing: Show */ + $handler->display->display_options['fields']['field_airing_show_ref']['id'] = 'field_airing_show_ref'; + $handler->display->display_options['fields']['field_airing_show_ref']['table'] = 'field_data_field_airing_show_ref'; + $handler->display->display_options['fields']['field_airing_show_ref']['field'] = 'field_airing_show_ref'; + $handler->display->display_options['fields']['field_airing_show_ref']['settings'] = array( + 'link' => 0, + ); + /* Field: Field: Live Source */ + $handler->display->display_options['fields']['field_live_source']['id'] = 'field_live_source'; + $handler->display->display_options['fields']['field_live_source']['table'] = 'field_data_field_live_source'; + $handler->display->display_options['fields']['field_live_source']['field'] = 'field_live_source'; + /* Field: Airing: Series Request */ + $handler->display->display_options['fields']['field_series_request']['id'] = 'field_series_request'; + $handler->display->display_options['fields']['field_series_request']['table'] = 'field_data_field_series_request'; + $handler->display->display_options['fields']['field_series_request']['field'] = 'field_series_request'; + $handler->display->display_options['fields']['field_series_request']['settings'] = array( + 'link' => 0, + ); + /* Field: Airing: Is Show Premiere Date? */ + $handler->display->display_options['fields']['field_is_show_premiere_date']['id'] = 'field_is_show_premiere_date'; + $handler->display->display_options['fields']['field_is_show_premiere_date']['table'] = 'field_data_field_is_show_premiere_date'; + $handler->display->display_options['fields']['field_is_show_premiere_date']['field'] = 'field_is_show_premiere_date'; + /* Field: Airing: Is Simultaneous Premiere */ + $handler->display->display_options['fields']['field_is_show_simul_premiere']['id'] = 'field_is_show_simul_premiere'; + $handler->display->display_options['fields']['field_is_show_simul_premiere']['table'] = 'field_data_field_is_show_simul_premiere'; + $handler->display->display_options['fields']['field_is_show_simul_premiere']['field'] = 'field_is_show_simul_premiere'; + $handler->display->display_options['fields']['field_is_show_simul_premiere']['label'] = 'Is Simultaneous Premiere?'; + /* Field: Content: Genres */ + $handler->display->display_options['fields']['field_pbcore_genres']['id'] = 'field_pbcore_genres'; + $handler->display->display_options['fields']['field_pbcore_genres']['table'] = 'field_data_field_pbcore_genres'; + $handler->display->display_options['fields']['field_pbcore_genres']['field'] = 'field_pbcore_genres'; + $handler->display->display_options['fields']['field_pbcore_genres']['relationship'] = 'field_airing_show_ref_target_id'; + /* Field: Content: Premiere Date */ + $handler->display->display_options['fields']['field_premier_date']['id'] = 'field_premier_date'; + $handler->display->display_options['fields']['field_premier_date']['table'] = 'field_data_field_premier_date'; + $handler->display->display_options['fields']['field_premier_date']['field'] = 'field_premier_date'; + $handler->display->display_options['fields']['field_premier_date']['relationship'] = 'field_airing_show_ref_target_id'; + $handler->display->display_options['fields']['field_premier_date']['settings'] = array( + 'format_type' => 'short', + 'fromto' => 'both', + 'multiple_number' => '', + 'multiple_from' => '', + 'multiple_to' => '', + 'show_repeat_rule' => 'show', + ); + /* Field: Content: Was it produced within Portland city limits? */ + $handler->display->display_options['fields']['field_produced_city']['id'] = 'field_produced_city'; + $handler->display->display_options['fields']['field_produced_city']['table'] = 'field_data_field_produced_city'; + $handler->display->display_options['fields']['field_produced_city']['field'] = 'field_produced_city'; + $handler->display->display_options['fields']['field_produced_city']['relationship'] = 'field_airing_show_ref_target_id'; + /* Field: Content: Was this show produced in PCM studios or using PCM equipment? */ + $handler->display->display_options['fields']['field_pcm_facilities']['id'] = 'field_pcm_facilities'; + $handler->display->display_options['fields']['field_pcm_facilities']['table'] = 'field_data_field_pcm_facilities'; + $handler->display->display_options['fields']['field_pcm_facilities']['field'] = 'field_pcm_facilities'; + $handler->display->display_options['fields']['field_pcm_facilities']['relationship'] = 'field_airing_show_ref_target_id'; + /* Field: Content: Was this show produced in the Metropolitan Portland area? */ + $handler->display->display_options['fields']['field_produced_where']['id'] = 'field_produced_where'; + $handler->display->display_options['fields']['field_produced_where']['table'] = 'field_data_field_produced_where'; + $handler->display->display_options['fields']['field_produced_where']['field'] = 'field_produced_where'; + $handler->display->display_options['fields']['field_produced_where']['relationship'] = 'field_airing_show_ref_target_id'; + /* Field: Content: Runtime */ + $handler->display->display_options['fields']['field_runtime']['id'] = 'field_runtime'; + $handler->display->display_options['fields']['field_runtime']['table'] = 'field_data_field_runtime'; + $handler->display->display_options['fields']['field_runtime']['field'] = 'field_runtime'; + $handler->display->display_options['fields']['field_runtime']['relationship'] = 'field_airing_show_ref_target_id'; + $handler->display->display_options['fields']['field_runtime']['settings'] = array( + 'format' => 'h:mm:ss', + 'leading_zero' => 1, + ); + /* Sort criterion: Airing: Date - start date (field_airing_date) */ + $handler->display->display_options['sorts']['field_airing_date_value']['id'] = 'field_airing_date_value'; + $handler->display->display_options['sorts']['field_airing_date_value']['table'] = 'field_data_field_airing_date'; + $handler->display->display_options['sorts']['field_airing_date_value']['field'] = 'field_airing_date_value'; + /* Filter criterion: Airing: Date - start date (field_airing_date) */ + $handler->display->display_options['filters']['field_airing_date_value']['id'] = 'field_airing_date_value'; + $handler->display->display_options['filters']['field_airing_date_value']['table'] = 'field_data_field_airing_date'; + $handler->display->display_options['filters']['field_airing_date_value']['field'] = 'field_airing_date_value'; + $handler->display->display_options['filters']['field_airing_date_value']['operator'] = 'between'; + $handler->display->display_options['filters']['field_airing_date_value']['exposed'] = TRUE; + $handler->display->display_options['filters']['field_airing_date_value']['expose']['operator_id'] = 'field_airing_date_value_op'; + $handler->display->display_options['filters']['field_airing_date_value']['expose']['label'] = 'Airing Date'; + $handler->display->display_options['filters']['field_airing_date_value']['expose']['operator'] = 'field_airing_date_value_op'; + $handler->display->display_options['filters']['field_airing_date_value']['expose']['identifier'] = 'field_airing_date_value'; + $handler->display->display_options['filters']['field_airing_date_value']['expose']['remember_roles'] = array( + 2 => '2', + 1 => 0, + 3 => 0, + 7 => 0, + 14 => 0, + 5 => 0, + 54 => 0, + 15 => 0, + 16 => 0, + 20 => 0, + 17 => 0, + 4 => 0, + 33 => 0, + 35 => 0, + 36 => 0, + 38 => 0, + 37 => 0, + 53 => 0, + 39 => 0, + 41 => 0, + 42 => 0, + 43 => 0, + 40 => 0, + 44 => 0, + 45 => 0, + 46 => 0, + 48 => 0, + 47 => 0, + 49 => 0, + 51 => 0, + 50 => 0, + 52 => 0, + ); + $handler->display->display_options['filters']['field_airing_date_value']['form_type'] = 'date_popup'; + $handler->display->display_options['filters']['field_airing_date_value']['default_date'] = 'now -365 day'; + $handler->display->display_options['filters']['field_airing_date_value']['default_to_date'] = 'now'; + + /* Display: Distribution Report */ + $handler = $view->new_display('page', 'Distribution Report', 'page'); + $handler->display->display_options['defaults']['header'] = FALSE; + /* Header: Global: PHP */ + $handler->display->display_options['header']['php']['id'] = 'php'; + $handler->display->display_options['header']['php']['table'] = 'views'; + $handler->display->display_options['header']['php']['field'] = 'php'; + $handler->display->display_options['header']['php']['php_output'] = ' +'; + $handler->display->display_options['path'] = 'admin/airings/reports/distribution'; + $handler->display->display_options['menu']['type'] = 'normal'; + $handler->display->display_options['menu']['title'] = 'Airing Distribution Report'; + $handler->display->display_options['menu']['name'] = 'management'; + + /* Display: Refresh Show Runtimes */ + $handler = $view->new_display('page', 'Refresh Show Runtimes', 'page_1'); + $handler->display->display_options['defaults']['fields'] = FALSE; + /* Field: Bulk operations: Airing */ + $handler->display->display_options['fields']['views_bulk_operations']['id'] = 'views_bulk_operations'; + $handler->display->display_options['fields']['views_bulk_operations']['table'] = 'cm_airing'; + $handler->display->display_options['fields']['views_bulk_operations']['field'] = 'views_bulk_operations'; + $handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['display_type'] = '0'; + $handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['enable_select_all_pages'] = 1; + $handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['row_clickable'] = 1; + $handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0; + $handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10'; + $handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'] = array( + 'action::cma_airing_report_resave_show_nodes' => array( + 'selected' => 1, + 'postpone_processing' => 0, + 'skip_confirmation' => 0, + 'override_label' => 0, + 'label' => '', + ), + ); + /* Field: Airing: Date */ + $handler->display->display_options['fields']['field_airing_date']['id'] = 'field_airing_date'; + $handler->display->display_options['fields']['field_airing_date']['table'] = 'field_data_field_airing_date'; + $handler->display->display_options['fields']['field_airing_date']['field'] = 'field_airing_date'; + $handler->display->display_options['fields']['field_airing_date']['settings'] = array( + 'format_type' => 'short', + 'fromto' => 'both', + 'multiple_number' => '', + 'multiple_from' => '', + 'multiple_to' => '', + 'show_repeat_rule' => 'show', + ); + /* Field: Airing: Title */ + $handler->display->display_options['fields']['field_airing_title']['id'] = 'field_airing_title'; + $handler->display->display_options['fields']['field_airing_title']['table'] = 'field_data_field_airing_title'; + $handler->display->display_options['fields']['field_airing_title']['field'] = 'field_airing_title'; + /* Field: Airing: Cablecast Airing ID */ + $handler->display->display_options['fields']['field_cablecast_airing_id']['id'] = 'field_cablecast_airing_id'; + $handler->display->display_options['fields']['field_cablecast_airing_id']['table'] = 'field_data_field_cablecast_airing_id'; + $handler->display->display_options['fields']['field_cablecast_airing_id']['field'] = 'field_cablecast_airing_id'; + $handler->display->display_options['fields']['field_cablecast_airing_id']['settings'] = array( + 'thousand_separator' => '', + 'prefix_suffix' => 1, + ); + /* Field: Airing: Project */ + $handler->display->display_options['fields']['field_airing_project_ref']['id'] = 'field_airing_project_ref'; + $handler->display->display_options['fields']['field_airing_project_ref']['table'] = 'field_data_field_airing_project_ref'; + $handler->display->display_options['fields']['field_airing_project_ref']['field'] = 'field_airing_project_ref'; + $handler->display->display_options['fields']['field_airing_project_ref']['settings'] = array( + 'link' => 0, + ); + /* Field: Airing: Show */ + $handler->display->display_options['fields']['field_airing_show_ref']['id'] = 'field_airing_show_ref'; + $handler->display->display_options['fields']['field_airing_show_ref']['table'] = 'field_data_field_airing_show_ref'; + $handler->display->display_options['fields']['field_airing_show_ref']['field'] = 'field_airing_show_ref'; + $handler->display->display_options['fields']['field_airing_show_ref']['settings'] = array( + 'link' => 0, + ); + /* Field: Field: Live Source */ + $handler->display->display_options['fields']['field_live_source']['id'] = 'field_live_source'; + $handler->display->display_options['fields']['field_live_source']['table'] = 'field_data_field_live_source'; + $handler->display->display_options['fields']['field_live_source']['field'] = 'field_live_source'; + /* Field: Airing: Series Request */ + $handler->display->display_options['fields']['field_series_request']['id'] = 'field_series_request'; + $handler->display->display_options['fields']['field_series_request']['table'] = 'field_data_field_series_request'; + $handler->display->display_options['fields']['field_series_request']['field'] = 'field_series_request'; + $handler->display->display_options['fields']['field_series_request']['settings'] = array( + 'link' => 0, + ); + /* Field: Airing: Is Show Premiere Date? */ + $handler->display->display_options['fields']['field_is_show_premiere_date']['id'] = 'field_is_show_premiere_date'; + $handler->display->display_options['fields']['field_is_show_premiere_date']['table'] = 'field_data_field_is_show_premiere_date'; + $handler->display->display_options['fields']['field_is_show_premiere_date']['field'] = 'field_is_show_premiere_date'; + /* Field: Airing: Is Simultaneous Premiere */ + $handler->display->display_options['fields']['field_is_show_simul_premiere']['id'] = 'field_is_show_simul_premiere'; + $handler->display->display_options['fields']['field_is_show_simul_premiere']['table'] = 'field_data_field_is_show_simul_premiere'; + $handler->display->display_options['fields']['field_is_show_simul_premiere']['field'] = 'field_is_show_simul_premiere'; + $handler->display->display_options['fields']['field_is_show_simul_premiere']['label'] = 'Is Simultaneous Premiere?'; + $handler->display->display_options['path'] = 'admin/shows/refresh-runtimes'; + + /* Display: Data export */ + $handler = $view->new_display('views_data_export', 'Data export', 'views_data_export_1'); + $handler->display->display_options['pager']['type'] = 'some'; + $handler->display->display_options['pager']['options']['items_per_page'] = '0'; + $handler->display->display_options['pager']['options']['offset'] = '0'; + $handler->display->display_options['style_plugin'] = 'views_data_export_csv'; + $handler->display->display_options['style_options']['provide_file'] = 1; + $handler->display->display_options['style_options']['filename'] = 'distribution_report.%timestamp-full == 2018-01-03T15-12-19.csv'; + $handler->display->display_options['style_options']['parent_sort'] = 0; + $handler->display->display_options['style_options']['quote'] = 1; + $handler->display->display_options['style_options']['trim'] = 0; + $handler->display->display_options['style_options']['replace_newlines'] = 0; + $handler->display->display_options['style_options']['newline_token'] = '1'; + $handler->display->display_options['style_options']['header'] = 1; + $handler->display->display_options['style_options']['keep_html'] = 0; + $handler->display->display_options['path'] = 'admin/airings/reports/distribution/download'; + $handler->display->display_options['displays'] = array( + 'page' => 'page', + 'default' => 0, + 'page_1' => 0, + ); + + // Add view to list of views to provide. + $views[$view->name] = $view; + + // ...Repeat all of the above for each view the module should provide. + // At the end, return array of default views. + return $views; +}