public function POST_createAgentRelation() { $this->requireAuthentication(); $app = App::i(); if (!$this->urlData['id']) { $app->pass(); } $has_control = key_exists('has_control', $this->postData) && $this->postData['has_control']; $owner = $this->repository->find($this->data['id']); if (key_exists('agentId', $this->postData)) { $agent = $app->repo('Agent')->find($this->data['agentId']); } else { $agent = new \MapasCulturais\Entities\Agent(); $agent->status = key_exists('invite', $this->postData) && $this->postData['invite'] ? Agent::STATUS_INVITED : Agent::STATUS_RELATED; foreach ($this->postData['agent'] as $prop => $val) { $agent->{$prop} = $val; } $agent->save(true); } $this->json($owner->createAgentRelation($agent, $this->postData['group'], $has_control)); }