Sélection par séance, réordonnancement et exclusion vie du labo
This commit is contained in:
@@ -44,10 +44,6 @@ class Thalim_NL_HTML_Exporter {
|
||||
/**
|
||||
* Generate a complete email-ready HTML document from a saved newsletter post.
|
||||
*/
|
||||
/** Month window timestamps — set by generate(), used by format_seminar_line() */
|
||||
private int $month_start = 0;
|
||||
private int $month_end = 0;
|
||||
|
||||
public function generate(WP_Post $post): string {
|
||||
$sections_json = get_post_meta($post->ID, '_newsletter_sections', true);
|
||||
$sections = json_decode($sections_json, true) ?: [];
|
||||
@@ -57,13 +53,6 @@ class Thalim_NL_HTML_Exporter {
|
||||
$subscribe_url = get_post_meta($post->ID, '_newsletter_subscribe_url', true) ?: '';
|
||||
$unsubscribe_url = get_post_meta($post->ID, '_newsletter_unsubscribe_url', true) ?: '';
|
||||
|
||||
// Compute month window from stored newsletter month
|
||||
$year_month = get_post_meta($post->ID, '_newsletter_month', true) ?: '';
|
||||
if ($year_month) {
|
||||
$this->month_start = strtotime($year_month . '-01 00:00:00') ?: 0;
|
||||
$this->month_end = strtotime('last day of ' . $year_month . ' 23:59:59') ?: 0;
|
||||
}
|
||||
|
||||
// Build ordered section blocks following the category hierarchy
|
||||
$groups = Thalim_NL_Post_Query::get_eligible_categories();
|
||||
$section_blocks = [];
|
||||
@@ -83,10 +72,16 @@ class Thalim_NL_HTML_Exporter {
|
||||
continue;
|
||||
}
|
||||
$items = [];
|
||||
foreach ($post_ids as $pid) {
|
||||
$line = $this->format_post_line((int) $pid, $cat_id);
|
||||
if ($line) {
|
||||
$items[] = $line;
|
||||
if ((int) $cat_id === THALIM_NL_CAT_SEMINAIRES) {
|
||||
// Selected items are séance IDs: group them by parent seminar,
|
||||
// rendering each seminar's title once above its séances.
|
||||
$items = $this->format_seminar_blocks(array_map('intval', $post_ids));
|
||||
} else {
|
||||
foreach ($post_ids as $pid) {
|
||||
$line = $this->format_post_line((int) $pid, $cat_id);
|
||||
if ($line) {
|
||||
$items[] = $line;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($items)) {
|
||||
@@ -305,11 +300,6 @@ body { margin: 0 !important; padding: 0 !important; }
|
||||
* Optional image on the left, title in serif, meta below in sans-serif.
|
||||
*/
|
||||
public function format_post_line(int $post_id, int $cat_id): string {
|
||||
// Seminars: special rendering with séances
|
||||
if ($cat_id === THALIM_NL_CAT_SEMINAIRES) {
|
||||
return $this->format_seminar_line($post_id);
|
||||
}
|
||||
|
||||
$post = get_post($post_id);
|
||||
if (!$post) {
|
||||
return '';
|
||||
@@ -394,11 +384,45 @@ body { margin: 0 !important; padding: 0 !important; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a seminar post: title (no dates) + list of séances with date, time, location.
|
||||
* Each séance links to the seminar page.
|
||||
* Render the seminar section from a flat list of selected séance IDs.
|
||||
* Séances are grouped by their parent seminar (first-appearance order),
|
||||
* and each seminar is rendered as one block with its title shown once.
|
||||
*
|
||||
* @return string[] One HTML block per seminar.
|
||||
*/
|
||||
private function format_seminar_line(int $post_id): string {
|
||||
$post = get_post($post_id);
|
||||
private function format_seminar_blocks(array $seance_ids): array {
|
||||
// Group séance IDs by parent seminar, preserving order of first appearance.
|
||||
$by_seminar = [];
|
||||
foreach ($seance_ids as $sid) {
|
||||
$sid = (int) $sid;
|
||||
$s_post = get_post($sid);
|
||||
if (!$s_post || $s_post->post_status !== 'publish') {
|
||||
continue;
|
||||
}
|
||||
$sem_id = Thalim_NL_Post_Query::get_seminar_id_for_seance($sid);
|
||||
if (!$sem_id) {
|
||||
continue;
|
||||
}
|
||||
$by_seminar[$sem_id][] = $sid;
|
||||
}
|
||||
|
||||
$blocks = [];
|
||||
foreach ($by_seminar as $sem_id => $sids) {
|
||||
$block = $this->format_seminar_block((int) $sem_id, $sids);
|
||||
if ($block) {
|
||||
$blocks[] = $block;
|
||||
}
|
||||
}
|
||||
return $blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format one seminar block: title (no dates) shown once + the given
|
||||
* séances with date, time, location. Each séance links to its anchor
|
||||
* on the seminar page.
|
||||
*/
|
||||
private function format_seminar_block(int $seminar_id, array $seance_ids): string {
|
||||
$post = get_post($seminar_id);
|
||||
if (!$post) {
|
||||
return '';
|
||||
}
|
||||
@@ -406,12 +430,12 @@ body { margin: 0 !important; padding: 0 !important; }
|
||||
$font_serif = "Gelasio, Georgia, 'Times New Roman', serif";
|
||||
$font_sans = "Arial, Helvetica, sans-serif";
|
||||
|
||||
$url = get_permalink($post_id);
|
||||
$title = get_the_title($post_id);
|
||||
$url = get_permalink($seminar_id);
|
||||
$title = get_the_title($seminar_id);
|
||||
|
||||
// Image
|
||||
// Image (first image from the seminar's documents_joints)
|
||||
$image_url = '';
|
||||
$doc_ids = get_post_meta($post_id, 'documents_joints', false);
|
||||
$doc_ids = get_post_meta($seminar_id, 'documents_joints', false);
|
||||
foreach ($doc_ids as $doc_id) {
|
||||
$mime = get_post_mime_type($doc_id);
|
||||
if ($mime && str_starts_with($mime, 'image/')) {
|
||||
@@ -423,28 +447,19 @@ body { margin: 0 !important; padding: 0 !important; }
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch séances within the newsletter month window
|
||||
$seance_ids = get_post_meta($post_id, 'seances', false);
|
||||
// Build the selected séances. Within a seminar, séances always display
|
||||
// in chronological order (seminars themselves are reorderable, séances
|
||||
// are not).
|
||||
$seances = [];
|
||||
foreach ($seance_ids as $sid) {
|
||||
$sid = (int) $sid;
|
||||
$s_post = get_post($sid);
|
||||
if (!$s_post || $s_post->post_status !== 'publish') continue;
|
||||
|
||||
$raw_debut = get_post_meta($sid, 'date_de_debut', true) ?: '';
|
||||
$ts = $raw_debut ? strtotime($raw_debut) : false;
|
||||
|
||||
// Filter: only séances within the month window
|
||||
if ($this->month_start && $this->month_end) {
|
||||
if (!$ts || $ts < $this->month_start || $ts > $this->month_end) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$seances[] = [
|
||||
'id' => $sid,
|
||||
'title' => get_the_title($sid),
|
||||
'date_debut' => $raw_debut,
|
||||
'date_debut' => get_post_meta($sid, 'date_de_debut', true) ?: '',
|
||||
'date_fin' => get_post_meta($sid, 'date_de_fin', true) ?: '',
|
||||
'heure_de_debut' => substr(get_post_meta($sid, 'heure_de_debut', true) ?: '', 0, 5),
|
||||
'heure_de_fin' => substr(get_post_meta($sid, 'heure_de_fin', true) ?: '', 0, 5),
|
||||
|
||||
Reference in New Issue
Block a user