/
Exercise.php
71 lines (62 loc) · 1.4 KB
/
Exercise.php
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
<?php
require_once 'Dase/DBO/Autogen/Exercise.php';
class Dase_DBO_Exercise extends Dase_DBO_Autogen_Exercise
{
public $str_lines;
public $lines = array();
public $set;
public $creator;
public function getSet()
{
$es = new Dase_DBO_ExerciseSet($this->db);
$es->load($this->exercise_set_id);
$this->set = $es;
return $this->set;
}
public function getLines($shuffle = false)
{
$line = new Dase_DBO_ExerciseLine($this->db);
$line->exercise_id = $this->id;
$line->orderBy('correct_sort_order');
$this->lines = $line->findAll(1);
//todo: guarantee that it'll never be correct sort order
if ($shuffle) {
shuffle($this->lines);
}
$set = array();
foreach ($this->lines as $ln) {
$set[] = trim($ln->text);
}
$this->str_lines = join("\n",$set);
return $this->lines;
}
public function getCorrect()
{
$lines = new Dase_DBO_ExerciseLine($this->db);
$lines->exercise_id = $this->id;
$lines->orderBy('correct_sort_order');
$correct = '';
foreach ($lines->findAll(1) as $line) {
$correct .= $line->id.'|';
}
return $correct;
}
public function deleteLines()
{
foreach ($this->getLines() as $line) {
$line->delete();
}
}
public function getCreator()
{
$u = new Dase_DBO_User($this->db);
$u->eid = $this->creator_eid;
$this->creator = $u->findOne();
return $this->creator;
}
public function delete()
{
$this->deleteLines();
parent::delete();
}
}