source: trunk/gsdl/src/recpt/datelistbrowserclass.cpp@ 1861

Last change on this file since 1861 was 1610, checked in by paynter, 24 years ago

Changed the formatstring parser in formattools so that an {If} macro (which
has the form {If}{decision,then,else}) can branch on any text, not just on
metadata. This means you can use extra cgi arguments and macros like
_cgiargmode_ to display documents in different modes and switch between
them. To accomplish all this, the formattools class needed to be able to
evaluate macros (through displayclass), so the other files have been
changed to pass in a displayclass object.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1/**********************************************************************
2 *
3 * datelistbrowserclass.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 *********************************************************************/
25
26#include "datelistbrowserclass.h"
27#include <assert.h>
28
29
30datelistbrowserclass::datelistbrowserclass () {
31}
32
33datelistbrowserclass::~datelistbrowserclass () {
34}
35
36text_t datelistbrowserclass::get_browser_name () {
37 return "DateList";
38}
39
40void datelistbrowserclass::load_metadata_defaults (text_tset &metadata) {
41 metadata.insert ("Date");
42 metadata.insert ("doctype");
43}
44
45text_t datelistbrowserclass::get_default_formatstring () {
46 return "<td>[link][icon][/link]</td><td>[highlight]{Or}{[Title],Untitled}[/highlight]</td><td>[Date]</td>";
47}
48
49int datelistbrowserclass::output_section_group (ResultDocInfo_t &/*section*/, cgiargsclass &/*args*/,
50 const text_t &/*collection*/, int /*colnumber*/,
51 format_t * /*formatlistptr*/, bool /*use_table*/,
52 text_tset &/*metadata*/, bool &/*getParents*/,
53 recptproto * /*collectproto*/, displayclass &/*disp*/,
54 outconvertclass &/*outconvert*/, ostream &/*textout*/,
55 ostream &/*logout*/) {
56 return 0;
57}
58
59int datelistbrowserclass::output_section_group (FilterResponse_t &sections, cgiargsclass &args,
60 const text_t &collection, int colnumber, format_t *formatlistptr,
61 bool use_table, text_tset &/*metadata*/, bool &/*getParents*/,
62 recptproto * collectproto, displayclass &disp,
63 outconvertclass &outconvert, ostream &textout, ostream &logout) {
64
65 text_t lastyear = "0000";
66 text_t lastmonth = "00";
67 text_t tabbing, endtabbing;
68
69 if (use_table || colnumber > 0) {
70 textout << "<table><tr><td>";
71 // get tab size
72 text_t tab; int itab;
73 disp.expandstring ("Global", "_tabwidth_", tab);
74 itab = tab.getint();
75 if (colnumber > 0)
76 textout << "<img src=\"_httpimg_/space.gif\" width=" << (itab*colnumber) << ">";
77 textout<< "</td><td>";
78 }
79
80 textout << "<table>\n";
81
82 ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
83 ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
84
85 while (thissection != endsection) {
86
87 text_t &doctype = (*thissection).metadata["doctype"].values[0];
88 text_t &date = (*thissection).metadata["Date"].values[0];
89
90 // bail on this document if it has no date
91 if (date.empty()) continue;
92
93 text_t::const_iterator datebegin = date.begin();
94 int datesize = date.size();
95
96 if (datesize < 4) continue;
97 text_t thisyear = substr (datebegin, datebegin+4);
98 text_t thismonth = "00";
99 if (datesize >= 6)
100 thismonth = substr (datebegin+4, datebegin+6);
101
102 text_t link = "<a href=\"_httpdocument_&cl=";
103 text_t icon = "_document:iconclosedbook_";
104
105 if (doctype == "classify") {
106 icon = "_document:iconclosedbookshelf_";
107 link += (*thissection).OID + "\">";
108 } else link += args["cl"] + "&d=" + (*thissection).OID + "\">";
109
110 textout << "<tr valign=top>";
111
112 if (thisyear != lastyear) {
113 textout << outconvert << "<td><b>" << thisyear << "</b></td>";
114 lastyear = thisyear;
115 } else
116 textout << "<td></td>";
117
118 if (thismonth != lastmonth) {
119 textout << outconvert << disp << ("<td><b>_textmonth" + thismonth + "_</b></td>");
120 lastmonth = thismonth;
121 } else
122 textout << "<td></td>";
123
124 if (!use_table) textout << "<td>\n";
125
126 textout << outconvert << disp
127 << get_formatted_string (collection, collectproto,
128 *thissection, disp, formatlistptr,
129 link, icon, false,
130 logout) << "\n";
131
132 if (!use_table) textout << "</td>";
133
134 textout << "</tr>\n";
135
136 thissection ++;
137 }
138
139 textout << "</table>\n";
140
141 if (use_table || colnumber > 0) textout << "</td></tr></table>\n";
142 return 1;
143}
Note: See TracBrowser for help on using the repository browser.