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