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
Branches
No related tags found
1 merge request!1Refactor and bugfixes
......@@ -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');
......
......@@ -556,9 +556,8 @@ 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) {
......@@ -567,24 +566,14 @@ class AdminController extends PluginController {
$match = OskaMatches::find([$mentor->user_id, $mentee_id]);
$match->delete();
}
$mentee = OskaMentees::find($mentee_id);
$mentee->delete();
} else {
PageLayout::postQuestion(
sprintf(
_('Mentee wirklich austragen?')
)
)->setAcceptURL(
$this->url_for("admin/delete_mentee/{$mentee_id}/true")
);
}
$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) {
......@@ -594,24 +583,14 @@ class AdminController extends PluginController {
$mentee->has_tutor = false;
$mentee->store();
}
$mentor = OskaMentors::find($mentor_id);
$mentor->delete();
} else {
PageLayout::postQuestion(
sprintf(
_('Mentor wirklich austragen?')
)
)->setAcceptURL(
$this->url_for("admin/delete_mentor/{$mentor_id}/true")
);
}
$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();
......@@ -622,15 +601,7 @@ class AdminController extends PluginController {
$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;
......
......@@ -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;
}
}
......@@ -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;
}
}
......
......@@ -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;
}
}
......
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
......
......@@ -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>
......
......@@ -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>
......
......@@ -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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment