diff --git a/OSKA.php b/OSKA.php index 1281e2820482302680042c4f5431ddea5e924568..a8f63d9b8d2060147d7527c06575bed24d915061 100644 --- a/OSKA.php +++ b/OSKA.php @@ -121,15 +121,16 @@ class OSKA extends StudIPPlugin implements StandardPlugin, PortalPlugin // Show widget only to first semester Bachelor or Master students $show_info = false; $studycourses = new SimpleCollection(UserStudyCourse::findByUser($GLOBALS['user']->id)); + $degree_ids = array_merge(OskaMatches::getBachelorIds(), OskaMatches::getMasterIds()); + $mentee_degree_ids = []; // go through all subjects of the user and check if user is first semester and Bachelor/Master student - $bachelor_degrees = ['08','12', '14', '61', '62', '65', '91']; - $master_degrees = ['10', '13', '17', '18', '19', '20', '46', '60', '63', '64', '66', '67', '68', '69', '70', '71', '72', '73', '74', '81', '82', '83', '84', '85']; foreach ($studycourses as $studycourse) { if ($studycourse->semester > 1 || - in_array($studycourse->abschluss_id, array_merge($bachelor_degrees, $master_degrees)) === false) { + in_array($studycourse->abschluss_id, $degree_ids) === false) { $show_info = true; } + $mentee_degree_ids[] = $studycourse->abschluss_id; } // show info if user has no subject @@ -148,7 +149,7 @@ class OSKA extends StudIPPlugin implements StandardPlugin, PortalPlugin // show form if button was clicked $template = $template_factory->open('widget_form'); $template->studycourses = $studycourses; - $template->isBachelor = in_array($studycourse->abschluss_id, $bachelor_degrees); + $template->isBachelor = (count(array_intersect($mentee_degree_ids, OskaMatches::getBachelorIds())) >= 1); } else { // show oska info for first semester students otherwise $template = $template_factory->open('widget_index'); diff --git a/controllers/admin.php b/controllers/admin.php index 06f6bc115193facc7bdcea8c65e97cb7112330ec..8f8f1a0108f8e600395f341807b742a84a81085e 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -556,81 +556,52 @@ class AdminController extends PluginController { $this->redirect('admin'); } - public function delete_mentee_action($mentee_id, $confirm = false) + public function delete_mentee_action($mentee_id) { - if ($confirm) { - $mentor = OskaMatches::getMentor($mentee_id); - - if ($mentor) { - $mentor->lowerCounter(); - $mentor->store(); - $match = OskaMatches::find([$mentor->user_id, $mentee_id]); - $match->delete(); - } + $mentor = OskaMatches::getMentor($mentee_id); - $mentee = OskaMentees::find($mentee_id); - $mentee->delete(); - } else { - PageLayout::postQuestion( - sprintf( - _('Mentee wirklich austragen?') - ) - )->setAcceptURL( - $this->url_for("admin/delete_mentee/{$mentee_id}/true") - ); + if ($mentor) { + $mentor->lowerCounter(); + $mentor->store(); + $match = OskaMatches::find([$mentor->user_id, $mentee_id]); + $match->delete(); } + $mentee = OskaMentees::find($mentee_id); + $mentee->delete(); + $this->redirect('admin/mentees'); } - public function delete_mentor_action($mentor_id, $confirm = false) + public function delete_mentor_action($mentor_id) { - if ($confirm) { - $mentees = OskaMatches::getMentees($mentor_id); - - foreach ($mentees as $mentee) { - $match = OskaMatches::find([$mentor_id, $mentee['user_id']]); - $match->delete(); - $mentee = OskaMentees::find($mentee['user_id']); - $mentee->has_tutor = false; - $mentee->store(); - } + $mentees = OskaMatches::getMentees($mentor_id); - $mentor = OskaMentors::find($mentor_id); - $mentor->delete(); - } else { - PageLayout::postQuestion( - sprintf( - _('Mentor wirklich austragen?') - ) - )->setAcceptURL( - $this->url_for("admin/delete_mentor/{$mentor_id}/true") - ); + foreach ($mentees as $mentee) { + $match = OskaMatches::find([$mentor_id, $mentee['user_id']]); + $match->delete(); + $mentee = OskaMentees::find($mentee['user_id']); + $mentee->has_tutor = false; + $mentee->store(); } + $mentor = OskaMentors::find($mentor_id); + $mentor->delete(); + $this->redirect('admin/mentors'); } - public function delete_match_action($mentee_id, $mentor_id, $confirm = false) + public function delete_match_action($mentee_id, $mentor_id) { - if ($confirm) { - $mentee = OskaMentees::find($mentee_id); - $mentee->has_tutor = false; - $mentee->store(); + $mentee = OskaMentees::find($mentee_id); + $mentee->has_tutor = false; + $mentee->store(); - $mentor = OskaMentors::find($mentor_id); - $mentor->lowerCounter(); - $mentor->store(); + $mentor = OskaMentors::find($mentor_id); + $mentor->lowerCounter(); + $mentor->store(); + + $match = OskaMatches::find([$mentor_id, $mentee_id]); + $match->delete(); - $match = OskaMatches::find([$mentor_id, $mentee_id]); - $match->delete(); - } else { - PageLayout::postQuestion( - sprintf( - _('Wollen Sie das Match wirklich löschen?') - ) - )->setAcceptURL( - $this->url_for("admin/delete_match/{$mentee_id}/{$mentor_id}/true") - ); - } $this->redirect('admin/matches'); } @@ -642,15 +613,17 @@ class AdminController extends PluginController { $role_table = 'oska_mentees'; } + $degree_ids = array_merge(OskaMatches::getBachelorIds(), OskaMatches::getMasterIds()); + $sql = "SELECT DISTINCT fach.fach_id, fach.name FROM $role_table JOIN user_studiengang " . "on $role_table.user_id = user_studiengang.user_id JOIN fach " . "on user_studiengang.fach_id = fach.fach_id join abschluss " . "on user_studiengang.abschluss_id = abschluss.abschluss_id " . - "WHERE abschluss.abschluss_id IN ('08','12','14','61','62','65','91','10','13','17','18','19','20','46','60','63','64','66','67','68','69','70','71','72','73','74','81','82','83','84','85')" . + "WHERE abschluss.abschluss_id IN (?)" . "ORDER BY fach.name ASC"; $statement = DBManager::get()->prepare($sql); - $statement->execute($parameters); + $statement->execute([$degree_ids]); $subjects = $statement->fetchAll(); return $subjects; diff --git a/models/OskaMatches.php b/models/OskaMatches.php index 6230a438b2917825080ca69619d5254ae0e2c874..caa897bb46b3bf2c700f3cb17574a2de7f78d577 100755 --- a/models/OskaMatches.php +++ b/models/OskaMatches.php @@ -118,4 +118,44 @@ class OskaMatches extends SimpleORMap return $matches; } + + public function getBachelorIds() + { + $sql = " + SELECT + abschluss_id + FROM + mvv_abschl_zuord + WHERE + kategorie_id = '1'"; + $statement = DBManager::get()->prepare($sql); + $statement->execute(); + $results = $statement->fetchAll(); + + $bachelor_ids = []; + foreach($results as $result) { + array_push($bachelor_ids, $result['abschluss_id']); + } + return array_merge($bachelor_ids, ['08']); + } + + public function getMasterIds() + { + $sql = " + SELECT + abschluss_id + FROM + mvv_abschl_zuord + WHERE + kategorie_id = '2'"; + $statement = DBManager::get()->prepare($sql); + $statement->execute(); + $results = $statement->fetchAll(); + + $master_ids = []; + foreach($results as $result) { + array_push($master_ids, $result['abschluss_id']); + } + return $master_ids; + } } diff --git a/models/OskaMentees.php b/models/OskaMentees.php index 3e925003be8e0fd540c92c14f8951a21ffd098f4..d26fdbcac7d9961341e2c58ca4de2856f2aff6bd 100755 --- a/models/OskaMentees.php +++ b/models/OskaMentees.php @@ -66,10 +66,10 @@ class OskaMentees extends SimpleORMap public function isMaster() { - $master_degrees = ['10', '13', '17', '18', '19', '20', '46', '60', '63', '64', '66', '67', '68', '69', '70', '71', '72', '73', '74', '81', '82', '83', '84', '85']; $studycourses = new SimpleCollection(UserStudyCourse::findByUser($this->user_id)); + $master_ids = OskaMatches::getMasterIds(); foreach ($studycourses as $studycourse) { - if (in_array($studycourse->abschluss_id, $master_degrees)) { + if (in_array($studycourse->abschluss_id, $master_ids)) { return true; } } diff --git a/models/OskaMentors.php b/models/OskaMentors.php index 46775320b928addf01af2d3e094aba65b3b260ec..30aaeecaeaa8ac810c30a57d34ae025d2bdcf33a 100755 --- a/models/OskaMentors.php +++ b/models/OskaMentors.php @@ -89,10 +89,10 @@ class OskaMentors extends SimpleORMap public function isMaster() { - $master_degrees = ['10', '13', '17', '18', '19', '20', '46', '60', '63', '64', '66', '67', '68', '69', '70', '71', '72', '73', '74', '81', '82', '83', '84', '85']; $studycourses = new SimpleCollection(UserStudyCourse::findByUser($this->user_id)); + $master_ids = OskaMatches::getMasterIds(); foreach ($studycourses as $studycourse) { - if (in_array($studycourse->abschluss_id, $master_degrees)) { + if (in_array($studycourse->abschluss_id, $master_ids)) { return true; } } diff --git a/plugin.manifest b/plugin.manifest index b9d5274ad01e0490a8c5a92bec799d795bf90edf..b299f63e5021f961e251ddf5b9ce6ef013f10630 100644 --- a/plugin.manifest +++ b/plugin.manifest @@ -1,7 +1,7 @@ pluginclassname=OSKA pluginname=OSKA origin=virtUOS -version=1.1.6 +version=1.1.7 studipMinVersion=4.0 studipMaxVersion=5.2.99 category=Kommunikation und Zusammenarbeit diff --git a/views/admin/matches.php b/views/admin/matches.php index c5e0123f65b29cf989a117fc3e1b789a00609907..313605de914f7f5ad08669cfea1680beed0008af 100644 --- a/views/admin/matches.php +++ b/views/admin/matches.php @@ -65,9 +65,8 @@ <? $actionMenu->addLink( $controller->url_for("admin/delete_match/{$match['mentee']->user_id}/{$match['mentor']->id}"), _('Match löschen'), - Icon::create('trash', 'clickable', [ - 'title' => _('Match löschen'), - ]) + Icon::create('trash', 'clickable'), + ['data-confirm' => _('Wollen Sie das Match wirklich löschen?')] ) ?> <?= $actionMenu->render() ?> </td> diff --git a/views/admin/mentees.php b/views/admin/mentees.php index 313c4a3f8f9254070e897bd20a5c439c04dab1da..f828dfdc6bc1addef2f268860c2c3ca5b77f1901 100644 --- a/views/admin/mentees.php +++ b/views/admin/mentees.php @@ -80,9 +80,8 @@ <? $actionMenu->addLink( $controller->url_for('admin/delete_mentee/' . $mentee['user']->user_id), _('Mentee löschen'), - Icon::create('trash', 'clickable', [ - 'title' => _('Mentee löschen'), - ]) + Icon::create('trash', 'clickable'), + ['data-confirm' => _('Mentee wirklich austragen?')] ) ?> <?= $actionMenu->render() ?> </td> diff --git a/views/admin/mentors.php b/views/admin/mentors.php index 96ebb679c259ab22a437997e422c9163d740bed9..4b0ca1df1f3bf63a2aa4e4f9e26dfdd6ddde9a0c 100644 --- a/views/admin/mentors.php +++ b/views/admin/mentors.php @@ -84,9 +84,8 @@ <? $actionMenu->addLink( $controller->url_for('admin/delete_mentor/' . $mentor['user']->id), _('Mentor löschen'), - Icon::create('trash', 'clickable', [ - 'title' => _('Mentor löschen'), - ]) + Icon::create('trash', 'clickable'), + ['data-confirm' => _('Mentor wirklich austragen?')] ) ?> <?= $actionMenu->render() ?> </td>