1 package com.dotmarketing.portlets.communications.factories; 2 3 import java.util.List ; 4 5 import com.dotmarketing.db.DotHibernate; 6 import com.dotmarketing.factories.InodeFactory; 7 import com.dotmarketing.portlets.communications.model.Communication; 8 import com.dotmarketing.util.UtilMethods; 9 import com.liferay.portal.model.User; 10 11 16 public class CommunicationsFactory { 17 18 public static List getCommunicationsByUser(User u) { 19 return getCommunicationsByUser(u, "",""); 20 } 21 22 public static List <Communication> getCommunicationsByUser(User u, String condition, String orderby) { 23 DotHibernate dh = new DotHibernate(Communication.class); 24 25 if(!UtilMethods.isSet(orderby)){ 26 orderby = "mod_date desc"; 27 } 28 29 String conditionQuery = ""; 30 if(UtilMethods.isSet(condition)){ 31 conditionQuery = " and "+condition; 32 } 33 dh.setQuery( 34 "from inode in class com.dotmarketing.portlets.communications.model.Communication where modified_by = ? "+conditionQuery+" order by "+ orderby); 35 dh.setParam(u.getUserId()); 36 37 return dh.list(); 38 39 } 40 41 public static List <Communication> getCommunications() { 42 return getCommunications("",""); 43 } 44 45 public static List <Communication> getCommunications(String condition, String orderby) { 46 DotHibernate dh = new DotHibernate(Communication.class); 47 if(!UtilMethods.isSet(orderby)){ 48 orderby = "mod_date desc"; 49 } 50 51 String conditionQuery = ""; 52 if(UtilMethods.isSet(condition)){ 53 conditionQuery = " where "+condition; 54 } 55 56 dh.setQuery("from inode in class com.dotmarketing.portlets.communications.model.Communication "+conditionQuery+" order by "+orderby); 57 58 return dh.list(); 59 } 60 61 public static Communication getCommunication(String inode, String userId) { 62 return getCommunication(inode,userId, ""); 63 } 64 65 public static Communication getCommunication(String inode, String userId, String orderby) { 66 DotHibernate dh = new DotHibernate(Communication.class); 67 if(!UtilMethods.isSet(orderby)){ 68 orderby = "mod_date"; 69 } 70 dh.setQuery( 71 "from inode in class com.dotmarketing.portlets.communications.model.Communication where inode = ? and modified_by = ? order by "+orderby); 72 dh.setParam(inode); 73 dh.setParam(userId); 74 75 return (Communication) dh.load(); 76 } 77 78 public static Communication getCommunication(String inode) { 79 DotHibernate dh = new DotHibernate(Communication.class); 80 dh.setQuery( 81 "from inode in class com.dotmarketing.portlets.communications.model.Communication where inode = ?"); 82 dh.setParam(inode); 83 84 return (Communication) dh.load(); 85 } 86 87 public static Communication newInstance() { 88 Communication c = new Communication(); 89 c.setType("communication"); 90 c.setModDate(new java.util.Date ()); 91 return c; 92 } 93 94 97 public static void deleteCommunication(Communication c, String userId) { 98 if ((userId == null) || (c.getModifiedBy() == null)) { 99 return; 100 } 101 102 InodeFactory.deleteInode(c); 103 104 } 105 106 107 } 108 | Popular Tags |