| @@ 15-34 (lines=20) @@ | ||
| 12 | /** |
|
| 13 | * Validates imported data. |
|
| 14 | */ |
|
| 15 | function validate_data($classes) { |
|
| 16 | $errors = array(); |
|
| 17 | foreach ($classes as $index => $class) { |
|
| 18 | // 1. Check wheter ClassName is available. |
|
| 19 | if (!isset($class['ClassName']) || strlen(trim($class['ClassName'])) == 0) { |
|
| 20 | $class['line'] = $index + 2; |
|
| 21 | $class['error'] = get_lang('MissingClassName'); |
|
| 22 | $errors[] = $class; |
|
| 23 | } |
|
| 24 | // 2. Check whether class doesn't exist yet. |
|
| 25 | else { |
|
| 26 | if (ClassManager::class_name_exists($class['ClassName'])) { |
|
| 27 | $class['line'] = $index + 2; |
|
| 28 | $class['error'] = get_lang('ClassNameExists').' <strong>'.$class['ClassName'].'</strong>'; |
|
| 29 | $errors[] = $class; |
|
| 30 | } |
|
| 31 | } |
|
| 32 | } |
|
| 33 | return $errors; |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * Save imported class data to database |
|
| @@ 13-34 (lines=22) @@ | ||
| 10 | /** |
|
| 11 | * Validates imported data. |
|
| 12 | */ |
|
| 13 | function validate_data($classes) { |
|
| 14 | $errors = array(); |
|
| 15 | $usergroup = new UserGroup(); |
|
| 16 | foreach ($classes as $index => $class) { |
|
| 17 | // 1. Check of class name is available. |
|
| 18 | if (!isset($class['name']) || strlen(trim($class['name'])) == 0) { |
|
| 19 | $class['line'] = $index + 2; |
|
| 20 | $class['error'] = get_lang('MissingClassName'); |
|
| 21 | $errors[] = $class; |
|
| 22 | } else { |
|
| 23 | // 2. Check whether class doesn't exist yet. |
|
| 24 | if ($usergroup->usergroup_exists($class['name'])) { |
|
| 25 | $class['line'] = $index + 2; |
|
| 26 | $class['error'] = get_lang('ClassNameExists') . |
|
| 27 | ': <strong>' .$class['name'] . '</strong>'; |
|
| 28 | $errors[] = $class; |
|
| 29 | } |
|
| 30 | } |
|
| 31 | } |
|
| 32 | ||
| 33 | return $errors; |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * Save imported class data to database |
|