From: idfx Date: Wed, 12 Sep 2001 14:20:44 +0000 (+0000) Subject: commentadmin better X-Git-Tag: prexmlproducerconfig~493 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=8bcb7e6ff26839de2f11aab160181b561cf276c1;p=mir.git commentadmin better --- diff --git a/source/mir/entity/EntityRelation.java b/source/mir/entity/EntityRelation.java index 8f44ac32..161855db 100755 --- a/source/mir/entity/EntityRelation.java +++ b/source/mir/entity/EntityRelation.java @@ -6,123 +6,151 @@ import freemarker.template.*; public class EntityRelation { - public String fromId; - public String toId; - public StorageObject storage; - public int type; - - public final static int TO_ONE = 1; - public final static int TO_MANY = 2; - - - /** - * Kontruktor fuer EntityRelation - * @param fromId ist der Feldname in der ausgehenden Tabelle fuer die Relation - * @param toId ist der Feldname in der Zieltablle - * @param storage ist das StorageObject, ueber das der Zugriff auf die abhaengige - * Tabelle erfolgt. - * @param type ist der Typ der EntityRelation (TO_ONE oder TO_MANY) - */ - - public EntityRelation(String fromId, String toId, StorageObject storage, int type) { - this.fromId = fromId; - this.toId = toId; - this.storage = storage; - this.type = type; - } - - /** - * @return Liefert eine abhaengige Entity mit den verknuepften - * Entities, wenn es sich um eine TO_ONE Beziehung handelt, ansonsten - * null. - */ - - public Entity getOne(Entity entity) throws StorageObjectException { - if (type==TO_ONE) { - return storage.selectById(entity.getValue(fromId)); - } - else return null; - } - - /** - * @return Liefert ein freemarker.template.SimpleHash mit den verknuepften - * Entities, wenn es sich um eine TO_ONE Beziehung handelt, ansonsten - * null. - */ - - public SimpleHash getOneAsSimpleHash(Entity entity) throws StorageObjectException { - if (type==TO_ONE) { - Entity returnEntity = getOne(entity); - if (returnEntity!=null) return HTMLTemplateProcessor.makeSimpleHash(returnEntity); - } - return null; - } - - /** - * @return Liefert eine freemarker.template.SimpleList mit den verknuepften - * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten - * null. - */ - - public EntityList getMany(Entity entity) throws StorageObjectException{ - if (type==TO_MANY) { - return storage.selectByFieldValue(toId, entity.getValue(fromId)); - } - else return null; - } - - /** - * @return Liefert eine freemarker.template.SimpleList mit den verknuepften - * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten - * null. - */ - - public EntityList getMany(Entity entity, String order) throws StorageObjectException{ - if (type==TO_MANY) { - return storage.selectByWhereClause(toId+"="+entity.getValue(fromId), order,-1); - } - else return null; - } - - /** - * @return Liefert eine freemarker.template.SimpleList mit den verknuepften - * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten - * null. - */ - - public SimpleList getManyAsSimpleList(Entity entity) - throws StorageObjectException { - - if (type==TO_MANY) { - EntityList returnList = getMany(entity); - if (returnList!=null) return HTMLTemplateProcessor.makeSimpleList(returnList); - } - return null; - } - - /** - * @return Liefert eine freemarker.template.SimpleList mit den verknuepften - * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten - * null. - */ - - public SimpleList getManyAsSimpleList(Entity entity, String order) - throws StorageObjectException { - - if (type==TO_MANY) { - EntityList returnList = getMany(entity, order); - if (returnList!=null) return HTMLTemplateProcessor.makeSimpleList(returnList); - } - return null; - } - - /** - * @return Liefert den Referenznamen der abhaengigen Tabelle - */ - - public String getName() { - return "to" + storage.getTableName(); - } - - -} \ No newline at end of file + public String fromId; + public String toId; + public StorageObject storage; + public int type; + + public final static int TO_ONE = 1; + public final static int TO_MANY = 2; + + + /** + * Kontruktor fuer EntityRelation + * @param fromId ist der Feldname in der ausgehenden Tabelle fuer die Relation + * @param toId ist der Feldname in der Zieltablle + * @param storage ist das StorageObject, ueber das der Zugriff auf die abhaengige + * Tabelle erfolgt. + * @param type ist der Typ der EntityRelation (TO_ONE oder TO_MANY) + */ + + public EntityRelation(String fromId, String toId, StorageObject storage, int type) { + this.fromId = fromId; + this.toId = toId; + this.storage = storage; + this.type = type; + } + + /** + * @return Liefert eine abhaengige Entity mit den verknuepften + * Entities, wenn es sich um eine TO_ONE Beziehung handelt, ansonsten + * null. + */ + + public Entity getOne(Entity entity) throws StorageObjectException { + if (type==TO_ONE) { + return storage.selectById(entity.getValue(fromId)); + } + else return null; + } + + /** + * @return Liefert ein freemarker.template.SimpleHash mit den verknuepften + * Entities, wenn es sich um eine TO_ONE Beziehung handelt, ansonsten + * null. + */ + + public SimpleHash getOneAsSimpleHash(Entity entity) throws StorageObjectException { + if (type==TO_ONE) { + Entity returnEntity = getOne(entity); + if (returnEntity!=null) return HTMLTemplateProcessor.makeSimpleHash(returnEntity); + } + return null; + } + + /** + * @return Liefert eine freemarker.template.SimpleList mit den verknuepften + * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten + * null. + */ + + public EntityList getMany(Entity entity) throws StorageObjectException{ + if (type==TO_MANY) { + return storage.selectByFieldValue(toId, entity.getValue(fromId)); + } + else return null; + } + + /** + * @return Liefert eine freemarker.template.SimpleList mit den verknuepften + * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten + * null. + */ + + public EntityList getMany(Entity entity, String order) throws StorageObjectException{ + if (type==TO_MANY) { + return storage.selectByWhereClause(toId+"="+entity.getValue(fromId), order,-1); + } + else return null; + } + + /** + * @return Liefert eine freemarker.template.SimpleList mit den verknuepften + * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten + * null. + */ + + public EntityList getMany(Entity entity, String order, String whereClause) throws StorageObjectException{ + if (type==TO_MANY) { + return storage.selectByWhereClause(toId + "=" + entity.getValue(fromId) + " and " + whereClause, order,-1); + } + else return null; + } + + /** + * @return Liefert eine freemarker.template.SimpleList mit den verknuepften + * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten + * null. + */ + + public SimpleList getManyAsSimpleList(Entity entity) + throws StorageObjectException { + + if (type==TO_MANY) { + EntityList returnList = getMany(entity); + if (returnList!=null) return HTMLTemplateProcessor.makeSimpleList(returnList); + } + return null; + } + + /** + * @return Liefert eine freemarker.template.SimpleList mit den verknuepften + * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten + * null. + */ + + public SimpleList getManyAsSimpleList(Entity entity, String order) + throws StorageObjectException { + + if (type==TO_MANY) { + EntityList returnList = getMany(entity, order); + if (returnList!=null) return HTMLTemplateProcessor.makeSimpleList(returnList); + } + return null; + } + + /** + * @return Liefert eine freemarker.template.SimpleList mit den verknuepften + * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten + * null. + */ + + public SimpleList getManyAsSimpleList(Entity entity, String order, String whereClause) + throws StorageObjectException { + + if (type==TO_MANY) { + EntityList returnList = getMany(entity, order, whereClause); + if (returnList!=null) return HTMLTemplateProcessor.makeSimpleList(returnList); + } + return null; + } + /** + * @return Liefert den Referenznamen der abhaengigen Tabelle + */ + + public String getName() { + return "to" + storage.getTableName(); + } + + +} diff --git a/source/mircoders/module/ModuleComment.java b/source/mircoders/module/ModuleComment.java index 5b64cfc7..4ef659f7 100755 --- a/source/mircoders/module/ModuleComment.java +++ b/source/mircoders/module/ModuleComment.java @@ -26,18 +26,39 @@ import mircoders.storage.*; public class ModuleComment extends AbstractModule { - static Logfile theLog; - - // Contructor - public ModuleComment(StorageObject theStorage) - { - if (theLog == null) theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("Module.Comment.Logfile")); - if (theStorage == null) theLog.printWarning("StorageObject was null!"); - this.theStorage = theStorage; - } - - // Methoden - public SimpleList getCommentAsSimpleList() { - return ((DatabaseComment)theStorage).getPopupData(); - } + static Logfile theLog; + + // Contructor + public ModuleComment(StorageObject theStorage) + { + if (theLog == null) theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("Module.Comment.Logfile")); + if (theStorage == null) theLog.printWarning("StorageObject was null!"); + this.theStorage = theStorage; + } + + // Methoden + public SimpleList getCommentAsSimpleList() { + return ((DatabaseComment)theStorage).getPopupData(); + } + + /** + * setValues in the Entity and updates them on the StorageObject + */ + public String set(HashMap theValues) throws ModuleException + { + try { + Entity theEntity = theStorage.selectById((String)theValues.get("id")); + if (theEntity == null) + throw new ModuleException("No Objekt with id in Database id: " + theValues.get("id")); + theEntity.setValues(theValues); + theEntity.update(); + //set content to unproduced + DatabaseContent.getInstance().setUnproduced("id=" + theEntity.getValue("to_media")); + return theEntity.getId(); + } + catch (StorageObjectException e){ + e.printStackTrace(System.err); + throw new ModuleException(e.toString()); + } + } } diff --git a/source/mircoders/storage/DatabaseContent.java b/source/mircoders/storage/DatabaseContent.java index fd97ca24..72286ff9 100755 --- a/source/mircoders/storage/DatabaseContent.java +++ b/source/mircoders/storage/DatabaseContent.java @@ -21,87 +21,88 @@ import mircoders.entity.*; public class DatabaseContent extends Database implements StorageObject { - private static DatabaseContent instance; - private static EntityRelation relationComments; - private static EntityRelation relationFeature; - - // Contructors / Singleton - - public static DatabaseContent getInstance() - throws StorageObjectException { - - if (instance == null ) { - instance = new DatabaseContent(); - instance.myselfDatabase = instance; - } - return instance; - } - - private DatabaseContent() - throws StorageObjectException { - - super(); - this.theTable="content"; - this.theCoreTable="media"; - relationComments = new EntityRelation("id", "to_media", DatabaseComment.getInstance(), EntityRelation.TO_MANY); - relationFeature = new EntityRelation("id", "to_feature", DatabaseFeature.getInstance(), EntityRelation.TO_ONE); - try { this.theEntityClass = Class.forName("mircoders.entity.EntityContent"); } - catch (Exception e) { throw new StorageObjectException(e.toString()); } - } - - // methods - - /** - * sets the database flag is_produced to unproduced - */ - - public void setUnproduced(String where) - { - Connection con=null;Statement stmt=null; - String sql = "update content set is_produced=0 where " + where; - try { - con = getPooledCon(); - // should be a preparedStatement because is faster - stmt = con.createStatement(); - executeSql(stmt,sql); - } - catch (Exception e) {theLog.printDebugInfo("-- set unproduced failed");} - finally { freeConnection(con,stmt);} - } - - /** - * returns the comments that belong to the article (via entityrelation) - */ - public SimpleList getComments(EntityContent entC) { - SimpleList comments=null; - try { - comments = relationComments.getManyAsSimpleList(entC,"webdb_create"); - } - catch (StorageObjectException e) { - theLog.printError("DatabaseComments :: failed to get comments"); - } - return comments; - } - - /** - * returns the features that belong to the article (via entityrelation) - */ - public SimpleList getFeature(EntityContent entC) { - SimpleList feature=null; - try { - feature = relationFeature.getManyAsSimpleList(entC); - } - catch (StorageObjectException e) { - theLog.printError("DatabaseComments :: failed to get features"); - } - return feature; - } - - public boolean delete(String id) - throws StorageObjectException { - DatabaseComment.getInstance().deleteByContentId(id); - super.delete(id); - return true; - } + private static DatabaseContent instance; + private static EntityRelation relationComments; + private static EntityRelation relationFeature; + + // Contructors / Singleton + + public static DatabaseContent getInstance() + throws StorageObjectException { + + if (instance == null ) { + instance = new DatabaseContent(); + instance.myselfDatabase = instance; + } + return instance; + } + + private DatabaseContent() + throws StorageObjectException { + + super(); + this.theTable="content"; + this.theCoreTable="media"; + relationComments = new EntityRelation("id", "to_media", DatabaseComment.getInstance(), EntityRelation.TO_MANY); + relationFeature = new EntityRelation("id", "to_feature", DatabaseFeature.getInstance(), EntityRelation.TO_ONE); + try { this.theEntityClass = Class.forName("mircoders.entity.EntityContent"); } + catch (Exception e) { throw new StorageObjectException(e.toString()); } + } + + // methods + + /** + * sets the database flag is_produced to unproduced + */ + + public void setUnproduced(String where) + { + Connection con=null;Statement stmt=null; + String sql = "update content set is_produced='0' where " + where; + try { + con = getPooledCon(); + // should be a preparedStatement because is faster + stmt = con.createStatement(); + executeUpdate(stmt,sql); + } + catch (Exception e) {theLog.printDebugInfo("-- set unproduced failed");} + finally { freeConnection(con,stmt);} + } + + /** + * returns the comments that belong to the article (via entityrelation) + * where db-flag is_published is true + */ + public SimpleList getComments(EntityContent entC) { + SimpleList comments=null; + try { + comments = relationComments.getManyAsSimpleList(entC,"webdb_create","is_published='1'"); + } + catch (StorageObjectException e) { + theLog.printError("DatabaseComments :: failed to get comments"); + } + return comments; + } + + /** + * returns the features that belong to the article (via entityrelation) + */ + public SimpleList getFeature(EntityContent entC) { + SimpleList feature=null; + try { + feature = relationFeature.getManyAsSimpleList(entC); + } + catch (StorageObjectException e) { + theLog.printError("DatabaseComments :: failed to get features"); + } + return feature; + } + + public boolean delete(String id) + throws StorageObjectException { + DatabaseComment.getInstance().deleteByContentId(id); + super.delete(id); + return true; + } } diff --git a/templates-dist/de/commentlist.template b/templates-dist/de/commentlist.template index efe0bfef..4897e46b 100755 --- a/templates-dist/de/commentlist.template +++ b/templates-dist/de/commentlist.template @@ -9,9 +9,11 @@ -
+
+ + ${entry.description} - edit + edit diff --git a/templates-dist/en/commentlist.template b/templates-dist/en/commentlist.template index 2a65351b..6206f66a 100755 --- a/templates-dist/en/commentlist.template +++ b/templates-dist/en/commentlist.template @@ -12,7 +12,8 @@ - + + ${entry.description} - edit + edit