aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Model/FollowRelation.php
diff options
context:
space:
mode:
authorwinter2024-12-19 20:59:18 +0000
committerwinter2024-12-19 20:59:18 +0000
commit72b07245f44c73ed41bfcca2465a9ee34426a922 (patch)
tree57372703100ad792c95c665a568aabe8a763bfdf /Digitigrade/Model/FollowRelation.php
parent1e070a7a0097c74f8ac30678d39267f19c76f9f6 (diff)
implement follow relationships (untested)
does NOT implement the actual behaviour behind follows (receiving posts and such)
Diffstat (limited to 'Digitigrade/Model/FollowRelation.php')
-rw-r--r--Digitigrade/Model/FollowRelation.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/Digitigrade/Model/FollowRelation.php b/Digitigrade/Model/FollowRelation.php
new file mode 100644
index 0000000..fc43a6f
--- /dev/null
+++ b/Digitigrade/Model/FollowRelation.php
@@ -0,0 +1,37 @@
+<?php
+namespace Digitigrade\Model;
+
+use Digitigrade\Model;
+
+class FollowRelation extends Model {
+ public Actor $subject;
+ public Actor $object;
+ public FollowRelationStatus $status;
+
+ /**
+ * Creates and saves a new follower/following relationship
+ * @param Actor $subject the follower
+ * @param Actor $object the followee
+ * @param FollowRelationStatus $status whether the relationship is pending or active
+ * @return FollowRelation
+ */
+ public static function create(Actor $subject, Actor $object, FollowRelationStatus $status): self {
+ $rel = new self();
+ $rel->subject = $subject;
+ $rel->object = $object;
+ $rel->status = $status;
+ $rel->save();
+ return $rel;
+ }
+
+ protected function getUpdateWhereClause(\PDO $db): ?string {
+ if (self::findWhere('subject = ? and object = ?', [$this->subject->id, $this->object->id]) != null) {
+ return 'subject = ' . $this->subject->id . ' and object = ' . $this->object->id;
+ }
+ return null;
+ }
+
+ public static function findByActors(Actor $subject, Actor $object): ?self {
+ return self::findWhere('subject = ? and object = ?', [$subject->id, $object->id]);
+ }
+} \ No newline at end of file