Add new group using PHP API

Any issue about Cyclos 4 scripting and Webservices

Moderators: hugo, alexandre, rmvanarkel

Post Reply
mazda91
Posts: 4
Joined: Fri Apr 20, 2018 9:59 am

Add new group using PHP API

Post by mazda91 » Mon Apr 23, 2018 6:16 am

Hello !

I am using PHP API or Cyclos4 PRO and trying to settle the system architecture. For this, I need to create a new group, what I can't manage to achieve.

I think that I should probably use the function 'getDataForNew' of the GroupService class, then update the DTO object returned and save this DTO. If this is the process to do it, the missing information is : what is the format parameter to give to the function 'getDataForNew' ? It expects a DP(DataParams) type, but there is not GroupDataParams in the documentation.

The code would be something like this :

$groupService = new Cyclos\GroupService();
$groupDP = new \stdClass();
//here fill the necessary attributes
...

$groupDTO = $groupService->getDataForNew($groupDP)->dto;

//here update $groupDTO
...

return $groupService->save($groupDTO);

Am I right ?

Thanks for your help !

mazda91
Posts: 4
Joined: Fri Apr 20, 2018 9:59 am

Re: Add new group using PHP API

Post by mazda91 » Thu May 03, 2018 5:26 am

I found a solution, hopefully it will help someone else. It actually looks like the option I described above.

Instead of looking for a kind of "groupDataParams" not available in the documentation (whereas transferTypeDataParams exists for instance), I did as follow :

_ retrieve the ID $id of an existing group, then get the groupDTO object using :
$groupService = new Cyclos\GroupService();
$groupDTO = $groupService->load($id)
_unset the id of the DTO object :
unset($groupDTO->id)
_modify the parameters you want, for instance :
$groupDTO->name = ThierryHenryKingOfLondon
$groupDTO->internalName = LondonIsRed
_save the object in Cyclos, it will be a new one (because the id is not specified I guess)
$groupService->save($groupDTO)

Post Reply