function major_summary($data, $echo = true) { global $hansardmajors; $html = ''; $db = new ParlDB(); $one_date = false; //if no printed majors passed, default to all if (!isset($printed_majors)) { $printed_majors = array(1, 2, 3, 5, 101, 7); # 8 } // single date? if (isset($data['date'])) { $one_date = true; } // remove empty entries, so they don't produce errors foreach (array_keys($hansardmajors) as $major) { if (array_key_exists($major, $data)) { if (count($data[$major]) == 0) { unset($data[$major]); } } } //work out the date text to be displaid $daytext = array(); if (!$one_date) { $todaystime = gmmktime(0, 0, 0, date('m'), date('d'), date('Y')); foreach ($data as $major => $array) { if (!in_array('timestamp', $array)) { $daytext[$major] = "The most recent "; } elseif ($todaystime - $array['timestamp'] == 86400) { $daytext[$major] = "Yesterday’s"; } elseif ($todaystime - $array['timestamp'] <= 6 * 86400) { $daytext[$major] = gmdate('l', $array['timestamp']) . "’s"; } else { $daytext[$major] = "The most recent "; } } } //build html foreach ($printed_majors as $p_major) { if (!array_key_exists($p_major, $data)) { continue; } if ($one_date) { $date = $data['date']; } else { $date = $data[$p_major]['hdate']; } $q = $db->query('SELECT body, gid FROM hansard, epobject WHERE hansard.epobject_id = epobject.epobject_id AND section_id = 0 AND hdate = "' . $date . '" AND major = ' . $p_major . ' ORDER BY hpos'); $out = ''; $LISTURL = new URL($hansardmajors[$p_major]['page_all']); for ($i = 0; $i < $q->rows(); $i++) { $gid = fix_gid_from_db($q->field($i, 'gid')); $body = $q->field($i, 'body'); //if (strstr($body, 'Chair]')) continue; $LISTURL->insert(array('id' => $gid)); $out .= '<li><a href="' . $LISTURL->generate() . '">'; $out .= $body . '</a>'; } if ($out) { $html .= _major_summary_title($p_major, $data, $LISTURL, $daytext); $html .= '<ul class="hansard-day">'; $html .= $out; $html .= '</ul>'; } } if (array_key_exists(4, $data)) { if ($one_date) { $date = $data['date']; } else { $date = $data[4]['hdate']; } $q = $db->query('SELECT section_id, body, gid FROM hansard,epobject WHERE hansard.epobject_id = epobject.epobject_id AND major=4 AND hdate="' . $date . '" AND subsection_id=0 ORDER BY major, hpos'); if ($q->rows()) { $LISTURL = new URL($hansardmajors[4]['page_all']); $html .= _major_summary_title(4, $data, $LISTURL, $daytext); $html .= "<ul>"; $current_sid = 0; for ($i = 0; $i < $q->rows(); $i++) { $gid = fix_gid_from_db($q->field($i, 'gid')); $body = $q->field($i, 'body'); $section_id = $q->field($i, 'section_id'); if (!$section_id) { if ($current_sid++) { $html .= '</ul>'; } $html .= '<li>' . $body . '<ul>'; } else { $LISTURL->insert(array('id' => $gid)); $html .= '<li><a href="' . $LISTURL->generate() . '">'; $html .= $body . '</a>'; } } $html .= '</ul>'; } } $html .= '</ul>'; if ($echo) { print $html; } else { return $html; } }
function major_summary($data, $limit = "") { global $hansardmajors; $db = new ParlDB(); $one_date = false; if (isset($data['date'])) { $one_date = true; } $limitsql = ""; if ($limit) { $limitsql = " limit {$limit}"; } $daytext = array(); if (!$one_date) { $todaystime = gmmktime(0, 0, 0, date('m'), date('d'), date('Y')); foreach ($data as $major => $array) { if ($todaystime - $array['timestamp'] == 86400) { $daytext[$major] = "Yesterday's"; } elseif ($todaystime - $array['timestamp'] <= 6 * 86400) { $daytext[$major] = gmdate('l', $array['timestamp']) . "'s"; } else { $daytext[$major] = "The most recent "; } } } $printed_majors = array(1, 2, 3, 5, 101); print '<ul id="hansard-day">'; while (count($printed_majors)) { if (!array_key_exists($printed_majors[0], $data)) { unset($printed_majors[0]); sort($printed_majors); continue; } if ($one_date) { $date = $data['date']; } else { $date = $data[$printed_majors[0]]['hdate']; } $q = $db->query('SELECT major, body, gid FROM hansard,epobject WHERE hansard.epobject_id = epobject.epobject_id AND section_id=0 AND hdate="' . $date . '" AND major IN (' . join(',', $printed_majors) . ') ORDER BY major desc, hpos' . $limitsql); $current_major = 0; for ($i = 0; $i < $q->rows(); $i++) { $gid = fix_gid_from_db($q->field($i, 'gid')); $major = $q->field($i, 'major'); $body = $q->field($i, 'body'); //if (strstr($body, 'Chair]')) continue; if ($major != $current_major) { if ($current_major) { print '</ul>'; } $LISTURL = new URL($hansardmajors[$major]['page_all']); _major_summary_title($major, $data, $LISTURL, $daytext); $current_major = $major; # XXX: Surely a better way of doing this? Oh well unset($printed_majors[array_search($major, $printed_majors)]); sort($printed_majors); } $LISTURL->insert(array('id' => $gid)); print '<li><a href="' . $LISTURL->generate() . '">'; print $body . '</a>'; } print '</ul>'; if ($one_date) { $printed_majors = array(); } } if (array_key_exists(4, $data)) { if ($one_date) { $date = $data['date']; } else { $date = $data[4]['hdate']; } $q = $db->query('SELECT section_id, body, gid FROM hansard,epobject WHERE hansard.epobject_id = epobject.epobject_id AND major=4 AND hdate="' . $date . '" AND subsection_id=0 ORDER BY major, hpos' . $limitsql); if ($q->rows()) { $LISTURL = new URL($hansardmajors[4]['page_all']); _major_summary_title(4, $data, $LISTURL, $daytext); $current_sid = 0; for ($i = 0; $i < $q->rows(); $i++) { $gid = fix_gid_from_db($q->field($i, 'gid')); $body = $q->field($i, 'body'); $section_id = $q->field($i, 'section_id'); if (!$section_id) { if ($current_sid++) { print '</ul>'; } print '<li>' . $body . '<ul>'; } else { $LISTURL->insert(array('id' => $gid)); print '<li><a href="' . $LISTURL->generate() . '">'; print $body . '</a>'; } } print '</ul></ul>'; } } print '</ul>'; }