source: main/trunk/greenstone2/runtime-src/src/recpt/datelistbrowserclass.cpp@ 27309

Last change on this file since 27309 was 27309, checked in by kjdon, 11 years ago

when we have just started a new year, output the month even if it is the same as the last month output, otherwise it seems as though the first item in the list has no month

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
RevLine 
[649]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
[7379]26#include "gsdl_modules_cfg.h"
27#ifdef GSDL_USE_DATELIST_BROWSER
28
[24810]29#include "browsetoolsclass.h"
[649]30#include "datelistbrowserclass.h"
31#include <assert.h>
32
33
34datelistbrowserclass::datelistbrowserclass () {
35}
36
37datelistbrowserclass::~datelistbrowserclass () {
38}
39
[668]40text_t datelistbrowserclass::get_browser_name () {
41 return "DateList";
[649]42}
43
[7379]44browserclass* datelistbrowserclass::clone()
45{
46 return new datelistbrowserclass();
47}
48
[668]49void datelistbrowserclass::load_metadata_defaults (text_tset &metadata) {
50 metadata.insert ("Date");
51 metadata.insert ("doctype");
[649]52}
53
[668]54text_t datelistbrowserclass::get_default_formatstring () {
[23453]55 return "<td>[link][icon][/link]</td><td>[highlight]{Or}{[dc.Title],[exp.Title],[ex.Title],Untitled}[/highlight]</td><td>{Or}{[format:dc.Date],[format:exp.Date],[format:ex.Date]}</td>";
[649]56}
57
[995]58int datelistbrowserclass::output_section_group (ResultDocInfo_t &/*section*/, cgiargsclass &/*args*/,
59 const text_t &/*collection*/, int /*colnumber*/,
60 format_t * /*formatlistptr*/, bool /*use_table*/,
61 text_tset &/*metadata*/, bool &/*getParents*/,
62 recptproto * /*collectproto*/, displayclass &/*disp*/,
63 outconvertclass &/*outconvert*/, ostream &/*textout*/,
64 ostream &/*logout*/) {
65 return 0;
66}
[668]67
68int datelistbrowserclass::output_section_group (FilterResponse_t &sections, cgiargsclass &args,
[1443]69 const text_t &collection, int colnumber, format_t *formatlistptr,
[668]70 bool use_table, text_tset &/*metadata*/, bool &/*getParents*/,
[1443]71 recptproto * collectproto, displayclass &disp,
72 outconvertclass &outconvert, ostream &textout, ostream &logout) {
[668]73
[24810]74 browsetoolsclass btools;
[668]75 text_t lastyear = "0000";
76 text_t lastmonth = "00";
77 text_t tabbing, endtabbing;
78
79 if (use_table || colnumber > 0) {
[3666]80 textout << outconvert << "<table><tr><td>";
[668]81 // get tab size
82 text_t tab; int itab;
[7433]83 disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab);
[668]84 itab = tab.getint();
85 if (colnumber > 0)
[17860]86 textout << outconvert << "<img alt=\"\" src=\"_httpiconspace_\" width=\"" << (itab*colnumber) << "\"/>";
[3666]87 textout << outconvert << "</td><td>";
[668]88 }
89
[11638]90 textout << outconvert << "<table class=\"date_list\">\n";
[668]91
92 ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
93 ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
[6645]94
95 // use the dm arg as date metadata or else Date
96 text_t date_meta = args["dm"];
97 if (date_meta == "") {
98 date_meta = "Date";
99 }
[10981]100 text_tarray dates;
101 splitchar(date_meta.begin(), date_meta.end(), ',', dates);
102
[668]103 while (thissection != endsection) {
104
105 text_t &doctype = (*thissection).metadata["doctype"].values[0];
106
[10981]107 text_tarray::iterator begin = dates.begin();
108 text_tarray::iterator end = dates.end();
109 text_t date;
110 while (begin!= end && date.empty()) {
111 date = (*thissection).metadata[*begin].values[0];
112 begin++;
113 }
[11770]114 text_t thisyear = "";
115 text_t thismonth = "";
116 if (!date.empty()) {
117 text_t::const_iterator datebegin = date.begin();
118 int datesize = date.size();
[668]119
[11770]120 if (datesize >=4) {
121 thisyear = substr (datebegin, datebegin+4);
122 thismonth = "00";
[13017]123 int pos = 4;
124 // allow for yyyy-mm-dd
[27108]125 if (datesize > pos && date[pos]=='-') {
[13017]126 ++pos;
127 }
128 if (datesize >= pos+2)
129 thismonth = substr (datebegin+pos, datebegin+pos+2);
[11770]130 }
131 }
132
[668]133 text_t link = "<a href=\"_httpdocument_&cl=";
134 text_t icon = "_document:iconclosedbook_";
135
136 if (doctype == "classify") {
137 icon = "_document:iconclosedbookshelf_";
138 link += (*thissection).OID + "\">";
[5124]139 } else {
140 link += args["cl"] + "&d=" + (*thissection).OID; // + "\">";
141 // [modification to allow default document detach settings -- kjdon]
142 if (args["xx"]=="1") {
143 // documents should be detached
144 link += "&x=1\" target=\\_blank>";
145 } else {
146 link += "\">";
147 }
148 }
[668]149
[3666]150 textout << outconvert << "<tr valign=top>";
[27309]151 bool new_year = false;
[11770]152 if (thisyear != "" && thisyear != lastyear) {
[11638]153 textout << outconvert << "<td><span class=\"date_list_year\">" << thisyear << "</span></td>";
[668]154 lastyear = thisyear;
[27309]155 new_year = true;
[11770]156 } else {
[3666]157 textout << outconvert << "<td></td>";
[11770]158 }
[27309]159 if (thismonth != "" && (thismonth != lastmonth || new_year)) {
[11638]160 textout << outconvert << disp << ("<td><span class=\"date_list_month\">_textmonth" + thismonth + "_</span></td>");
[668]161 lastmonth = thismonth;
[11770]162 } else {
[3666]163 textout << outconvert << "<td></td>";
[11770]164 }
[3666]165 if (!use_table) textout << outconvert << "<td>\n";
[4906]166
167 text_tmap options;
168 options["link"] = link;
169 options["icon"] = icon;
170 options["highlight"] = "0";
[24810]171 options["DocImage"] = btools.get_cover_image();
172 options["assocfilepath"] = btools.get_assocfile_path();
173
[668]174 textout << outconvert << disp
[1443]175 << get_formatted_string (collection, collectproto,
[1610]176 *thissection, disp, formatlistptr,
[4906]177 options, logout) << "\n";
[668]178
[3666]179 if (!use_table) textout << outconvert << "</td>";
[668]180
[3666]181 textout << outconvert << "</tr>\n";
[668]182
[9620]183 ++thissection;
[668]184 }
185
[3666]186 textout << outconvert << "</table>\n";
[668]187
[3666]188 if (use_table || colnumber > 0) textout << outconvert << "</td></tr></table>\n";
[668]189 return 1;
190}
[7379]191
192#endif //GSDL_USE_DATELIST_BROWSER
Note: See TracBrowser for help on using the repository browser.