Create Note object, simple database schema, and readonly web view
부모
47539de2d7
커밋
841bf184f7
@ -1,4 +1,5 @@
|
||||
vendor
|
||||
settings.php
|
||||
nbproject/private
|
||||
*.sync-conflict*
|
||||
*.sync-conflict*
|
||||
*.bak
|
Binary file not shown.
@ -0,0 +1,5 @@
|
||||
{
|
||||
"New": "New",
|
||||
"Note": "Note",
|
||||
"Edit": "Edit"
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
"home": "Home",
|
||||
"test": "Test"
|
||||
"Notes": "Notes"
|
||||
}
|
||||
|
@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
class Note {
|
||||
|
||||
private $noteid;
|
||||
private $ownerid;
|
||||
private $content = "";
|
||||
private $color = "FFFFFF";
|
||||
|
||||
/**
|
||||
* Create a new Note object.
|
||||
* @param string $content Note content in Markdown
|
||||
* @param string $color Hex color "RRGGBB"
|
||||
* @param int $ownerid The owner's user ID
|
||||
*/
|
||||
public function __construct(string $content, string $color = "FFFFFF", int $ownerid = null, int $noteid = null) {
|
||||
$this->content = $content;
|
||||
$this->color = $color;
|
||||
$this->ownerid = $ownerid;
|
||||
$this->noteid = $noteid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a note from the database and return it.
|
||||
* @global type $database
|
||||
* @param int $noteid
|
||||
* @return \Note
|
||||
* @throws NoSuchNoteException When the note ID isn't found.
|
||||
*/
|
||||
public static function loadNote(int $noteid): Note {
|
||||
global $database;
|
||||
|
||||
if (!$database->has('notes', ['noteid' => $noteid])) {
|
||||
throw new NoSuchNoteException();
|
||||
}
|
||||
|
||||
$notedata = $database->get('notes', ['noteid', 'ownerid', 'color', 'content'], ['noteid' => $noteid]);
|
||||
|
||||
return new Note($notedata['content'], $notedata['color'], $notedata['ownerid'], $notedata['noteid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the note to the database.
|
||||
* @global type $database
|
||||
* @param bool $saveas If true, save the note under a new ID. Forced to
|
||||
* true if the current note ID is missing or invalid.
|
||||
* @return int The database ID of the saved note
|
||||
* @throws Exception If there is no note owner set.
|
||||
*/
|
||||
public function saveNote(bool $saveas = false): int {
|
||||
global $database;
|
||||
|
||||
$data = [
|
||||
'ownerid' => $this->ownerid,
|
||||
'color' => $this->color,
|
||||
'content' => $this->content
|
||||
];
|
||||
|
||||
// We can't UPDATE the database, so use save as for INSERT
|
||||
if (empty($this->noteid) || !$database->has('notes', ['noteid' => $this->noteid])) {
|
||||
$saveas = true;
|
||||
}
|
||||
|
||||
if (empty($this->ownerid)) {
|
||||
throw new Exception("No owner set.");
|
||||
}
|
||||
|
||||
if ($saveas) {
|
||||
$database->insert('notes', $data);
|
||||
return $database->id();
|
||||
} else {
|
||||
$database->update('notes', $data, ['noteid' => $this->noteid]);
|
||||
return $this->noteid;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Markdown content of the note.
|
||||
* @return string
|
||||
*/
|
||||
public function getText(): string {
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML render of the note.
|
||||
* @param bool $fragment Get just the HTML content, instead of a whole HTML5 file
|
||||
* @return string
|
||||
*/
|
||||
public function getHTML(bool $fragment = true): string {
|
||||
$parsedown = new Parsedown;
|
||||
$parsedown->setSafeMode(true);
|
||||
return $parsedown->text($this->content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the note ID.
|
||||
* @return int
|
||||
*/
|
||||
public function getID(): int {
|
||||
return $this->noteid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the note color as RRGGBB hex.
|
||||
* @return string
|
||||
*/
|
||||
public function getColor(): string {
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the owner UID
|
||||
* @return int
|
||||
*/
|
||||
public function getOwnerID(): int {
|
||||
return $this->ownerid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the owner as a User object
|
||||
* @return \User
|
||||
*/
|
||||
public function getOwner(): User {
|
||||
return new User($this->ownerid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the note content
|
||||
* @param string $markdown
|
||||
*/
|
||||
public function setText(string $markdown) {
|
||||
$this->content = $markdown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the note color to a hex string
|
||||
* @param string $color "RRGGBB"
|
||||
*/
|
||||
public function setColor(string $color) {
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the owner by UID
|
||||
* @param int $uid
|
||||
*/
|
||||
public function setOwnerID(int $uid) {
|
||||
$this->ownerid = $uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the owner
|
||||
* @param User $user
|
||||
*/
|
||||
public function setOwner(User $owner) {
|
||||
$this->ownerid = $owner->getUID();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this note as an array.
|
||||
* @return string
|
||||
*/
|
||||
public function toArray(): array {
|
||||
$owner = new User($this->ownerid);
|
||||
$arr = [
|
||||
'noteid' => $this->noteid,
|
||||
'color' => $this->color,
|
||||
'content' => $this->content,
|
||||
'owner' => [
|
||||
'uid' => $owner->getUID(),
|
||||
'username' => $owner->getUsername(),
|
||||
'name' => $owner->getName()
|
||||
]
|
||||
];
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an array with the structure from toArray().
|
||||
* @param array $arr
|
||||
* @return \Note A Note constructed from the array data.
|
||||
*/
|
||||
public static function fromArray(array $arr): Note {
|
||||
return new Note($arr['content'], $arr['color'], $arr['owner']['uid'], $arr['noteid']);
|
||||
}
|
||||
|
||||
}
|
@ -1,78 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="512"
|
||||
height="512"
|
||||
viewBox="0 0 512.00001 512.00001"
|
||||
id="svg2"
|
||||
version="1.1"
|
||||
inkscape:version="0.91 r13725"
|
||||
sodipodi:docname="logo.svg"
|
||||
inkscape:export-filename="/home/skylar/Documents/Projects/Sources/WebAppTemplate/static/img/logo.png"
|
||||
inkscape:export-xdpi="90"
|
||||
inkscape:export-ydpi="90">
|
||||
<defs
|
||||
id="defs4">
|
||||
<inkscape:perspective
|
||||
sodipodi:type="inkscape:persp3d"
|
||||
inkscape:vp_x="-493.3276 : 245.89848 : 1"
|
||||
inkscape:vp_y="0 : 1000 : 0"
|
||||
inkscape:vp_z="464.45088 : 245.89848 : 1"
|
||||
inkscape:persp3d-origin="-14.438371 : 160.56515 : 1"
|
||||
id="perspective4236" />
|
||||
</defs>
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="0.49497475"
|
||||
inkscape:cx="-135.9681"
|
||||
inkscape:cy="352.66131"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
units="px" />
|
||||
<metadata
|
||||
id="metadata7">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(0,-540.36216)">
|
||||
<rect
|
||||
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:20;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.74509804"
|
||||
id="rect4726"
|
||||
width="512"
|
||||
height="512"
|
||||
x="0"
|
||||
y="540.36218"
|
||||
rx="50"
|
||||
ry="50" />
|
||||
<path
|
||||
id="path4348"
|
||||
style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:9.87128067;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 132.93564,682.51771 213.96788,-43.14304 0,313.97496 -213.96788,-37.9643 z m 213.96788,-43.14304 0,313.97496 32.16084,-45.18373 0,-217.44396 z m -213.96788,43.14304 213.96788,-43.14304 32.16084,51.34727 -167.21823,22.47784 z m 78.91049,30.68207 167.21823,-22.47784 0,217.44396 -167.21823,-19.77968 z m -78.91049,-30.68207 0,232.86762 78.91049,-26.99911 0,-175.18644 z m 0,232.86762 213.96788,37.9643 32.16084,-45.18373 -167.21823,-19.77968 z"
|
||||
inkscape:connector-curvature="0" />
|
||||
</g>
|
||||
</svg>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="512" height="512" version="1.1" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0 -540.36)"><rect y="540.36" width="512" height="512" rx="50" ry="50" fill="#fff"/><g stroke="#fff" stroke-width="7.7927"><rect x="233.35" y="641.56" width="233.78" height="233.78" rx="15.585" ry="15.585" fill="#ffeb3b"/><rect x="35.044" y="592.36" width="233.78" height="233.78" rx="15.585" ry="15.585" fill="#ef5350"/><rect x="113.35" y="755.34" width="233.78" height="233.78" rx="15.585" ry="15.585" fill="#ffeb3b"/></g></g></svg>
|
||||
|
Before Width: | Height: | 크기: 2.9 KiB After Width: | Height: | 크기: 598 B |
불러오는 중...
Reference in New Issue