sant = $sant; $this->santTemp = $santTemp; $this->post = $post; $this->santLocation = $santLocation; } /** * @return array */ public function getSantList($data) { $response = []; try { $santData = $this->sant->where('status','2'); if (isset($data['name']) && !empty($data['name'])) { $santData = $santData->where('name', 'LIKE', "%{$data['name']}%"); } if (isset($data['sant_id']) && !empty($data['sant_id'])) { $santData = $santData->where('id', '!=', $data['sant_id']); } if (isset($data['dharma_id']) && !empty($data['dharma_id'])) { $santData = $santData->where('dharma_id', $data['dharma_id']); } if (isset($data['sampraday_id']) && !empty($data['sampraday_id'])) { $santData = $santData->where('sampraday_id', $data['sampraday_id']); } $santData = $santData->paginate($data['limit'] ?? 10, ['*'], 'page', $data['page'] ?? 1); // if ($santData) { $response['data'] = $santData; $response['message'] = trans('sant.list_sant_success'); $response['status'] = Constant::CODE_200; // } else { // $response['data'] = []; // $response['status'] = Constant::CODE_401; // } } catch (\Exception $ex) { Log::error($ex); $response['message'] = trans('sant.something_went_wrong'); $response['status'] = Constant::CODE_403; } return $response; } /** * @param array $data * @return array */ public function createSant($data) { try { // $santExist = $this->sant->where('name', $data['name'])->first(); $user = loggedInUser(); if ($user) { if (isset($data['honor']) && !empty($data['honor'])) { $honors = stringToArray($data['honor']); } else { $honors = []; } $santData['user_id'] = $user->id ?? Constant::NULL; $santData['name'] = $data['name'] ?? Constant::NULL; $santData['father_name'] = $data['father_name'] ?? Constant::NULL; $santData['mother_name'] = $data['mother_name'] ?? Constant::NULL; $santData['guru_name'] = $data['guru_name'] ?? Constant::NULL; $santData['gender'] = $data['gender'] ?? Constant::NULL; $santData['honor'] = $honors; $santData['qualification'] = $data['qualification'] ?? Constant::NULL; $santData['dharma_id'] = $data['dharma_id'] ?? Constant::NULL; $santData['sampraday_id'] = $data['sampraday_id'] ?? Constant::NULL; $santData['guru_id'] = $data['guru_id'] ?? Constant::NULL; $santData['birth_date'] = $data['birth_date'] ?? Constant::NULL; $santData['diksha_date'] = $data['diksha_date'] ?? Constant::NULL; $santData['diksha_place'] = $data['diksha_place'] ?? Constant::NULL; $santData['diksha_place_latitude'] = $data['diksha_place_latitude'] ?? Constant::NULL; $santData['diksha_place_longitude'] = $data['diksha_place_longitude'] ?? Constant::NULL; $santData['about'] = $data['about'] ?? Constant::NULL; $santData['status'] = $data['status'] ?? Constant::STATUS_TWO; $santData['verification_status'] = Constant::STATUS_TWO; $santData['created_by'] = $user->id ?? Constant::NULL; $santData['updated_by'] = $user->id ?? Constant::NULL; $santData['reviewed_fields']['name'] = Constant::STATUS_TRUE; $santData['reviewed_fields']['dharma'] = Constant::STATUS_TRUE; $santData['reviewed_fields']['sampraday'] = Constant::STATUS_TRUE; $santData['reviewed_fields']['birth_date'] = Constant::STATUS_TRUE; $santData['reviewed_fields']['gender'] = Constant::STATUS_TRUE; $santData['reviewed_fields']['diksha_date'] = Constant::STATUS_TRUE; $santData['reviewed_fields']['diksha_place'] = Constant::STATUS_TRUE; $santData['reviewed_fields']['guru'] = Constant::STATUS_TRUE; $santData['reviewed_fields']['father_name'] = Constant::STATUS_TRUE; $santData['reviewed_fields']['mother_name'] = Constant::STATUS_TRUE; $santData['reviewed_fields']['about'] = Constant::STATUS_TRUE; $santData['reviewed_fields']['avatar'] = Constant::STATUS_TRUE; if (!empty($data['avatar'])) { $imageName = uploadImage($data, 'avatar', Constant::SANT_IMAGE_UPLOAD_PATH . Constant::SLASH); $santData['avatar'] = $imageName['image_name'] ?? Constant::NULL; } $sant = $this->sant->create($santData); $santTempImage = $sant->getRawOriginal('avatar'); $santTemp = $sant->toArray(); $santTemp['sant_id'] = $sant->id; $santTemp['avatar'] = $santTempImage; $santTemp = $this->santTemp->create($santTemp); if (isset($data['father_id']) && isset($data['father_type']) && !empty($data['father_id']) && !empty($data['father_type'])) { if (!empty($data['father_type']) && $data['father_type'] == 'sant') { $santRelation = [ 'relation_type' => Constant::SANT_RELATION, 'relation_id' => $data['father_id'], 'type' => 'father', ]; } if (!empty($data['father_type']) && $data['father_type'] == 'user') { $santRelation = [ 'relation_type' => Constant::USER_RELATION, 'relation_id' => $data['father_id'], 'type' => 'father', ]; } $sant->santFather()->create($santRelation); } if (isset($data['mother_id']) && isset($data['mother_type']) && !empty($data['mother_id']) && !empty($data['mother_type'])) { if (!empty($data['mother_type']) && $data['mother_type'] == 'sant') { $santRelation = [ 'relation_type' => Constant::SANT_RELATION, 'relation_id' => $data['mother_id'], 'type' => 'mother', ]; } if (!empty($data['mother_type']) && $data['mother_type'] == 'user') { $santRelation = [ 'relation_type' => Constant::USER_RELATION, 'relation_id' => $data['mother_id'], 'type' => 'mother', ]; } $sant->santFather()->create($santRelation); } if ($sant) { $responseData['data'] = $sant->load(['father.'.$data['father_type'].'','mother.'.$data['mother_type'].''])->toArray(); $responseData['message'] = trans('sant.sant_in_review'); $responseData['status'] = Constant::CODE_200; } else { $responseData['message'] = trans('sant.something_went_wrong'); $responseData['status'] = Constant::CODE_403; } } else { // $responseData['message'] = trans('sant.sant_already_exist'); $responseData['message'] = trans('sant.something_went_wrong'); $responseData['status'] = Constant::CODE_403; } } catch (\Exception $ex) { Log::error($ex); $responseData['message'] = trans('sant.something_went_wrong'); $responseData['status'] = Constant::CODE_403; } return $responseData; } /** * @param object $sant * @param $data * @return array */ public function updateSant(object $sant,$data) { try { $santTemp = $this->santTemp->where('sant_id', $sant->id)->first(); $user = loggedInUser(); //honors if ($data['honor']) { $honors = stringToArray($data['honor']); } else if (isset($data['honor']) === false) { $honors = $sant->honor; } else { $honors = []; } if (!empty($data['birth_date'])) { $birthDate = $data['birth_date']; } else if (isset($data['birth_date']) === true) { $birthDate = $sant->birth_date; } else { $birthDate = Constant::NULL; } if (!empty($data['diksha_date'])) { $dikshaDate = $data['diksha_date']; } else if (isset($data['birth_date']) === true) { $dikshaDate = $sant->diksha_date; } else { $dikshaDate = Constant::NULL; } $santData['name'] = $data['name'] ?? $santTemp->name; $santData['father_name'] = $data['father_name'] ?? $santTemp->father_name; $santData['mother_name'] = $data['mother_name'] ?? $santTemp->mother_name; $santData['guru_name'] = $data['guru_name'] ?? $santTemp->guru_name; $santData['gender'] = $data['gender'] ?? $santTemp->gender; $santData['honor'] = $honors; $santData['qualification'] = $data['qualification'] ?? $santTemp->qualification; $santData['dharma_id'] = $data['dharma_id'] ?? $santTemp->dharma_id; $santData['sampraday_id'] = $data['sampraday_id'] ?? $santTemp->sampraday_id; $santData['guru_id'] = $data['guru_id'] ?? $santTemp->guru_id; $santData['birth_date'] = $birthDate; $santData['diksha_date'] = $dikshaDate; $santData['diksha_place'] = $data['diksha_place'] ?? $santTemp->diksha_place; $santData['diksha_place_latitude'] = $data['diksha_place_latitude'] ?? $santTemp->diksha_place_latitude; $santData['diksha_place_longitude'] = $data['diksha_place_longitude'] ?? $santTemp->diksha_place_longitude; $santData['about'] = $data['about'] ?? $santTemp->about; $santData['status'] = $data['status'] ?? $santTemp->status; if ($santTemp->verification_status === Constant::STATUS_ONE || $santTemp->verification_status === Constant::STATUS_FIVE) { $santData['verification_status'] = Constant::STATUS_FOUR; } else if ($santTemp->verification_status === Constant::STATUS_THREE) { $santData['verification_status'] = Constant::STATUS_TWO; } else { $santData['verification_status'] = Constant::STATUS_THREE; } $santData['updated_by'] = $user->id ?? $santTemp->updated_by; if(!empty($data['avatar'])) { $imageName = uploadImage($data, 'avatar', Constant::SANT_IMAGE_UPLOAD_PATH . Constant::SLASH, $santTemp->getRawOriginal('avatar')); $santData['avatar'] = $imageName['image_name'] ?? Constant::NULL; } $santExist = $this->sant->where('id', $sant->id)->first(); $santFind = Sant::find($sant->id); // $sant->update($santData); $santTemp->update($santData); if (isset($data['father_id']) && isset($data['father_type']) && !empty($data['father_id']) && !empty($data['father_type'])) { if (!empty($data['father_type']) && $data['father_type'] == 'sant') { $santRelation = [ 'relation_type' => Constant::SANT_RELATION, 'relation_id' => $data['father_id'], 'type' => 'father', ]; } if (!empty($data['father_type']) && $data['father_type'] == 'user') { $santRelation = [ 'relation_type' => Constant::USER_RELATION, 'relation_id' => $data['father_id'], 'type' => 'father', ]; } $santFatherExist = $santTemp->santFather()->where('type', 'father')->first(); if (!empty($santFatherExist)) { $santTemp->santFather()->where('type', 'father')->update($santRelation); } else { $santTemp->santFather()->create($santRelation); } } else { $santTemp->santFather()->where('type', 'father')->delete(); } if (isset($data['mother_id']) && isset($data['mother_type']) && !empty($data['mother_id']) && !empty($data['mother_type'])) { if (!empty($data['mother_type']) && $data['mother_type'] == 'sant') { $santRelation = [ 'relation_type' => Constant::SANT_RELATION, 'relation_id' => $data['mother_id'], 'type' => 'mother', ]; } if (!empty($data['mother_type']) && $data['mother_type'] == 'user') { $santRelation = [ 'relation_type' => Constant::USER_RELATION, 'relation_id' => $data['mother_id'], 'type' => 'mother', ]; } $santMotherExist = $santTemp->santFather()->where('type', 'mother')->first(); if (!empty($santMotherExist)) { $santTemp->santFather()->where('type', 'mother')->update($santRelation); } else { $santTemp->santFather()->create($santRelation); } } else { $santTemp->santFather()->where('type', 'mother')->delete(); } if ($santExist) { $responseData['data'] = $this->santTemp->where('sant_id', $sant->id)->with(['father.'.$data['father_type'].'','mother.'.$data['mother_type'].''])->get()->toArray(); // $responseData['data'] = $this->santTemp->where('sant_id', $sant->id)->get()->toArray(); $responseData['message'] = trans('sant.update_sant_success'); $responseData['status'] = Constant::CODE_200; } else { $responseData['message'] = trans('sant.something_went_wrong'); $responseData['status'] = Constant::CODE_403; } } catch (\Exception $ex) { Log::error($ex); $responseData['message'] = trans('sant.update_sant_error'); $responseData['status'] = Constant::CODE_403; } return $responseData; } /** * @param object $sant * @param $data * @return array */ public function santFatherList($data) { try { $users = User::select( 'users.id', 'users.name', 'users.avatar', ) ->where('users.gender', Constant::MALE) ->join('model_has_roles', 'users.id', '=', 'model_has_roles.model_id') ->join('roles', 'model_has_roles.role_id', '=', 'roles.id') ->where('roles.name', '=', config('access.users.shravak')) ->where('roles.name', '!=', config('access.users.super_admin_role')) ->addSelect(DB::raw("'user' as type")); if (isset($data['name']) && !empty($data['name'])) { $users = $users->where('users.name', 'LIKE', "%{$data['name']}%"); } // $users = $users->limit(20)->get(); $sants = Sant::select('id', 'name', 'avatar') ->where('gender', Constant::MALE) ->addSelect(DB::raw("'sant' as type")); // ->union($users); if (isset($data['name']) && !empty($data['name'])) { $sants = $sants->where('name', 'LIKE', "%{$data['name']}%"); } $sants = $sants->limit(20)->get(); $sants = $sants->merge($users); $responseData['data'] = $sants->toArray(); $responseData['message'] = trans('sant.list_sant_father'); $responseData['status'] = Constant::CODE_200; } catch (\Exception $ex) { Log::error($ex); $responseData['message'] = trans('sant.something_went_wrong'); $responseData['status'] = Constant::CODE_403; } return $responseData; } /** * @param object $sant * @param $data * @return array */ public function santMotherList($data) { try { $users = User::select( 'users.id', 'users.name', 'users.avatar', ) ->where('users.gender', Constant::FEMALE) ->join('model_has_roles', 'users.id', '=', 'model_has_roles.model_id') ->join('roles', 'model_has_roles.role_id', '=', 'roles.id') ->where('roles.name', '=', config('access.users.shravak')) ->where('roles.name', '!=', config('access.users.super_admin_role')) ->addSelect(DB::raw("'user' as type")); if (isset($data['name']) && !empty($data['name'])) { $users = $users->where('users.name', 'LIKE', "%{$data['name']}%"); } // $users = $users->limit(20)->get(); $sants = Sant::select('id', 'name', 'avatar') ->where('gender', Constant::FEMALE) ->addSelect(DB::raw("'sant' as type")); // ->union($users); if (isset($data['name']) && !empty($data['name'])) { $sants = $sants->where('name', 'LIKE', "%{$data['name']}%"); } $sants = $sants->limit(20)->get(); $sants = $sants->merge($users); $responseData['data'] = $sants->toArray(); $responseData['message'] = trans('sant.list_sant_mother'); $responseData['status'] = Constant::CODE_200; } catch (\Exception $ex) { Log::error($ex); $responseData['message'] = trans('sant.something_went_wrong'); $responseData['status'] = Constant::CODE_403; } return $responseData; } /** * Get info of sant */ public function showSant(object $sant) { $response = [ 'status' => Constant::CODE_403, 'error' => trans('api.something_went_wrong'), 'success' => Constant::STATUS_FALSE ]; try { $fatherType = $sant->father()->pluck('relation_type')[0] ?? ""; $motherType = $sant->mother()->pluck('relation_type')[0] ?? ""; $fatherType = ($fatherType == 1) ? 'user' : 'sant'; $motherType = ($motherType == 1) ? 'user' : 'sant'; $thanaMember = ThanaMember::where('sant_id', $sant->id)->select('thana_id')->first(); $count = 0; if ($thanaMember) { $thanaOfSant = $sant->ownedThana()->first(); if (isset($thanaOfSant) && !empty($thanaOfSant)) { $createdThanaId = Thana::find($thanaOfSant->id); } else { $createdThanaId = Thana::find($thanaMember->thana_id); } $count = $createdThanaId->getThanaMember()->count(); } $sant = $sant->loadCount('followers') ->load([ 'followers' => function ($query) { $query->limit(3); }, 'dharm', 'shishya:id,name,avatar,guru_id', 'maharaj:id,name,avatar,guru_id', 'mahasatiJi:id,name,avatar,guru_id', 'guru:id,name,avatar', 'sampraday.gachadhipati:id,name,avatar', 'father.'.$fatherType.':id,name,avatar', 'mother.'.$motherType.':id,name,avatar', // 'location.createdBy:id,name,avatar', // 'location.updatedBy:id,name,avatar', 'pastLocation.createdBy:id,name,avatar', 'pastLocation.updatedBy:id,name,avatar', 'editedLocation.createdBy:id,name,avatar', 'editedLocation.updatedBy:id,name,avatar', 'createdBy:id,name,avatar', 'updatedBy:id,name,avatar', ])->toArray(); // if ((isset($sant['location']) && !empty($sant['location'])) && ($sant['edited_location']['updated_at'] <= $sant['location']['created_at'])) { // $sant['sant_location'] = $sant['location']['to'] ?? Constant::NULL; // $sant['sant_location_latitude'] = $sant['location']['to_latitude'] ?? Constant::NULL; // $sant['sant_location_longitude'] = $sant['location']['to_longitude'] ?? Constant::NULL; // $sant['is_vihaar_location'] = Constant::STATUS_ONE; // $sant['sant_location_created_by']['id'] = $sant['location']['created_by']['id'] ?? Constant::NULL; // $sant['sant_location_created_by']['name'] = $sant['location']['created_by']['name'] ?? Constant::NULL; // $sant['sant_location_created_by']['created_ago'] = $sant['location']['created_ago']?? Constant::NULL; // $sant['sant_location_updated_by']['id'] = $sant['location']['updated_by']['id'] ?? Constant::NULL; // $sant['sant_location_updated_by']['name'] = $sant['location']['updated_by']['name'] ?? Constant::NULL; // $sant['sant_location_updated_by']['updated_ago'] = $sant['location']['updated_ago']?? Constant::NULL; // } else if (!empty($sant['edited_location'])) { $sant['sant_location'] = $sant['edited_location']['location'] ?? Constant::NULL; $sant['sant_location_latitude'] = $sant['edited_location']['latitude'] ?? Constant::NULL; $sant['sant_location_longitude'] = $sant['edited_location']['longitude'] ?? Constant::NULL; $sant['sant_location_type'] = $sant['edited_location']['type'] ?? Constant::NULL; $sant['sant_location_sangh_id'] = $sant['edited_location']['sangh_id'] ?? Constant::NULL; $sant['is_vihaar_location'] = Constant::STATUS_ZERO; $sant['sant_location_created_by']['id'] = $sant['edited_location']['created_by']['id'] ?? Constant::NULL; $sant['sant_location_created_by']['name'] = $sant['edited_location']['created_by']['name'] ?? Constant::NULL; $sant['sant_location_created_by']['created_ago'] = $sant['edited_location']['created_ago']?? Constant::NULL; $sant['sant_location_updated_by']['id'] = $sant['edited_location']['updated_by']['id'] ?? Constant::NULL; $sant['sant_location_updated_by']['name'] = $sant['edited_location']['updated_by']['name'] ?? Constant::NULL; $sant['sant_location_updated_by']['updated_ago'] = $sant['edited_location']['updated_ago']?? Constant::NULL; } else { $sant['sant_location'] = $sant['past_location']['to'] ?? Constant::NULL; $sant['sant_location_latitude'] = $sant['past_location']['to_latitude'] ?? Constant::NULL; $sant['sant_location_longitude'] = $sant['past_location']['to_longitude'] ?? Constant::NULL; $sant['is_vihaar_location'] = Constant::STATUS_ONE; $sant['sant_location_created_by']['id'] = $sant['past_location']['created_by']['id'] ?? Constant::NULL; $sant['sant_location_created_by']['name'] = $sant['past_location']['created_by']['name'] ?? Constant::NULL; $sant['sant_location_created_by']['created_ago'] = $sant['past_location']['created_ago']?? Constant::NULL; $sant['sant_location_updated_by']['id'] = $sant['past_location']['updated_by']['id'] ?? Constant::NULL; $sant['sant_location_updated_by']['name'] = $sant['past_location']['updated_by']['name'] ?? Constant::NULL; $sant['sant_location_updated_by']['updated_ago'] = $sant['past_location']['updated_ago']?? Constant::NULL; $sant['location'] = $sant['past_location']; } $sant['thana_member_count'] = $count; $response['data'] = $sant; $response['status'] = Constant::CODE_200; $response['success'] = Constant::STATUS_TRUE; $response['message'] = trans('api.sant.show'); unset($response['error']); } catch (\Exception $ex) { Log::error($ex); } return $response; } /** * Get list of in review sant */ public function inReviewSant($data) { $response = [ 'status' => Constant::CODE_403, 'error' => trans('api.something_went_wrong'), 'success' => Constant::STATUS_FALSE ]; try { $santInReview = $this->santTemp ->with('dharm', 'sampraday') ->select('id', 'sant_id', 'name', 'avatar', 'about', 'verification_status', 'status', 'dharma_id', 'sampraday_id', 'description') ->where('status', Constant::STATUS_TWO) ->where(function ($query) { $query->where('created_by', loggedInUser()->id) ->orWhere('updated_by', loggedInUser()->id); }) ->whereIn('verification_status', [Constant::STATUS_TWO, Constant::STATUS_THREE, Constant::STATUS_FOUR, Constant::STATUS_FIVE]) ->paginate($data['limit'] ?? 10, ['*'], 'page', $data['page'] ?? 1); unreadSantActionCounter(loggedInUser()->id, Constant::STATUS_ZERO); //Set sant in-review badge to default state $response['data'] = $santInReview; $response['status'] = Constant::CODE_200; $response['success'] = Constant::STATUS_TRUE; $response['message'] = trans('api.sant.show'); unset($response['error']); } catch (\Exception $ex) { Log::error($ex); } return $response; } /** * Get info of in review sant */ public function inReviewSantDetail(object $sant) { $response = [ 'status' => Constant::CODE_403, 'error' => trans('api.something_went_wrong'), 'success' => Constant::STATUS_FALSE ]; try { $santTemp = SantTemp::where('sant_id', $sant->id)->first(); $sant = Sant::where('id', $santTemp->sant_id)->first(); $fatherType = $santTemp->father()->pluck('relation_type')[0] ?? null; $motherType = $santTemp->mother()->pluck('relation_type')[0] ?? null; $fatherType = ($fatherType == 1) ? 'user' : 'sant'; $motherType = ($motherType == 1) ? 'user' : 'sant'; $thanaMember = ThanaMember::where('sant_id', $sant->id)->select('thana_id')->first(); $count = 0; if ($thanaMember) { $thanaOfSant = $sant->ownedThana()->first(); if (isset($thanaOfSant) && !empty($thanaOfSant)) { $createdThanaId = Thana::find($thanaOfSant->id); } else { $createdThanaId = Thana::find($thanaMember->thana_id); } $count = $createdThanaId->getThanaMember()->count(); } $sant = $santTemp->loadCount('followers') ->load([ 'followers' => function ($query) { $query->limit(3); }, 'shishya:id,name,avatar,guru_id', 'maharaj:id,name,avatar,guru_id', 'mahasatiJi:id,name,avatar,guru_id', 'guru:id,name,avatar', 'sampraday.gachadhipati:id,name,avatar', 'dharm:id,name', 'father.'.$fatherType.':id,name,avatar', 'mother.'.$motherType.':id,name,avatar', 'editedLocation.createdBy:id,name,avatar', 'editedLocation.updatedBy:id,name,avatar', 'location.createdBy:id,name,avatar', 'location.updatedBy:id,name,avatar', 'pastLocation.createdBy:id,name,avatar', 'pastLocation.updatedBy:id,name,avatar', 'createdBy:id,name,avatar', ])->toArray(); if (!empty($sant['edited_location'])) { $sant['sant_location'] = $sant['edited_location']['location'] ?? Constant::NULL; $sant['sant_location_latitude'] = $sant['edited_location']['latitude'] ?? Constant::NULL; $sant['sant_location_longitude'] = $sant['edited_location']['longitude'] ?? Constant::NULL; $sant['sant_location_type'] = $sant['edited_location']['type'] ?? Constant::NULL; $sant['sant_location_sangh_id'] = $sant['edited_location']['sangh_id'] ?? Constant::NULL; $sant['is_vihaar_location'] = Constant::STATUS_ZERO; $sant['sant_location_created_by']['id'] = $sant['edited_location']['created_by']['id'] ?? Constant::NULL; $sant['sant_location_created_by']['name'] = $sant['edited_location']['created_by']['name'] ?? Constant::NULL; $sant['sant_location_created_by']['created_ago'] = $sant['edited_location']['created_ago']?? Constant::NULL; $sant['sant_location_updated_by']['id'] = $sant['edited_location']['updated_by']['id'] ?? Constant::NULL; $sant['sant_location_updated_by']['name'] = $sant['edited_location']['updated_by']['name'] ?? Constant::NULL; $sant['sant_location_updated_by']['updated_ago'] = $sant['edited_location']['updated_ago']?? Constant::NULL; } else { $sant['sant_location'] = $sant['past_location']['to'] ?? Constant::NULL; $sant['sant_location_latitude'] = $sant['past_location']['to_latitude'] ?? Constant::NULL; $sant['sant_location_longitude'] = $sant['past_location']['to_longitude'] ?? Constant::NULL; $sant['is_vihaar_location'] = Constant::STATUS_ONE; $sant['sant_location_created_by']['id'] = $sant['past_location']['created_by']['id'] ?? Constant::NULL; $sant['sant_location_created_by']['name'] = $sant['past_location']['created_by']['name'] ?? Constant::NULL; $sant['sant_location_created_by']['created_ago'] = $sant['past_location']['created_ago']?? Constant::NULL; $sant['sant_location_updated_by']['id'] = $sant['past_location']['updated_by']['id'] ?? Constant::NULL; $sant['sant_location_updated_by']['name'] = $sant['past_location']['updated_by']['name'] ?? Constant::NULL; $sant['sant_location_updated_by']['updated_ago'] = $sant['past_location']['updated_ago']?? Constant::NULL; $sant['location'] = $sant['past_location']; } $sant['thana_member_count'] = $count; $response['data'] = $sant; $response['status'] = Constant::CODE_200; $response['success'] = Constant::STATUS_TRUE; $response['message'] = trans('api.sant.show'); unset($response['error']); } catch (\Exception $ex) { Log::error($ex); } return $response; } /** * Get list of sant which is created by user */ public function userSantList($data) { $response = [ 'status' => Constant::CODE_403, 'error' => trans('api.something_went_wrong'), 'success' => Constant::STATUS_FALSE ]; try { $santInReview = $this->sant->select( 'id', 'name', 'avatar', 'about', 'status', 'profile_statistics' )->with([ 'followers:id,name,avatar', 'followings:id,name,avatar', ])->where('created_by', loggedInUser()->id) ->where('verification_status', Constant::STATUS_ONE)->where('status', Constant::STATUS_TWO)->paginate($data['limit'] ?? 10, ['*'], 'page', $data['page'] ?? 1); $response['data'] = $santInReview; $response['status'] = Constant::CODE_200; $response['success'] = Constant::STATUS_TRUE; $response['message'] = trans('api.sant.show'); unset($response['error']); } catch (\Exception $ex) { Log::error($ex); } return $response; } /** * @return array */ public function santFollow($data) { $response = [ 'status' => Constant::CODE_403, 'error' => trans('api.something_went_wrong'), 'success' => Constant::STATUS_FALSE ]; try { $user = loggedInUser(); if (!$user->followings->contains($data['sant_id'])) { $user->followings()->attach(['sant_id' => $data['sant_id']]); $response['status'] = Constant::CODE_200; $response['success'] = Constant::STATUS_TRUE; $response['message'] = trans('api.sant.follow'); unset($response['error']); } else { $user->followings()->detach(['sant_id' => $data['sant_id']]); $response['status'] = Constant::CODE_200; $response['success'] = Constant::STATUS_TRUE; $response['message'] = trans('api.sant.unfollow'); unset($response['error']); } } catch (\Exception $ex) { Log::error($ex); $response['message'] = trans('api.something_went_wrong'); $response['status'] = Constant::CODE_403; } return $response; } /** * @return array */ public function santSuggestion($data) { $response = [ 'status' => Constant::CODE_403, 'error' => trans('api.something_went_wrong'), 'success' => Constant::STATUS_FALSE ]; try { $user = loggedInUser(); $userIds = $user->friendRequests()->where('requests.status', Constant::STATUS_ONE)->get()->pluck('id')->toArray(); $myFollowingList = SantFollower::where('user_id', $user->id)->pluck('sant_id')->toArray(); // $santSuggestionIds = SantFollower::whereIn('user_id', $userIds)->whereNotIn('sant_id', $myFollowingList)->pluck('sant_id'); $mySantSuggestionList = Sant::select( 'id', 'name', 'sampraday_id', 'dharma_id', 'guru_id', 'avatar', 'profile_statistics' )->where('status', Constant::STATUS_TWO); if (!empty($user->dharma_id)) { $mySantSuggestionList = $mySantSuggestionList->where('dharma_id', $user->dharma_id); } // ->whereIn('id', $santSuggestionIds) $mySantSuggestionList = $mySantSuggestionList ->whereNotIn('id', $myFollowingList) ->with([ 'sampraday:id,name', 'dharm:id,name' ]) ->paginate($data['limit'] ?? 10, ['*'], 'page', $data['page'] ?? 1); unreadSantMenuCounter($user->id, Constant::STATUS_ZERO); //Set sant menu badge to default state $response['data'] = $mySantSuggestionList->toArray(); $response['status'] = Constant::CODE_200; $response['success'] = Constant::STATUS_TRUE; $response['message'] = trans('api.sant.unfollow'); unset($response['error']); } catch (\Exception $ex) { Log::error($ex); $response['message'] = trans('api.something_went_wrong'); $response['status'] = Constant::CODE_403; } return $response; } /** * Get followers of sant */ public function santFollowers(array $data, object $sant) { $response = [ 'status' => Constant::CODE_403, 'error' => trans('api.something_went_wrong'), 'success' => Constant::STATUS_FALSE ]; try { $sant = $sant->followers()->paginate($data['limit'] ?? 10, ['*'], 'page', $data['page'] ?? 1); $response['data'] = $sant->toArray(); $response['status'] = Constant::CODE_200; $response['success'] = Constant::STATUS_TRUE; $response['message'] = trans('api.sant.followlist'); unset($response['error']); } catch (\Exception $ex) { Log::error($ex); } return $response; } /** * Get followers of sant */ public function getSantFeeds(array $data) { $response = [ 'status' => Constant::CODE_403, 'error' => trans('api.something_went_wrong'), 'success' => Constant::STATUS_FALSE ]; try { $user = loggedInUser(); $inactiveSants = Sant::where('status', Constant::STATUS_ONE)->pluck('id')->toArray(); if (!empty($data['sant_id'])) { $santFeeds = Activity::with('causer:id,name,avatar,profile_statistics', 'subject:id,name,avatar,profile_statistics') ->where(function ($query) { $query->where('description', 'chaturmas_created') ->orWhere('description', 'chaturmas_updated') ->orWhere('description', 'vihar_created') ->orWhere('description', 'vihar_updated') ->orWhere('description', 'location_updated'); }) ->where(function ($query) use ($data) { $query->where('subject_type', Sant::class) ->where('subject_id', $data['sant_id']); // ->orWhereIn('subject_id', $createdByMe); }) ->where(function ($query) use ($inactiveSants) { $query->where('subject_type', Sant::class) ->whereNotIn('subject_id', $inactiveSants); }) ->latest()->paginate($data['limit'] ?? 10, ['*'], 'page', $data['page'] ?? 1); } else { $myFollowingList = SantFollower::where('user_id', $user->id)->pluck('sant_id')->toArray(); $createdByMe = Sant::where('created_by', $user->id)->where('status', Constant::STATUS_TWO)->pluck('id')->toArray(); $santFeeds = Activity::with('causer:id,name,avatar,profile_statistics', 'subject:id,name,avatar,profile_statistics') ->where(function ($query) { $query->where('description', 'chaturmas_created') ->orWhere('description', 'chaturmas_updated') ->orWhere('description', 'vihar_created') ->orWhere('description', 'vihar_updated') ->orWhere('description', 'location_updated'); }) ->where(function ($query) use ($myFollowingList, $createdByMe) { $query->where('subject_type', Sant::class) ->whereIn('subject_id', $myFollowingList) ->orWhereIn('subject_id', $createdByMe); }) ->where(function ($query) use ($inactiveSants) { $query->where('subject_type', Sant::class) ->whereNotIn('subject_id', $inactiveSants); }) ->latest()->paginate($data['limit'] ?? 10, ['*'], 'page', $data['page'] ?? 1); } $response['data'] = $santFeeds; $response['status'] = Constant::CODE_200; $response['success'] = Constant::STATUS_TRUE; $response['message'] = trans('api.sant.feeds'); unset($response['error']); } catch (\Exception $ex) { Log::error($ex); } return $response; } /** * Store/update sant current location. */ public function updateSantLocation(array $data) { $response = []; try { $user = loggedInUser(); if (!empty($user)) { $santLocation = $this->santLocation->where('sant_id', $data['sant_id'])->first(); $sant = $this->sant->where('id', $data['sant_id'])->first(); $sanghId = Constant::NULL; $type = Constant::STATUS_ONE; $location = $data['location'] ?? Constant::NULL; $latitude = $data['latitude'] ?? Constant::NULL; $longitude = $data['longitude'] ?? Constant::NULL; if (isset($data['sangh_id']) && $data['sangh_id'] != Constant::NULL) { $sangh = Sangh::where('id', $data['sangh_id'])->first(); $sanghId = $data['sangh_id']; $type = Constant::STATUS_TWO; $location = $sangh->name; $latitude = $sangh->latitude; $longitude = $sangh->longitude; } $thanaID = Constant::NULL; $thanaSantID = []; $thanaID = ThanaMember::where('sant_id', $sant->id)->value('thana_id'); $thanaSantID = ThanaMember::where('thana_id', $thanaID)->pluck('sant_id'); if (empty($santLocation)) { if (!empty($thanaSantID) && count($thanaSantID) > 0) { foreach ($thanaSantID as $santID) { $santLocation = $this->santLocation->create([ 'sant_id' => $santID, 'sangh_id' => $sanghId ?? Constant::NULL, 'type' => $type, 'location' => $location, 'latitude' => $latitude, 'longitude' => $longitude, 'created_by' => $user->id ?? Constant::NULL, 'updated_by' => Constant::NULL, ]); $sant = $this->sant->where('id', $santID)->first(); //Push notification to all followers dispatch(new SendSantLocationChange($user, $sant)); $properties = [ 'attributes' => [ 'location_information' => $santLocation->toArray(), 'message' => 'Location updated by '.$user->name.', Location is '.$location, 'sant_id' => $santID, ], ]; logActivity($sant, $user, $properties, 'location_updated'); } $response['message'] = trans('sant.sant_location_update'); $response['status'] = Constant::CODE_200; } else { $santLocation = $this->santLocation->create([ 'sant_id' => $data['sant_id'] ?? Constant::NULL, 'sangh_id' => $sanghId ?? Constant::NULL, 'type' => $type, 'location' => $location, 'latitude' => $latitude, 'longitude' => $longitude, 'created_by' => $user->id ?? Constant::NULL, 'updated_by' => Constant::NULL, ]); //Push notification to all followers dispatch(new SendSantLocationChange($user, $sant)); $properties = [ 'attributes' => [ 'location_information' => $santLocation->toArray(), 'message' => 'Location updated by '.$user->name.', Location is '.$location, 'sant_id' => $data['sant_id'], ], ]; logActivity($sant, $user, $properties, 'location_updated'); $response['message'] = trans('sant.sant_location_update'); $response['status'] = Constant::CODE_200; } } else { if ($latitude != $santLocation->latitude || $longitude != $santLocation->longitude) { if (!empty($thanaSantID) && count($thanaSantID) > 0) { foreach ($thanaSantID as $santID) { SantLocation::where('sant_id', $santID)->update([ 'sant_id' => $santID, 'sangh_id' => $sanghId, 'type' => $type ?? $santLocation->type, 'location' => $location ?? $santLocation->location, 'latitude' => $latitude ?? $santLocation->latitude, 'longitude' => $longitude ?? $santLocation->longitude, 'created_by' => $user->id ?? $santLocation->created_by, 'updated_by' => $user->id ?? Constant::NULL, ]); $sant = $this->sant->where('id', $santID)->first(); //Push notification to all followers dispatch(new SendSantLocationChange($user, $sant)); $properties = [ 'attributes' => [ 'location_information' => $santLocation->toArray(), 'message' => 'Location updated by '.$user->name.', Location is '.$location, 'sant_id' => $santID, ], ]; logActivity($sant, $user, $properties, 'location_updated'); } $response['message'] = trans('sant.sant_location_update'); $response['status'] = Constant::CODE_200; } else { $santLocation->update([ 'sant_id' => $santLocation->sant_id, 'sangh_id' => $sanghId ?? Constant::NULL, 'type' => $type ?? $santLocation->type, 'location' => $location ?? $santLocation->location, 'latitude' => $latitude ?? $santLocation->latitude, 'longitude' => $longitude ?? $santLocation->longitude, 'created_by' => $user->id ?? $santLocation->created_by, 'updated_by' => $user->id ?? Constant::NULL, ]); //Push notification to all followers dispatch(new SendSantLocationChange($user, $sant)); $properties = [ 'attributes' => [ 'location_information' => $santLocation->toArray(), 'message' => 'Location updated by '.$user->name.', Location is '.$location, 'sant_id' => $data['sant_id'], ], ]; logActivity($sant, $user, $properties, 'location_updated'); $response['message'] = trans('sant.sant_location_update'); $response['status'] = Constant::CODE_200; } } else { $response['message'] = trans('sant.same_location'); $response['status'] = Constant::CODE_403; } } } else { $response['data'] = []; $response['status'] = Constant::CODE_200; } } catch (\Exception $ex) { Log::error($ex); $response['message'] = trans('auth.something_went_wrong'); $response['status'] = Constant::CODE_403; } return $response; } }