diff options
Diffstat (limited to 'src/web/_model/profile.php')
-rw-r--r-- | src/web/_model/profile.php | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/web/_model/profile.php b/src/web/_model/profile.php new file mode 100644 index 0000000..d35cc46 --- /dev/null +++ b/src/web/_model/profile.php @@ -0,0 +1,70 @@ +<?php /* Copyright (c) 2024 Freya Murphy */ +class Profile_model extends XSS_Model { + + private $auth_model; + + function __construct() { + $this->auth_model = $this->load_model('auth'); + } + + public function get_data(): ?array { + $uid = $this->get_int('id'); + $session = $this->auth_model->session(); + + if (!$uid && $session) + $uid = $session['id']; + if (!$uid) + return NULL; + + $user = $this->db() + ->select('*') + ->from('api.user u') + ->where('u.id') + ->eq($uid) + ->row(); + + if (!$user) + return NULL; + + // am i following $uid? + $following = FALSE; + $following_id = NULL; + // is $uid following me? + $followed = FALSE; + + if ($session) { + $sid = $session['id']; + // am i following $uid? + $res = $this->db() + ->select('f.value, f.id') + ->from('xssbook.follow f') + ->where('f.follower_id') + ->eq($sid) + ->where('f.followee_id') + ->eq($uid) + ->row(); + $following = $res ? $res['value'] : FALSE; + $following_id = $res ? $res['id'] : NULL; + // is $uid following me? + $res = $this->db() + ->select('f.value') + ->from('xssbook.follow f') + ->where('f.follower_id') + ->eq($uid) + ->where('f.followee_id') + ->eq($sid) + ->row(); + $followed = $res ? $res['value'] : FALSE; + } + + $data = parent::get_data(); + $data['user'] = $user; + $data['following'] = $following; + $data['following_id'] = $following_id; + $data['followed'] = $followed; + + $name = $this->format_name($user); + $data['title'] .= " - $name"; + return $data; + } +} |