public function update($data)
 {
     $response = new ApiResponse();
     $status = 200;
     $mission = Mission::find(\Request::get('id'));
     if ($mission == null) {
         $response->status = 'error';
         $response->message = ['id' => '', 'code' => 'mission_not_found', 'description' => 'The mission was not found'];
         $status = 400;
     } else {
         $mission = $this->sanitize($data, $mission);
         try {
             $this->radicalIntegrationManager->updateMission($mission);
         } catch (RadicalApiException $e) {
             Log::error($e);
             //For now ingore, see [CIT-380]
             //                $response->status = 'error';
             //                $response->message = $e->getMessage();
             //                $status = 500;
         }
         $mission->save();
         $response->status = 'success';
         $response->message = $mission->id;
     }
     return \Response::json($response, $status);
 }
 public function getObservationsByDate($missionId, $date)
 {
     $response = new ApiResponse();
     if ($missionId != null) {
         $mission = Mission::with('devices')->find($missionId);
         if ($mission == null) {
             $response->status = 'error';
             $response->message = ['id' => '', 'code' => 'mission_null', 'description' => 'The mission was not found'];
             return \Response::json($response);
         }
         $timestamp = \Carbon::parse($date)->timestamp;
         //for each device, get its observations
         foreach ($mission->devices as $device) {
             $deviceUUID = env('RADICAL_CITYNAME') . '.' . $mission->radical_service_id . '.' . $device->device_uuid;
             $obs = $this->radicalIntegrationManager->getMeasurementsByDeviceUUID($deviceUUID, $timestamp);
             $device->measurements = json_decode($obs);
         }
         $response->status = 'success';
         $response->message = ['mission' => $mission];
         return \Response::json($response);
     } else {
         $response->status = 'error';
         $response->message = ['id' => '', 'code' => 'mission_id_null', 'description' => 'The missionId should not null'];
         return \Response::json($response);
     }
 }
 /**
  * Run the database seeds.
  * Use php artisan db:seed to run the seed files.
  *
  * @return void
  */
 public function run()
 {
     $radical = new RadicalIntegrationManager();
     $radical->registerMission(Mission::create(['name' => 'Cafe/Bar προσβάσιμα σε ΑμεΑ', 'description' => 'Ποιους χώρους μπορούν να απολαύσουν οι συμπολίτες μας με κινητικές αναπηρίες; Μοιραστείτε Cafe/Bar που είναι προσβάσιμα από ΑμεΑ. Η Αθήνα είναι όμορφη. Και πρέπει να την χαίρονται όλοι ανεξαιρέτως. Για τους συνανθρώπους μας με κινητικές αναπηρίες πρέπει να κάνουμε πολλά, που δεν γίνονται από τη μια μέρα στην άλλη. Ας αρχίσουμε να δίνουμε λύσεις σήμερα. Για να γίνεται η Αθήνα σιγά - σιγά η πόλη του “μπορώ”.', 'type_id' => 1, 'radical_service_id' => 'cityrus_cafeBarForDisabled']));
     $radical->registerMission(Mission::create(['name' => 'Διαδρομές και χώροι αναψυχής προσβάσιμοι από ΑμεΑ', 'description' => 'Πού μπορούν να κινηθούν με το αναπηρικό αμαξίδιο οι συμπολίτες μας με κινητικές αναπηρίες; Ποιούς χώρους  αναψυχής μπορούν να επισκεφτούν; Τους ξέρετε; Πόσους από αυτούς επισκεφτήκατε και θέλετε να το μοιραστείτε; Καταγράψτε τις διαδρομές και τα Cafe/Bar που θα επιτρέψουν και σε άλλους να απολαύσουν λίγο περισσότερο αυτούς τους ξεχωριστούς χώρους. Και μην παραλείψετε να ενημερώνεστε για τα νέα προσβάσιμα σημεία που συνεισφέρουν άλλοι χρήστες από το χάρτη.', 'type_id' => 2, 'radical_service_id' => 'cityrus_routesForDisabled']));
     $radical->registerMission(Mission::create(['name' => 'Όμορφες διαδρομές για περπάτημα', 'description' => 'Ας απολαύσουμε βόλτες στην πόλη! Για ψώνια, για τη φανταστική θέα, για την ιστορία, για ρομαντζάδα, για να ονειρεύεστε... πού σας αρέσει να περπατάτε; Μοιραστείτε το για να μάθουμε και οι υπόλοιποι αυτά τα υπέροχα μέρη! Και μην ξεχάσετε να μάθετε για νέες διαδρομές για περπάτημα που έχουν συνεισφέρει άλλοι χρήστες από το χάρτη. Η Αθήνα είναι μέρος για βόλτα. Ας τη χαρούμε όλοι!', 'type_id' => 2, 'radical_service_id' => 'cityrus_niceWalkRoutes']));
     $radical->registerMission(Mission::create(['name' => 'Όμορφες διαδρομές για τρέξιμο', 'description' => 'Η κίνηση είναι ζωή! Το τρέξιμο στην πόλη είναι ολοένα για περισσότερους από εμάς ένας υπέροχος τρόπος να ηρεμήσουμε, να αδειάσουμε το μυαλό μας από έγνοιες, να γυμναστούμε, να αποκτήσουμε αντοχή... Τα οφέλη είναι πάμπολλα και δύσκολα περιγράφονται! Καταγράψτε πού σας αρέσει να τρέχετε. Πού απολαμβάνετε το τρέξιμο; Μοιραστείτε το με άλλους! Και μην ξεχάσετε να μάθετε για νέες διαδρομές για τρέξιμο που έχουν συνεισφέρει άλλοι χρήστες από το χάρτη.', 'type_id' => 2, 'radical_service_id' => 'cityrus_niceRunningRoutes']));
     $radical->registerMission(Mission::create(['name' => 'Όμορφες διαδρομές για ποδηλασία', 'description' => 'Το ποδήλατο είναι ελευθερία! Ποιες διαδρομές είναι ωραίες για ποδηλατοβόλτες; Πού σας αρέσει να πηγαίνετε με το ποδήλατο; Και μην ξεχάσετε να μάθετε για νέες διαδρομές για ποδήλατο που έχουν συνεισφέρει άλλοι χρήστες από το χάρτη.', 'type_id' => 2, 'radical_service_id' => 'cityrus_niceBicyclingRoutes']));
 }
Example #4
0
 public function observationReward()
 {
     $mission = Mission::with('type')->find(\Request::get('mission_id'));
     if ($mission->type->name == 'location') {
         return $this->locationReward(\Auth::user()->id, $mission->id);
     } else {
         return $this->routeReward(\Auth::user()->id, $mission->id);
     }
 }
 /**
  * Get the top contributors for a certain mission
  *
  * @return \Illuminate\Http\JsonResponse
  *
  * @SWG\Get(
  *     summary="Get the top contributors for a certain mission",
  *     path="/missions/topContributors",
  *     description="Get the top contributors",
  *     operationId="api.missions.topContributors",
  *     produces={"application/json"},
  *     tags={"missions"},
  *     @SWG\Parameter(
  *       name="missionId",
  *       description="The mission's id",
  *       required=true,
  *       type="string",
  *       in="query"
  *     ),
  *     @SWG\Response(
  *         response=200,
  *         description="",
  *     ),
  *     @SWG\Response(
  *         response=400,
  *         description="Unauthorized action",
  *     )
  * )
  */
 public function topContributors()
 {
     $mission = Mission::with('devices.observations', 'devices.user')->find(\Request::get('missionId'));
     $users = [];
     if ($mission != null) {
         foreach ($mission->devices as $device) {
             $device->user->totalContribution = sizeof($device->observations);
             array_push($users, $device->user);
         }
         $response = new ApiResponse();
         $response->status = 'success';
         $response->message = ['users' => $users];
         return \Response::json($response);
     } else {
         $response = new ApiResponse();
         $response->status = 'error';
         $response->message = [];
         return \Response::json($response);
     }
 }
 /**
  * Validate the observation data before performing any action
  *
  */
 private function validateObservation()
 {
     $response = new ApiResponse();
     if (!\Request::has('device_uuid')) {
         $response->status = 'error';
         $response->message = ['id' => '', 'code' => 'device_uuid_null', 'description' => 'The device uuid should not be null'];
     } else {
         $device = Device::where('device_uuid', \Request::get('device_uuid'))->first();
         if ($device == null) {
             $response->status = 'error';
             $response->message = ['id' => '', 'code' => 'device_not_found', 'description' => 'The device could not be found'];
         }
     }
     if (!\Request::has('mission_id')) {
         $response->status = 'error';
         $response->message = ['id' => '', 'code' => 'mission_id_null', 'description' => 'The mission id should not be null'];
     } else {
         //check that the mission_id exists
         $this->mission = Mission::with('type')->find(\Request::get('mission_id'));
         if ($this->mission == null) {
             $response->status = 'error';
             $response->message = ['id' => '', 'code' => 'mission_id_not_found', 'description' => 'The requested mission could not be found'];
         }
     }
     if (\Request::has('observation_date')) {
         if (!$this->validateDate(\Request::get('observation_date'))) {
             $response->status = 'error';
             $response->message = ['id' => '', 'code' => 'wrong_date_format', 'description' => 'The date should be in the following format: Y-m-d hh:mm:ss'];
         }
     }
     if (\Request::has('latitude') && !is_numeric(\Request::get('latitude')) || \Request::has('longitude') && !is_numeric(\Request::get('longitude'))) {
         $response->status = 'error';
         $response->message = ['id' => '', 'code' => 'coordinates_not_numeric', 'description' => 'The coordinates of the observation should be numeric'];
     }
     if (!\Request::has('measurements')) {
         $response->status = 'error';
         $response->message = ['id' => '', 'code' => 'measurements_null', 'description' => 'The measurements should not be null'];
     } else {
         foreach (\Request::get('measurements') as $measurement) {
             if (!isset($measurement['latitude']) || $measurement['latitude'] == '' || !isset($measurement['longitude']) || $measurement['longitude'] == '') {
                 $response->status = 'error';
                 $response->message = ['id' => '', 'code' => 'coordinates_null', 'description' => 'The coordinates of the measurements should not be null'];
             } else {
                 if (!is_numeric($measurement['latitude']) || !is_numeric($measurement['longitude'])) {
                     $response->status = 'error';
                     $response->message = ['id' => '', 'code' => 'coordinates_not_numeric', 'description' => 'The coordinates of the measurements should be numeric'];
                 }
             }
         }
     }
     return $response;
 }
Example #7
0
 /**
  * Bind data to the view.
  *
  * @param  View  $view
  * @return void
  */
 public function compose(View $view)
 {
     $society = $view->getData()['soc'];
     $data['services'] = Society::with('service')->where('society', '=', $society)->first();
     foreach ($data['services']->service as $service) {
         if ($service['language'] == "English" and $service['description'] == "") {
             $service->description = "Our " . $service->servicetime . " service is led in English by a minister or local preacher and a team of musicians. Everyone is welcome!";
         } elseif ($service['language'] == "isiZulu" and $service['description'] == "") {
             $service->description = "Our " . $service->servicetime . " service is led in isiZulu by a minister or local preacher and uses the liturgy and music of the Methodist Hymn Book. Everyone is welcome!";
         }
         $data['allservices'][] = $service;
     }
     if (!count($data['services'])) {
         return View::make('errors.404');
     }
     if (isset($view->getData()['pagetitle'])) {
         $data['pagetitle'] = $view->getData()['pagetitle'];
     } else {
         $data['pagetitle'] = $society;
     }
     $socid = Society::where('society', '=', $society)->select('id')->first()->id;
     if (Helpers::is_online() and $data['services']->society_calendar != "") {
         $privatecal = new GoogleCalendar();
         $data['cals'] = $privatecal->getTen($data['services']->society_calendar, 8);
     }
     $data['sermon'] = Sermon::with(['series' => function ($query) use($socid) {
         $query->where('society_id', '=', $socid);
     }])->orderBy('servicedate', 'DESC')->first();
     if (!$data['sermon'] or !$data['sermon']->series) {
         $data['sermon'] = "None";
     } else {
         if ($data['sermon']->preachable_type == 'App\\Models\\Minister') {
             $data['preacher'] = Minister::find($data['sermon']->preachable_id);
         } elseif ($data['sermon']->preachable_type == 'App\\Models\\Guest') {
             $data['preacher'] = Guest::find($data['sermon']->preachable_id);
         } else {
             $data['preacher'] = Preacher::find($data['sermon']->preachable_id);
         }
     }
     $data['welcome_page'] = "together a transforming discipleship movement";
     $data['welcome_page_pic'] = "/public/images/715.jpg";
     if ($data['services']->roster) {
         $data['roster'] = $data['services']->roster;
     }
     $data['society'] = Society::where('society', '=', $society)->first();
     if ($data['society']->roster) {
         $data['roster'] = $data['society']->roster;
     }
     $webpage = Webpage::where('society_id', '=', $data['society']->id)->get();
     foreach ($webpage as $pg) {
         $data[$pg->fieldname] = $pg->fieldvalue;
         $data[$pg->fieldname . '_pic'] = $pg->pageimage;
     }
     $data['route'] = Route::getCurrentRoute()->getPath();
     if ($data['route'] != "{society}" and $data['route'] != "/") {
         $linkadd = Helpers::makeUrl(strtolower($society), '');
     } else {
         $linkadd = "";
     }
     $menu['link'] = $linkadd . "#sundays";
     $menu['label'] = "Sundays";
     $menu['longlabel'] = "Sunday services";
     $data['menu'][] = $menu;
     $data['youth'] = Mission::where('society_id', '=', $data['society']->id)->where('category', '=', 'youth')->orderBy('created_at')->take(5)->get();
     if (count($data['youth'])) {
         $menu['link'] = $linkadd . "#youth";
         $menu['label'] = "Youth";
         $menu['longlabel'] = "Children and Youth";
         $data['menu'][] = $menu;
     }
     $data['groups'] = Group::where('society_id', '=', $data['society']->id)->where('publish', '=', 1)->get();
     if (count($data['groups'])) {
         foreach ($data['groups'] as $obj) {
             $dum[0] = $obj->groupname;
             $dum[1] = $obj->latitude;
             $dum[2] = $obj->longitude;
             $dum[3] = Helpers::makeUrl(strtolower($data['services']->society), 'groups/' . $obj->slug);
             $fin[] = $dum;
         }
         $data['fin'] = json_encode($fin);
         $menu['link'] = "#groups";
         $menu['label'] = "Groups";
         $menu['longlabel'] = "Small groups";
         $data['menu'][] = $menu;
     } else {
         $data['fin'] = "";
     }
     $data['missions'] = Mission::where('society_id', '=', $data['society']->id)->where('category', '=', 'project')->take(5)->get();
     if (count($data['missions'])) {
         $menu['link'] = $linkadd . "#projects";
         $menu['label'] = "Projects";
         $menu['longlabel'] = "Mission projects";
         $data['menu'][] = $menu;
     }
     $blogs = Blog::with('individual')->orderBy('created_at', 'desc')->take(10)->get();
     if (count($blogs)) {
         $first = true;
         foreach ($blogs as $blog) {
             $societies = explode(',', $blog->societies);
             if (in_array($data['society']->id, $societies)) {
                 if ($first) {
                     $data['firstblog'] = $blog;
                     $first = false;
                 } else {
                     $data['blogs'][] = $blog;
                 }
             }
         }
         if (isset($data['firstblog'])) {
             $menu['link'] = $linkadd . "#blog";
             $menu['label'] = "Blog";
             $menu['longlabel'] = "Latest blogs";
             $data['menu'][] = $menu;
         }
     }
     $menu['link'] = $linkadd . "#contact";
     $menu['label'] = "Contact";
     $menu['longlabel'] = "Contact us";
     $data['menu'][] = $menu;
     $data['counter'] = 1;
     $view->with('data', $data);
 }
Example #8
0
 /**
  * Update the specified resource in storage.
  *
  * @param \Illuminate\Http\Request $request
  * @param int                      $id
  *
  * @return \Illuminate\Http\Response
  */
 public function update(MissionsRequest $request, $society, $category, $id)
 {
     $mission = Mission::find($id);
     $mission->fill($request->all());
     if ($request->file('missionbanner')) {
         $fileName = "missionbanner_" . $mission->id . "." . $request->file('missionbanner')->getClientOriginalExtension();
         $request->file('missionbanner')->move(base_path() . '/storage/app/images/', $fileName);
         $mission->missionbanner = '/storage/app/images/' . $fileName;
         $img = Image::make(base_path() . $mission->missionbanner);
         $img->resize(null, 350);
         $img->save(base_path() . '/storage/app/images/' . $fileName);
     }
     $mission->save();
     return redirect($society . '/missions/' . $category)->with('okmessage', 'Data updated');
 }