Created
February 22, 2018 00:54
-
-
Save jackbravo/576d2eebc1f98c760ca675ec414096fb to your computer and use it in GitHub Desktop.
Tell me what you see
This file contains hidden or 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