X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fpoco.php;h=2bc9e7276244117e0040a5a85074d3ce8b6aff85;hb=dd93420b08910a8bf9967dad7906351695d1ac55;hp=d7b082163ee21eb4199be57d17463f49f21f7fc5;hpb=8eb66467165e107d0c80c64f6c429fed1d1101d5;p=quix0rs-gnu-social.git diff --git a/lib/poco.php b/lib/poco.php index d7b082163e..2bc9e72762 100644 --- a/lib/poco.php +++ b/lib/poco.php @@ -137,12 +137,8 @@ class PoCo return null; } - function fromProfile($profile) + static function fromProfile(Profile $profile) { - if (empty($profile)) { - return null; - } - $poco = new PoCo(); $poco->preferredUsername = $profile->nickname; @@ -168,12 +164,8 @@ class PoCo return $poco; } - function fromGroup($group) + static function fromGroup(User_group $group) { - if (empty($group)) { - return null; - } - $poco = new PoCo(); $poco->preferredUsername = $group->nickname; @@ -241,4 +233,42 @@ class PoCo $url->outputTo($xo); } } + + /** + * Output a Portable Contact as an array suitable for serializing + * as JSON + * + * @return $array the PoCo array + */ + + function asArray() + { + $poco = array(); + + $poco['preferredUsername'] = $this->preferredUsername; + $poco['displayName'] = $this->displayName; + + if (!empty($this->note)) { + $poco['note'] = $this->note; + } + + if (!empty($this->address)) { + $poco['addresses'] = $this->address->asArray(); + } + + if (!empty($this->urls)) { + + $urls = array(); + + foreach ($this->urls as $url) { + $urls[] = $url->asArray(); + } + + $poco['urls'] = $urls; + } + + return $poco; + } + } +