blob: bafa3fc56ac0df77b7781ae7ac9c30b41b7f3313 (
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;
- // The model handles all interactions with the database
- class Model{
- MyDB db=new MyDB();
- Model(){}
- // When running the program, it clears the participation database
- void initialize() {
- clearParticipation();
- }
- // Returns the integer value of the activity's index
- int getActivityIndeks(String name) {
- 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());
- }
- // Inserts the given activity into participation using the activity's index
- void addParticipation(int activityIndex) {
- db.cmd("insert into participation values(123, "+activityIndex+");");
- }
- // Returns all activity names from activities currently in participation
- ArrayList<String> getParticipation(String program) {
- return db.query("select name from participation p inner join activity a on p.indeks = a.indeks where program is '" + program + "';", "name");
- }
- // Removes all entries in the participation database
- void clearParticipation() {
- db.cmd("delete from participation");
- }
- // Returns an arraylist of activities within the given program
- ArrayList<String> selectProgram(String program) {
- return db.query("select name from activity where program is '" + program + "';", "name");
- }
- // Returns the sum of ECTS points under the given category from the student as a string
- String getSumEcts(String program){
- 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");
- }
- }
|