From 8eb86e649d1e02bdc46c32191651c5abaf894b5c Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Wed, 15 Jun 2016 10:16:05 +0200 Subject: [PATCH] Improve glossary messages see BT#10895 --- main/glossary/index.php | 66 +++++++++++++++++++----- main/inc/lib/glossary.lib.php | 23 +++++---- main/lang/english/trad4all.inc.php | 23 +++++++++ tests/main/inc/lib/glossary.lib.test.php | 2 +- 4 files changed, 91 insertions(+), 23 deletions(-) diff --git a/main/glossary/index.php b/main/glossary/index.php index c0279488d4..c06127b5af 100755 --- a/main/glossary/index.php +++ b/main/glossary/index.php @@ -215,29 +215,69 @@ switch ($action) { } } $data = Import::csv_reader($_FILES['file']['tmp_name']); - $good = 0; - $bad = 0; + $goodList = []; + $badList = []; + $doubles = []; + $added = []; + $termsPerKey = []; + if ($data) { + $termsToAdd = []; foreach ($data as $item) { - $result = GlossaryManager::save_glossary( - array( - 'glossary_title' => $item['term'], - 'glossary_comment' => $item['definition'] - ) - ); + $items = [ + 'glossary_title' => $item['term'], + 'glossary_comment' => $item['definition'] + ]; + $termsToAdd[] = $items; + $termsPerKey[$item['term']] = $items; + } + + if (empty($termsToAdd)) { + Display::return_message(get_lang("NothingToAdd"), 'warning'); + header('Location: '.$currentUrl); + exit; + } + + $repeatItems = array_count_values(array_column($termsToAdd, 'glossary_title')); + foreach ($repeatItems as $item => $count) { + if ($count > 1) { + $doubles[] = $item; + } + } + + $uniqueTerms = array_unique(array_keys($repeatItems)); + + foreach ($uniqueTerms as $itemTerm) { + $item = $termsPerKey[$itemTerm]; + $result = GlossaryManager::save_glossary($item, false); if ($result) { - $good++; + $goodList[] = $item['glossary_title']; } else { - $bad++; + $badList[] = $item['glossary_title']; } } } - Display::return_message(get_lang("TermsImported") . ':' . $good); - if ($bad) { - Display::return_message(get_lang("TermsNotImported") . ':' . $bad, 'error'); + if (count($goodList) > 0) { + Display::addFlash( + Display::return_message(get_lang("TermsImported").': '.implode(', ', $goodList)) + ); + } + + if (count($badList) > 0) { + Display::addFlash( + Display::return_message(get_lang("GlossaryTermAlreadyExists").': ' . implode(', ', $badList), 'error') + ); } + + if (count($doubles) > 0) { + Display::addFlash( + Display::return_message(get_lang("TermsDuplicatedInFile").': '.implode(', ', $doubles), 'warning') + ); + } + + header('Location: '.$currentUrl); exit; } diff --git a/main/inc/lib/glossary.lib.php b/main/inc/lib/glossary.lib.php index b090d67804..f97aef3464 100755 --- a/main/inc/lib/glossary.lib.php +++ b/main/inc/lib/glossary.lib.php @@ -95,11 +95,12 @@ class GlossaryManager * @author Patrick Cool , Ghent University, Belgium * @version januari 2009, dokeos 1.8.6 */ - public static function save_glossary($values) + public static function save_glossary($values, $showMessage = true) { if (!is_array($values) || !isset($values['glossary_title'])) { return false; } + // Database table definition $t_glossary = Database :: get_course_table(TABLE_GLOSSARY); @@ -112,9 +113,11 @@ class GlossaryManager // check if the glossary term already exists if (GlossaryManager::glossary_exists($values['glossary_title'])) { // display the feedback message - Display::addFlash( - Display::return_message(get_lang('GlossaryTermAlreadyExistsYouShouldEditIt'), 'error') - ); + if ($showMessage) { + Display::addFlash( + Display::return_message(get_lang('GlossaryTermAlreadyExistsYouShouldEditIt'), 'error') + ); + } return false; } else { @@ -145,9 +148,11 @@ class GlossaryManager $_SESSION['max_glossary_display'] = GlossaryManager::get_max_glossary_item(); // display the feedback message - Display::addFlash( - Display::return_message(get_lang('TermAdded')) - ); + if ($showMessage) { + Display::addFlash( + Display::return_message(get_lang('TermAdded')) + ); + } return $id; } @@ -434,7 +439,7 @@ class GlossaryManager } if ($view == 'list') { - $content .= GlossaryManager::display_glossary_list(); + $content .= GlossaryManager::displayGlossaryList(); } return $content; @@ -446,7 +451,7 @@ class GlossaryManager * @author Patrick Cool , Ghent University, Belgium * @version januari 2009, dokeos 1.8.6 */ - public static function display_glossary_list() + public static function displayGlossaryList() { $glossary_data = self::get_glossary_data(0,1000,0,'ASC'); $content = ''; diff --git a/main/lang/english/trad4all.inc.php b/main/lang/english/trad4all.inc.php index 98dc0a67c4..3a963a7bef 100644 --- a/main/lang/english/trad4all.inc.php +++ b/main/lang/english/trad4all.inc.php @@ -7711,13 +7711,36 @@ $ForumEndDate = "Closing date"; $ForumStartDateComment = "The forum will be visible starting from this date"; $ForumEndDateComment = "Once this date has passed, the forum will be closed"; $ModeratedForum = "Moderated forum"; +$DiagnosisFilledSubject = "Diagnosis filled successfully"; +$DiagnosisFilledDescription = "The diagnosis has been filled successfully"; +$UserXHasFilledTheDiagnosis = "User %s has filled the diagnosis"; +$UserXHasFilledTheDiagnosisDescription = "User %s has filled the diagnosis on the platform and it is ready for you to review."; $SendLegal = "Send legal agreement"; $DeleteLegal = "Delete legal agreement"; $LegalAccepted = "Legal accepted"; $LoadTermConditionsSectionTitle = "Load term conditions section"; $LoadTermConditionsSectionDescription = "The legal agreement will appear during the login or when enter to a course."; +$SendTermsSubject = "Your terms and conditions are ready to be signed"; +$SendTermsDescriptionToUrlX = "Hello, + +Your tutor sent you your terms and conditions. You can sign it following this url: %s"; $UserXSignedTheAgreement = "User %s signed the agreement."; $UserXSignedTheAgreementTheY = "User %s signed the agreement the %s."; +$ShowTermsIfProfileCompletedTitle = "Terms and conditions only if profile complete"; +$ShowTermsIfProfileCompletedComment = "By enabling this option, terms and conditions will be available to the user only when the extra profile fields that start with 'terms_' and set to visible are completed."; $EnableProfileUsersAddressGeolocalizationTitle = "Enable user's geolocalization"; $EnableProfileUsersAddressGeolocalizationComment = "Enable user's address field and show it on a map using geolocalization features"; +$ProfileIsNotCompleted = "You must first fill your profile to continue"; +$TermActivatedIsNeededDescription = "The terms and conditions have not yet been validated by your tutor."; +$DiagnosisManagement = "Diagnosis management"; +$TermYourProfileIsNotCompleted = "You must first fill your profile to enable the terms and conditions validation."; +$Diagnostic = "Diagnostic"; +$AllowShowSkypeAccountTitle = "Allow show the user Skype account"; +$AllowShowSkypeAccountComment = "Add a link on the user social block allowing start a chat by Skype"; +$AllowShowLinkedInUrlTitle = "Allow show the user LinkedIn URL"; +$AllowShowLinkedInUrlComment = "Add a link on the user social block, allowing visit the user's LinkedIn profile"; +$LaunchVideoConferenceRoom = "Launch videoconference room"; +$VideoConference = "Videoconference"; +$TermsDuplicatedInFile = "Terms duplicated in file"; +$GlossaryTermAlreadyExists = "Term already exists"; ?> \ No newline at end of file diff --git a/tests/main/inc/lib/glossary.lib.test.php b/tests/main/inc/lib/glossary.lib.test.php index adb0fc3c48..744a903bba 100755 --- a/tests/main/inc/lib/glossary.lib.test.php +++ b/tests/main/inc/lib/glossary.lib.test.php @@ -92,7 +92,7 @@ class TestGlossary extends UnitTestCase { function testDisplayGlossaryList() { ob_start(); - $res = GlossaryManager::display_glossary_list(); + $res = GlossaryManager::displayGlossaryList(); ob_end_clean(); $this->assertTrue($res); }