Page 1 of 1

Add new group using PHP API

Posted: Mon Apr 23, 2018 6:16 am
by mazda91
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 !

Re: Add new group using PHP API

Posted: Thu May 03, 2018 5:26 am
by mazda91
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 :
_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)