/** * Ensures that every field in the {@code Event} are immutable to avoid confusion later. * * @param event event to make immutable. */ private static void makeImmutable(Event event) { // Make the tags unmodifiable event.setTags(Collections.unmodifiableMap(event.getTags())); // Make the extra properties unmodifiable (everything in it is still mutable though) event.setExtra(Collections.unmodifiableMap(event.getExtra())); // Make the SentryInterfaces unmodifiable event.setSentryInterfaces(Collections.unmodifiableMap(event.getSentryInterfaces())); }
/* * get top 3 (today and tomorrow) events that most people are attending */ public ArrayList<Event> getDayHotEvent() { ArrayList<Event> list = new ArrayList<Event>(); String query = " SELECT a.att_evn_id, e.* , COUNT(att_evn_id) AS count "; query += " FROM tb_events e JOIN tb_attending a ON e.evn_id = a.att_evn_id "; query += " WHERE evn_start_time BETWEEN now() AND DATE_ADD(NOW(), INTERVAL 1 DAY) "; query += " GROUP BY a.att_evn_id "; query += " ORDER BY COUNT(att_evn_id) DESC LIMIT 3"; List<HashMap<String, String>> result = DBComunicationLayer.executeHttpPost(DBComunicationLayer.PHP_SELECT, query); Log.i(LOG_TAG, query); for (int i = 1; i < result.size(); i++) { Event e = new Event(); for (Map.Entry<String, String> item : result.get(i).entrySet()) { if (item.getKey().equalsIgnoreCase("evn_id")) { e.setId(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_titile")) { e.setTitle(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_description")) { e.setDescription(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_location")) { e.setLocation(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_start_time")) { e.setStartDayTime(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_end_time")) { e.setEndDayTime(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_created_time")) { e.setCreatedDayTime(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_contact_info")) { e.setContact(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_cat_id")) { e.setCategory(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_url")) { e.setUrl(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_count_like")) { e.setLike(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_count_dislike")) { e.setDislike(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_status")) { e.setStatus(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_tag")) { e.setTags(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_tag_id")) { e.setTagId(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("count")) { e.setCount(Integer.parseInt(item.getValue().trim())); } } list.add(e); } // eventList now holds all events return list; }
/* * get top 3 (today and tomorrow) events that most people are attending */ public ArrayList<Event> getEventById(String id) { ArrayList<Event> list = new ArrayList<Event>(); String query = " SELECT * FROM tb_events "; query += " WHERE env_id = '" + id + "'"; List<HashMap<String, String>> result = DBComunicationLayer.executeHttpPost(DBComunicationLayer.PHP_SELECT, query); Log.i(LOG_TAG, query); for (int i = 1; i < result.size(); i++) { Event e = new Event(); for (Map.Entry<String, String> item : result.get(i).entrySet()) { if (item.getKey().equalsIgnoreCase("evn_id")) { e.setId(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_titile")) { e.setTitle(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_description")) { e.setDescription(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_location")) { e.setLocation(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_start_time")) { e.setStartDayTime(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_end_time")) { e.setEndDayTime(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_created_time")) { e.setCreatedDayTime(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_contact_info")) { e.setContact(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_cat_id")) { e.setCategory(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_url")) { e.setUrl(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_count_like")) { e.setLike(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_count_dislike")) { e.setDislike(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_status")) { e.setStatus(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_tag")) { e.setTags(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_tag_id")) { e.setTagId(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("count")) { e.setCount(Integer.parseInt(item.getValue().trim())); } } list.add(e); } // eventList now holds all events return list; }
public boolean getAllEvents() { resetEventList(); String query = "SELECT * FROM tb_events"; List<HashMap<String, String>> result = DBComunicationLayer.executeHttpPost(DBComunicationLayer.PHP_SELECT, query); for (int i = 1; i < result.size(); i++) { Event e = new Event(); for (Map.Entry<String, String> item : result.get(i).entrySet()) { if (item.getKey().equalsIgnoreCase("evn_id")) { e.setId(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_titile")) { e.setTitle(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_description")) { e.setDescription(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_location")) { e.setLocation(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_start_time")) { e.setStartDayTime(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_end_time")) { e.setEndDayTime(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_created_time")) { e.setCreatedDayTime(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_contact_info")) { e.setContact(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_cat_id")) { e.setCategory(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_url")) { e.setUrl(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_count_like")) { e.setLike(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_count_dislike")) { e.setDislike(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_status")) { e.setStatus(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_tag")) { e.setTags(item.getValue().trim()); } else if (item.getKey().equalsIgnoreCase("evn_tag_id")) { e.setTagId(item.getValue().trim()); } } if (!eventList.contains(e)) eventList.add(e); } // return Integer.parseInt( result.get( 0 ).get( "result" ) ) == 1; return true; }