public static Intervention getIntervention(int intervention_id) { Intervention intervention = null; // return only intervention of a user for (Intervention inter : listInterventions) { if (inter.getId() == intervention_id) { intervention = inter; break; } } return intervention; }
public static ArrayList<Intervention> getListInterventions(int user_id) { // if current user is admin, load all interventions else load only user's interventions if (User.getUser_by_id(user_id).getIsAdmin()) return listInterventions; else { // return only intervention of a user ArrayList myArrayList = new ArrayList(); for (Intervention inter : listInterventions) { if (inter.getUser_id() == user_id) { myArrayList.add(inter); } } return myArrayList; } }
public static ArrayList<Intervention> parseInterventionsFromJsonString(String jsonString) throws Exception { String DEBUG_TAG = "AEMMS-parseInterventionsFromJsonString"; listInterventions = new ArrayList<Intervention>(); try { JSONArray interventions = new JSONArray(jsonString); for (int i = 0; i < interventions.length(); i++) { String id = interventions.getJSONObject(i).getString("id"); String chantier_id = interventions.getJSONObject(i).getString("chantier_id"); String user_id = interventions.getJSONObject(i).getString("user_id"); String contact_nom = interventions.getJSONObject(i).getString("contact_nom"); String contact_tel = interventions.getJSONObject(i).getString("contact_tel"); String date_inter = interventions.getJSONObject(i).getString("date"); String horaires = interventions.getJSONObject(i).getString("horaires"); String kits = interventions.getJSONObject(i).getString("kits"); String kits_qte = interventions.getJSONObject(i).getString("kits_qte"); String kitsfournis = interventions.getJSONObject(i).getString("kitsfournis"); String nbr_jour = interventions.getJSONObject(i).getString("nbr_jour"); String nbr_meulages = interventions.getJSONObject(i).getString("nbr_meulage"); String nbr_nuit = interventions.getJSONObject(i).getString("nbr_nuit"); String nbr_soudure = interventions.getJSONObject(i).getString("nbr_soudure"); String obs = interventions.getJSONObject(i).getString("obs"); String periode = interventions.getJSONObject(i).getString("periode"); String semaine = interventions.getJSONObject(i).getString("semaine"); // convert english date format to french date format SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date date_english = format.parse(date_inter); DateFormat format_french = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()); String formattedDate = format_french.format(date_english); Intervention intervention = new Intervention( Integer.parseInt(id), Integer.parseInt(chantier_id), Integer.parseInt(user_id), contact_nom, contact_tel, formattedDate, horaires, kits, kits_qte, kitsfournis, nbr_jour, nbr_meulages, nbr_nuit, nbr_soudure, obs, periode, semaine); listInterventions.add(intervention); Log.v(DEBUG_TAG, intervention.to_s()); } return listInterventions; } catch (Exception e) { Log.v(DEBUG_TAG, e.getMessage().toString()); return null; } }