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; } }