blob: 73f2f6b573203171ab7d6126e25a99cf8efad16c (
plain)
- // SPDX-FileCopyrightText: <Alexander Marthin Klemensen stud-marthin@ruc.dk>
- // SPDX-FileCopyrightText: <Ian Valentin Christensen stud-ianc@ruc.dk>
- // SPDX-FileCopyrightText: <Zahed Noos zahed@ruc.dk>
- // SPDX-License-Identifier: GPL-3.0-or-later
- package com.example.portfolio2;
- import java.util.ArrayList;
- class Model{ // The model handles all interactions with the database
- MyDB db=new MyDB();
- Model(){}
- void initialize() { // When running the program, it clears the participation database
- clearParticipation();
- }
- int getActivityIndeks(String name) { // Returns the integer value of the activity's index
- if(name ==null) return -1;
- ArrayList<String> result = db.query("select indeks from activity a where name is '"+name+"';", "indeks");
- return Integer.parseInt(result.getFirst());
- }
- void addParticipation(int activityIndex) { // Inserts the given activity into participation using the activity's index
- db.cmd("insert into participation values(123, "+activityIndex+");");
- }
- ArrayList<String> getParticipation(String program) { // Returns all activity names from activities currently in participation
- return db.query("select name from participation p inner join activity a on p.indeks = a.indeks where program is '" + program + "';", "name");
- }
- void clearParticipation() { // Removes all entries in the participation database
- db.cmd("delete from participation");
- }
- ArrayList<String> selectProgram(String program) { // Returns an arraylist of activities within the given program
- return db.query("select name from activity where program is '" + program + "';", "name");
- }
- String getSumEcts(String program){ // Returns the sum of ECTS points under the given category from the student as a string
- if(program==null)return "0";
- ArrayList<String> result = db.query("select sum(activity.ects) as total_ects,student.name from student left outer join participation on student.studid = participation.studid inner join activity on participation.indeks = activity.indeks where program is '"+program+"' group by student.studid ;", "total_ects");
- if (result.isEmpty()) return "0";
- return result.getFirst();
- }
- ArrayList<String> getAllActivities() {
- return db.query("select name from activity;", "name");
- }
- }
|