aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Model/Actor.php
diff options
context:
space:
mode:
authorwinter2024-12-17 20:03:55 +0000
committerwinter2024-12-17 20:03:55 +0000
commit7cb4ef6c6b82bbca3300154ae89a7bb05c1d91cd (patch)
tree24328c094598835913152affca844d208f10bd59 /Digitigrade/Model/Actor.php
parent1243bf45f04d5292c4f147b9a46c878d19cf2ba5 (diff)
add methods to create models easierly
Diffstat (limited to 'Digitigrade/Model/Actor.php')
-rw-r--r--Digitigrade/Model/Actor.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/Digitigrade/Model/Actor.php b/Digitigrade/Model/Actor.php
index 8e8799d..5974f40 100644
--- a/Digitigrade/Model/Actor.php
+++ b/Digitigrade/Model/Actor.php
@@ -18,6 +18,43 @@ class Actor extends PushableModel {
public ActorEndpoints $endpoints;
public array $extensions = [];
+ /**
+ * Creates and saves a new local actor with the specified fields pre-set
+ * @param string $handle handle local part
+ * @param ?string $displayName display name (default = same as handle)
+ * @param ?string $bio biography / description
+ * @param bool $automated is this account automated? (e.g. a bot)
+ * @param bool $requestToFollow does this account check follow requests manually?
+ * @return self
+ */
+ public static function create(
+ string $handle,
+ ?string $displayName = null,
+ ?string $bio = null,
+ bool $automated = false,
+ bool $requestToFollow = true // setting this true by default as i think it's better for privacy
+ ): self {
+ $actor = new self();
+ $actor->uri = path_to_uri("/user/$handle");
+ $actor->isLocal = true;
+ $date = new \DateTimeImmutable();
+ $actor->created = $date;
+ $actor->modified = $date;
+ // don't really need to set this as it's generated by the view at /user/:handle
+ $actor->homepage = path_to_uri("/@/$handle");
+ $actor->handle = $handle;
+ $actor->displayName = $displayName ?? $handle;
+ $actor->bio = $bio;
+ $actor->automated = $automated;
+ $actor->requestToFollow = $requestToFollow;
+ // don't actually need to set these either
+ // just need to set the basicFeed since it's a required field
+ $actor->endpoints = new ActorEndpoints();
+ $actor->endpoints->basicFeed = path_to_uri("/user/$handle/basicFeed");
+ $actor->save();
+ return $actor;
+ }
+
protected function getUpdateWhereClause(\PDO $db): ?string {
if (self::findWhere('uri = ?', [$this->uri]) != null)
return 'uri = ' . $db->quote($this->uri);