示例#1
0
 protected function createPins()
 {
     $items = ['اصفهان' => ['اماکن تاریخی' => ['آتشگاه اصفهان', 'آرامگاه الراشد بالله', 'آرامگاه پیربکران', 'آرامگاه سلطان بخت آقا', 'سی و سه پل']], 'تهران' => ['اماکن تاریخی' => ['عمارت مسعودیه', 'کاخ نیاوران']]];
     foreach ($items as $provinceName => $categories) {
         $province = \Tajrish\Models\Province::where('name', $provinceName)->firstOrFail();
         foreach ($categories as $categoryTitle => $pines) {
             $category = \Tajrish\Models\Category::where('title', $categoryTitle)->firstOrFail();
             foreach ($pines as $data) {
                 \Tajrish\Models\Pin::create(array_merge(['category_id' => $category->id, 'province_id' => $province->id], ['title' => $data]));
             }
         }
     }
 }
示例#2
0
 public function getProvinceStatus(UserTokenHandler $tokens, $token, $provinceId)
 {
     $user = $tokens->getUserFromToken($token, true);
     Province::findOrFail($provinceId);
     $trains = Train::where('destination_province_id', $provinceId)->where('start_province_id', $user['province_id'])->get();
     $planes = Plane::where('destination_province_id', $provinceId)->where('start_province_id', $user['province_id'])->get();
     $buses = Plane::where('destination_province_id', $provinceId)->where('start_province_id', $user['province_id'])->get();
     $numberOfVisitors = Visit::selectRaw('count(distinct user_id) as count')->where('user_id', $user['id'])->where('province_id', $provinceId)->first();
     $ownNumberOfVisitors = OwnVisit::selectRaw('count(distinct own_visits.user_id) as count')->join('pins', 'pins.id', '=', 'own_visits.pin_id')->where('pins.province_id', $provinceId)->where('own_visits.user_id', $user['id'])->first();
     $ownNumberOfVisitors = $ownNumberOfVisitors ? $ownNumberOfVisitors->count : 0;
     $numberOfVisitors = $numberOfVisitors ? $numberOfVisitors->count : 0;
     $numberOfVisitors = $ownNumberOfVisitors + $numberOfVisitors;
     $numberOfCheckinsInPin = Visit::selectRaw('count(distinct visit_pin.pin_id) as count')->join('visit_pin', 'visit_pin.visit_id', '=', 'visits.id')->join('pins', 'pins.id', '=', 'visit_pin.pin_id')->where('pins.province_id', $provinceId)->first();
     $ownCheckinsInPin = OwnVisit::selectRaw('count(distinct own_visits.pin_id) as count')->join('pins', 'pins.id', '=', 'own_visits.pin_id')->where('pins.province_id', $provinceId)->first();
     $ownCheckinsInPin = $ownCheckinsInPin ? $ownCheckinsInPin->count : 0;
     $numberOfCheckinsInPin = $numberOfCheckinsInPin ? $numberOfCheckinsInPin->count : 0;
     $numberOfCheckinsInPin = $ownCheckinsInPin + $numberOfCheckinsInPin;
     $currentUserCheckIns = Visit::selectRaw('count(distinct visit_pin.pin_id) as count')->join('visit_pin', 'visit_pin.visit_id', '=', 'visits.id')->where('visits.province_id', $provinceId)->where('visits.user_id', $user->id)->first();
     $ownCurrent = OwnVisit::selectRaw('count(distinct own_visits.pin_id) as count')->join('pins', 'pins.id', '=', 'own_visits.pin_id')->where('pins.province_id', '=', $provinceId)->where('own_visits.user_id', $user['id'])->first();
     $ownCurrent = $ownCurrent ? $ownCurrent->count : 0;
     $currentUserCheckIns = $currentUserCheckIns ? $currentUserCheckIns->count : 0;
     $currentUserCheckIns = $currentUserCheckIns + $ownCurrent;
     $numberOfPins = Pin::where('province_id', $provinceId)->count();
     return ['trains' => $trains, 'planes' => $planes, 'buses' => $buses, 'number_of_visitors' => (int) $numberOfVisitors, 'number_of_checkins_in_pin' => (int) $numberOfCheckinsInPin, 'current_user_checkins' => (int) $currentUserCheckIns, 'number_of_pins' => (int) $numberOfPins];
 }