From 1c20e7a4dd8ede0668c9ee8eb36b0c8f02f9a3a8 Mon Sep 17 00:00:00 2001
From: Ron Barack
Date: Mon, 14 Oct 2019 20:56:53 +0200
Subject: [PATCH] Additional List can have same groupings as main list
---
bmlt-meeting-list.php | 321 ++++++++++++++++++++---------------
js/bmlt_meeting_list.js | 10 --
partials/_meetings_setup.php | 3 +-
3 files changed, 186 insertions(+), 148 deletions(-)
diff --git a/bmlt-meeting-list.php b/bmlt-meeting-list.php
index a134023..df58871 100644
--- a/bmlt-meeting-list.php
+++ b/bmlt-meeting-list.php
@@ -909,7 +909,10 @@ function bmlt_meeting_list($atts = null, $content = null) {
$this->sortBySubkey($formats_all, 'key_string');
$this->formats_by_key[$this->options['asm_language']] = array();
foreach($formats_all as $thisFormat) {
- $this->formats_by_key[$this->options['asm_language']][$thisFormat['key_string']] = $thisFormat;
+ $this->formats_by_key[$this->options['asm_language']][$thisFormat['key_string']] = $thisFormat;
+ if ($thisFormat['key_string']==$this->options['asm_format_key']) {
+ $this->options['asm_format_id'] = $thisFormat['id'];
+ }
}
}
if ( strpos($this->options['custom_section_content'].$this->options['front_page_content'].$this->options['last_page_content'], '[format_codes_used_basic_es') !== false ) {
@@ -944,37 +947,7 @@ function bmlt_meeting_list($atts = null, $content = null) {
$this->meeting_count = count($result_meetings);
$unique_heading = array();
- $days = array_column($result_meetings, 'weekday_tinyint');
- $today_str = $this->options['weekday_start'];
- $result_meetings = array_merge(
- array_splice($result_meetings, array_search($today_str, $days)),
- array_splice($result_meetings, 0)
- );
- $this->upgradeHeaderData();
- $levels = $this->getHeaderLevels();
- foreach ($result_meetings as &$value) {
- $enFormats = explode ( ",", $value['formats'] );
- if ( $this->options['include_asm'] == 0 && in_array ( $this->options['asm_format_key'], $enFormats ) ) { continue; }
- $value = $this->enhance_meeting($value, $this->options['weekday_language']);
- $header1 = $this->getHeaderItem($value, 'header1');
- if (!isset($headerMeetings[$header1])) {
- $headerMeetings[$header1] = array();
- if ($levels == 1) {
- $headerMeetings[$header1][0] = array();
- }
- }
- if ($levels == 2) {
- $header2 = $this->getHeaderItem($value, 'header2');
- if (!isset($headerMeetings[$header1][$header2])) {
- $headerMeetings[$header1][$header2] = array();
- }
- $headerMeetings[$header1][$header2][] = $value;
- } else {
- $headerMeetings[$header1][0][] = $value;
- }
- }
- $unique_heading = array_keys($headerMeetings);
- asort($unique_heading, SORT_NATURAL | SORT_FLAG_CASE);
+ $result_meetings = $this->orderByWeekdayStart($result_meetings);
if ( $this->options['page_fold'] === 'full' || $this->options['page_fold'] === 'half' || $this->options['page_fold'] === 'flyer') {
$num_columns = 0;
} elseif ( $this->options['page_fold'] === 'tri' ) {
@@ -987,93 +960,15 @@ function bmlt_meeting_list($atts = null, $content = null) {
}
$this->mpdf->SetColumns($num_columns, '', $this->options['column_gap']);
- $header_style = "color:".$this->options['header_text_color'].";";
- $header_style .= "background-color:".$this->options['header_background_color'].";";
- $header_style .= "font-size:".$this->options['header_font_size']."pt;";
- $header_style .= "line-height:".$this->options['content_line_height'].";";
- $header_style .= "text-align:center;padding-top:2px;padding-bottom:3px;";
-
- if ( $this->options['header_uppercase'] == 1 ) {
- $header_style .= 'text-transform: uppercase;';
- }
- if ( $this->options['header_bold'] == 0 ) {
- $header_style .= 'font-weight: normal;';
- }
- if ( $this->options['header_bold'] == 1 ) {
- $header_style .= 'font-weight: bold;';
- }
- $cont = '('.$this->translate[$this->options['weekday_language']]['CONT'].')';
-
if ( $this->options['page_fold'] == 'half' || $this->options['page_fold'] == 'full') {
$this->write_front_page();
}
$this->mpdf->WriteHTML('td{font-size: '.$this->options['content_font_size']."pt;line-height:".$this->options['content_line_height'].';}',1);
$this->mpdf->SetDefaultBodyCSS('font-size', $this->options['content_font_size'] . 'pt');
$this->mpdf->SetDefaultBodyCSS('line-height', $this->options['content_line_height']);
-
- $this->options['meeting_template_content'] = wpautop(stripslashes($this->options['meeting_template_content']));
- $this->options['meeting_template_content'] = preg_replace('/[[:^print:]]/', ' ', $this->options['meeting_template_content']);
+ $this->upgradeHeaderData();
- $this->options['meeting_template_content'] = str_replace(" ", " ", $this->options['meeting_template_content']);
- $analysedTemplate = $this->analyseTemplate($this->options['meeting_template_content']);
- $first_meeting = true;
- $newMajorHeading = false;
- $test_pages = deep_copy($this->mpdf);
- foreach ($unique_heading as $this_heading_raw) {
- $newMajorHeading = true;
- $this_heading = $this->remove_sort_key($this_heading_raw);
- $unique_subheading = array_keys($headerMeetings[$this_heading_raw]);
- asort($unique_subheading, SORT_NATURAL | SORT_FLAG_CASE);
- foreach ($unique_subheading as $this_subheading_raw) {
- $newSubHeading = true;
- $this_subheading = $this->remove_sort_key($this_subheading_raw);
- foreach ($headerMeetings[$this_heading_raw][$this_subheading_raw] as $meeting_value) {
- $header = '';
- if ( !empty($this->options['combine_headings'])) {
- $header_string = $this->options['combine_headings'];
- $header_string = str_replace('header1',$this_heading, $header_string);
- $header_string = str_replace('header2',$this_subheading, $header_string);
- $header .= "".$header_string."
";
- } elseif ( $levels == 2 ) {
- if ( $newMajorHeading === true ) {
- $xtraMargin = '';
- if ( !$first_meeting ) {
- $xtraMargin = 'margin-top:2pt;';
- }
- $header .= ''.$this_heading."
";
- }
- if ($newSubHeading && $this->options['sub_header_shown']==1) {
- $header .= "".$this_subheading."
";
- }
- } elseif ( $newMajorHeading === true ) {
- $header .= "".$this_heading."
";
- }
- if ($this->options['suppress_heading']==1) {
- $header = '';
- }
- $data = $header . $this->write_single_meeting($meeting_value,
- $this->options['meeting_template_content'], $analysedTemplate,
- $meeting_value['area_name']);
- $data = mb_convert_encoding($data, 'HTML-ENTITIES');
- $data = utf8_encode($data);
- $this->writeBreak($test_pages);
- $y_startpos = $test_pages->y;
- $test_pages->WriteHTML($data);
- $y_diff = $test_pages->y - $y_startpos;
- if ($y_diff >= $this->mpdf->h - ($this->mpdf->y + $this->mpdf->bMargin + 5) - $this->mpdf->kwt_height) {
- $this->writeBreak($this->mpdf);
- if (!$newMajorHeading && $this->options['cont_header_shown']) {
- $header = "".$this_heading." " . $cont . "
";
- $data = $header.$data;
- }
- }
- $this->mpdf->WriteHTML($data);
- $first_meeting = false;
- $newSubHeading = false;
- $newMajorHeading = false;
- }
- }
- }
+ $this->writeMeetings($result_meetings,$this->options['meeting_template_content'],$this->options['weekday_language'],$this->options['include_asm']==0 ? -1 : 0);
if ( $this->options['page_fold'] !== 'half' && $this->options['page_fold'] !== 'full' ) {
$this->write_custom_section();
@@ -1217,6 +1112,137 @@ function bmlt_meeting_list($atts = null, $content = null) {
$this->mpdf->Output($FilePath,'I');
exit;
}
+ function orderByWeekdayStart(&$result_meetings) {
+ $days = array_column($result_meetings, 'weekday_tinyint');
+ $today_str = $this->options['weekday_start'];
+ return array_merge(
+ array_splice($result_meetings, array_search($today_str, $days)),
+ array_splice($result_meetings, 0)
+ );
+ }
+ // include_asm = 0 - let everything through
+ // 1 - only meetings with asm format
+ // -1 - only meetings without asm format
+ function writeMeetings($result_meetings,$template,$lang,$include_asm) {
+ $headerMeetings = $this->getHeaderMeetings($result_meetings,$lang,$include_asm);
+ $unique_heading = $this->getUniqueHeadings($headerMeetings);
+
+ $header_style = "color:".$this->options['header_text_color'].";";
+ $header_style .= "background-color:".$this->options['header_background_color'].";";
+ $header_style .= "font-size:".$this->options['header_font_size']."pt;";
+ $header_style .= "line-height:".$this->options['content_line_height'].";";
+ $header_style .= "text-align:center;padding-top:2px;padding-bottom:3px;";
+
+ if ( $this->options['header_uppercase'] == 1 ) {
+ $header_style .= 'text-transform: uppercase;';
+ }
+ if ( $this->options['header_bold'] == 0 ) {
+ $header_style .= 'font-weight: normal;';
+ }
+ if ( $this->options['header_bold'] == 1 ) {
+ $header_style .= 'font-weight: bold;';
+ }
+ $cont = '('.$this->translate[$lang]['CONT'].')';
+
+
+ $template = wpautop(stripslashes($template));
+ $template = preg_replace('/[[:^print:]]/', ' ', $template);
+
+ $template = str_replace(" ", " ", $template);
+ $analysedTemplate = $this->analyseTemplate($template);
+ $first_meeting = true;
+ $newMajorHeading = false;
+ $test_pages = deep_copy($this->mpdf);
+ foreach ($unique_heading as $this_heading_raw) {
+ $newMajorHeading = true;
+ $this_heading = $this->remove_sort_key($this_heading_raw);
+ $unique_subheading = array_keys($headerMeetings[$this_heading_raw]);
+ asort($unique_subheading, SORT_NATURAL | SORT_FLAG_CASE);
+ foreach ($unique_subheading as $this_subheading_raw) {
+ $newSubHeading = true;
+ $this_subheading = $this->remove_sort_key($this_subheading_raw);
+ foreach ($headerMeetings[$this_heading_raw][$this_subheading_raw] as $meeting_value) {
+ $header = '';
+ if ( !empty($this->options['combine_headings'])) {
+ $header_string = $this->options['combine_headings'];
+ $header_string = str_replace('header1',$this_heading, $header_string);
+ $header_string = str_replace('header2',$this_subheading, $header_string);
+ $header .= "".$header_string."
";
+ } elseif ( $levels == 2 ) {
+ if ( $newMajorHeading === true ) {
+ $xtraMargin = '';
+ if ( !$first_meeting ) {
+ $xtraMargin = 'margin-top:2pt;';
+ }
+ $header .= ''.$this_heading."
";
+ }
+ if ($newSubHeading && $this->options['sub_header_shown']==1) {
+ $header .= "".$this_subheading."
";
+ }
+ } elseif ( $newMajorHeading === true ) {
+ $header .= "".$this_heading."
";
+ }
+ if ($this->options['suppress_heading']==1) {
+ $header = '';
+ }
+ $data = $header . $this->write_single_meeting($meeting_value,
+ $template, $analysedTemplate,
+ $meeting_value['area_name']);
+ $data = mb_convert_encoding($data, 'HTML-ENTITIES');
+ $data = utf8_encode($data);
+ $this->writeBreak($test_pages);
+ $y_startpos = $test_pages->y;
+ $test_pages->WriteHTML($data);
+ $y_diff = $test_pages->y - $y_startpos;
+ if ($y_diff >= $this->mpdf->h - ($this->mpdf->y + $this->mpdf->bMargin + 5) - $this->mpdf->kwt_height) {
+ $this->writeBreak($this->mpdf);
+ if (!$newMajorHeading && $this->options['cont_header_shown']) {
+ $header = "".$this_heading." " . $cont . "
";
+ $data = $header.$data;
+ }
+ }
+ $this->mpdf->WriteHTML($data);
+ $first_meeting = false;
+ $newSubHeading = false;
+ $newMajorHeading = false;
+ }
+ }
+ }
+ }
+ // include_asm = 0 - let everything through
+ // 1 - only meetings with asm format
+ // -1 - only meetings without asm format
+ function getHeaderMeetings(&$result_meetings, $lang, $include_asm) {
+ $levels = $this->getHeaderLevels();
+ foreach ($result_meetings as &$value) {
+ $enFormats = explode ( ",", $value['formats'] );
+ if ( $include_asm < 0 && in_array ( $this->options['asm_format_key'], $enFormats ) ) { continue; }
+ if ( $include_asm > 0 && !in_array ( $this->options['asm_format_key'], $enFormats ) ) { continue; }
+ $value = $this->enhance_meeting($value, $lang);
+ $header1 = $this->getHeaderItem($value, 'header1');
+ if (!isset($headerMeetings[$header1])) {
+ $headerMeetings[$header1] = array();
+ if ($levels == 1) {
+ $headerMeetings[$header1][0] = array();
+ }
+ }
+ if ($levels == 2) {
+ $header2 = $this->getHeaderItem($value, 'header2');
+ if (!isset($headerMeetings[$header1][$header2])) {
+ $headerMeetings[$header1][$header2] = array();
+ }
+ $headerMeetings[$header1][$header2][] = $value;
+ } else {
+ $headerMeetings[$header1][0][] = $value;
+ }
+ }
+ return $headerMeetings;
+ }
+ function getUniqueHeadings($headerMeetings) {
+ $unique_heading = array_keys($headerMeetings);
+ asort($unique_heading, SORT_NATURAL | SORT_FLAG_CASE);
+ return $unique_heading;
+ }
function remove_sort_key($this_heading) {
if (mb_substr($this_heading,0,1)=='[') {
$end = strpos($this_heading,']');
@@ -1524,8 +1550,7 @@ function write_front_page() {
$mod_qs_ci = str_replace("]", "", str_replace("[", "" ,$querystring_custom_item));
$this->options['front_page_content'] = str_replace($querystring_custom_item, (isset($_GET[$mod_qs_ci]) ? $_GET[$mod_qs_ci] : "NOT SET"), $this->options['front_page_content']);
}
- $this->options['front_page_content'] = mb_convert_encoding($this->options['front_page_content'], 'HTML-ENTITIES');
- $this->mpdf->WriteHTML(utf8_encode(wpautop(stripslashes($this->options['front_page_content']))));
+ $this->writeHTMLwithServiceMeetings($this->options['front_page_content'],'front_page');
$this->mpdf->showWatermarkImage = false;
}
@@ -1534,8 +1559,7 @@ function write_last_page() {
$this->mpdf->SetDefaultBodyCSS('font-size', $this->options['last_page_font_size'] . 'pt');
$this->mpdf->SetDefaultBodyCSS('line-height', $this->options['last_page_line_height']);
$this->standard_shortcode_replacement($this->options['last_page_content'], 'last_page');
- $this->options['last_page_content'] = mb_convert_encoding($this->options['last_page_content'], 'HTML-ENTITIES');
- $this->mpdf->WriteHTML(utf8_encode(wpautop(stripslashes($this->options['last_page_content']))));
+ $this->writeHTMLwithServiceMeetings($this->options['last_page_content'], 'last_page');
}
function write_custom_section() {
@@ -1547,8 +1571,7 @@ function write_custom_section() {
$this->mpdf->SetDefaultBodyCSS('font-size', $this->options['custom_section_font_size'] . 'pt');
$this->standard_shortcode_replacement($this->options['custom_section_content'], 'custom_section');
$this->mpdf->WriteHTML('td{font-size: '.$this->options['custom_section_font_size']."pt;line-height:".$this->options['custom_section_line_height'].';}',1);
- $this->options['custom_section_content'] = mb_convert_encoding($this->options['custom_section_content'], 'HTML-ENTITIES');
- $this->mpdf->WriteHTML(utf8_encode(wpautop(stripslashes($this->options['custom_section_content']))));
+ $this->writeHTMLwithServiceMeetings($this->options['custom_section_content'],'custom_section');
}
function locale_month_replacement($data, $case, $sym) {
$strpos = strpos($data, "[month_$case"."_");
@@ -1580,13 +1603,24 @@ function standard_shortcode_replacement(&$data, $page) {
$data = str_replace($search_strings,$replacements,$data);
$this->replace_format_shortcodes($data, $page);
$data = str_replace("[date]", strtoupper( date ( "F Y" ) ), $data);
- if ($this->asm_required($data)) {
- $str = $this->write_service_meetings($this->options[$page.'_font_size'], $this->options[$page.'_line_height'] );
- $data = str_replace('[service_meetings]
', $str, $data);
- $data = str_replace('[service_meetings]', $str, $data);
- $data = str_replace('[additional_meetings]
', $str, $data);
- $data = str_replace('[additional_meetings]', $str, $data);
+ }
+ function writeHTML($str) {
+ $str = mb_convert_encoding($str, 'HTML-ENTITIES');
+ $this->mpdf->WriteHTML(utf8_encode(wpautop(stripslashes($str))));
+ }
+ function writeHTMLwithServiceMeetings($data,$page) {
+ $strs = array('[service_meetings]
','[service_meetings]',
+ '[additional_meetings]
','[additional_meetings]');
+
+ foreach($strs as $str) {
+ $pos = strpos($data,$str);
+ if (!$pos) continue;
+ $this->WriteHTML(substr($data,0,$pos));
+ $this->write_service_meetings($this->options[$page.'_font_size'], $this->options[$page.'_line_height']);
+ $this->WriteHTML(substr($data,$pos+strlen($str)));
+ return;
}
+ $this->WriteHTML($data);
}
function replace_format_shortcodes(&$data, $page_name) {
@@ -1659,7 +1693,14 @@ function get_field($obj,$field) {
function write_service_meetings($font_size, $line_height) {
if ( $this->service_meeting_result == null ) {
// Why not add a query string that limits to meetings having the desired format????
- $asm_query = "client_interface/json/?switcher=GetSearchResults$this->services&sort_keys=$this->options['asm_sort_order']";
+ $sort_order = $this->options['asm_sort_order'];
+ if ($sort_order=='same') {
+ $sort_order = 'weekday_tinyint,start_time';
+ }
+ $asm_id = -1;
+ if (isset($this->options['asm_format_id']))
+ $asm_id = $this->options['asm_format_id'];
+ $asm_query = "client_interface/json/?switcher=GetSearchResults$this->services&formats=$asm_id&sort_keys=$sort_order";
// I'm not sure we need this, but for now we need to emulate the old behavior
if ($this->options['asm_format_key']==='ASM') {
$asm_query .= "&advanced_published=0";
@@ -1667,18 +1708,28 @@ function write_service_meetings($font_size, $line_height) {
$results = $this->get_configured_root_server_request( $asm_query );
$this->service_meeting_result = json_decode(wp_remote_retrieve_body($results), true);
}
- $data = '';
- $x = 0;
+
+ if ($this->options['asm_sort_order']=='same') {
+ if (isset($this->options['asm_template_content']) && trim($this->options['asm_template_content'])) {
+ $template = $this->options['asm_template_content'];
+ } else {
+ $template = $this->options['meeting_template_content'];
+ }
+ $this->writeMeetings($this->service_meeting_result,$template,$this->options['asm_language'],1);
+ return;
+ }
+ $temp = array();
foreach ($this->service_meeting_result as $value) {
$enFormats = explode ( ",", $value['formats'] );
- if ( ! in_array ( $this->options['asm_format_key'], $enFormats ) ) {
- continue;
+ if ( in_array ( $this->options['asm_format_key'], $enFormats ) ) {
+ $temp[] = $value;
}
- $x++;
}
- if ( $x == 0 ) {
- return $data;
+ $this->service_meeting_result = $temp;
+ if ( empty($temp) ) {
+ return;
}
+ $data = '';
$template = '';
if (isset($this->options['asm_template_content']) && trim($this->options['asm_template_content'])) {
$template = $this->options['asm_template_content'];
@@ -1686,10 +1737,6 @@ function write_service_meetings($font_size, $line_height) {
$data .= "";
}
foreach ($this->service_meeting_result as $value) {
- $enFormats = explode ( ",", $value['formats'] );
- if ( ! in_array ( $this->options['asm_format_key'], $enFormats ) ) {
- continue;
- }
$area_name = $this->get_area_name($meeting_value);
if ($template != '') {
$template = str_replace(" ", " ", $template);
@@ -1740,7 +1787,7 @@ function write_service_meetings($font_size, $line_height) {
}
if ($template == '')
$data .= "
";
- return $data;
+ $this->writeHTML($data);
}
/**
diff --git a/js/bmlt_meeting_list.js b/js/bmlt_meeting_list.js
index 5cd6e64..8292a05 100644
--- a/js/bmlt_meeting_list.js
+++ b/js/bmlt_meeting_list.js
@@ -380,11 +380,6 @@ var $ml = jQuery.noConflict
$ml('#meeting-list-tabs').tabs().addClass('ui-tabs-vertical ui-helper-clearfix');
$ml("#container").removeClass('hide');
var meeting_sort_val = $ml("#meeting_sort").val();
- if (meeting_sort_val === 'day' || meeting_sort_val === 'weekday_area' || meeting_sort_val === 'weekday_city' || meeting_sort_val === 'weekday_county') {
- $ml('.weekday_start_div').show();
- } else {
- $ml('.weekday_start_div').hide();
- }
$ml('.borough_by_suffix').hide();
$ml('.county_by_suffix').hide();
if (meeting_sort_val === 'borough_county') {
@@ -432,11 +427,6 @@ var $ml = jQuery.noConflict
$ml('.county_by_suffix').hide();
$ml('.neighborhood_by_suffix').hide();
$ml('.city_by_suffix').hide();
- if (meeting_sort_val === 'day' || meeting_sort_val === 'weekday_area' || meeting_sort_val === 'weekday_city' || meeting_sort_val === 'weekday_county') {
- $ml('.weekday_start_div').show();
- } else {
- $ml('.weekday_start_div').hide();
- }
if (meeting_sort_val === 'borough_county') {
$ml('.borough_by_suffix').show();
$ml('.county_by_suffix').show();
diff --git a/partials/_meetings_setup.php b/partials/_meetings_setup.php
index 9d7bca3..dc0f7d5 100644
--- a/partials/_meetings_setup.php
+++ b/partials/_meetings_setup.php
@@ -365,7 +365,8 @@