blob: 3879d519957ed9fc626e3868a0364788de21f343 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
package com.jetbrains.python.edu.course;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.xmlb.annotations.Transient;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Lesson implements Stateful{
public String name;
public List<Task> taskList = new ArrayList<Task>();
private Course myCourse = null;
public int myIndex = -1;
public static final String LESSON_DIR = "lesson";
public LessonInfo myLessonInfo = new LessonInfo();
public LessonInfo getLessonInfo() {
return myLessonInfo;
}
@Transient
public StudyStatus getStatus() {
for (Task task : taskList) {
StudyStatus taskStatus = task.getStatus();
if (taskStatus == StudyStatus.Unchecked || taskStatus == StudyStatus.Failed) {
return StudyStatus.Unchecked;
}
}
return StudyStatus.Solved;
}
@Override
public void setStatus(StudyStatus status, StudyStatus oldStatus) {
for (Task task : taskList) {
task.setStatus(status, oldStatus);
}
}
public List<Task> getTaskList() {
return taskList;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
* Creates lesson directory in its course folder in project user created
*
* @param courseDir project directory of course
* @param resourceRoot directory where original lesson stored
* @throws java.io.IOException
*/
public void create(@NotNull final VirtualFile courseDir, @NotNull final File resourceRoot) throws IOException {
String lessonDirName = LESSON_DIR + Integer.toString(myIndex + 1);
VirtualFile lessonDir = courseDir.createChildDirectory(this, lessonDirName);
for (int i = 0; i < taskList.size(); i++) {
Task task = taskList.get(i);
task.setIndex(i);
task.create(lessonDir, new File(resourceRoot, lessonDir.getName()));
}
}
/**
* Initializes state of lesson
*
* @param course course which lesson belongs to
*/
public void init(final Course course, boolean isRestarted) {
myCourse = course;
myLessonInfo.setTaskNum(taskList.size());
myLessonInfo.setTaskUnchecked(taskList.size());
for (Task task : taskList) {
task.init(this, isRestarted);
}
}
public Lesson next() {
List<Lesson> lessons = myCourse.getLessons();
if (myIndex + 1 >= lessons.size()) {
return null;
}
return lessons.get(myIndex + 1);
}
public void setIndex(int index) {
myIndex = index;
}
public int getIndex() {
return myIndex;
}
public Lesson prev() {
if (myIndex - 1 < 0) {
return null;
}
return myCourse.getLessons().get(myIndex - 1);
}
}
|