-
Notifications
You must be signed in to change notification settings - Fork 342
/
Document.php
49 lines (38 loc) · 1.11 KB
/
Document.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
<?php
class Document {
public $user;
public $name;
public function init($name, User $user) {
assert(strlen($name) > 5);
$this->user = $user;
$this->name = $name;
}
public function getTitle() {
$db = Database::getInstance();
$row = $db->query('SELECT * FROM document WHERE name = "' . $this->name . '" LIMIT 1');
return $row[3]; // third column in a row
}
public function getContent() {
$db = Database::getInstance();
$row = $db->query('SELECT * FROM document WHERE name = "' . $this->name . '" LIMIT 1');
return $row[6]; // sixth column in a row
}
public static function getAllDocuments() {
// to be implemented later
}
}
class User {
public function makeNewDocument($name) {
$doc = new Document();
$doc->init($name, $this);
return $doc;
}
public function getMyDocuments() {
$list = array();
foreach (Document::getAllDocuments() as $doc) {
if ($doc->user == $this)
$list[] = $doc;
}
return $list;
}
}