1 package com.dotmarketing.portlets.webevents.factories; 2 3 import java.util.ArrayList ; 4 import java.util.Date ; 5 import java.util.GregorianCalendar ; 6 import java.util.HashSet ; 7 8 import com.dotmarketing.db.DbConnectionFactory; 9 import com.dotmarketing.db.DotHibernate; 10 import com.dotmarketing.factories.InodeFactory; 11 import com.dotmarketing.util.Config; 12 import com.dotmarketing.portlets.webevents.model.WebEvent; 13 17 public class WebEventFactory { 18 19 public static java.util.List getAllWebEvents() { 20 DotHibernate dh = new DotHibernate(WebEvent.class); 21 dh.setQuery( 22 "from inode in class com.dotmarketing.portlets.webevents.model.WebEvent order by sort_order"); 23 return dh.list(); 24 } 25 public static java.util.List getUpcomingPublicWebEvents() { 26 DotHibernate dh = new DotHibernate(WebEvent.class); 27 dh.setSQLQuery("select {web_event.*} from web_event as web_event, inode as web_event_1_, web_event_location as web_event_location where web_event_1_.inode = web_event.inode and web_event.inode = web_event_location.web_event_inode and web_event_location.start_date >= ? and web_event.show_on_web = " + DbConnectionFactory.getDBTrue() + " order by web_event.sort_order"); 28 GregorianCalendar cal = new GregorianCalendar (); 29 cal.setTime(new Date ()); 30 cal.set(GregorianCalendar.HOUR_OF_DAY, 0); 31 cal.set(GregorianCalendar.MINUTE, 0); 32 cal.set(GregorianCalendar.SECOND, 0); 33 dh.setDate(cal.getTime()); 34 return new ArrayList (new HashSet (dh.list())); 35 } 36 public static java.util.List getUpcomingPublicWebEvents(boolean institute) { 37 DotHibernate dh = new DotHibernate(WebEvent.class); 38 String condition = ""; 39 if (institute) { 40 condition = " and web_event.is_institute = " + DbConnectionFactory.getDBTrue(); 41 } 42 else { 43 condition = " and web_event.is_institute = " + DbConnectionFactory.getDBFalse(); 44 } 45 String query = "select {web_event.*} from web_event as web_event, inode as web_event_1_, web_event_location as web_event_location where web_event_1_.inode = web_event.inode and web_event.inode = web_event_location.web_event_inode and web_event_location.start_date >= ? and web_event.show_on_web = " + DbConnectionFactory.getDBTrue() + condition + " order by web_event.sort_order"; 46 dh.setSQLQuery(query); 47 GregorianCalendar cal = new GregorianCalendar (); 48 cal.setTime(new Date ()); 49 cal.set(GregorianCalendar.HOUR_OF_DAY, 0); 50 cal.set(GregorianCalendar.MINUTE, 0); 51 cal.set(GregorianCalendar.SECOND, 0); 52 dh.setDate(cal.getTime()); 53 return new ArrayList (new HashSet (dh.list())); 54 } 55 56 57 public static java.util.List getUpcomingWebEvents() { 58 DotHibernate dh = new DotHibernate(WebEvent.class); 59 dh.setSQLQuery("select {web_event.*} from web_event as web_event, inode as web_event_1_, web_event_location as web_event_location where web_event_1_.inode = web_event.inode and web_event.inode = web_event_location.web_event_inode and web_event_location.start_date >= ? order by web_event.sort_order"); 60 GregorianCalendar cal = new GregorianCalendar (); 61 cal.setTime(new Date ()); 62 cal.set(GregorianCalendar.HOUR_OF_DAY, 0); 63 cal.set(GregorianCalendar.MINUTE, 0); 64 cal.set(GregorianCalendar.SECOND, 0); 65 dh.setDate(cal.getTime()); 66 return new ArrayList (new HashSet (dh.list())); 67 } 68 public static java.util.List getEventsWithNoLocations() { 69 DotHibernate dh = new DotHibernate(WebEvent.class); 70 dh.setSQLQuery("select {web_event.*} from web_event as web_event left join web_event_location as web_event_location on web_event.inode = web_event_location.web_event_inode, inode as web_event_1_ where web_event_1_.inode = web_event.inode and web_event_location.web_event_inode is null"); 71 return dh.list(); 72 } 73 public static java.util.List getEventsWithNoLocationsByKeywords(String keywords) { 74 DotHibernate dh = new DotHibernate(WebEvent.class); 75 dh.setSQLQuery("select {web_event.*} from web_event as web_event left join web_event_location as web_event_location on web_event.inode = web_event_location.web_event_inode, inode as web_event_1_ where web_event_1_.inode = web_event.inode and web_event_location.web_event_inode is null and web_event.title like '%" + keywords + "%' "); 76 return dh.list(); 77 } 78 public static java.util.List getPastWebEvents() { 79 DotHibernate dh = new DotHibernate(WebEvent.class); 80 dh.setSQLQuery("select {web_event.*} from web_event as web_event, inode as web_event_1_, web_event_location as web_event_location where web_event_1_.inode = web_event.inode and web_event.inode = web_event_location.web_event_inode and web_event_location.start_date < ? order by web_event.sort_order"); 81 GregorianCalendar cal = new GregorianCalendar (); 82 cal.setTime(new Date ()); 83 cal.set(GregorianCalendar.HOUR_OF_DAY, 23); 84 cal.set(GregorianCalendar.MINUTE, 59); 85 cal.set(GregorianCalendar.SECOND, 59); 86 dh.setParam(cal.getTime()); 87 return new ArrayList (new HashSet (dh.list())); 88 } 89 public static java.util.List getAllWebEventsByKeywords(String keywords) { 90 DotHibernate dh = new DotHibernate(WebEvent.class); 91 dh.setQuery( 92 "from inode in class com.dotmarketing.portlets.webevents.model.WebEvent where title like '%" + keywords + "%' order by sort_order"); 93 return dh.list(); 94 } 95 public static java.util.List getUpcomingWebEventsByKeywords(String keywords) { 96 DotHibernate dh = new DotHibernate(WebEvent.class); 97 dh.setSQLQuery("select {web_event.*} from web_event as web_event, inode as web_event_1_, web_event_location as web_event_location where web_event_1_.inode = web_event.inode and web_event.inode = web_event_location.web_event_inode and web_event.title like '%" + keywords + "%' and web_event_location.start_date >= ? order by web_event.sort_order"); 98 dh.setParam(new Date ()); 99 return dh.list(); 100 } 101 public static java.util.List getAllWebEvents(String orderby) { 102 DotHibernate dh = new DotHibernate(WebEvent.class); 103 dh.setQuery( 104 "from inode in class com.dotmarketing.portlets.webevents.model.WebEvent order by " + orderby); 105 return dh.list(); 106 } 107 108 public static java.util.List getEventLocations(WebEvent event, String orderby) { 109 return WebEventLocationFactory.getWebEventLocationsPerEvent(event.getInode(),orderby); 110 } 111 public static java.util.List getUpcomingEventLocations(WebEvent event, String orderby) { 112 return WebEventLocationFactory.getUpcomingWebEventLocationsPerEvent(event.getInode(),orderby); 113 } 114 115 public static WebEvent getWebEvent(long inode) { 116 return (WebEvent) InodeFactory.getInode(inode, WebEvent.class); 117 } 118 119 public static WebEvent getWebEvent(String inode) { 120 return (WebEvent) InodeFactory.getInode(inode, WebEvent.class); 121 } 122 123 public static WebEvent newInstance() { 124 WebEvent m = new WebEvent(); 125 return m; 126 } 127 128 public static void saveWebEvent(WebEvent webEvent) { 129 InodeFactory.saveInode(webEvent); 130 } 131 132 public static void deleteWebEvent(WebEvent webEvent) { 133 InodeFactory.deleteInode(webEvent); 134 } 135 136 } 137 | Popular Tags |