get('net15.restifier.dispatch')->map('VIEW',$this,'listServices'); return $this->get('net15.restifier.dispatch')->exec(); } public function serviceAction(){ $this->get('net15.restifier.dispatch')->map('VIEW',$this,'listServices'); $this->get('net15.restifier.dispatch')->map('POST',$this,'listServices'); $this->get('net15.restifier.dispatch')->map('PROPFIND',$this,'detailService'); return $this->get('net15.restifier.dispatch')->exec(); } /* * logic */ public function detailService() { $data = $this->get('net15.restifier.dispatch')->getUnserialized(); if(!isset($data['service']['publicKey'])) return $this->get('net15.restifier.dispatch')->error('Data #1 is missing'); $s = $this->get('net15.company.service.manager')->getByPublicKey($data['service']['publicKey']); if(!$s instanceof CustomCompanyServiceInterface) return $this->get('net15.restifier.dispatch')->error('Cannot get data #1'); $u = $this->getUser(); if(!$u instanceof CustomUserInterface) return $this->get('net15.restifier.dispatch')->error('Cannot get data #2'); if(!$this->get('net15.company.manager')->canView($s->getCompany(), $u)) return $this->get('net15.restifier.dispatch')->error('Access denied #1'); $ret = $this->get('net15.restifier.process')->objectToArray($s, ['id','name','publicKey']); $list = $this->get('net15.company.role.manager')->getWhereServiceIs($s); $ret['employee'] = $this->get('net15.restifier.process')->objectsToArray($list, ['id','name','publicKey']); return new JsonResponse($ret); } public function listServices() { $data = $this->get('net15.restifier.dispatch')->getUnserialized(); if(!isset($data['company']['publicKey'])) return $this->get('net15.restifier.dispatch')->error('Data #1 is missing'); $c = $this->get('net15.company.manager')->getByPublicKey($data['company']['publicKey']); if(!$c instanceof CustomCompanyInterface) return $this->get('net15.restifier.dispatch')->error('Cannot get data #1'); $u = $this->getUser(); if(!$u instanceof CustomUserInterface) return $this->get('net15.restifier.dispatch')->error('Cannot get data #2'); if(!$this->get('net15.company.manager')->canView($c, $u)) return $this->get('net15.restifier.dispatch')->error('Access denied #1'); $list = $this->get('net15.company.service.manager')->getServicesFor($c); $ret = $this->get('net15.restifier.process')->objectsToArray($list, ['id','name','publicKey']); if(!is_array($ret)) $ret = []; return new JsonResponse($ret); } }