|
|
|
@ -14,6 +14,7 @@ class Note {
|
|
|
|
|
private $title = "";
|
|
|
|
|
private $modified = "";
|
|
|
|
|
private $color = "FFFFFF";
|
|
|
|
|
private $favorite = false;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new Note object.
|
|
|
|
@ -42,11 +43,12 @@ class Note {
|
|
|
|
|
throw new NoSuchNoteException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$notedata = $database->get('notes', ['noteid', 'ownerid', 'color', 'content', 'title', 'modified'], ['noteid' => $noteid]);
|
|
|
|
|
$notedata = $database->get('notes', ['noteid', 'ownerid', 'color', 'content', 'title', 'modified', 'favorite'], ['noteid' => $noteid]);
|
|
|
|
|
|
|
|
|
|
$note = new Note($notedata['content'], $notedata['color'], $notedata['ownerid'], $notedata['noteid']);
|
|
|
|
|
$note->setTitle(is_null($notedata['title']) ? "" : $notedata['title']);
|
|
|
|
|
$note->setModified(is_null($notedata['modified']) ? date("Y-m-d H:i:s") : $notedata['modified']);
|
|
|
|
|
$note->setFavorite($notedata['favorite'] == true);
|
|
|
|
|
|
|
|
|
|
return $note;
|
|
|
|
|
}
|
|
|
|
@ -67,7 +69,8 @@ class Note {
|
|
|
|
|
'color' => $this->getColor(),
|
|
|
|
|
'content' => $this->getText(),
|
|
|
|
|
'title' => $this->getTitle(),
|
|
|
|
|
'modified' => $this->getModified()
|
|
|
|
|
'modified' => $this->getModified(),
|
|
|
|
|
'favorite' => $this->getFavorite() ? 1 : 0
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// We can't UPDATE the database, so use save as for INSERT
|
|
|
|
@ -167,6 +170,10 @@ class Note {
|
|
|
|
|
return $title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the note title stripped of Markdown and trimmed
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getCleanTitle(): string {
|
|
|
|
|
$title = $this->getTitle();
|
|
|
|
|
$title = str_replace("*", "", $title);
|
|
|
|
@ -187,6 +194,14 @@ class Note {
|
|
|
|
|
return date("Y-m-d H:i:s", strtotime($this->modified));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get if the note is favorited (starred).
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function getFavorite(): bool {
|
|
|
|
|
return $this->favorite;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the note content
|
|
|
|
|
* @param string $markdown
|
|
|
|
@ -232,9 +247,21 @@ class Note {
|
|
|
|
|
* @param string $datetime
|
|
|
|
|
*/
|
|
|
|
|
public function setModified(string $datetime) {
|
|
|
|
|
if (is_numeric($datetime)) {
|
|
|
|
|
$this->modified = date("Y-m-d H:i:s", $datetime);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$this->modified = date("Y-m-d H:i:s", strtotime($datetime));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the note as favorite or not
|
|
|
|
|
* @param bool $favorite
|
|
|
|
|
*/
|
|
|
|
|
public function setFavorite(bool $favorite) {
|
|
|
|
|
$this->favorite = $favorite;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get this note as an array.
|
|
|
|
|
* @return string
|
|
|
|
@ -247,6 +274,7 @@ class Note {
|
|
|
|
|
'content' => $this->getText(),
|
|
|
|
|
'title' => $this->getTitle(),
|
|
|
|
|
'modified' => $this->getModified(),
|
|
|
|
|
'favorite' => $this->getFavorite(),
|
|
|
|
|
'owner' => [
|
|
|
|
|
'uid' => $owner->getUID(),
|
|
|
|
|
'username' => $owner->getUsername(),
|
|
|
|
@ -269,7 +297,7 @@ class Note {
|
|
|
|
|
"title" => $this->getTitle(),
|
|
|
|
|
"category" => null,
|
|
|
|
|
"content" => $this->getText(),
|
|
|
|
|
"favorite" => false
|
|
|
|
|
"favorite" => $this->getFavorite()
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -304,6 +332,7 @@ class Note {
|
|
|
|
|
$note = new Note($arr['content'], $arr['color'], $arr['owner']['uid'], $arr['noteid']);
|
|
|
|
|
$note->setTitle($arr['title']);
|
|
|
|
|
$note->setModified($arr['modified']);
|
|
|
|
|
$note->setFavorite($arr['favorite']);
|
|
|
|
|
return $note;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|