Skip to content
Browse files

MDL-36710 calendar: Implementing proper required rules for filepicker

  • Loading branch information...
1 parent 17475a2 commit cfb59253f61a679436b4bab38a1a49728d315fe6 @ankitagarwal ankitagarwal committed Nov 22, 2012
Showing with 18 additions and 7 deletions.
  1. +18 −7 calendar/managesubscriptions_form.php
View
25 calendar/managesubscriptions_form.php
@@ -105,19 +105,30 @@ public function definition() {
* @return array
*/
public function validation($data, $files) {
+ global $USER;
+
$errors = parent::validation($data, $files);
- if (empty($data['url']) && empty($data['importfile'])) {
- if (!empty($data['importfrom']) && $data['importfrom'] == CALENDAR_IMPORT_FROM_FILE) {
+ if ($data['importfrom'] == CALENDAR_IMPORT_FROM_FILE) {
+ if (empty($data['importfile'])) {
$errors['importfile'] = get_string('errorrequiredurlorfile', 'calendar');
} else {
- $errors['url'] = get_string('errorrequiredurlorfile', 'calendar');
- }
- } else if (!empty($data['url'])) {
- if (clean_param($data['url'], PARAM_URL) !== $data['url']) {
- $errors['url'] = get_string('invalidurl', 'error');
+ // Make sure the file area is not empty and contains only one file.
+ $draftitemid = $data['importfile'];
+ $fs = get_file_storage();
+ $usercontext = context_user::instance($USER->id);
+ $files = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id DESC', false);
+ if (count($files) !== 1) {
+ $errors['importfile'] = get_string('errorrequiredurlorfile', 'calendar');
+ }
}
+ } else if (($data['importfrom'] == CALENDAR_IMPORT_FROM_URL) && (clean_param($data['url'], PARAM_URL) !== $data['url'])) {
+ $errors['url'] = get_string('invalidurl', 'error');
+ } else {
+ // Shouldn't happen.
+ $errors['url'] = get_string('errorrequiredurlorfile', 'calendar');
}
+
return $errors;
}

0 comments on commit cfb5925

Please sign in to comment.
Something went wrong with that request. Please try again.