indy.nl update
[mir.git] / source / mirlocal / indymedia.nl / IndyNLDataModelLocalizer.java
1 package mirlocal.indymedia.nl;
2
3 import mir.entity.adapter.*;
4 import mircoders.localizer.*;
5 import mircoders.localizer.basic.*;
6 import mircoders.storage.*;
7
8 public class IndyNLDataModelLocalizer extends MirBasicDataModelLocalizer {
9   protected void constructContentAdapterDefinition(EntityAdapterDefinition anEntityAdapterDefinition) throws MirLocalizerFailure {
10     super.constructContentAdapterDefinition( anEntityAdapterDefinition );
11
12     try {
13       anEntityAdapterDefinition.addCalculatedField("to_trashedcomments", new ContentToCommentsField(" and is_published='0'"));
14       anEntityAdapterDefinition.addCalculatedField("trashedcommentcount", new ContentCommentCountField(" and is_published='0'"));
15       anEntityAdapterDefinition.addCalculatedField("commentcount", new ContentCommentCountField(" and is_published='1'"));
16       anEntityAdapterDefinition.addCalculatedField("to_allcomments", new ContentToCommentsField(""));
17       anEntityAdapterDefinition.addCalculatedField("to_comments_reversed", new ContentToCommentsField(" and is_published='1'", "webdb_create desc"));
18     }
19     catch (Throwable t) {
20       throw new MirLocalizerFailure(t.getMessage(), t);
21     }
22   }
23
24
25   protected class ContentToCommentsField implements EntityAdapterDefinition.CalculatedField {
26     private String extraCondition;
27     private String order;
28
29
30     public ContentToCommentsField(String anExtraCondition, String anOrder) {
31       super();
32
33       order = anOrder;
34       extraCondition = anExtraCondition;
35     }
36
37     public ContentToCommentsField(String anExtraCondition) {
38       this(anExtraCondition, "webdb_create");
39     }
40
41     public Object getValue(EntityAdapter anEntityAdapter) {
42       try {
43         return anEntityAdapter.getRelation(
44                     "to_media="+anEntityAdapter.get("id") + " " + extraCondition,
45                     order,
46                     "comment" );
47       }
48       catch (Throwable t) {
49         throw new RuntimeException(t.getMessage());
50       }
51     }
52   }
53
54   protected class ContentCommentCountField implements EntityAdapterDefinition.CalculatedField {
55     private String extraCondition;
56
57     public ContentCommentCountField(String anExtraCondition) {
58       super();
59
60       extraCondition = anExtraCondition;
61     }
62
63     public Object getValue(EntityAdapter anEntityAdapter) {
64       try {
65         return Integer.toString(
66             DatabaseComment.getInstance().getSize(
67                   "to_media="+anEntityAdapter.get("id")+" " + extraCondition));
68       }
69       catch (Throwable t) {
70         throw new RuntimeException(t.getMessage());
71       }
72     }
73   }
74 }