1 package com.dotmarketing.viewtools; 2 3 import java.text.SimpleDateFormat ; 4 import java.util.ArrayList ; 5 import java.util.Collections ; 6 import java.util.Date ; 7 import java.util.GregorianCalendar ; 8 import java.util.HashMap ; 9 import java.util.Iterator ; 10 import java.util.List ; 11 import java.util.Map ; 12 13 import javax.servlet.http.HttpServletRequest ; 14 import javax.servlet.http.HttpServletResponse ; 15 16 import org.apache.velocity.tools.view.context.ViewContext; 17 import org.apache.velocity.tools.view.tools.ViewTool; 18 19 import com.dotmarketing.beans.Identifier; 20 import com.dotmarketing.beans.UserProxy; 21 import com.dotmarketing.db.DbConnectionFactory; 22 import com.dotmarketing.factories.IdentifierFactory; 23 import com.dotmarketing.factories.InodeFactory; 24 import com.dotmarketing.factories.UserProxyFactory; 25 import com.dotmarketing.portlets.files.model.File; 26 import com.dotmarketing.portlets.links.model.Link; 27 import com.dotmarketing.util.Config; 28 import com.dotmarketing.portlets.event_registrations.factories.WebEventRegistrationFactory; 29 import com.dotmarketing.portlets.event_registrations.model.WebEventAttendee; 30 import com.dotmarketing.portlets.event_registrations.model.WebEventRegistration; 31 import com.dotmarketing.portlets.webevents.factories.WebEventFactory; 32 import com.dotmarketing.portlets.webevents.factories.WebEventLocationFactory; 33 import com.dotmarketing.portlets.webevents.model.WebEvent; 34 import com.dotmarketing.portlets.webevents.model.WebEventLocation; 35 import com.dotmarketing.portlets.organization.model.Organization; 36 import com.dotmarketing.util.UtilMethods; 37 38 public class WebEventsWebAPI implements ViewTool { 39 private static final java.text.SimpleDateFormat DATE_TO_PRETTY_HTML_DATE_2 = new java.text.SimpleDateFormat ( 40 "MMMM d, yyyy"); 41 private HttpServletRequest request; 42 43 public void init(Object obj) { 44 ViewContext context = (ViewContext) obj; 45 this.request = context.getRequest(); 46 47 } 48 49 public void init(HttpServletRequest req, HttpServletResponse response) { 50 this.request = req; 51 52 } 53 54 public WebEvent getWebEvent(String inode) { 55 return (WebEvent) InodeFactory.getInodeOfClassByCondition(WebEvent.class, "inode = " + inode + " and show_on_web = " + DbConnectionFactory.getDBTrue()); 56 } 57 58 public WebEventLocation getWebEventLocation(String inode) { 59 return (WebEventLocation) InodeFactory.getInode(inode, WebEventLocation.class); 60 } 61 62 public WebEvent getWebEvent(long inode) { 63 return (WebEvent) InodeFactory.getInodeOfClassByCondition(WebEvent.class, "inode = " + inode + " and show_on_web = " + DbConnectionFactory.getDBTrue()); 64 } 65 public List getWebEventFiles(WebEvent e) { 66 ArrayList <HashMap > files = new ArrayList <HashMap >(); 67 List identifiers = InodeFactory.getChildrenClass(e, Identifier.class); 68 Iterator it = identifiers.iterator(); 69 while (it.hasNext()) { 70 Identifier identifier = (Identifier)it.next(); 71 File file = (File) IdentifierFactory.getWorkingChildOfClass(identifier, File.class); 72 HashMap <String ,String > hm = new HashMap <String ,String >(); 73 hm.put("filepath", identifier.getURI()); 74 hm.put("filename", file.getTitle()); 75 files.add(hm); 76 } 77 return files; 78 } 79 80 public WebEventLocation getWebEventLocation(long inode) { 81 return (WebEventLocation) InodeFactory.getInode(inode, WebEventLocation.class); 82 } 83 84 public List getWebEventLocationsPerEvent(String eventInode) { 85 long inode = 0; 86 try { inode = Long.parseLong(eventInode); } catch (NumberFormatException e) { } 87 return WebEventLocationFactory.getWebEventLocationsPerEvent(inode, "start_date"); 88 } 89 90 public List getWebEventLocationsPerEvent(long eventInode) { 91 return WebEventLocationFactory.getWebEventLocationsPerEvent(eventInode, "start_date"); 92 } 93 94 public List getWebEventLocationsPerEvent(WebEvent event) { 95 return WebEventLocationFactory.getWebEventLocationsPerEvent(event.getInode(), "start_date"); 96 } 97 98 public List getUpcomingWebEventLocationsPerEvent(WebEvent event) { 99 List locations = WebEventLocationFactory.getUpcomingWebEventLocationsPerEvent(event.getInode(), "start_date"); 100 return locations.subList(0, locations.size() > 3?3:locations.size()); 101 } 102 103 public List getPastWebEventLocationsPerEvent(WebEvent event) { 104 List locations = WebEventLocationFactory.getPastWebEventLocationsPerEvent(event.getInode(), "start_date"); 105 return locations.subList(0, locations.size() > 3?3:locations.size()); 106 } 107 108 public List getUpcomingWebEvents () { 109 List events = WebEventFactory.getUpcomingPublicWebEvents(); 110 Collections.sort(events); 111 return events; 112 } 113 114 public List getUpcomingWebEvents (boolean institute) { 115 List events = WebEventFactory.getUpcomingPublicWebEvents(institute); 116 Collections.sort(events); 117 return events; 118 } 119 120 public List getPastWebEvents () { 121 return WebEventFactory.getPastWebEvents(); 122 } 123 124 public float getEventLocationPrice (WebEventLocation loc) { 125 126 if (request.getSession().getAttribute("isPartner") != null && request.getSession().getAttribute("isPartner").equals("true")){ 127 Organization organization = (Organization)request.getSession().getAttribute("userOrganization"); 128 if (organization != null){ 129 if (loc.isDefaultContractPartnerPrice()) 130 if (organization.getInstitute_price() > 0) 131 return organization.getInstitute_price(); 132 else 133 return loc.getPartnerPrice(); 134 else 135 return loc.getPartnerPrice(); 136 } 137 else{ 138 return loc.getNonPartnerPrice(); 139 } 140 } 141 else 142 return loc.getNonPartnerPrice(); 143 144 145 } 146 147 public boolean isEventLocationAlmostAtCapacity (WebEventLocation loc) { 148 return loc.isAlmostAtCapacity(); 149 } 150 151 public WebEventRegistration getRegistration (String registrationInode) { 152 return WebEventRegistrationFactory.getWebEventRegistration(registrationInode); 153 } 154 155 public List <WebEventAttendee> getRegistrationAttendees (WebEventRegistration reg) { 156 if (reg == null) 157 return new ArrayList <WebEventAttendee>(); 158 159 return WebEventRegistrationFactory.getEventAttendees(reg); 160 } 161 162 public String getHotelLinkURL (long linkInode) { 163 Identifier id = (Identifier) InodeFactory.getInode(linkInode, Identifier.class); 164 Link link = (Link) IdentifierFactory.getLiveChildOfClass(id, Link.class); 165 return link.getWorkingURL(); 166 } 167 168 public String getPastEventLinkURL (long linkInode) { 169 Identifier id = (Identifier) InodeFactory.getInode(linkInode, Identifier.class); 170 Link link = (Link) IdentifierFactory.getLiveChildOfClass(id, Link.class); 171 return link.getWorkingURL(); 172 } 173 174 public String getEventDateRange (Date date1, Date date2) { 175 return UtilMethods.getEventDateRange(date1, date2); 176 } 177 178 @SuppressWarnings ("unchecked") 179 public List <Map > getPaymentMethods (boolean institute) { 180 List <Map > paymentsList = new ArrayList <Map > (); 181 String [] paymentMethods; 182 if (institute) { 183 paymentMethods = Config.getStringArrayProperty("EREG_PAYMENT_TYPES"); 184 } 185 else { 186 paymentMethods = Config.getStringArrayProperty("EREG_WEBINAR_PAYMENT_TYPES"); 187 } 188 String partnerOnly = "EREG_PURCHASE_ORDER"; 189 190 for (String paymentMethod : paymentMethods) { 191 192 String value = Config.getStringProperty(paymentMethod); 193 String friendlyName = Config.getStringProperty(paymentMethod + "_FN"); 194 Map paymentMethodMap = new HashMap (); 195 paymentMethodMap.put("value", value); 196 paymentMethodMap.put("friendlyName", friendlyName); 197 paymentMethodMap.put("name", paymentMethod); 198 199 if (paymentMethod.equals(partnerOnly)) { 200 if (request.getSession().getAttribute("isPartner") != null && request.getSession().getAttribute("isPartner").equals("true")){ 201 paymentsList.add(paymentMethodMap); 202 } 203 } 204 else { 205 paymentsList.add(paymentMethodMap); 206 } 207 } 208 return paymentsList; 209 } 210 211 public List <Map > getPaymentMethods () { 212 List <Map > paymentsList = new ArrayList <Map > (); 213 String [] paymentMethods = Config.getStringArrayProperty("EREG_PAYMENT_TYPES"); 214 for (String paymentMethod : paymentMethods) { 215 String value = Config.getStringProperty(paymentMethod); 216 String friendlyName = Config.getStringProperty(paymentMethod + "_FN"); 217 Map paymentMethodMap = new HashMap (); 218 paymentMethodMap.put("value", value); 219 paymentMethodMap.put("friendlyName", friendlyName); 220 paymentMethodMap.put("name", paymentMethod); 221 paymentsList.add(paymentMethodMap); 222 } 223 return paymentsList; 224 } 225 226 public List <String > getCreditCardTypes () { 227 String [] cardTypes = Config.getStringArrayProperty("EREG_CREDIT_CARD_TYPES"); 228 ArrayList <String > retList = new ArrayList <String >(); 229 for (String type : cardTypes) { 230 retList.add(type); 231 } 232 return retList; 233 } 234 235 @SuppressWarnings ("unchecked") 236 public List <WebEventRegistration> getWebEventRegistrationByUser(String userId){ 237 if (userId == null) 238 return new ArrayList <WebEventRegistration>(); 239 String inode = String.valueOf(UserProxyFactory.getUserProxy(userId).getInode()); 240 return WebEventRegistrationFactory.getWebEventRegistrationsByUser(inode,"date_posted desc"); 241 } 242 243 @SuppressWarnings ("unchecked") 244 public List <WebEventRegistration> getWebEventRegistrationByUserInode(String inode){ 245 if (inode == null) 246 return new ArrayList <WebEventRegistration>(); 247 248 249 return WebEventRegistrationFactory.getWebEventRegistrationsByUser(inode); 250 } 251 252 public java.util.HashMap getRegistrationStatus() { 253 254 String [] statusesArray = com.dotmarketing.util.Config.getStringArrayProperty("EREG_STATUSES"); 256 java.util.HashMap <String , String > statuses = new java.util.HashMap <String , String >(); 257 for (int i=0;i<statusesArray.length;i++) { 258 String status = statusesArray[i]; 259 statuses.put(com.dotmarketing.util.Config.getStringProperty(status),com.dotmarketing.util.Config.getStringProperty(status + "_FN")); 260 } 261 return statuses; 262 263 } 264 265 public String valueOfStatus(Object value){ 266 267 return String.valueOf(value); 268 } 269 public String dateToPrettyHTMLDate(java.util.Date x) { 270 if (x == null) { 271 return ""; 272 } 273 274 return DATE_TO_PRETTY_HTML_DATE_2.format(x); 275 } 276 277 278 public String getContactOrganizationTitle(WebEventRegistration registration){ 279 String title = ""; 280 Organization organization; 281 if (registration != null){ 282 UserProxy userProxy = UserProxyFactory.getUserProxy(registration.getUserInode()); 283 if (userProxy.getInode() > 0){ 284 organization = (Organization) InodeFactory.getParentOfClass(userProxy, Organization.class); 285 if (organization.getInode() > 0){ 286 title = organization.getTitle()!=null?organization.getTitle():""; 287 } 288 } 289 } 290 return title; 291 } 292 } | Popular Tags |