Skip to content
Snippets Groups Projects
Commit 3cbe2aae authored by Manuel Schwarz's avatar Manuel Schwarz :headphones: Committed by Elmar Ludwig
Browse files

Refactor and bugfixes

parent 6f70749f
No related branches found
No related tags found
1 merge request!1Refactor and bugfixes
...@@ -121,15 +121,16 @@ class OSKA extends StudIPPlugin implements StandardPlugin, PortalPlugin ...@@ -121,15 +121,16 @@ class OSKA extends StudIPPlugin implements StandardPlugin, PortalPlugin
// Show widget only to first semester Bachelor or Master students // Show widget only to first semester Bachelor or Master students
$show_info = false; $show_info = false;
$studycourses = new SimpleCollection(UserStudyCourse::findByUser($GLOBALS['user']->id)); $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 // 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) { foreach ($studycourses as $studycourse) {
if ($studycourse->semester > 1 || 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; $show_info = true;
} }
$mentee_degree_ids[] = $studycourse->abschluss_id;
} }
// show info if user has no subject // show info if user has no subject
...@@ -148,7 +149,7 @@ class OSKA extends StudIPPlugin implements StandardPlugin, PortalPlugin ...@@ -148,7 +149,7 @@ class OSKA extends StudIPPlugin implements StandardPlugin, PortalPlugin
// show form if button was clicked // show form if button was clicked
$template = $template_factory->open('widget_form'); $template = $template_factory->open('widget_form');
$template->studycourses = $studycourses; $template->studycourses = $studycourses;
$template->isBachelor = in_array($studycourse->abschluss_id, $bachelor_degrees); $template->isBachelor = (count(array_intersect($mentee_degree_ids, OskaMatches::getBachelorIds())) >= 1);
} else { } else {
// show oska info for first semester students otherwise // show oska info for first semester students otherwise
$template = $template_factory->open('widget_index'); $template = $template_factory->open('widget_index');
......
...@@ -556,9 +556,8 @@ class AdminController extends PluginController { ...@@ -556,9 +556,8 @@ class AdminController extends PluginController {
$this->redirect('admin'); $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); $mentor = OskaMatches::getMentor($mentee_id);
if ($mentor) { if ($mentor) {
...@@ -567,24 +566,14 @@ class AdminController extends PluginController { ...@@ -567,24 +566,14 @@ class AdminController extends PluginController {
$match = OskaMatches::find([$mentor->user_id, $mentee_id]); $match = OskaMatches::find([$mentor->user_id, $mentee_id]);
$match->delete(); $match->delete();
} }
$mentee = OskaMentees::find($mentee_id); $mentee = OskaMentees::find($mentee_id);
$mentee->delete(); $mentee->delete();
} else {
PageLayout::postQuestion(
sprintf(
_('Mentee wirklich austragen?')
)
)->setAcceptURL(
$this->url_for("admin/delete_mentee/{$mentee_id}/true")
);
}
$this->redirect('admin/mentees'); $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); $mentees = OskaMatches::getMentees($mentor_id);
foreach ($mentees as $mentee) { foreach ($mentees as $mentee) {
...@@ -594,24 +583,14 @@ class AdminController extends PluginController { ...@@ -594,24 +583,14 @@ class AdminController extends PluginController {
$mentee->has_tutor = false; $mentee->has_tutor = false;
$mentee->store(); $mentee->store();
} }
$mentor = OskaMentors::find($mentor_id); $mentor = OskaMentors::find($mentor_id);
$mentor->delete(); $mentor->delete();
} else {
PageLayout::postQuestion(
sprintf(
_('Mentor wirklich austragen?')
)
)->setAcceptURL(
$this->url_for("admin/delete_mentor/{$mentor_id}/true")
);
}
$this->redirect('admin/mentors'); $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 = OskaMentees::find($mentee_id);
$mentee->has_tutor = false; $mentee->has_tutor = false;
$mentee->store(); $mentee->store();
...@@ -622,15 +601,7 @@ class AdminController extends PluginController { ...@@ -622,15 +601,7 @@ class AdminController extends PluginController {
$match = OskaMatches::find([$mentor_id, $mentee_id]); $match = OskaMatches::find([$mentor_id, $mentee_id]);
$match->delete(); $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'); $this->redirect('admin/matches');
} }
...@@ -642,15 +613,17 @@ class AdminController extends PluginController { ...@@ -642,15 +613,17 @@ class AdminController extends PluginController {
$role_table = 'oska_mentees'; $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 " . $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 $role_table.user_id = user_studiengang.user_id JOIN fach " .
"on user_studiengang.fach_id = fach.fach_id join abschluss " . "on user_studiengang.fach_id = fach.fach_id join abschluss " .
"on user_studiengang.abschluss_id = abschluss.abschluss_id " . "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"; "ORDER BY fach.name ASC";
$statement = DBManager::get()->prepare($sql); $statement = DBManager::get()->prepare($sql);
$statement->execute($parameters); $statement->execute([$degree_ids]);
$subjects = $statement->fetchAll(); $subjects = $statement->fetchAll();
return $subjects; return $subjects;
......
...@@ -118,4 +118,44 @@ class OskaMatches extends SimpleORMap ...@@ -118,4 +118,44 @@ class OskaMatches extends SimpleORMap
return $matches; 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;
}
} }
...@@ -66,10 +66,10 @@ class OskaMentees extends SimpleORMap ...@@ -66,10 +66,10 @@ class OskaMentees extends SimpleORMap
public function isMaster() 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)); $studycourses = new SimpleCollection(UserStudyCourse::findByUser($this->user_id));
$master_ids = OskaMatches::getMasterIds();
foreach ($studycourses as $studycourse) { foreach ($studycourses as $studycourse) {
if (in_array($studycourse->abschluss_id, $master_degrees)) { if (in_array($studycourse->abschluss_id, $master_ids)) {
return true; return true;
} }
} }
......
...@@ -89,10 +89,10 @@ class OskaMentors extends SimpleORMap ...@@ -89,10 +89,10 @@ class OskaMentors extends SimpleORMap
public function isMaster() 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)); $studycourses = new SimpleCollection(UserStudyCourse::findByUser($this->user_id));
$master_ids = OskaMatches::getMasterIds();
foreach ($studycourses as $studycourse) { foreach ($studycourses as $studycourse) {
if (in_array($studycourse->abschluss_id, $master_degrees)) { if (in_array($studycourse->abschluss_id, $master_ids)) {
return true; return true;
} }
} }
......
pluginclassname=OSKA pluginclassname=OSKA
pluginname=OSKA pluginname=OSKA
origin=virtUOS origin=virtUOS
version=1.1.6 version=1.1.7
studipMinVersion=4.0 studipMinVersion=4.0
studipMaxVersion=5.2.99 studipMaxVersion=5.2.99
category=Kommunikation und Zusammenarbeit category=Kommunikation und Zusammenarbeit
......
...@@ -65,9 +65,8 @@ ...@@ -65,9 +65,8 @@
<? $actionMenu->addLink( <? $actionMenu->addLink(
$controller->url_for("admin/delete_match/{$match['mentee']->user_id}/{$match['mentor']->id}"), $controller->url_for("admin/delete_match/{$match['mentee']->user_id}/{$match['mentor']->id}"),
_('Match löschen'), _('Match löschen'),
Icon::create('trash', 'clickable', [ Icon::create('trash', 'clickable'),
'title' => _('Match löschen'), ['data-confirm' => _('Wollen Sie das Match wirklich löschen?')]
])
) ?> ) ?>
<?= $actionMenu->render() ?> <?= $actionMenu->render() ?>
</td> </td>
......
...@@ -80,9 +80,8 @@ ...@@ -80,9 +80,8 @@
<? $actionMenu->addLink( <? $actionMenu->addLink(
$controller->url_for('admin/delete_mentee/' . $mentee['user']->user_id), $controller->url_for('admin/delete_mentee/' . $mentee['user']->user_id),
_('Mentee löschen'), _('Mentee löschen'),
Icon::create('trash', 'clickable', [ Icon::create('trash', 'clickable'),
'title' => _('Mentee löschen'), ['data-confirm' => _('Mentee wirklich austragen?')]
])
) ?> ) ?>
<?= $actionMenu->render() ?> <?= $actionMenu->render() ?>
</td> </td>
......
...@@ -84,9 +84,8 @@ ...@@ -84,9 +84,8 @@
<? $actionMenu->addLink( <? $actionMenu->addLink(
$controller->url_for('admin/delete_mentor/' . $mentor['user']->id), $controller->url_for('admin/delete_mentor/' . $mentor['user']->id),
_('Mentor löschen'), _('Mentor löschen'),
Icon::create('trash', 'clickable', [ Icon::create('trash', 'clickable'),
'title' => _('Mentor löschen'), ['data-confirm' => _('Mentor wirklich austragen?')]
])
) ?> ) ?>
<?= $actionMenu->render() ?> <?= $actionMenu->render() ?>
</td> </td>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment