aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Model/Note.php
diff options
context:
space:
mode:
Diffstat (limited to 'Digitigrade/Model/Note.php')
-rw-r--r--Digitigrade/Model/Note.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/Digitigrade/Model/Note.php b/Digitigrade/Model/Note.php
index 1e867fa..e80d972 100644
--- a/Digitigrade/Model/Note.php
+++ b/Digitigrade/Model/Note.php
@@ -29,6 +29,43 @@ class Note extends PushableModel {
public array $attachments = [];
public array $extensions = [];
+ /**
+ * Creates and saves a new note with the specified fields pre-set
+ * @param Actor $author who wrote the note
+ * @param string $plainContent text of the note, without any markup
+ * @param string $language ISO 639-3 3-letter language code
+ * @param ?string $summary summary line or content warning
+ * @param NotePrivacyScope $scope who is allowed to view this note
+ * @param bool $indexable whether this note should be findable e.g. in search results
+ * @return self
+ */
+ public static function create(
+ Actor $author,
+ string $plainContent,
+ string $language,
+ ?string $summary = null,
+ NotePrivacyScope $scope = NotePrivacyScope::PUBLIC ,
+ bool $indexable = true
+ ): self {
+ $note = new self();
+ // can't set the note uri properly until it's been saved and we have an id
+ $note->uri = "UNKNOWN";
+ $note->created = new \DateTimeImmutable();
+ $note->author = $author;
+ $note->summary = $summary;
+ $note->plainContent = $plainContent;
+ $note->language = $language;
+ $note->privacy = new NotePrivacy();
+ $note->privacy->scope = $scope;
+ $note->privacy->indexable = $indexable;
+
+ $note->save();
+ $note->uri = path_to_uri("/post/$note->id");
+ $note->save();
+
+ return $note;
+ }
+
protected function getUpdateWhereClause(\PDO $db): ?string {
if (self::findWhere('uri = ?', [$this->uri]) != null)
return 'uri = ' . $db->quote($this->uri);