PHP user+document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment