Skip to content

Commit 270fc6f

Browse files
author
Yegor Bugayenko
committed
Document.php
1 parent fd659c6 commit 270fc6f

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

Document.php

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
class Document {
3+
4+
public $user;
5+
6+
public $name;
7+
8+
public function init($name, User $user) {
9+
assert(strlen($name) > 5);
10+
$this->user = $user;
11+
$this->name = $name;
12+
}
13+
14+
public function getTitle() {
15+
$db = Database::getInstance();
16+
$row = $db->query('SELECT * FROM document WHERE name = "' . $this->name . '" LIMIT 1');
17+
return $row[3]; // third column in a row
18+
}
19+
20+
public function getContent() {
21+
$db = Database::getInstance();
22+
$row = $db->query('SELECT * FROM document WHERE name = "' . $this->name . '" LIMIT 1');
23+
return $row[6]; // sixth column in a row
24+
}
25+
26+
public static function getAllDocuments() {
27+
// to be implemented later
28+
}
29+
30+
}
31+
32+
class User {
33+
34+
public function makeNewDocument($name) {
35+
$doc = new Document();
36+
$doc->init($name, $this);
37+
return $doc;
38+
}
39+
40+
public function getMyDocuments() {
41+
$list = array();
42+
foreach (Document::getAllDocuments() as $doc) {
43+
if ($doc->user == $this)
44+
$list[] = $doc;
45+
}
46+
return $list;
47+
}
48+
49+
}

0 commit comments

Comments
 (0)