aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Accounts
diff options
context:
space:
mode:
authorChristopher Ng <chrng8@gmail.com>2022-03-08 00:49:00 +0000
committerChristopher Ng <chrng8@gmail.com>2022-03-17 16:33:19 +0000
commit2d9d0702f00410c5868482c0017fc93a06eaef90 (patch)
tree4ebe2bdf58abd10c6c08bd32ee2b3f3236aceff3 /lib/private/Accounts
parent2a75c303b5ce01f809866a0afb326663b9f9d125 (diff)
downloadnextcloud-server-2d9d0702f00410c5868482c0017fc93a06eaef90.tar.gz
nextcloud-server-2d9d0702f00410c5868482c0017fc93a06eaef90.zip
Add method to set all account properties from json
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'lib/private/Accounts')
-rw-r--r--lib/private/Accounts/Account.php22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/private/Accounts/Account.php b/lib/private/Accounts/Account.php
index 7d36af561ce..d3287b219d0 100644
--- a/lib/private/Accounts/Account.php
+++ b/lib/private/Accounts/Account.php
@@ -72,6 +72,28 @@ class Account implements IAccount {
});
}
+ public function setAllPropertiesFromJson(array $properties): IAccount {
+ foreach ($properties as $propertyName => $propertyObject) {
+ if ($this->isCollection($propertyName)) {
+ $collection = new AccountPropertyCollection($propertyName);
+ /** @var array<int, IAccountProperty> $collectionProperties */
+ $collectionProperties = [];
+ /** @var array<int, array<string, string>> $propertyObject */
+ foreach ($propertyObject as ['value' => $value, 'scope' => $scope, 'verified' => $verified, 'verificationData' => $verificationData]) {
+ $collectionProperties[] = new AccountProperty($collection->getName(), $value, $scope, $verified, $verificationData);
+ }
+ $collection->setProperties($collectionProperties);
+ $this->setPropertyCollection($collection);
+ } else {
+ /** @var array<string, string> $propertyObject */
+ ['value' => $value, 'scope' => $scope, 'verified' => $verified, 'verificationData' => $verificationData] = $propertyObject;
+ $this->setProperty($propertyName, $value, $scope, $verified, $verificationData);
+ }
+ }
+
+ return $this;
+ }
+
public function getAllProperties(): Generator {
foreach ($this->properties as $propertyObject) {
if ($propertyObject instanceof IAccountProperty) {