Skip to content

Commit

Permalink
MDL-36014 cohorts: Support cohort visibility in Upload cohorts
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Oct 3, 2014
1 parent 80f9846 commit fbb250f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
20 changes: 13 additions & 7 deletions cohort/tests/behat/upload_cohorts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions cohort/tests/fixtures/uploadcohorts1.csv
Original file line number Diff line number Diff line change
@@ -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
15 changes: 14 additions & 1 deletion cohort/upload_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ protected function process_upload_file($file, $encoding, $delimiter, $defaultcon
$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();
Expand Down Expand Up @@ -453,6 +453,19 @@ protected function clean_cohort_data(&$hash) {
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;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lang/en/cohort.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
* 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.<br/>
Expand Down

0 comments on commit fbb250f

Please sign in to comment.