public function addAction() { $newName = $this->request->getQuery("name", "string", null); if (!$newName) { return $this->json(['success' => false, 'message' => 'Missing Name']); } $service = new Service(); $service->name = $newName; return $this->json(['success' => $service->save()]); }
public function createCallAction() { if (!$this->user) { return $this->json(['success' => false, 'message' => 'Invalid Email-Token']); } // Get Service $service = $this->request->getQuery("service", "string", null); if (!$service) { return $this->json(['success' => false, 'message' => 'Invalid Service']); } // Search Providers $lat = (double) $this->request->getQuery("lat", "string", null); $lon = (double) $this->request->getQuery("lon", "string", null); $providers = User::find(['conditions' => ['location' => ['$near' => [$lat, $lon]], 'services' => $service], 'limit' => 10]); if (!$providers) { return $this->json(['success' => false, 'message' => 'Providers not found']); } $pushIds = []; $call = new Call(); $call->service = $service; $call->user = $this->user->_id; $call->location = [$lat, $lon]; foreach ($providers as $provider) { $call->providers[] = $provider->_id; $pushIds[] = $provider->registrationId; } $call->save(); // Contact Providers $service = Service::findById($service); Push::send('Serviço: ' . $service->name, $pushIds); return $this->json(['success' => true]); }