From 48586d6a08a8c088242b5f85232fcaaba463110e Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Thu, 25 May 2017 13:06:13 +1200 Subject: [PATCH] Added id to the `User`'s `toJson`, and replaced call to `getId()` for the owner in `Room`'s `toJson` with a null check. This means that `toJson` can be called on a `Room` regardless of if it has an owner or not (since rooms returned by get_all_rooms don't have their owners included in the return), and by adding the `id` field to `User`'s `toJson`, the api remains backwards compatible. --- Model/Room.php | 4 ++-- Model/User.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Model/Room.php b/Model/Room.php index 297171b..8b290e8 100644 --- a/Model/Room.php +++ b/Model/Room.php @@ -93,8 +93,8 @@ public function toJson() $json['is_archived'] = $this->isArchived(); $json['is_guest_accessible'] = $this->isGuestAccessible(); $json['topic'] = $this->getTopic(); - $json['owner'] = array('id' => $this->getOwner()->getId()); - } else { //Paramters for POST call + $json['owner'] = is_null($this->getOwner()) ? null : $this->getOwner()->toJson(); + } else { //Parameters for POST call $json['guest_access'] = $this->isGuestAccessible(); if ($this->getOwner()) { $json['owner_user_id'] = $this->getOwner()->getId(); diff --git a/Model/User.php b/Model/User.php index 7d3d6cb..9657b3a 100644 --- a/Model/User.php +++ b/Model/User.php @@ -83,6 +83,7 @@ public function parseJson($json) public function toJson() { $json = array(); + $json['id'] = $this->id; $json['name'] = $this->name; $json['title'] = $this->title; $json['mention_name'] = $this->mentionName;