|
|
|
@@ -21,7 +21,7 @@ var devices_count: int
|
|
|
|
|
@export var email: String
|
|
|
|
|
var password: String
|
|
|
|
|
@export var token: String
|
|
|
|
|
@export var last_modified: String
|
|
|
|
|
@export var last_modified: String = ""
|
|
|
|
|
|
|
|
|
|
func update_from_dict(dict: Dictionary) -> void:
|
|
|
|
|
if dict.has("account_type"):
|
|
|
|
@@ -56,7 +56,8 @@ func update_student_name(student_code: int, student_name: String) -> void:
|
|
|
|
|
if student_data.code == student_code:
|
|
|
|
|
student_data.name = student_name
|
|
|
|
|
Logger.trace("TeacherSettings: Updated student code " + str(student_code) + ": new name is " + student_name)
|
|
|
|
|
(ServerManager as ServerManagerClass).update_student(student_data)
|
|
|
|
|
student_data.last_modified = Time.get_datetime_string_from_system(true)
|
|
|
|
|
UserDataManager.save_all()
|
|
|
|
|
return
|
|
|
|
|
Logger.warn("TeacherSettings: update_student_name: student not found with code " + str(student_code))
|
|
|
|
|
|
|
|
|
@@ -66,12 +67,17 @@ func update_student_device(student_code: int, new_student_device: int) -> void:
|
|
|
|
|
var studentsData: Array[StudentData] = students[current_student_device]
|
|
|
|
|
for student_data: StudentData in studentsData:
|
|
|
|
|
if student_data.code == student_code:
|
|
|
|
|
if current_student_device == new_student_device:
|
|
|
|
|
Logger.trace("TeacherSettings: update_student_device: student %d new device is already current student device, no update necessary" % student_code)
|
|
|
|
|
return
|
|
|
|
|
studentsData.erase(student_data)
|
|
|
|
|
if not students.has(new_student_device):
|
|
|
|
|
Logger.warn("TeacherSettings: update_student_device: student new device does not exists, it should not be possible. Update will still work anyway.")
|
|
|
|
|
Logger.warn("TeacherSettings: update_student_device: student %d new device does not exists, it should not be possible. Update will still work anyway." % student_code)
|
|
|
|
|
students[new_student_device] = []
|
|
|
|
|
students[new_student_device].append(student_data)
|
|
|
|
|
UserDataManager.move_user_device_folder(str(current_student_device), str(new_student_device), student_code)
|
|
|
|
|
student_data.last_modified = Time.get_datetime_string_from_system(true)
|
|
|
|
|
UserDataManager.save_all()
|
|
|
|
|
return
|
|
|
|
|
Logger.warn("TeacherSettings: update_student_device: student not found with code " + str(student_code))
|
|
|
|
|
|
|
|
|
@@ -92,25 +98,13 @@ func get_new_code() -> int :
|
|
|
|
|
var code: int = codes.pick_random()
|
|
|
|
|
return code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func get_students_count() -> int :
|
|
|
|
|
if not students:
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
var count: int = 0
|
|
|
|
|
for device: int in students.keys():
|
|
|
|
|
var students_array: Array = students[device] as Array
|
|
|
|
|
if students_array:
|
|
|
|
|
count += students_array.size()
|
|
|
|
|
|
|
|
|
|
return count
|
|
|
|
|
|
|
|
|
|
func to_dict() -> Dictionary:
|
|
|
|
|
var dict: Dictionary = {
|
|
|
|
|
"account_type": account_type,
|
|
|
|
|
"email": email,
|
|
|
|
|
"password": password,
|
|
|
|
|
"education_method": education_method,
|
|
|
|
|
"last_modified": last_modified,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dict["students"] = {}
|
|
|
|
@@ -123,6 +117,8 @@ func to_dict() -> Dictionary:
|
|
|
|
|
return dict
|
|
|
|
|
|
|
|
|
|
func get_number_of_students() -> int:
|
|
|
|
|
if not students:
|
|
|
|
|
return 0
|
|
|
|
|
var result: int = 0
|
|
|
|
|
for datas: Array[StudentData] in students.values():
|
|
|
|
|
result += datas.size()
|
|
|
|
@@ -133,3 +129,36 @@ func get_all_students_data() -> Array[StudentData]:
|
|
|
|
|
for datas: Array[StudentData] in students.values():
|
|
|
|
|
result.append_array(datas)
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
func delete_student(student_code: int) -> void:
|
|
|
|
|
for device: int in students.keys():
|
|
|
|
|
for index: int in students[device].size():
|
|
|
|
|
if students[device][index].code == student_code:
|
|
|
|
|
students[device].remove_at(index)
|
|
|
|
|
if students[device].is_empty():
|
|
|
|
|
students.erase(device)
|
|
|
|
|
return
|
|
|
|
|
Logger.warn("TeacherSettings: Trying to delete student, but code %d not found" % student_code)
|
|
|
|
|
|
|
|
|
|
func get_student_with_code(student_code: int) -> StudentData:
|
|
|
|
|
for student_data: StudentData in get_all_students_data():
|
|
|
|
|
if student_data.code == student_code:
|
|
|
|
|
return student_data
|
|
|
|
|
return null
|
|
|
|
|
|
|
|
|
|
func get_student_device(student_code: int) -> int:
|
|
|
|
|
for device: int in students.keys():
|
|
|
|
|
for index: int in students[device].size():
|
|
|
|
|
if students[device][index].code == student_code:
|
|
|
|
|
return device
|
|
|
|
|
return -1
|
|
|
|
|
|
|
|
|
|
func set_data_student_with_code(student_code: int, new_device_id: int, new_name: String, new_age: int, new_last_modified: String) -> void:
|
|
|
|
|
update_student_device(student_code, new_device_id)
|
|
|
|
|
for student_data: StudentData in students[new_device_id]:
|
|
|
|
|
if student_data.code == student_code:
|
|
|
|
|
student_data.name = new_name
|
|
|
|
|
student_data.age = new_age
|
|
|
|
|
student_data.last_modified = new_last_modified
|
|
|
|
|
return
|
|
|
|
|
Logger.error("TeacherSettings: Student %d not found to set data on it" % student_code)
|
|
|
|
|