super.constructContentAdapterDefinition( anEntityAdapterDefinition );
try {
- anEntityAdapterDefinition.addCalculatedField("to_trashedcomments", new ContentToTrashedCommentsField());
- anEntityAdapterDefinition.addCalculatedField("trashedcommentcount", new ContentTrashedCommentCountField());
- anEntityAdapterDefinition.addCalculatedField("commentcount", new ContentCommentCountField());
+ anEntityAdapterDefinition.addCalculatedField("to_trashedcomments", new ContentToCommentsField(" and is_published='0'"));
+ anEntityAdapterDefinition.addCalculatedField("trashedcommentcount", new ContentCommentCountField(" and is_published='0'"));
+ anEntityAdapterDefinition.addCalculatedField("commentcount", new ContentCommentCountField(" and is_published='1'"));
+ anEntityAdapterDefinition.addCalculatedField("to_allcomments", new ContentToCommentsField(""));
+ anEntityAdapterDefinition.addCalculatedField("to_comments_reversed", new ContentToCommentsField(" and is_published='1'", "webdb_create desc"));
}
catch (Throwable t) {
throw new MirLocalizerFailure(t.getMessage(), t);
}
- protected class ContentToTrashedCommentsField implements EntityAdapterDefinition.CalculatedField {
+ protected class ContentToCommentsField implements EntityAdapterDefinition.CalculatedField {
+ private String extraCondition;
+ private String order;
+
+
+ public ContentToCommentsField(String anExtraCondition, String anOrder) {
+ super();
+
+ order = anOrder;
+ extraCondition = anExtraCondition;
+ }
+
+ public ContentToCommentsField(String anExtraCondition) {
+ this(anExtraCondition, "webdb_create");
+ }
+
public Object getValue(EntityAdapter anEntityAdapter) {
try {
return anEntityAdapter.getRelation(
- "to_media="+anEntityAdapter.get("id")+" and is_published='0'",
- "webdb_create",
+ "to_media="+anEntityAdapter.get("id") + " " + extraCondition,
+ order,
"comment" );
}
catch (Throwable t) {
}
protected class ContentCommentCountField implements EntityAdapterDefinition.CalculatedField {
- public Object getValue(EntityAdapter anEntityAdapter) {
- try {
- return Integer.toString(
- DatabaseComment.getInstance().getSize(
- "to_media="+anEntityAdapter.get("id")+" and is_published='1'"));
- }
- catch (Throwable t) {
- throw new RuntimeException(t.getMessage());
- }
+ private String extraCondition;
+
+ public ContentCommentCountField(String anExtraCondition) {
+ super();
+
+ extraCondition = anExtraCondition;
}
- }
- protected class ContentTrashedCommentCountField implements EntityAdapterDefinition.CalculatedField {
public Object getValue(EntityAdapter anEntityAdapter) {
try {
return Integer.toString(
DatabaseComment.getInstance().getSize(
- "to_media="+anEntityAdapter.get("id")+" and is_published='0'"));
+ "to_media="+anEntityAdapter.get("id")+" " + extraCondition));
}
catch (Throwable t) {
throw new RuntimeException(t.getMessage());