From fc1f8365da29d42ab3c366b2bff0a0868ea60d83 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey Date: Thu, 31 Jul 2014 02:29:00 +0100 Subject: [PATCH] add update-group.php integration example and required connector method --- .../connectors/groups-service-connector.php | 13 ++--- .../php/src/programs/groups/update-group.php | 50 +++++++++++++++++++ integration/php/src/utils.php | 19 +++++++ 3 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 integration/php/src/programs/groups/update-group.php diff --git a/integration/php/src/connectors/groups-service-connector.php b/integration/php/src/connectors/groups-service-connector.php index b97ad4d..02ae2d7 100644 --- a/integration/php/src/connectors/groups-service-connector.php +++ b/integration/php/src/connectors/groups-service-connector.php @@ -171,12 +171,15 @@ function AddGroup( * @return SimpleXmlElement folder XML element */ function UpdateGroup( - $serviceUri, $groupID, $charter, $groupPictureID, + $serviceUri, $groupID, $requestingUserId, $charter, $groupPictureID, $allowPublish, $maturePublish, $openEnrollment, $membershipFee, $shownInList = TRUE, $debug = FALSE) { if (!IsUuid($groupID)) - throw new InvalidArgumentException("allowPublish '$allowPublish' is not a bool"); + throw new InvalidArgumentException("groupID '$groupID' is not a UUID"); + + if (!IsUuid($requestingUserId)) + throw new InvalidArgumentException("requestingUserId '$requestingUserId' is not a UUID"); if (!is_bool($allowPublish)) throw new InvalidArgumentException("allowPublish '$allowPublish' is not a bool"); @@ -185,7 +188,7 @@ function UpdateGroup( throw new InvalidArgumentException("maturePublish '$maturePublish' is not a bool"); if (!IsUuid($groupPictureID)) - throw new InvalidArgumentException("groupPictureID '$groupPictureID' is not a valid UUID"); + throw new InvalidArgumentException("groupPictureID '$groupPictureID' is not a UUID"); if (!is_bool($openEnrollment)) throw new InvalidArgumentException("openEnrollment '$openEnrollment' is not a bool"); @@ -198,7 +201,7 @@ function UpdateGroup( $params = array( - 'RequestingAgentID' => UUID_ZERO, + 'RequestingAgentID' => $requestingUserId, 'GroupID' => $groupID, 'AllowPublish' => $allowPublish ? "true" : "false", 'MaturePublish' => $maturePublish ? "true" : "false", @@ -216,6 +219,4 @@ function UpdateGroup( $responseXml = PostToService($serviceUri, http_build_query($params), $debug); } - - ?> \ No newline at end of file diff --git a/integration/php/src/programs/groups/update-group.php b/integration/php/src/programs/groups/update-group.php new file mode 100644 index 0000000..6c82271 --- /dev/null +++ b/integration/php/src/programs/groups/update-group.php @@ -0,0 +1,50 @@ +addArgument('groupName'); +$parser->addArgument('charter'); + +try +{ + $params = $parser->parse(); +} +catch (Exception $e) +{ + $parser->displayError($e->getMessage()); + exit(1); +} + +$groupId = $params->args['groupName']; +$charter = $params->args['charter']; + +// Unfortunately, due to current OpenSimulator limitations all data is set so we have to get first +// and feed back the fields we don't want to change! +$existingGroupE = GetGroupByName($GROUPS_SERVICE_URI, $groupId)->RESULT; + +$existingFounderId = (string)$existingGroupE->FounderID; +$existingGroupId = (string)$existingGroupE->GroupID; +$existingGroupPictureId = (string)$existingGroupE->InsigniaID; +$existingAllowPublish = ToBool((string)$existingGroupE->AllowPublish); +$existingMaturePublish = ToBool((string)$existingGroupE->MaturePublish); +$existingOpenEnrollment = ToBool((string)$existingGroupE->OpenEnrollment); +$existingMembershipFee = (int)$existingGroupE->MembershipFee; +$existingShownInList = ToBool((string)$existingGroupE->ShownInList); + +echo "existingGroupId '$existingGroupId'\n"; +echo "existingGroupPictureId '$existingGroupPictureId'\n"; +echo "existingAllowPublish '$existingAllowPublish'\n"; + +UpdateGroup( + $GROUPS_SERVICE_URI, $existingGroupId, $existingFounderId, $charter, + $existingGroupPictureId, $existingAllowPublish, $existingMaturePublish, + $existingOpenEnrollment, $existingMembershipFee, $existingShownInList, TRUE); \ No newline at end of file diff --git a/integration/php/src/utils.php b/integration/php/src/utils.php index 0c01d82..2fee701 100644 --- a/integration/php/src/utils.php +++ b/integration/php/src/utils.php @@ -26,6 +26,25 @@ function IsUuid($data) return preg_match('/^[a-f\d]{8}-(?:[a-f\d]{4}-){3}[a-f\d]{12}$/i', $data); } +function ToBool($var) +{ + //echo "Got '$var' ", is_string($var), "\n"; + if (!is_string($var)) + return (bool) $var; + + switch (strtolower($var)) + { + case '1': + case 'true': + case 'on': + case 'yes': + case 'y': + return true; + default: + return false; + } +} + function GetPrettyXML($xml) { $dom = new DOMDocument();