Initial revision
[mir.git] / source / mircoders / producer / ProducerTopics.java
1 package mircoders.producer;
2
3 import java.io.*;
4 import java.lang.*;
5 import java.util.*;
6 import java.sql.*;
7
8 import freemarker.template.*;
9
10 import webdb.misc.*;
11 import webdb.storage.*;
12 import webdb.module.*;
13 import webdb.entity.*;
14
15 import mir.module.*;
16 import mir.entity.*;
17 import mir.storage.*;
18
19
20
21 public class ProducerTopics extends ProducerList {
22
23         public String where;
24
25         public void setAdditional(String key, TemplateModel value) {
26                 additional.put(key,value);
27         }
28
29   public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id)
30     throws StorageObjectException, ModuleException {
31     where=id;
32     handle(htmlout,user,force,sync);
33   }
34
35         public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
36                 throws StorageObjectException, ModuleException {
37
38                 orderBy="date desc, webdb_create desc";
39                 listTemplate = Configuration.getProperty("Producer.TopicList.Template");
40
41     EntityList topicsEntityList;
42     if(where==null){
43       topicsEntityList = topicsModule.getByWhereClause("","title", -1);
44     } else {
45       topicsEntityList = topicsModule.getByWhereClause(where,"title", -1);
46     }
47                 SimpleList topicsList = HTMLTemplateProcessor.makeSimpleList(topicsEntityList);
48
49                 for(int i=0; i < topicsEntityList.size(); i++){
50
51                         EntityTopics currentTopic = (EntityTopics)topicsEntityList.elementAt(i);
52                         EntityList contentEntityList = DatabaseContentToTopics.getInstance().getContent(currentTopic);
53       String whereClauseSpecial=null;
54
55       if (contentEntityList!=null || force==true) {
56         if (contentEntityList!=null){
57           boolean first=true;
58           whereClause="is_published='1' AND to_article_type >= 1 AND to_article_type <=2 AND id IN (";
59           whereClauseSpecial="is_published='1' AND to_article_type=3 AND id IN (";
60           for(int j=0; j < contentEntityList.size(); j++){
61             if(first==false) {
62               whereClause += ",";
63               whereClauseSpecial += ",";
64             }
65             EntityContent currentContent = (EntityContent)contentEntityList.elementAt(j);
66             whereClause += currentContent.getId();
67             whereClauseSpecial += currentContent.getId();
68
69             setAdditional("topic",HTMLTemplateProcessor.makeSimpleHash(currentTopic));
70
71             first = false;
72           }
73           whereClause += ")";
74           whereClauseSpecial += ")";
75         }
76
77         if(contentEntityList==null && force==true){
78           //hihi, das ist eigentlich boese
79           whereClause="is_published='1' AND to_article_type>=1 AND id IN (0)";
80         }
81
82         fileDesc = currentTopic.getValue("filename");
83
84         // get the startarticle
85         EntityList entityList = contentModule.getContent(whereClauseSpecial,"date desc, webdb_create desc",0,1);
86         SimpleList specialList = HTMLTemplateProcessor.makeSimpleList(entityList);
87         String currentMediaId = null;
88         SimpleHash imageHash = new SimpleHash();
89         EntityContent currentContent;
90         if(entityList != null){
91           for (int k=0; k < entityList.size();k++) {
92             currentContent = (EntityContent)entityList.elementAt(k);
93             currentMediaId = currentContent.getValue("to_media");
94             if (currentMediaId!=null && !currentMediaId.equals("")) {
95               imageHash.put(currentMediaId, HTMLTemplateProcessor.makeSimpleHash(imageModule.getById(currentMediaId)));
96             }
97           }
98           setAdditional("specialimage",imageHash);
99         }
100         setAdditional("special",specialList);
101
102         //set the list of topics
103         setAdditional("topicslist",topicsList);
104
105         handleIt(htmlout,user,force);
106       }
107     }
108         }
109
110         public static void main(String argv[]){
111                 try {
112                         new ProducerOpenPosting().handle(new PrintWriter(System.out), null,false, false);
113                 } catch(Exception e) {
114                         System.err.println(e.toString());
115                 }
116         }
117 }