Skip to content

Instantly share code, notes, and snippets.

@jackbravo
Created February 22, 2018 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackbravo/576d2eebc1f98c760ca675ec414096fb to your computer and use it in GitHub Desktop.
Save jackbravo/576d2eebc1f98c760ca675ec414096fb to your computer and use it in GitHub Desktop.
Tell me what you see
<?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