From 48e6eecf55a2db43388a235fd5fe4f8494f1608f Mon Sep 17 00:00:00 2001 From: Moritz Strohm <strohm@data-quest.de> Date: Wed, 18 Apr 2018 11:25:41 +0200 Subject: [PATCH] made proof checkboxes configurable --- .gitignore | 1 + LICENSE | 0 controllers/admin.php | 279 +++++++++++------- controllers/profile.php | 182 ++++++------ ...nfig_tandemplugin_proof_fields_enabled.php | 47 +++ plugin.manifest | 2 +- views/_common/_profile.php | 206 ++++++------- views/admin/config.php | 22 +- views/profile/_add_edit_form.php | 31 +- 9 files changed, 451 insertions(+), 319 deletions(-) create mode 100644 .gitignore mode change 100755 => 100644 LICENSE create mode 100644 migrations/05_add_config_tandemplugin_proof_fields_enabled.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..99cf5ff --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.*~ diff --git a/LICENSE b/LICENSE old mode 100755 new mode 100644 diff --git a/controllers/admin.php b/controllers/admin.php index dd8b11a..abd26a9 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -36,12 +36,12 @@ class AdminController extends PluginController public function pairs_action() { //build sidebar: - + $this->status = (int)Request::get('status', 1); - - + + $sidebar = Sidebar::get(); - + $actions = new ActionsWidget(); $actions->addLink( dgettext('TandemPlugin', 'CSV-Export'), @@ -52,9 +52,9 @@ class AdminController extends PluginController ), Icon::create('file-excel', 'clickable') ); - + $sidebar->addWidget($actions); - + if(($this->status < -1) or ($this->status > 1)) { $this->status = 1; @@ -64,12 +64,12 @@ class AdminController extends PluginController if(Navigation::hasItem('/tandemplugin/admin/rejected')) { Navigation::activateItem('/tandemplugin/admin/rejected'); } - + } elseif($this->status == 0) { if(Navigation::hasItem('/tandemplugin/admin/requested')) { Navigation::activateItem('/tandemplugin/admin/requested'); } - + } elseif($this->status == 1) { if(Navigation::hasItem('/tandemplugin/admin/established')) { Navigation::activateItem('/tandemplugin/admin/established'); @@ -82,20 +82,30 @@ class AdminController extends PluginController 'status = :status', ['status' => $this->status] ); - + if(Request::get('csv_export')) { //A CSV file with all pairs shall be created instead of //showing the view. - + $csv_data = []; - $csv_data[] = [ - 'name1', 'vorname1', 'email1', 'studiengang1', 'geschlecht1', - 'muttersprache1', 'lernsprache1', 'Scheininteresse1', - 'name2', 'vorname2', 'email2', 'studiengang2', 'geschlecht2', - 'muttersprache2', 'lernsprache2', 'Scheininteresse2', - 'paarzeitaktiv' - ]; - + if (Config::get()->TANDEMPLUGIN_PROOF_FIELDS_ENABLED) { + $csv_data[] = [ + 'name1', 'vorname1', 'email1', 'studiengang1', 'geschlecht1', + 'muttersprache1', 'lernsprache1', 'Scheininteresse1', + 'name2', 'vorname2', 'email2', 'studiengang2', 'geschlecht2', + 'muttersprache2', 'lernsprache2', 'Scheininteresse2', + 'paarzeitaktiv' + ]; + } else { + $csv_data[] = [ + 'name1', 'vorname1', 'email1', 'studiengang1', 'geschlecht1', + 'muttersprache1', 'lernsprache1', + 'name2', 'vorname2', 'email2', 'studiengang2', 'geschlecht2', + 'muttersprache2', 'lernsprache2', + 'paarzeitaktiv' + ]; + } + foreach($this->pairs as $pair) { $user1_study_names = []; if($pair->request->user->studycourses) { @@ -103,83 +113,116 @@ class AdminController extends PluginController $user1_study_names[] = $studycourse->studycourse->name; } } - + $user1_proofs = ''; - if($pair->request->proof_of_achievement) { - $user1_proofs .= 'L'; - } - if($pair->request->proof_of_attendance) { - $user1_proofs .= 'T'; + if (Config::get()->TANDEMPLUGIN_PROOF_FIELDS_ENABLED) { + if($pair->request->proof_of_achievement) { + $user1_proofs .= 'L'; + } + if($pair->request->proof_of_attendance) { + $user1_proofs .= 'T'; + } } - $user2_study_names = []; if($pair->offer->user->studycourses) { foreach($pair->offer->user->studycourses as $studycourse) { $user2_study_names[] = $studycourse->studycourse->name; } } - + $user2_proofs = ''; - if($pair->offer->proof_of_achievement) { - $user2_proofs .= 'L'; + if (Config::get()->TANDEMPLUGIN_PROOF_FIELDS_ENABLED) { + if($pair->offer->proof_of_achievement) { + $user2_proofs .= 'L'; + } + if($pair->offer->proof_of_attendance) { + $user2_proofs .= 'T'; + } } - if($pair->offer->proof_of_attendance) { - $user2_proofs .= 'T'; + + if (Config::get()->TANDEMPLUGIN_PROOF_FIELDS_ENABLED) { + $csv_data[] = [ + $pair->request->user->nachname, + $pair->request->user->vorname, + $pair->request->user->email, + implode(',', $user1_study_names), + (($pair->request->user->geschlecht == '1') + ? 'm' + : ($pair->request->user->geschlecht == '2') + ? 'w' + : '?'), + $pair->offer->target_language_id, + $pair->request->target_language_id, + $user1_proofs, + + $pair->offer->user->nachname, + $pair->offer->user->vorname, + $pair->offer->user->email, + implode(',', $user2_study_names), + (($pair->offer->user->geschlecht == '1') + ? 'm' + : ($pair->offer->user->geschlecht == '2') + ? 'w' + : '?'), + $pair->request->target_language_id, + $pair->offer->target_language_id, + $user2_proofs, + + date('d.m.Y H:i', $pair->chdate) + ]; + } else { + $csv_data[] = [ + $pair->request->user->nachname, + $pair->request->user->vorname, + $pair->request->user->email, + implode(',', $user1_study_names), + (($pair->request->user->geschlecht == '1') + ? 'm' + : ($pair->request->user->geschlecht == '2') + ? 'w' + : '?'), + $pair->offer->target_language_id, + $pair->request->target_language_id, + + $pair->offer->user->nachname, + $pair->offer->user->vorname, + $pair->offer->user->email, + implode(',', $user2_study_names), + (($pair->offer->user->geschlecht == '1') + ? 'm' + : ($pair->offer->user->geschlecht == '2') + ? 'w' + : '?'), + $pair->request->target_language_id, + $pair->offer->target_language_id, + + date('d.m.Y H:i', $pair->chdate) + ]; } - - $csv_data[] = [ - $pair->request->user->nachname, - $pair->request->user->vorname, - $pair->request->user->email, - implode(',', $user1_study_names), - (($pair->request->user->geschlecht == '1') - ? 'm' - : ($pair->request->user->geschlecht == '2') - ? 'w' - : '?'), - $pair->offer->target_language_id, - $pair->request->target_language_id, - $user1_proofs, - - $pair->offer->user->nachname, - $pair->offer->user->vorname, - $pair->offer->user->email, - implode(',', $user2_study_names), - (($pair->offer->user->geschlecht == '1') - ? 'm' - : ($pair->offer->user->geschlecht == '2') - ? 'w' - : '?'), - $pair->request->target_language_id, - $pair->offer->target_language_id, - $user2_proofs, - - date('d.m.Y H:i', $pair->chdate) - ]; } - + //The CSV file's content was created. Now we can send it: - + $csv_text = array_to_csv($csv_data); - + header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename=' . - dgettext('TandemPlugin', 'Tandem-Paare') . - '_' . date('Y-m-d') . '.csv'); - + dgettext('TandemPlugin', 'Tandem-Paare') . + '_' . date('Y-m-d') . '.csv'); + //For Content-Length we must use strlen instead of mb_strlen //to get the number of bytes rather than the number of characters: header('Content-Length: ' . strlen($csv_text)); - + $this->render_text($csv_text); } } - - + + public function terminated_pairs_action() { $sidebar = Sidebar::get(); - + $actions = new ActionsWidget(); $actions->addLink( dgettext('TandemPlugin', 'CSV-Export'), @@ -189,9 +232,9 @@ class AdminController extends PluginController 'admin/terminated_pairs' ) ); - + $sidebar->addWidget($actions); - + if(Navigation::hasItem('/tandemplugin/admin/terminated')) { Navigation::activateItem('/tandemplugin/admin/terminated'); } @@ -202,11 +245,11 @@ class AdminController extends PluginController 'TRUE ORDER BY mkdate DESC', [] ); - + if(Request::get('csv_export')) { //A CSV file with all terminated pairs shall be created instead of //showing the view. - + $csv_data = []; $csv_data[] =[ 'name1', 'vorname1', 'email1', 'studiengang1', 'geschlecht1', @@ -215,7 +258,7 @@ class AdminController extends PluginController 'muttersprache2', 'lernsprache2', 'datum_auflösung' ]; - + foreach($this->terminated_pairs as $pair) { $user1_study_names = []; if($pair->requester->studycourses) { @@ -223,56 +266,56 @@ class AdminController extends PluginController $user1_study_names[] = $studycourse->studycourse->name; } } - + $user2_study_names = []; if($pair->offerer->studycourses) { foreach($pair->offerer->studycourses as $studycourse) { $user2_study_names[] = $studycourse->studycourse->name; } } - + $csv_data[] = [ $pair->requester->nachname, $pair->requester->vorname, $pair->requester->email, implode(',', $user1_study_names), (($pair->requester->geschlecht == '1') - ? 'm' - : ($pair->requester->geschlecht == '2') - ? 'w' - : '?'), + ? 'm' + : ($pair->requester->geschlecht == '2') + ? 'w' + : '?'), $pair->offerer_language_id, $pair->requester_language_id, - + $pair->offerer->nachname, $pair->offerer->vorname, $pair->offerer->email, implode(',', $user2_study_names), (($pair->offerer->geschlecht == '1') - ? 'm' - : ($pair->offerer->geschlecht == '2') - ? 'w' - : '?'), + ? 'm' + : ($pair->offerer->geschlecht == '2') + ? 'w' + : '?'), $pair->requester_language_id, $pair->offerer_language_id, - + date('d.m.Y H:i', $pair->mkdate) ]; } - + //The CSV file's content was created. Now we can send it: - + $csv_text = array_to_csv($csv_data); - + header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename=' . - dgettext('TandemPlugin', 'Aufgelöste_Tandems') . - '_' . date('Y-m-d') . '.csv'); - + dgettext('TandemPlugin', 'Aufgelöste_Tandems') . + '_' . date('Y-m-d') . '.csv'); + //For Content-Length we must use strlen instead of mb_strlen //to get the number of bytes rather than the number of characters: header('Content-Length: ' . strlen($csv_text)); - + $this->render_text($csv_text); } } @@ -401,15 +444,15 @@ class AdminController extends PluginController foreach ($this->search_results as $search_result) { $csv_array[] = [ ($search_result->user - ? $search_result->user->getFullName() - : dgettext('TandemPlugin', 'Unbekannter Nutzer') + ? $search_result->user->getFullName() + : dgettext('TandemPlugin', 'Unbekannter Nutzer') ), $search_result->user->email, $this->mother_language->getLocalName() . ' - ' . ($search_result->target_language - ? $search_result->target_language->getLocalName() - : dgettext('TandemPlugin', 'Unbekannte Sprache') + ? $search_result->target_language->getLocalName() + : dgettext('TandemPlugin', 'Unbekannte Sprache') ), date('d.m.Y H:i', $search_result->mkdate) ]; @@ -419,16 +462,16 @@ class AdminController extends PluginController header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename=' . - dgettext('TandemPlugin', 'Tandem-Gesuche') . - '-' . - $this->mother_language_id . - '-' . - $this->target_language_id . - '-' . - $this->age_of_request . - '_' . - date('Y-m-d') . - '.csv' + dgettext('TandemPlugin', 'Tandem-Gesuche') . + '-' . + $this->mother_language_id . + '-' . + $this->target_language_id . + '-' . + $this->age_of_request . + '_' . + date('Y-m-d') . + '.csv' ); //For Content-Length we must use strlen instead of mb_strlen @@ -454,8 +497,10 @@ class AdminController extends PluginController $config = Config::get(); if(Request::submitted('save')) { + CSRFProtection::verifyUnsafeRequest(); $this->gender_search_enabled = (bool)Request::get('gender_search_enabled', false); $this->delete_old_period = (int)Request::int('delete_old_period', 6); + $this->proof_fields_enabled = (bool)Request::get('proof_fields_enabled', false); if(($this->delete_old_period < 1) or ($this->delete_old_period > 24)) { PageLayout::postError( @@ -466,6 +511,12 @@ class AdminController extends PluginController //get the config entries and store them: + $proof_fields_enabled = ConfigEntry::findByField('TANDEMPLUGIN_PROOF_FIELDS_ENABLED')[0]; + if($proof_fields_enabled) { + $proof_fields_enabled->value = (int)$this->proof_fields_enabled; + $proof_fields_enabled->store(); + } + $gender_search_enabled = ConfigEntry::findByField('TANDEMPLUGIN_GENDER_SEARCH_ENABLED')[0]; if($gender_search_enabled) { $gender_search_enabled->value = (int)$this->gender_search_enabled; @@ -483,13 +534,17 @@ class AdminController extends PluginController ); } else { + $this->proof_fields_enabled = (bool) + ($config->TANDEMPLUGIN_PROOF_FIELDS_ENABLED ? + $config->TANDEMPLUGIN_PROOF_FIELDS_ENABLED : false); + $this->gender_search_enabled = (bool) - ($config->TANDEMPLUGIN_GENDER_SEARCH_ENABLED ? - $config->TANDEMPLUGIN_GENDER_SEARCH_ENABLED : false); + ($config->TANDEMPLUGIN_GENDER_SEARCH_ENABLED ? + $config->TANDEMPLUGIN_GENDER_SEARCH_ENABLED : false); $this->delete_old_period = (int) - ($config->TANDEMPLUGIN_DELETE_OLD_PERIOD ? - $config->TANDEMPLUGIN_DELETE_OLD_PERIOD : 6); + ($config->TANDEMPLUGIN_DELETE_OLD_PERIOD ? + $config->TANDEMPLUGIN_DELETE_OLD_PERIOD : 6); } } } diff --git a/controllers/profile.php b/controllers/profile.php index 67e7b71..f39ba9f 100644 --- a/controllers/profile.php +++ b/controllers/profile.php @@ -24,12 +24,12 @@ require_once(__DIR__ . '/../classes/TandemManager.class.php'); class ProfileController extends PluginController { protected $utf8decode_xhr = true; - + private function addEditHandler($edit_mode = false) { //load the list of languages: $this->language_list = TandemLanguage::findBySql('TRUE'); - + $this->tandem_profile_id = Request::get('tandem_profile_id'); if(!$this->tandem_profile_id and $edit_mode) { PageLayout::postError( @@ -38,9 +38,9 @@ class ProfileController extends PluginController $this->hide_form = true; return; } - + $this->tandem_profile = new TandemProfile($this->tandem_profile_id); - + if($edit_mode) { //In edit mode we have to check, if the tandem profile referenced by its //ID exists in the database: @@ -52,34 +52,36 @@ class ProfileController extends PluginController return; } } - + $mother_languages = TandemUserMotherLanguage::findByUser_id( User::findCurrent()->id ); - + if(!$mother_languages) { PageLayout::postError( dgettext('TandemPlugin', 'Es kann kein Gesuch erstellt werden, solange keine Muttersprache eingegeben wurde!') ); return; } - + if($edit_mode) { $this->pair_exists = (TandemPair::countByProfileAndStatus($this->tandem_profile, 1) > 0); } - + if(Request::submitted('save')) { //A tandem profile shall be saved. - + //Read all attributes: $this->target_language_id = Request::get('target_language_id', null); $this->level = Request::get('level', null); $this->comment = Request::get('comment', ''); $this->gender = Request::get('gender', ''); - $this->proof_of_achievement = Request::get('proof_of_achievement', ''); - $this->proof_of_attendance = Request::get('proof_of_attendance', ''); - - + if (Config::get()->TANDEMPLUGIN_PROOF_FIELDS_ENABLED) { + $this->proof_of_achievement = Request::get('proof_of_achievement', ''); + $this->proof_of_attendance = Request::get('proof_of_attendance', ''); + } + + if(!$this->target_language_id) { //mother_language_id is mandatory! PageLayout::postError( @@ -87,7 +89,7 @@ class ProfileController extends PluginController ); return; } - + if(!$this->level) { //level is mandatory! PageLayout::postError( @@ -95,7 +97,7 @@ class ProfileController extends PluginController ); return; } - + //Check if the selected target language is found in the database: if(!TandemLanguage::exists($this->target_language_id)) { PageLayout::postError( @@ -103,7 +105,7 @@ class ProfileController extends PluginController ); return; } - + //Level may contain only the strings A1, A2, B1, B2, C1 or C2. $this->level = mb_strtoupper($this->level); if(!preg_match('(^[ABC][12]$)', $this->level)) { @@ -112,32 +114,32 @@ class ProfileController extends PluginController ); return; } - + /* - //disabled on 2017-01-31: multiple profiles for one target language may exist! - //Check, if profiles for the target language already exist: - $profiles_exist = TandemProfile::countBySql( - 'target_language_id = :target_language_id - AND - user_id = :user_id', - [ - 'target_language_id' => $this->target_language_id, - 'user_id' => User::findCurrent()->id - ] - ); - if($profiles_exist > 0) { - PageLayout::postError( - dgettext('TandemPlugin', 'Es wurde bereits ein Gesuch für die Zielsprache erstellt. Bitte eine andere Zielsprache wählen!') - ); - return; - } */ - + //disabled on 2017-01-31: multiple profiles for one target language may exist! + //Check, if profiles for the target language already exist: + $profiles_exist = TandemProfile::countBySql( + 'target_language_id = :target_language_id + AND + user_id = :user_id', + [ + 'target_language_id' => $this->target_language_id, + 'user_id' => User::findCurrent()->id + ] + ); + if($profiles_exist > 0) { + PageLayout::postError( + dgettext('TandemPlugin', 'Es wurde bereits ein Gesuch für die Zielsprache erstellt. Bitte eine andere Zielsprache wählen!') + ); + return; + } */ + $this->mother_language_ids = []; - + foreach($mother_languages as $ml) { $this->mother_language_ids[] = $ml->language_id; } - + //Check, if the target language is a mother language: if(in_array($this->target_language_id, $this->mother_language_ids)) { PageLayout::postError( @@ -145,7 +147,7 @@ class ProfileController extends PluginController ); return; } - + //check value for gender: Either it is set to 'm' or 'w' //or it isn't set at all: if($this->gender !== '') { @@ -156,12 +158,12 @@ class ProfileController extends PluginController return; } } - - - - + + + + //ok, checks are done, we can store the tandem profile: - + if(!$edit_mode) { //add mode: create tandem profile and its data $this->tandem_profile->user_id = User::findCurrent()->id; @@ -170,29 +172,31 @@ class ProfileController extends PluginController //the following is common for add and edit mode: $this->tandem_profile->target_language_id = $this->target_language_id; $this->tandem_profile->level = $this->level; - + $this->tandem_profile->comment = $this->comment; $this->tandem_profile->gender = $this->gender; - $this->tandem_profile->proof_of_achievement = (int)$this->proof_of_achievement; - $this->tandem_profile->proof_of_attendance = (int)$this->proof_of_attendance; - - + if (Config::get()->TANDEMPLUGIN_PROOF_FIELDS_ENABLED) { + $this->tandem_profile->proof_of_achievement = (int)$this->proof_of_achievement; + $this->tandem_profile->proof_of_attendance = (int)$this->proof_of_attendance; + } + + $result = true; - + if($this->tandem_profile->isDirty() or $this->tandem_profile->isNew()) { $result = $this->tandem_profile->store(); } - + if($result == true) { //Saving was successful. We can now look for matches. $matches = TandemMatching::findMatches( $this->tandem_profile ); - + if(!$edit_mode) { //Notify potential tandem partners about the new offer //(when seen from their point of view). - + foreach($matches as $match) { TandemManager::sendMatchNotification( $match, @@ -200,10 +204,10 @@ class ProfileController extends PluginController ); } } - - + + $pair_exists = (TandemPair::countByProfileAndStatus($this->tandem_profile, 1) > 0); - + if($pair_exists) { PageLayout::postSuccess( dgettext('TandemPlugin', 'Gesuch wurde gespeichert!') @@ -223,7 +227,7 @@ class ProfileController extends PluginController $any_matches = TandemMatching::matchesExist( TandemProfile::findByUser_id(User::findCurrent()->id) ); - + if($any_matches) { PageLayout::postSuccess( dgettext('TandemPlugin', 'Gesuch wurde gespeichert!') . ' ' . @@ -233,7 +237,7 @@ class ProfileController extends PluginController ) ); } else { - + PageLayout::postSuccess( dgettext('TandemPlugin', 'Gesuch wurde gespeichert!') . ' ' . dgettext('TandemPlugin', 'Aktuell wurden keine passenden Tandem-Angebote gefunden!') @@ -247,7 +251,7 @@ class ProfileController extends PluginController dgettext('TandemPlugin', 'Fehler beim Speichern des Gesuchs!') ); } - + $this->redirect( PluginEngine::getURL( $this->plugin, @@ -255,34 +259,38 @@ class ProfileController extends PluginController 'my_tandems/index' ) ); - + } else { //A new tandem profile shall be added or an existing tandem profile //shall be displayed for editing. - + if($edit_mode) { //edit mode $this->target_language_id = $this->tandem_profile->target_language_id; $this->level = $this->tandem_profile->level; - + $this->comment = $this->tandem_profile->comment; $this->gender = $this->tandem_profile->gender; - $this->proof_of_achievement = $this->tandem_profile->proof_of_achievement; - $this->proof_of_attendance = $this->tandem_profile->proof_of_attendance; + if (Config::get()->TANDEMPLUGIN_PROOF_FIELDS_ENABLED) { + $this->proof_of_achievement = $this->tandem_profile->proof_of_achievement; + $this->proof_of_attendance = $this->tandem_profile->proof_of_attendance; + } } else { //add mode $this->target_language_id = ''; $this->level = 'A1'; - + $this->comment = ''; $this->gender = ''; - $this->proof_of_achievement = ''; - $this->proof_of_attendance = ''; + if (Config::get()->TANDEMPLUGIN_PROOF_FIELDS_ENABLED) { + $this->proof_of_achievement = ''; + $this->proof_of_attendance = ''; + } } } } - - + + public function add_action() { @@ -291,8 +299,8 @@ class ProfileController extends PluginController ); $this->addEditHandler(false); } - - + + public function edit_action() { PageLayout::setTitle( @@ -300,30 +308,30 @@ class ProfileController extends PluginController ); $this->addEditHandler(true); } - - + + public function delete_action($profile_id = null) { PageLayout::setTitle( dgettext('TandemPlugin', 'Profil löschen') ); - + if(!$profile_id) { PageLayout::postError( dgettext('TandemPlugin', 'Es wurde kein Tandem-Profil angegeben!') ); return; } - + $this->profile = TandemProfile::find($profile_id); - + if(!$this->profile) { PageLayout::postError( dgettext('TandemPlugin', 'Das angegebene Tandem-Profil wurde nicht in der Datenbank gefunden!') ); return; } - + $this->profile_pairs = TandemPair::findBySql( "(request_profile_id = :profile_id OR @@ -332,12 +340,12 @@ class ProfileController extends PluginController 'profile_id' => $profile_id ] ); - - + + $this->user = User::findCurrent(); - + if(Request::submitted('confirmed')) { - + if($this->profile_pairs) { foreach($this->profile_pairs as $pair) { if($pair->status == 1) { @@ -349,7 +357,7 @@ class ProfileController extends PluginController } } } - + if($this->profile->delete()) { PageLayout::postSuccess( dgettext('TandemPlugin', 'Das Tandem-Profil wurde gelöscht!') @@ -362,8 +370,8 @@ class ProfileController extends PluginController $this->profile = null; } } - - + + /** * Shows all matches for a profile */ @@ -376,9 +384,9 @@ class ProfileController extends PluginController $this->show_results = false; return; } - + $this->profile = TandemProfile::find($profile_id); - + if(!$this->profile) { PageLayout::postError( dgettext('TandemPlugin', 'Das angegebene Tandem-Profil wurde nicht in der Datenbank gefunden!') @@ -386,11 +394,11 @@ class ProfileController extends PluginController $this->show_results = false; return; } - + $this->show_results = true; $this->matches = [ $this->profile->id => TandemMatching::findMatches($this->profile) ]; - + } } diff --git a/migrations/05_add_config_tandemplugin_proof_fields_enabled.php b/migrations/05_add_config_tandemplugin_proof_fields_enabled.php new file mode 100644 index 0000000..02f3289 --- /dev/null +++ b/migrations/05_add_config_tandemplugin_proof_fields_enabled.php @@ -0,0 +1,47 @@ +<?php + +/** + * This file is part of the TandemPlugin for Stud.IP + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * @author Moritz Strohm <strohm@data-quest.de> + * @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2 + * @category Plugin + **/ + + +class AddConfigTandempluginProofFieldsEnabled extends Migration +{ + + public function up() + { + //Create configuration field, if it doesn't exist yet: + + $proof_fields_enabled = ConfigEntry::findByField('TANDEMPLUGIN_PROOF_FIELDS_ENABLED'); + if(!$proof_fields_enabled) { + $proof_fields_enabled = new ConfigEntry(); + $proof_fields_enabled->field = 'TANDEMPLUGIN_PROOF_FIELDS_ENABLED'; + $proof_fields_enabled->type = 'boolean'; + $proof_fields_enabled->value = '1'; + $proof_fields_enabled->section = 'tandemplugin'; + $proof_fields_enabled->store(); + } + } + + + public function down() + { + //Delete configuration field: + + $proof_fields_enabled = ConfigEntry::findByField('TANDEMPLUGIN_PROOF_FIELDS_ENABLED'); + if($proof_fields_enabled) { + foreach($proof_fields_enabled as $pfe) { + $pfe->delete(); + } + } + } +} diff --git a/plugin.manifest b/plugin.manifest index e7c3c90..14ee1fd 100644 --- a/plugin.manifest +++ b/plugin.manifest @@ -1,6 +1,6 @@ pluginname=TandemPlugin pluginclassname=TandemPlugin origin=data-quest -version=0.7.2 +version=0.8 description=Dieses Plugin ermöglicht es, Sprachtandems innerhalb der Stud.IP Platform zu bilden. studipMinVersion=4.0 diff --git a/views/_common/_profile.php b/views/_common/_profile.php index d18af56..bb88acb 100644 --- a/views/_common/_profile.php +++ b/views/_common/_profile.php @@ -1,44 +1,44 @@ <?= Avatar::getAvatar($profile->user_id)->getImageTag( Avatar::MEDIUM, ['style' => 'float:left; margin-right: 0.5em;'] - ) ?> +) ?> <div style="float:left;"> <? if ($profile->user): ?> - <a href="<?= URLHelper::getLink( - 'dispatch.php/profile', - ['username' => $profile->user->username] - ) ?>"> - <strong><?= htmlReady($profile->user->getFullName()) ?></strong> - </a> + <a href="<?= URLHelper::getLink( + 'dispatch.php/profile', + ['username' => $profile->user->username] + ) ?>"> + <strong><?= htmlReady($profile->user->getFullName()) ?></strong> + </a> <? else: ?> - <strong><?= dgettext('TandemPlugin', 'Unbekannter Nutzer') ?></strong> + <strong><?= dgettext('TandemPlugin', 'Unbekannter Nutzer') ?></strong> <? endif ?> <? if($established_pair or $admin_view): ?> - <? if ($profile->user) : ?> - <a href="<?= URLHelper::getLink( - 'dispatch.php/messages/write', - ['rec_uname' => $profile->user->username] - ) ?>" data-dialog> - <?= Icon::create('mail', 'clickable')->asImg('20px', ['class' => 'text-bottom']) ?> - </a> - <? endif ?> - + <? if ($profile->user) : ?> + <a href="<?= URLHelper::getLink( + 'dispatch.php/messages/write', + ['rec_uname' => $profile->user->username] + ) ?>" data-dialog> + <?= Icon::create('mail', 'clickable')->asImg('20px', ['class' => 'text-bottom']) ?> + </a> + <? endif ?> + <? endif ?> <div> <? if ($profile->user): ?> - <strong><?= dgettext('TandemPlugin', 'Geschlecht') ?>:</strong> - <?= ($profile->user->geschlecht == '1') - ? dgettext('TandemPlugin', 'männlich') - : (($profile->user->geschlecht == '2') - ? dgettext('TandemPlugin', 'weiblich') - : dgettext('TandemPlugin', 'Keine Angabe')) ?> + <strong><?= dgettext('TandemPlugin', 'Geschlecht') ?>:</strong> + <?= ($profile->user->geschlecht == '1') + ? dgettext('TandemPlugin', 'männlich') + : (($profile->user->geschlecht == '2') + ? dgettext('TandemPlugin', 'weiblich') + : dgettext('TandemPlugin', 'Keine Angabe')) ?> <? endif ?> </div> - + <? $study_names = null; ?> <? if ($profile->user): ?> <? if($profile->user->studycourses): ?> - <? $study_names = []; + <? $study_names = []; foreach($profile->user->studycourses as $studycourse) { $study_names[] = $studycourse->studycourse->name; } ?> @@ -46,95 +46,95 @@ <? endif ?> <div> <strong><?= dgettext('TandemPlugin', 'Studiengänge') ?>:</strong> - <?= ($study_names - ? htmlReady(implode(', ', $study_names)) - : dgettext('TandemPlugin', 'Keine Angabe')) ?> + <?= ($study_names + ? htmlReady(implode(', ', $study_names)) + : dgettext('TandemPlugin', 'Keine Angabe')) ?> </div> - + <? if($established_pair or $admin_view): ?> <? if($highlighted_languages): ?> + <div> + <strong><?= htmlReady($highlighted_languages[0]) ?></strong> + <?= Icon::create('group', 'info')->asImg('16px', ['class' => 'text-bottom']) ?> + <?= htmlReady($profile->getTargetName()) ?> + </div> + <? endif ?> + <? else: ?> <div> - <strong><?= htmlReady($highlighted_languages[0]) ?></strong> - <?= Icon::create('group', 'info')->asImg('16px', ['class' => 'text-bottom']) ?> + <strong><?= dgettext('TandemPlugin', 'Sucht') ?>:</strong> <?= htmlReady($profile->getTargetName()) ?> </div> - <? endif ?> - <? else: ?> - <div> - <strong><?= dgettext('TandemPlugin', 'Sucht') ?>:</strong> - <?= htmlReady($profile->getTargetName()) ?> - </div> - <div> - <strong><?= dgettext('TandemPlugin', 'Spricht') ?>:</strong> - <? $user_mother_languages = TandemUserMotherLanguage::findSortedByName($profile->user_id) ?> - <? foreach($user_mother_languages as $uml): ?> - <span style="white-space: nowrap;"> - <? if($highlighted_languages): ?> - <? if(in_array($uml->language->getLocalName(), $highlighted_languages)): ?> - <strong> - <?= htmlReady($uml->language->getLocalName()) ?> - </strong> - <? if($verbose_mother_language and - ($uml->country or $uml->region)): ?> - - <? if($uml->country and !$uml->region): ?> - (<?= htmlReady($uml->country) ?>) - <? elseif($uml->country and $uml->region): ?> - (<?= htmlReady($uml->country) ?>, <?= htmlReady($uml->region) ?>) - <? elseif($uml->region): ?> - (<?= htmlReady($uml->region) ?>) - <? endif ?> - <? endif ?> - <? else: ?> - <?= htmlReady($uml->language->getLocalName()) ?> - <? if($verbose_mother_language and - ($uml->country or $uml->region)): ?> - <? if($uml->country and !$uml->region): ?> - (<?= htmlReady($uml->country) ?>) - <? elseif($uml->country and $uml->region): ?> - (<?= htmlReady($uml->country) ?>, <?= htmlReady($uml->region) ?>) - <? elseif($uml->region): ?> - (<?= htmlReady($uml->region) ?>) + <div> + <strong><?= dgettext('TandemPlugin', 'Spricht') ?>:</strong> + <? $user_mother_languages = TandemUserMotherLanguage::findSortedByName($profile->user_id) ?> + <? foreach($user_mother_languages as $uml): ?> + <span style="white-space: nowrap;"> + <? if($highlighted_languages): ?> + <? if(in_array($uml->language->getLocalName(), $highlighted_languages)): ?> + <strong> + <?= htmlReady($uml->language->getLocalName()) ?> + </strong> + <? if($verbose_mother_language and + ($uml->country or $uml->region)): ?> + + <? if($uml->country and !$uml->region): ?> + (<?= htmlReady($uml->country) ?>) + <? elseif($uml->country and $uml->region): ?> + (<?= htmlReady($uml->country) ?>, <?= htmlReady($uml->region) ?>) + <? elseif($uml->region): ?> + (<?= htmlReady($uml->region) ?>) + <? endif ?> + <? endif ?> + <? else: ?> + <?= htmlReady($uml->language->getLocalName()) ?> + <? if($verbose_mother_language and + ($uml->country or $uml->region)): ?> + <? if($uml->country and !$uml->region): ?> + (<?= htmlReady($uml->country) ?>) + <? elseif($uml->country and $uml->region): ?> + (<?= htmlReady($uml->country) ?>, <?= htmlReady($uml->region) ?>) + <? elseif($uml->region): ?> + (<?= htmlReady($uml->region) ?>) + <? endif ?> + <? endif ?> + <? endif ?> + <? else: ?> + <?= htmlReady($uml->language->getLocalName()) ?> + <? if($verbose_mother_language and + ($uml->country or $uml->region)): ?> + <? if($uml->country and !$uml->region): ?> + (<?= htmlReady($uml->country) ?>) + <? elseif($uml->country and $uml->region): ?> + (<?= htmlReady($uml->country) ?>, <?= htmlReady($uml->region) ?>) + <? elseif($uml->region): ?> + (<?= htmlReady($uml->region) ?>) + <? endif ?> + <? endif ?> <? endif ?> - <? endif ?> - <? endif ?> - <? else: ?> - <?= htmlReady($uml->language->getLocalName()) ?> - <? if($verbose_mother_language and - ($uml->country or $uml->region)): ?> - <? if($uml->country and !$uml->region): ?> - (<?= htmlReady($uml->country) ?>) - <? elseif($uml->country and $uml->region): ?> - (<?= htmlReady($uml->country) ?>, <?= htmlReady($uml->region) ?>) - <? elseif($uml->region): ?> - (<?= htmlReady($uml->region) ?>) - <? endif ?> - <? endif ?> - <? endif ?> - </span> - <? endforeach ?> - </div> + </span> + <? endforeach ?> + </div> <? endif ?> <? if($profile->comment): ?> - <div> - <strong><?= dgettext('TandemPlugin', 'Bemerkung') ?>:</strong> - <?= htmlReady($profile->comment) ?> - </div> - <? endif ?> - <? if($admin_view): ?> - <div> - <? if($profile->proof_of_achievement): ?> <div> - <strong><?= dgettext('TandemPlugin', 'Leistungsbescheinigung') ?>:</strong> - <span><?= dgettext('TandemPlugin', 'gewünscht') ?></span> + <strong><?= dgettext('TandemPlugin', 'Bemerkung') ?>:</strong> + <?= htmlReady($profile->comment) ?> </div> - <? endif ?> - <? if($profile->proof_of_attendance): ?> + <? endif ?> + <? if($admin_view and Config::get()->TANDEMPLUGIN_PROOF_FIELDS_ENABLED): ?> <div> - <strong><?= dgettext('TandemPlugin', 'Teilnahmebestätigung') ?>:</strong> - <span><?= dgettext('TandemPlugin', 'gewünscht') ?></span> + <? if($profile->proof_of_achievement): ?> + <div> + <strong><?= dgettext('TandemPlugin', 'Leistungsbescheinigung') ?>:</strong> + <span><?= dgettext('TandemPlugin', 'gewünscht') ?></span> + </div> + <? endif ?> + <? if($profile->proof_of_attendance): ?> + <div> + <strong><?= dgettext('TandemPlugin', 'Teilnahmebestätigung') ?>:</strong> + <span><?= dgettext('TandemPlugin', 'gewünscht') ?></span> + </div> + <? endif ?> + <? endif ?> </div> - <? endif ?> - <? endif ?> - </div> </div> diff --git a/views/admin/config.php b/views/admin/config.php index 7adaf79..7747d47 100644 --- a/views/admin/config.php +++ b/views/admin/config.php @@ -24,7 +24,7 @@ </fieldset> <fieldset> <legend> - <?= dgettext('TandemPlugin', 'Entfernung alter Gesuche' ) ?> + <?= dgettext('TandemPlugin', 'Entfernung alter Gesuche') ?> </legend> <p> <?= dgettext( @@ -45,6 +45,26 @@ value="<?= htmlReady($delete_old_period) ?>"> </label> </fieldset> + <fieldset> + <legend> + <?= dgettext('TandemPlugin', 'ECTS-Punkte und Nachweis') ?> + </legend> + <p> + <?= dgettext( + 'TandemPlugin', + 'Sofern die Möglichkeiten, eine Leistungsbescheinigung und eine Teilnahmebestätigung auszustellen, angeboten werden, kann diese Funktionalität hier eingeschaltet werden.' + ) ?> + </p> + <label> + <?= dgettext( + 'TandemPlugin', + 'Leistungsbescheinigung und Teilnahmebestätigung anbieten' + ) ?> + <input type="checkbox" name="proof_fields_enabled" + <?= $proof_fields_enabled ? 'checked="checked"' : '' ?> + value="1"> + </label> + </fieldset> <div> <?= \Studip\Button::create( dgettext('TandemPlugin', 'Speichern'), diff --git a/views/profile/_add_edit_form.php b/views/profile/_add_edit_form.php index 8f56a57..7c6973f 100644 --- a/views/profile/_add_edit_form.php +++ b/views/profile/_add_edit_form.php @@ -36,22 +36,23 @@ <textarea name="comment" placeholder="<?= dgettext('TandemPlugin', 'Z.B. Ich habe Mittwochs zwischen 15 und 18 Uhr Zeit.') ?>"><?= htmlReady($comment) ?></textarea> </label> <? if(TandemPlugin::isGenderSearchEnabled()): ?> - <label> - <?= dgettext('TandemPlugin', 'Suchen Sie Tandem Partner/-innen eines bestimmten Geschlechtes?') ?> - <input type="radio" name="gender" value="" <?= ($gender == '' ? 'checked="checked"' : '' ) ?>><?= dgettext('TandemPlugin', 'Nein') ?></input> - <input type="radio" name="gender" value="m" <?= ($gender == 'm' ? 'checked="checked"' : '' ) ?>><?= dgettext('TandemPlugin', 'Nur Männliche') ?></input> - <input type="radio" name="gender" value="w" <?= ($gender == 'w' ? 'checked="checked"' : '' ) ?>><?= dgettext('TandemPlugin', 'Nur Weibliche') ?></input> - </label> + <label> + <?= dgettext('TandemPlugin', 'Suchen Sie Tandem Partner/-innen eines bestimmten Geschlechtes?') ?> + <input type="radio" name="gender" value="" <?= ($gender == '' ? 'checked="checked"' : '' ) ?>><?= dgettext('TandemPlugin', 'Nein') ?></input> + <input type="radio" name="gender" value="m" <?= ($gender == 'm' ? 'checked="checked"' : '' ) ?>><?= dgettext('TandemPlugin', 'Nur Männliche') ?></input> + <input type="radio" name="gender" value="w" <?= ($gender == 'w' ? 'checked="checked"' : '' ) ?>><?= dgettext('TandemPlugin', 'Nur Weibliche') ?></input> + </label> + <? endif ?> + <? if (Config::get()->TANDEMPLUGIN_PROOF_FIELDS_ENABLED): ?> + <label> + <?= dgettext('TandemPlugin', 'Ich möchte eine Leistungsbescheinigung (ECTS-Punkte).') ?> + <input type="checkbox" name="proof_of_achievement" value="1" <?= $proof_of_achievement ? 'checked="checked"' : '' ?>> + </label> + <label> + <?= dgettext('TandemPlugin', 'Ich möchte eine Teilnahmebestätigung.') ?> + <input type="checkbox" name="proof_of_attendance" value="1" <?= $proof_of_attendance ? 'checked="checked"' : '' ?>> + </label> <? endif ?> - <label> - <?= dgettext('TandemPlugin', 'Ich möchte eine Leistungsbescheinigung (ECTS-Punkte).') ?> - <input type="checkbox" name="proof_of_achievement" value="1" <?= $proof_of_achievement ? 'checked="checked"' : '' ?>> - </label> - <label> - <?= dgettext('TandemPlugin', 'Ich möchte eine Teilnahmebestätigung.') ?> - <input type="checkbox" name="proof_of_attendance" value="1" <?= $proof_of_attendance ? 'checked="checked"' : '' ?>> - </label> - </fieldset> <fieldset> <legend><?= dgettext('TandemPlugin', 'Wichtiger Hinweis') ?></legend> -- GitLab