From fbb250f8efc7798bf6ab820b883bf1330b534824 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Wed, 10 Sep 2014 16:42:43 +0800 Subject: [PATCH] MDL-36014 cohorts: Support cohort visibility in Upload cohorts --- cohort/tests/behat/upload_cohorts.feature | 20 +++++++++++++------- cohort/tests/fixtures/uploadcohorts1.csv | 14 +++++++------- cohort/upload_form.php | 15 ++++++++++++++- lang/en/cohort.php | 2 +- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/cohort/tests/behat/upload_cohorts.feature b/cohort/tests/behat/upload_cohorts.feature index 2ca6592e1a2..9a70da368bc 100644 --- a/cohort/tests/behat/upload_cohorts.feature +++ b/cohort/tests/behat/upload_cohorts.feature @@ -19,13 +19,13 @@ Feature: A privileged user can create cohorts using a CSV file And I upload "cohort/tests/fixtures/uploadcohorts1.csv" file to "File" filemanager And I click on "Preview" "button" Then the following should exist in the "previewuploadedcohorts" table: - | name | idnumber | description | Context | Status | - | cohort name 1 | cohortid1 | first description | System | | - | cohort name 2 | cohortid2 | | System | | - | cohort name 3 | cohortid3 | | Miscellaneous | | - | cohort name 4 | cohortid4 | | Cat 1 | | - | cohort name 5 | cohortid5 | | Cat 2 | | - | cohort name 6 | cohortid6 | | Cat 3 | | + | name | idnumber | description | Context | visible | Status | + | cohort name 1 | cohortid1 | first description | System | 1 | | + | cohort name 2 | cohortid2 | | System | 1 | | + | cohort name 3 | cohortid3 | | Miscellaneous | 0 | | + | cohort name 4 | cohortid4 | | Cat 1 | 1 | | + | cohort name 5 | cohortid5 | | Cat 2 | 0 | | + | cohort name 6 | cohortid6 | | Cat 3 | 1 | | And I press "Upload cohorts" And I should see "Uploaded 6 cohorts" And I press "Continue" @@ -42,6 +42,12 @@ Feature: A privileged user can create cohorts using a CSV file | Cat 1 | cohort name 4 | cohortid4 | | 0 | Created manually | | Cat 2 | cohort name 5 | cohortid5 | | 0 | Created manually | | Cat 3 | cohort name 6 | cohortid6 | | 0 | Created manually | + And the "class" attribute of "cohort name 1" "table_row" should not contain "dimmed_text" + And the "class" attribute of "cohort name 2" "table_row" should not contain "dimmed_text" + And the "class" attribute of "cohort name 3" "table_row" should contain "dimmed_text" + And the "class" attribute of "cohort name 4" "table_row" should not contain "dimmed_text" + And the "class" attribute of "cohort name 5" "table_row" should contain "dimmed_text" + And the "class" attribute of "cohort name 6" "table_row" should not contain "dimmed_text" @javascript Scenario: Upload cohorts with default category context as admin diff --git a/cohort/tests/fixtures/uploadcohorts1.csv b/cohort/tests/fixtures/uploadcohorts1.csv index b9ed12ffcc9..8fe77ed628f 100644 --- a/cohort/tests/fixtures/uploadcohorts1.csv +++ b/cohort/tests/fixtures/uploadcohorts1.csv @@ -1,7 +1,7 @@ -name,idnumber,description,category -cohort name 1,cohortid1,first description, -cohort name 2,cohortid2,, -cohort name 3,cohortid3,,Miscellaneous -cohort name 4,cohortid4,,CAT1 -cohort name 5,cohortid5,,CAT2 -cohort name 6,cohortid6,,CAT3 +name,idnumber,description,category,visible +cohort name 1,cohortid1,first description,, +cohort name 2,cohortid2,,, +cohort name 3,cohortid3,,Miscellaneous,no +cohort name 4,cohortid4,,CAT1,yes +cohort name 5,cohortid5,,CAT2,0 +cohort name 6,cohortid6,,CAT3,1 diff --git a/cohort/upload_form.php b/cohort/upload_form.php index fa041aaa5df..a7ee3a81afb 100644 --- a/cohort/upload_form.php +++ b/cohort/upload_form.php @@ -359,7 +359,7 @@ class cohort_upload_form extends moodleform { $columns = $cir->get_columns(); // Check that columns include 'name' and warn about extra columns. - $allowedcolumns = array('contextid', 'name', 'idnumber', 'description', 'descriptionformat'); + $allowedcolumns = array('contextid', 'name', 'idnumber', 'description', 'descriptionformat', 'visible'); $additionalcolumns = array('context', 'category', 'category_id', 'category_idnumber', 'category_path'); $displaycolumns = array(); $extracolumns = array(); @@ -453,6 +453,19 @@ class cohort_upload_form extends moodleform { case 'idnumber': $hash[$key] = core_text::substr(clean_param($value, PARAM_RAW), 0, 254); break; case 'description': $hash[$key] = clean_param($value, PARAM_RAW); break; case 'descriptionformat': $hash[$key] = clean_param($value, PARAM_INT); break; + case 'visible': + $tempstr = trim(core_text::strtolower($value)); + if ($tempstr === '') { + // Empty string is treated as "YES" (the default value for cohort visibility). + $hash[$key] = 1; + } else { + if ($tempstr === core_text::strtolower(get_string('no')) || $tempstr === 'n') { + // Special treatment for 'no' string that is not included in clean_param(). + $value = 0; + } + $hash[$key] = clean_param($value, PARAM_BOOL) ? 1 : 0; + } + break; } } } diff --git a/lang/en/cohort.php b/lang/en/cohort.php index 68146ef390c..868194e73e4 100644 --- a/lang/en/cohort.php +++ b/lang/en/cohort.php @@ -81,7 +81,7 @@ $string['uploadcohorts_help'] = 'Cohorts may be uploaded via text file. The form * Each record is a series of data separated by commas (or other delimiters) * The first record contains a list of fieldnames defining the format of the rest of the file * Required fieldname is name -* Optional fieldnames are idnumber, description, descriptionformat, context, category, category_id, category_idnumber, category_path +* Optional fieldnames are idnumber, description, descriptionformat, visible, context, category, category_id, category_idnumber, category_path '; $string['visible'] = 'Visible'; $string['visible_help'] = "Any cohort can be viewed by users who have 'moodle/cohort:view' capability in the cohort context.
-- 2.43.0