aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Model/FollowRelation.php
diff options
context:
space:
mode:
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