/** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) { $schedule->call(function () { $players = DB::connection('game')->table('player_characters')->get(); foreach ($players as $player) { if (!Player::where('id', $player->id)->exists()) { $player_info = ['id' => $player->id, 'name' => $player->given_name, 'level' => $player->level, 'class' => 0, 'gold' => $player->gold, 'family_name' => $player->family_id ? DB::connection('game')->table('family')->where('id', $player->family_id)->first()->name : '-']; Player::create($player_info); } } })->everyTenMinutes(); $schedule->call(function () { $families = DB::connection('game')->table('family')->get(); foreach ($families as $family) { if (!Family::where('id', $family->id)->exists()) { $gold = 0; foreach (DB::connection('game')->table('player_characters')->where('family_id', $family->id)->get() as $player) { $gold += $player->gold; } $family_info = ['id' => $family->id, 'name' => $family->name, 'level' => $family->lv, 'gold' => $gold, 'members' => DB::connection('game')->table('player_characters')->where('family_id', $family->id)->count(), 'leader' => DB::connection('game')->table('player_characters')->where('id', $family->leader_id)->first()->given_name]; Family::create($family_info); } } })->everyTenMinutes(); }
/** * Execute the console command. * * @return mixed */ public function handle() { $users = User::where('type', 'ecole')->get(); foreach ($users as $user) { $sc = SchoolYear::where('user_id', $user->id)->where('current', 1)->first(); if ($sc) { if ($sc->type == 'Semis' && $sc->endch2 < Carbon::now()->toDateString() || $sc->type == 'Trim' && $sc->endch3 < Carbon::now()->toDateString()) { foreach ($user->families as $famille) { $f = Family::where('email_responsable', $famille->email_responsable)->where('school_year_id', $sc->id)->first(); if ($f) { $f->email_responsable = $sc->ann_scol . $f->email_responsable; $f->cin = $sc->cin . $f->cin; $f->save(); $fu = User::where('type', 'famille')->where('email', substr($f->email_responsable, 9))->first(); if ($fu) { $fu->email = $sc->ann_scol . $fu->email; $fu->save(); } } } $sc->current = 0; $sc->save(); $ynow = Carbon::now()->year; $ynext = Carbon::now()->year + 1; $yes = SchoolYear::where('user_id', $user->id)->where('ann_scol', $ynow . '-' . $ynext)->first(); if ($yes) { $yes->current = 1; $yes->save(); } } } } }
public function show(Person $person) { $logged_in_user = \Auth::user(); $id = $person->id; $solo_images = Image::where('subject', $id)->orderBy('year', 'asc')->get(); $featured_image = Image::where('subject', $id)->orderBy('year', 'asc')->Where('featured', 1)->get(); $made_family = PeopleController::get_made_family($person); $notes = PeopleController::get_notes_about_person($person); $origin_family = Family::where('id', $person->family_of_origin)->first(); return view('person.show', compact('person', 'solo_images', 'made_family', 'featured_image', 'origin_family', 'notes', 'logged_in_user')); }
function get_by_specy() { $aFamilies = Family::where('species_id', Input::get('specy_id'))->get(); /*$sHtml = '<option value="" disabled selected>Choose your Character</option>'; foreach($aFamilies as $aFamily){ }*/ echo json_encode($aFamilies); //echo (Family::all()->where('species_id', Input::get('specy_id'))); exit; }
public function profile($user_name = null) { if (trim($user_name) == "") { if (Session::has('user')) { $aUser = User::where('id', Session::get('user')['id'])->first()->toArray(); $aCurrentCharacter = Character::where('id', $aUser['current_character_id'])->first()->toArray(); $aCharacters = Character::where('user_id', $aUser['id'])->get()->toArray(); /*if(count($aCharacters) == 0){ return view('users.users.show')->with('characters', $aCharacters); }*/ //dd($aCharacters);die(); $aFamilies = Family::get()->toArray(); $aSpecies = Specy::get()->toArray(); return view('users.users.show')->with('aCharacters', $aCharacters)->with('aFamilies', $aFamilies)->with('aSpecies', $aSpecies)->with('aCharacters', $aCharacters)->with('aCurrentCharacter', $aCurrentCharacter); } else { return redirect('user'); } } else { } }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $data = array('title' => 'Dashboard', 'household_count' => Household::all()->count(), 'family_count' => Family::all()->count(), 'person_count' => Person::all()->count(), 'guest_count' => Guest::all()->count()); return view('dashboard')->with($data); }
public function profile($user_name = null) { if (trim($user_name) == "") { if (Session::has('user')) { $aUser['user'] = User::where('id', Session::get('user')['id'])->first()->toArray(); $aUser['current_character'] = Character::where('id', $aUser['user']['current_character_id'])->first()->toArray(); $aUser['active_characters'] = Character::where('user_id', $aUser['user']['id'])->where('status', Character::CHARACTER_STATUS_DEFAULT)->orWhere('status', Character::CHARACTER_STATUS_ENABLED_BY_USER)->orWhere('status', Character::CHARACTER_STATUS_ENABLED_BY_ADMIN)->get()->toArray(); $aUser['inactive_characters'] = Character::where('user_id', $aUser['user']['id'])->where('status', Character::CHARACTER_STATUS_DISABLED_BY_USER)->orWhere('status', Character::CHARACTER_STATUS_INACTIVE)->get()->toArray(); $aCharacters = Character::get()->toArray(); $aLoggedInUser['current_character'] = $aUser['current_character']; $aFamilies = Family::get()->toArray(); $aSpecies = Specy::get()->toArray(); return view('users.users.show')->with('aUser', $aUser)->with('aFamilies', $aFamilies)->with('aSpecies', $aSpecies)->with('aCharacters', $aCharacters)->with('aLoggedInUser', $aLoggedInUser); } else { return redirect('user'); } } else { } }
public function search() { $child = Child::where('nom_enfant', 'LIKE', '%' . \Input::get('terms') . '%')->where('user_id', \Auth::user()->id)->get(); $family = Family::where('nom_pere', 'LIKE', '%' . \Input::get('terms') . '%')->where('user_id', \Auth::user()->id)->orWhere('nom_mere', 'LIKE', '%' . \Input::get('terms') . '%')->get(); return view('families.search')->with(['child' => $child, 'family' => $family]); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(FormValidationChildFamilyRequest $request) { $cr = Classroom::where('user_id', \Auth::user()->id)->where('id', $request->classe)->first(); if ($cr->children()->where('school_year_id', $request->id_ann_scol)->count() > $cr->capacite_classe) { return redirect()->back()->withErrors("la classe est saturée"); } // promotion Exceptional check if (PromotionExceptional::checkExceptionalPromotion()) { if (PromotionExceptional::checkExcTimeOfPromotionIfExpired()) { if (PromotionExceptional::checkExcPriceandReturnIt() == 'no') { return redirect()->back()->withErrors("la promotion Exceptionnelle est active mais aucun prix n'est défini")->withInput(); } else { $prix_exc = PromotionExceptional::checkExcPriceandReturnIt(); } } else { return redirect()->back()->withErrors("la promotion Exceptionnelle est active mais la durée est expirée"); } } // promotion advanced check $prix_advance = ''; if (PromotionAdvance::checkAdvancePromotion()) { if ($request->nbr_month > 1) { if (PromotionAdvance::checkAdvIfPriceIsSet($request->nbr_month) !== false) { $prix_advance = PromotionAdvance::checkAdvIfPriceIsSet($request->nbr_month); } else { return redirect()->back()->withErrors("Aucun prix n'est\n défini pour cette Promotion de " . $request->nbr_month . ' Mois'); } } } $niveau_global = \Auth::user()->grades()->where('id', $request->grade)->first()->name; // famille for family profile $famille = Family::where('user_id', \Auth::user()->id)->where('email_responsable', $request->email_responsable)->first(); if (!$famille) { $family = new Family(); $family->nom_pere = ucfirst($request->nom_pere); $family->nom_mere = ucfirst($request->nom_mere); $family->email_responsable = $request->email_responsable; $family->adresse = $request->adresse; $family->numero_fixe = $request->numero_fixe; $family->numero_portable = $request->numero_portable; $family->cin = strtoupper($request->cin); $family->responsable = $request->responsable; $family->user_id = \Auth::user()->id; $family->school_year_id = $request->id_ann_scol; $family->save(); if ($family->id) { $father = Family::findOrFail($family->id); $child = new Child(); $child->date_naissance = Carbon::parse($request->date_naissance); $child->transport = $request->transport; $child->sexe = $request->sexe; $child->nom_enfant = ucfirst($request->nom_enfant); $child->age_enfant = $child->date_naissance->diffInYears(Carbon::now()); $child->nationalite = \DB::table('countries')->where('id', $request->nationalite)->first()->nom_fr_fr; $child->user_id = \Auth::user()->id; $child->school_year_id = $request->id_ann_scol; $image = \Input::file('photo'); if (!$image && empty($image)) { $filename = ''; } else { $filename = $image->getClientOriginalName(); $path = public_path('uploads/' . $filename); Image::make($image->getRealPath())->resize(313, 300)->save($path); } $child->photo = $filename; $child->family_id = $family->id; $child->save(); if ($child->id) { $ch = Child::find($child->id); if ($niveau_global == 'Lycée') { $ch->branches()->attach([$request->branche]); } if ($niveau_global == 'Maternelle' || $niveau_global == 'Primaire' || $niveau_global == 'Collège' || $niveau_global == 'Lycée' || $niveau_global == 'Crèche') { $ch->levels()->attach([$request->niveau]); } /*if($niveau_global == 'Crèche') { $ch->classrooms()->attach([$request->classe]); }*/ //classe $cr = Classroom::where('user_id', \Auth::user()->id)->where('id', $request->classe)->first(); $cr->children()->attach([$child->id]); $bill = new Bill(); $bill->status = 0; // if no promotion is active if (!PromotionAdvance::checkAdvancePromotion() && !PromotionExceptional::checkExceptionalPromotion()) { if (isset($request->reduction) && !empty($request->reduction) && !is_null($request->reduction)) { $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString(); $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString(); $bill->somme = PriceBill::countWhenNoPromotionButReduction($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $request->reduction); $bill->reductionPrix = $request->reduction; $bill->reduction = 1; $bill->school_year_id = SchoolYear::getSchoolYearId(); $bill->nbrMois = $request->nbr_month; } else { $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString(); $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString(); $bill->somme = PriceBill::countWhenNoPromotion($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport)); $bill->reduction = 0; $bill->school_year_id = $request->id_ann_scol; $bill->nbrMois = $request->nbr_month; } } if (PromotionAdvance::checkAdvancePromotion()) { if ($request->nbr_month >= 3) { $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString(); $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString(); $bill->somme = PromotionAdvance::countAccordingTo($prix_advance, PriceBill::assignPrice($request->niveau, $request->transport), $request->nbr_month); $bill->reduction = 1; $bill->reductionPrix = $prix_advance; $bill->school_year_id = $request->id_ann_scol; $bill->nbrMois = $request->nbr_month; } if ($request->nbr_month == 1) { if (isset($request->reduction) && !empty($request->reduction) && !is_null($request->reduction)) { $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString(); $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString(); $bill->somme = PriceBill::countWhenNoPromotionButReduction($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $request->reduction); $bill->reductionPrix = $request->reduction; $bill->reduction = 1; $bill->school_year_id = SchoolYear::getSchoolYearId(); $bill->nbrMois = $request->nbr_month; } else { $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString(); $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString(); $bill->somme = PriceBill::countWhenNoPromotion($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport)); $bill->reduction = 0; $bill->school_year_id = $request->id_ann_scol; $bill->nbrMois = $request->nbr_month; } } } if (PromotionExceptional::checkExceptionalPromotion()) { $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString(); $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString(); $bill->somme = PromotionExceptional::countAccordingTo($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $prix_exc); $bill->reductionPrix = $prix_exc; $bill->reduction = 1; $bill->school_year_id = $request->id_ann_scol; $bill->nbrMois = $request->nbr_month; } $bill->child_id = $child->id; $bill->user_id = \Auth::user()->id; $bill->save(); $enfant = Child::findOrFail($child->id); if ($father->responsable == 0) { $resp = $father->nom_mere; } else { $resp = $father->nom_pere; } event(new SendEmailToRespAfterRegistrationEvent($child->id, $resp, $enfant->nom_enfant, $enfant->created_at->toDateString(), $enfant->created_at->addMonth()->toDateString(), $father->email_responsable, $father->responsable, str_random(6))); } } return redirect()->back()->with('success', "l'élève et les parents ont bien été ajoutés! "); } else { // if the parent already in the database $child = new Child(); $child->date_naissance = Carbon::parse($request->date_naissance); $child->nom_enfant = $request->nom_enfant; $child->sexe = $request->sexe; $child->age_enfant = $child->date_naissance->diffInYears(Carbon::now()); $child->nationalite = \DB::table('countries')->where('id', $request->nationalite)->first()->nom_fr_fr; $child->school_year_id = $request->id_ann_scol; $child->transport = $request->transport; $child->user_id = \Auth::user()->id; $image = \Input::file('photo'); if (!$image && empty($image)) { $filename = ''; } else { $filename = $image->getClientOriginalName(); $path = public_path('uploads/' . $filename); Image::make($image->getRealPath())->resize(313, 300)->save($path); } $child->photo = $filename; $child->family_id = $famille->id; $resp = Family::findOrFail($famille->id); $user = User::where('email', $resp->email_responsable)->first(); if ($user) { $child->f_id = $user->id; $child->save(); if ($child->id) { $ch = Child::find($child->id); if ($niveau_global == 'Lycée') { $ch->branches()->attach([$request->branche]); } if ($niveau_global == 'Maternelle' || $niveau_global == 'Primaire' || $niveau_global == 'Collège' || $niveau_global == 'Lycée' || $niveau_global == 'Crèche') { $ch->levels()->attach([$request->niveau]); } if ($niveau_global == 'Crèche') { $ch->classrooms()->attach([$request->classe]); } $cr = Classroom::where('user_id', \Auth::user()->id)->where('id', $request->classe)->first(); $cr->children()->attach([$child->id]); $bill = new Bill(); $bill->status = 0; if (!PromotionAdvance::checkAdvancePromotion() && !PromotionExceptional::checkExceptionalPromotion()) { if (isset($request->reduction) && !empty($request->reduction) && !is_null($request->reduction)) { $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString(); $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString(); $bill->somme = PriceBill::countWhenNoPromotionButReduction($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $request->reduction); $bill->reductionPrix = $request->reduction; $bill->reduction = 1; $bill->school_year_id = $request->id_ann_scol; $bill->nbrMois = $request->nbr_month; } else { $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString(); $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString(); $bill->somme = PriceBill::countWhenNoPromotion($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport)); $bill->reduction = 0; $bill->school_year_id = $request->id_ann_scol; $bill->nbrMois = $request->nbr_month; } } if (PromotionAdvance::checkAdvancePromotion()) { if ($request->nbr_month >= 3) { $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString(); $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString(); $bill->somme = PromotionAdvance::countAccordingTo($prix_advance, PriceBill::assignPrice($request->niveau, $request->transport), $request->nbr_month); $bill->reduction = 1; $bill->reductionPrix = $prix_advance; $bill->school_year_id = $request->id_ann_scol; $bill->nbrMois = $request->nbr_month; } if ($request->nbr_month == 1) { if (isset($request->reduction) && !empty($request->reduction) && !is_null($request->reduction)) { $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString(); $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString(); $bill->somme = PriceBill::countWhenNoPromotionButReduction($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $request->reduction); $bill->reductionPrix = $request->reduction; $bill->reduction = 1; $bill->school_year_id = $request->id_ann_scol; $bill->nbrMois = $request->nbr_month; } else { $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString(); $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString(); $bill->somme = PriceBill::countWhenNoPromotion($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport)); $bill->reduction = 0; $bill->school_year_id = $request->id_ann_scol; $bill->nbrMois = $request->nbr_month; } } } if (PromotionExceptional::checkExceptionalPromotion()) { $bill->start = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->toDateString(); $bill->end = SchoolYear::find($request->id_ann_scol)->startch1->firstOfMonth()->addMonths($request->nbr_month)->toDateString(); $bill->somme = PromotionExceptional::countAccordingTo($request->nbr_month, PriceBill::assignPrice($request->niveau, $request->transport), $prix_exc); $bill->reductionPrix = $prix_exc; $bill->reduction = 1; $bill->school_year_id = $request->id_ann_scol; $bill->nbrMois = $request->nbr_month; } $bill->child_id = $child->id; $bill->f_id = $user->id; $bill->user_id = \Auth::user()->id; $bill->save(); } } return redirect()->back()->with('success', "l'élève a bien été ajouté! "); } }
<li class="menu_li"> <img src="{{ asset('images/tableau_de_bord.png') }}" alt=""> <a href="{{ url('index') }}"> Tableau de bord</a> </li> <li class="menu_li"> <img src="{{ asset('images/qui_sommes_nous.png') }}" alt="" id="qui_sommes_nous"><a href="">Qui sommes nous ?</a></li> <li class="menu_li"> <img src="{{ asset('images/contactez_nous.png') }}" alt="" id="contactez_nous"><a href="" >Contactez-nous</a></li> <li class="menu_li"> <img src="{{ asset('images/comment_ca_marche.png') }}" alt="" id="comment_ca_marche"><a href="" >Comment Ca marche</a></li> </ul> <div class="account" id="account"> <a href="{{ \Auth::user()->isAdmin() ? action('SchoolsController@edit',[\Auth::user()->id]): '' }}"> @if(Auth::user() && Auth::user()->isFamily()) <?php $resp = \App\Family::where('email_responsable', Auth::user()->email)->first(); if ($resp->responsable == 0) { echo 'Bienvenue ' . $resp->nom_mere; } else { echo 'Bienvenue ' . $resp->nom_pere; } ?> @else {{ 'Bienvenue '. \Auth::user()->name }} @endif </a> <img src="{{ asset('images/user.png') }}" alt="user">
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // $family = Family::find($id); if ($family) { User::where("family_id", "=", $id)->update(["family_id" => null]); Family::destroy($id); Session::flash('status', 'The user has been deleted!'); } return redirect('families'); }
/** * Get the families of the household. * * @return \Illuminate\Http\JsonResponse */ public function familyData($id) { $records = Family::join('households', 'families.household_id', '=', 'households.id')->join('persons', 'families.id', '=', 'persons.family_id')->select(['families.id', 'households.household_code', 'families.family_code', 'households.barangay', 'households.zone', \DB::raw('CONCAT(persons.last_name, ", ", persons.first_name) as family_head')])->where('persons.relationship', 'LIKE', 'Head of the%')->where('households.id', '=', $id); return Datatables::of($records)->addColumn('action', function ($record) { return '<a title="View" href="/family/' . $record->id . '" class="btn btn-xs blue"><i class="fa fa-search"></i></a> <a title="Edit" href="/family/' . $record->id . '/edit" class="btn btn-xs green"><i class="fa fa-edit"></i></a> <a title="Family Members" href="/family/' . $record->id . '/persons" class="btn btn-xs yellow"><i class="fa fa-user"></i></a>'; })->make(true); }
public function control($sUserName) { switch ($sUserName) { case 'logout': return redirect('user/logout'); case 'characters': return redirect('character/index'); case 'users': return redirect('user/index'); default: $oUser = User::where('user_name', $sUserName)->first(); if ($oUser == null) { dd("ALALALHJ!"); } else { $aLoggedInUser = null; $bOwner = false; $oMate = null; $bLoggedInUser = Session::has('user'); if ($bLoggedInUser) { if ($oUser->toArray()['id'] == Session::get('user')['id']) { $bOwner = true; } $aLoggedInUser['user'] = User::where('id', Session::get('user')['id'])->first()->toArray(); $aLoggedInUser['current_character'] = Character::where('id', $aLoggedInUser['user']['current_character_id'])->first()->toArray(); } $aUser['user'] = $oUser->toArray(); $aUser['current_character'] = Character::where('id', $aUser['user']['current_character_id'])->first()->toArray(); $aUser['active_characters'] = Character::where('user_id', $aUser['user']['id'])->where('status', Character::CHARACTER_STATUS_DEFAULT)->orWhere('status', Character::CHARACTER_STATUS_ENABLED_BY_USER)->orWhere('status', Character::CHARACTER_STATUS_ENABLED_BY_ADMIN)->get()->toArray(); $aUser['inactive_characters'] = Character::where('user_id', $aUser['user']['id'])->where('status', Character::CHARACTER_STATUS_DISABLED_BY_USER)->orWhere('status', Character::CHARACTER_STATUS_INACTIVE)->get()->toArray(); $aUser['user_settings'] = UserSetting::where('user_id', $oUser->toArray()['id'])->first()->toArray(); $aUser['current_photo'] = Photo::where('id', $aUser['user']['photo_id'])->first()->toArray(); //Mates $bRequestedFromLoggedInUser = false; if ($bLoggedInUser) { $sSql = 'SELECT * from mates where ((from_user_id = ' . $aUser['user']['id'] . ' AND to_user_id = ' . Session::get('user')['id'] . ') OR (from_user_id = ' . Session::get('user')['id'] . ' AND to_user_id = ' . $aUser['user']['id'] . ')) AND (status = ' . Mate::MATE_STATUS_ADDED_BY_USER . ' OR status <> ' . Mate::MATE_STATUS_ADDED_BY_ADMIN . ')'; $oMate = DB::select($sSql); $oMate = Mate::where('from_user_id', $aUser['user']['id'])->orWhere('to_user_id', Session::get('user')['id'])->orWhere(function ($query) { $query->where('status', Mate::MATE_STATUS_ADDED_BY_ADMIN)->where('status', Mate::MATE_STATUS_ADDED_BY_ADMIN); })->orderBy('id', 'desc')->first(); } $aUser['mate'] = is_null($oMate) || empty($oMate) ? NULL : $oMate->toArray(); if ($aUser['mate']['from_user_id'] == Session::get('user')['id']) { $bRequestedFromLoggedInUser = true; } //End of mate //Likes $oUserUserLikers = Like::where('to_user_id', $aUser['user']['id'])->where('like_type', Like::LIKE_TYPE_USER)->where('user_id', $aUser['user']['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aUser['user']['likers'] = $oUserUserLikers ? $oUserUserLikers->toArray() : []; $aUser['user']['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aUser['user']['likers'], $aLoggedInUser['user']['id']); $oCurrentCharacterLikers = Like::where('to_user_id', $aUser['user']['id'])->where('like_type', Like::LIKE_TYPE_CHARACTER)->where('character_id', $aUser['user']['current_character_id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aUser['current_character']['likers'] = $oCurrentCharacterLikers ? $oCurrentCharacterLikers->toArray() : []; $aUser['current_character']['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aUser['current_character']['likers'], $aLoggedInUser['user']['id']); for ($i = 0; $i < count($aUser['active_characters']); $i++) { $aActiveCharacterLikers = Like::where('to_user_id', $aUser['user']['id'])->where('like_type', Like::LIKE_TYPE_CHARACTER)->where('character_id', $aUser['active_characters'][$i]['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aUser['active_characters'][$i]['likers'] = $aActiveCharacterLikers ? $aActiveCharacterLikers->toArray() : []; $aUser['active_characters'][$i]['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aUser['active_characters'][$i]['likers'], $aLoggedInUser['user']['id']); } for ($i = 0; $i < count($aUser['inactive_characters']); $i++) { $aInActiveCharacterLikers = Like::where('to_user_id', $aUser['user']['id'])->where('like_type', Like::LIKE_TYPE_CHARACTER)->where('character_id', $aUser['inactive_characters'][$i]['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aUser['inactive_characters'][$i]['likers'] = $aInActiveCharacterLikers ? $aInActiveCharacterLikers->toArray() : []; $aUser['inactive_characters'][$i]['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aUser['inactive_characters'][$i]['likers'], $aLoggedInUser['user']['id']); } $oCurrentPhotoLikers = Like::where('to_user_id', $aUser['user']['id'])->where('like_type', Like::LIKE_TYPE_PHOTO)->where('photo_id', $aUser['current_photo']['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aUser['current_photo']['likers'] = $oCurrentPhotoLikers ? $oCurrentPhotoLikers->toArray() : []; $aUser['current_photo']['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aUser['current_photo']['likers'], $aLoggedInUser['user']['id']); //dd($aUser); $aFamilies = Family::where('status', Family::FAMILY_STATUS_DEFAULT)->get()->toArray(); $aSpecies = Specy::where('status', Specy::SPECY_STATUS_DEFAULT)->get()->toArray(); return view('users.users.profile')->with('aLoggedInUser', is_array($aLoggedInUser) ? $aLoggedInUser : null)->with('aUser', $aUser)->with('bOwner', $bOwner)->with('bRequestedFromLoggedInUser', $bRequestedFromLoggedInUser)->with('bLoggedInUser', $bLoggedInUser)->with('aSpecies', $aSpecies)->with('aFamilies', $aFamilies); } } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy(Family $family) { $family->delete(); return redirect()->route('family.index'); }
/** * Get family rankings based on type * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function getFamily(Request $request) { pagetitle([trans('ranking.player') . ' ' . trans('main.apps.ranking'), settings('server_name')]); $families = Family::type($request->segment(3))->paginate(); return view('front.ranking.family', compact('families')); }
function get_comments_by_photo_id() { $iFromType = Input::get('from_type'); $iFromID = Input::get('from_id'); $aLoggedInUser = User::where('id', Session::get('user')['id'])->first()->toArray(); switch ($iFromType) { case Comment::COMMENT_FROM_TYPE_USER: $aFromItem = User::where('id', $iFromID)->first()->toArray(); $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_USER)->where('user_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : []; $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']); $oComments = Comment::where('user_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get(); break; case Comment::COMMENT_FROM_TYPE_CHARACTER: $aFromItem = Character::where('id', $iFromID)->first()->toArray(); $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_CHARACTER)->where('character_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : []; $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']); $oComments = Comment::where('character_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get(); break; case Comment::COMMENT_FROM_TYPE_FAMILY: $aFromItem = Family::where('id', $iFromID)->first()->toArray(); $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_FAMILY)->where('family_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : []; $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']); $oComments = Comment::where('family_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get(); break; case Comment::COMMENT_FROM_TYPE_SPECY: $aFromItem = Specy::where('id', $iFromID)->first()->toArray(); $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_SPECY)->where('specy_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : []; $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']); $oComments = Comment::where('specy_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get(); break; case Comment::COMMENT_FROM_TYPE_PHOTO: $aFromItem = Photo::where('id', $iFromID)->first()->toArray(); $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_PHOTO)->where('photo_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : []; $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']); $oComments = Comment::where('photo_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get(); break; case Comment::COMMENT_FROM_TYPE_POST: $aFromItem = Post::where('id', $iFromID)->first()->toArray(); $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_POST)->where('post_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : []; $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']); $oComments = Comment::where('post_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get(); break; case Comment::COMMENT_FROM_TYPE_MATE: $aFromItem = Mate::where('id', $iFromID)->first()->toArray(); $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_MATE)->where('mate_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : []; $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']); $oComments = Comment::where('mate_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get(); break; default: $aFromItem = User::where('id', $iFromID)->first()->toArray(); $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_USER)->where('user_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : []; $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']); $oComments = Comment::where('user_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get(); break; } $oComments = is_array($oComments->toArray()) && count($oComments->toArray() > 0) ? $oComments->toArray() : []; $aComments = null; $iFromWhereID = null; for ($i = 0; $i < count($oComments); $i++) { $aComments[$i] = $oComments[$i]; $aComments[$i]['from_user'] = User::where('id', $oComments[$i]['from_user_id'])->first()->toArray(); if ($oComments[$i]['comment_photo_id'] > 0) { $aComments[$i]['photo_comment'] = Photo::where('id', $oComments[$i]['comment_photo_id'])->first()->toArray(); } $iFromType = $oComments[$i]['comment_from_type']; switch ($iFromType) { case Comment::COMMENT_FROM_TYPE_USER: $iFromWhereID = "user_id"; $aComments[$i]['from'] = User::where('id', $oComments[$i][$iFromWhereID])->first()->toArray(); break; case Comment::COMMENT_FROM_TYPE_CHARACTER: $iFromWhereID = "character_id"; $aComments[$i]['from'] = Character::where('id', $oComments[$i][$iFromWhereID])->first()->toArray(); break; case Comment::COMMENT_FROM_TYPE_FAMILY: $iFromWhereID = "family_id"; $aComments[$i]['from'] = Family::where('id', $oComments[$i][$iFromWhereID])->first()->toArray(); break; case Comment::COMMENT_FROM_TYPE_SPECY: $iFromWhereID = "specy_id"; $aComments[$i]['from'] = Specy::where('id', $oComments[$i][$iFromWhereID])->first()->toArray(); break; case Comment::COMMENT_FROM_TYPE_PHOTO: $iFromWhereID = "photo_id"; $aComments[$i]['from'] = Photo::where('id', $oComments[$i][$iFromWhereID])->first()->toArray(); break; case Comment::COMMENT_FROM_TYPE_POST: $iFromWhereID = "post_id"; $aComments[$i]['from'] = Post::where('id', $oComments[$i][$iFromWhereID])->first()->toArray(); break; case Comment::COMMENT_FROM_TYPE_MATE: $iFromWhereID = "mate_id"; $aComments[$i]['from'] = Mate::where('id', $oComments[$i][$iFromWhereID])->first()->toArray(); break; default: $iFromWhereID = "user_id"; $aComments[$i]['from'] = User::where('id', $oComments[$i][$iFromWhereID])->first()->toArray(); break; } } $view = view('users.comments.show')->with('aComments', $aComments); $htmlFromWhatView = view('users.comments.partials.partial-comment-from-what-display')->with('aFromItem', $aFromItem)->with('iFromType', $iFromType); if ($oComments) { return response()->json(['view' => (string) $view, 'status' => true, 'message' => "Successfully archived character", 'what_to_display' => (string) $htmlFromWhatView]); } else { $htmlFromWhatView = view('users.comments.partials.partial-comment-from-what-display')->with('aFromItem', $aFromItem)->with('iFromType', $iFromType); $view = view('users.comments.show')->with('aComments', []); if ($htmlFromWhatView != "") { return response()->json(['view' => (string) $view, 'status' => true, 'message' => "Successfully archived character", 'what_to_display' => (string) $htmlFromWhatView]); } else { echo json_encode(array('status' => false, 'message' => "Something went wrong. Please try again later")); } } die; }
public function forgetpass() { if (\Request::ajax()) { $cin = \Input::get('cin'); if (isset($cin) && !empty($cin)) { $lacarte = Family::where('cin', $cin)->first(); if ($lacarte) { $pass_without = str_random(6); $user = User::where('email', $lacarte->email_responsable)->first(); $user->password = \Hash::make($pass_without); $user->save(); $info = ['email' => $user->email, 'new_password' => $pass_without, 'name' => $user->nom_responsable, 'ecole' => $user->name, 'sexe' => $user->sexe, 'responsable' => $lacarte->responsable, 'date' => Carbon::now()->toDateString()]; Mail::queue('emails.forgetpass', $info, function ($message) use($info) { $message->to($info['email'], 'ok')->from('*****@*****.**')->subject('Bienvenue !'); }); echo 'Votre Nouveau mot de pass a bien été envoyé à votre email'; } else { echo 'Le Numéro de Cin fourni est Incorrect'; } } else { $email = \Input::get('email'); $email = User::where('email', $email)->whereIn('type', ['famille', 'ecole'])->first(); if ($email) { if ($email->type == 'famille') { echo 'famille'; } elseif ($email->type == 'ecole') { $utilisateur = User::where('email', $email->email)->where('type', 'ecole')->first(); $pass_without = str_random(6); $utilisateur->password = \Hash::make($pass_without); $utilisateur->save(); $infor = ['email' => $utilisateur->email, 'new_password' => $pass_without, 'name' => $utilisateur->nom_responsable, 'ecole' => $utilisateur->name, 'sexe' => $utilisateur->sexe, 'date' => Carbon::now()->toDateString()]; Mail::queue('emails.forgetpass', $infor, function ($message) use($infor) { $message->to($infor['email'], 'ok')->from('*****@*****.**')->subject('Bienvenue !'); }); echo 'Votre Nouveau mot de pass a bien été envoyé à votre email'; } /* Mail::send('emails.school',$info,function($message){ $message->to($this->email,'ok')->from('*****@*****.**')->subject('Bienvenue !'); });*/ } else { echo 'cet Email est incorrect'; } } } }
public function checktoreturn(Request $request) { /* "email_resp" => "*****@*****.**" "fix" => "0537451258" "portable" => "0663083611" "nom_pere" => "Hamid bouslami" "nom_mere" => "Samar fati"*/ if (\Request::ajax()) { $count = 0; $fix = Family::where('numero_fixe', $request->fix)->where('user_id', \Auth::user()->id)->first(); if ($fix) { $count++; } $portable = Family::where('numero_portable', $request->portable)->where('user_id', \Auth::user()->id)->first(); if ($portable) { $count++; } $email = Family::where('email_responsable', $request->email_resp)->where('user_id', \Auth::user()->id)->first(); if ($email) { $count++; } $pere = Family::where('nom_pere', $request->nom_pere)->where('user_id', \Auth::user()->id)->first(); if ($pere) { $count++; } $mere = Family::where('nom_mere', $request->nom_mere)->where('user_id', \Auth::user()->id)->first(); if ($mere) { $count++; } $cin = Family::where('cin', 'LIKE', $request->cin . '%')->where('user_id', \Auth::user()->id)->first(); if ($cin) { $count++; } if ($count >= 3) { echo 'here'; } } }
public function outline() { $user = \Auth::user(); // $original_families = Family::original('created_at')->get(); $original_keems = Family::keems('created_at')->original()->get(); $original_husbands = Family::husbands('created_at')->original()->get(); $original_kemlers = Family::kemlers('created_at')->original()->get(); $original_kaplans = Family::kaplans('created_at')->original()->get(); return view('pages.outline', compact('user', 'original_keems', 'original_husbands', 'original_kemlers', 'original_kaplans')); }
/** * ajouter un enfant avec seulement l'id de parent * @param Request $request */ public function store_enfant(ajouterEnfantRequest $request) { $child = new Child(); $child->date_naissance = Carbon::parse($request->date_naissance); $child->nom_enfant = $request->nom_enfant; $child->age_enfant = $child->date_naissance->diffInYears(Carbon::now()); $child->transport = $request->transport; $child->user_id = \Auth::user()->id; $image = Input::file('photo'); $filename = $image->getClientOriginalName(); $path = public_path('uploads/' . $filename); if (Image::make($image->getRealPath())->resize(313, 300)->save($path)) { $child->photo = $filename; $child->family_id = $request->pere; $resp = Family::findOrFail($request->pere); $user = User::where('email', $resp->email_responsable)->first(); if ($user) { $child->f_id = $user->id; $child->save(); if ($child->id) { $bill = new Bill(); $bill->start = Carbon::now()->toDateString(); $bill->end = Carbon::now()->addMonth()->toDateString(); $bill->status = 0; if ($request->transport == 1) { if (Transport::where('user_id', \Auth::user()->id)->exists()) { $transport_somme = Transport::where('user_id', \Auth::user()->id)->first()->somme; $bill_somme = CategoryBill::getYear(Carbon::parse($request->date_naissance)); $bill->somme = $transport_somme + $bill_somme; } else { $bill->somme = CategoryBill::getYear(Carbon::parse($request->date_naissance)); } } else { $bill->somme = CategoryBill::getYear(Carbon::parse($request->date_naissance)); } $bill->child_id = $child->id; $bill->user_id = \Auth::user()->id; $bill->save(); } } } return redirect()->back()->with('success', "l'enfant a bien été ajouté! "); }
public function families() { return Family::whereIn("id", $this->users()->whereNotNull("family_id")->select('family_id')->lists('family_id'))->get(); // or whatever your namespace is }
/** * @param $ids */ public function exportPdf($ids = null) { $ids = explode(',', substr($ids, 0, -1)); $ids = array_unique($ids); $family = Family::whereIn('id', $ids)->where('user_id', \Auth::user()->id)->get(['id', 'responsable', 'nom_pere', 'nom_mere']); Excel::create('La liste des familles', function ($excel) use($family, $ids) { $excel->sheet('La liste des familles', function ($sheet) use($family, $ids) { foreach ($family as $f) { $count = 0; if ($f->responsable == 0) { $f->responsable = $f->nom_mere; } else { $f->responsable = $f->nom_pere; } foreach ($f->children as $c) { foreach ($c->bills as $b) { if ($b->status == 0) { $count += 1; } } } if ($count > 0) { $f->status = 'Non Réglée'; } else { $f->status = 'Réglée'; } unset($f->id); } $sheet->setWidth('A', 20); $sheet->setWidth('B', 20); $sheet->setWidth('C', 20); $sheet->setWidth('D', 20); $sheet->fromModel($family); $sheet->setAllBorders('thin'); $sheet->setFontFamily('OpenSans'); $sheet->setFontSize(13); $sheet->setFontBold(false); for ($i = 1; $i <= count($ids) + 1; $i++) { $sheet->setHeight($i, 25); $sheet->row($i, function ($rows) { $rows->setFontColor('#556b7b'); $rows->setAlignment('center'); }); $sheet->cells('A' . $i . ':' . 'D' . $i, function ($cells) { $cells->setValignment('middle'); $cells->setFontColor('#556b7b'); $cells->setFont(array('family' => 'OpenSans', 'size' => '13', 'bold' => false)); }); } // normal header $sheet->cells('A1:D1', function ($cells) { $cells->setBackground('#e9f1f3'); $cells->setFontColor('#556b7b'); $cells->setFont(array('family' => 'OpenSans', 'size' => '15', 'bold' => true)); }); $sheet->row(1, array('Responsable', 'Nom Père', 'Nom Mère', 'Statut de Paiement')); }); })->export('pdf'); }
public function exportExcel() { if (Gate::denies('download', Family::class)) { abort(403); } $records = Family::join('households', 'families.household_id', '=', 'households.id')->join('persons', 'families.id', '=', 'persons.family_id')->select(['households.household_code', 'families.family_code', \DB::raw("CONCAT(persons.last_name, ', ', persons.first_name) as 'family_head'"), 'households.barangay', 'households.zone', 'families.years_living', 'families.current_living', 'families.current_living_other', 'families.still_living', 'families.assistance_ngo_agency', 'families.assistance_what', 'families.first_source', 'families.first_source_specific', 'families.first_source_member', 'families.first_source_gender', 'families.first_source_amount', 'families.second_source', 'families.second_source_specific', 'families.second_source_member', 'families.second_source_gender', 'families.second_source_amount', 'families.third_source', 'families.third_source_specific', 'families.third_source_member', 'families.third_source_gender', 'families.third_source_amount', 'families.combined_family_income', 'families.family_monthly_expenditure', 'families.amount_to_access_house', 'families.coping_strategies', 'families.power_making_decision', 'families.distance_health_facility', 'families.latrine_access', 'families.latrine_type', 'families.human_waste_disposal', 'families.source_for_drinking', 'families.source_domestic_use', 'families.access_sanitation_facilities', 'families.closest_evac_center', 'families.aware_living_in_ndz', 'families.hazards_affected_community', 'families.hazards_affected_community_other', 'families.land_ownership_status', 'families.with_land_title', 'families.pay_anything_to_live', 'families.aware_relocation_program', 'families.relocation_preference', 'families.relocation_preference_other', 'families.relocation_plan', 'families.relocation_plan_other', 'families.number_relatives_within_brgy', 'families.number_family_members', 'families.gps_points', 'families.ofda_beneficiary', 'families.remarks', 'families.profiling_date', 'families.interviewer_name'])->where('persons.relationship', 'LIKE', 'Head of the%'); if (\Auth::user()->group->assigned_barangay != 'All') { $records = $records->where('households.barangay', '=', \Auth::user()->group->assigned_barangay); } $records = $records->orderBy('families.family_code', 'asc')->get(); $recordsArray = []; $recordsArray[] = ['household_code', 'family_code', 'family_head', 'barangay', 'zone', 'years_living', 'current_living', 'current_living_other', 'still_living', 'assistance_ngo_agency', 'assistance_what', 'first_source', 'first_source_specific', 'first_source_member', 'first_source_gender', 'first_source_amount', 'second_source', 'second_source_specific', 'second_source_member', 'second_source_gender', 'second_source_amount', 'third_source', 'third_source_specific', 'third_source_member', 'third_source_gender', 'third_source_amount', 'combined_family_income', 'family_monthly_expenditure', 'amount_to_access_house', 'coping_strategies', 'power_making_decision', 'distance_health_facility', 'latrine_access', 'latrine_type', 'human_waste_disposal', 'source_for_drinking', 'source_domestic_use', 'access_sanitation_facilities', 'closest_evac_center', 'aware_living_in_ndz', 'hazards_affected_community', 'hazards_affected_community_other', 'land_ownership_status', 'with_land_title', 'pay_anything_to_live', 'aware_relocation_program', 'relocation_preference', 'relocation_preference_other', 'relocation_plan', 'relocation_plan_other', 'number_relatives_within_brgy', 'number_family_members', 'gps_points', 'ofda_beneficiary', 'remarks', 'profiling_date', 'interviewer_name']; foreach ($records as $record) { $recordsArray[] = $record->toArray(); } $now = Carbon::now('Asia/Manila'); $file_name = 'arp_families_' . $now->format('Ymd_His'); Excel::create($file_name, function ($excel) use($recordsArray) { $excel->setTitle('ARP Families'); $excel->setDescription('List of ARP Families'); $excel->sheet('Families', function ($sheet) use($recordsArray) { $sheet->fromArray($recordsArray, null, 'A1', false, false); }); })->download('xlsx'); }
/** * Execute the console command. * * @return mixed */ public function fire() { // $file = fopen("/home/daniel/Downloads/new_file.csv", "r"); while (!feof($file)) { print_r(fgetcsv($file)); $row = fgetcsv($file); $family_name = $row[1]; $user_name = $row[2]; $church_id = 1; $church = Church::find($church_id); // $zone_hash = {}; // $zone_hash["0"] = $church->zones()->where("name","=","Zone 0")->first()->id; // $zone_hash["1"] = $church->zones()->where("name","=","Zone 1")->first()->id; // $zone_hash["2"] = $church->zones()->where("name","=","Zone 2")->first()->id; // $zone_hash["3"] = $church->zones()->where("name","=","Zone 3")->first()->id; // $zone_hash["4"] = $church->zones()->where("name","=","Zone 4")->first()->id; // $zone_hash["5"] = $church->zones()->where("name","=","Zone 5")->first()->id; // $no_zone = $church->zones()->where("name","=","No Zone")->first()->id; $user = App\User::where("name", "=", $user_name)->where("church_id", "=", $church_id)->first(); $family = App\Family::where("name", "=", $family_name)->first(); if ($user) { if ($family) { $family_id = $family->id; if ($family_id == $user->family_id) { } else { $user->family_id = $family_id; $user->save(); } } else { $new_family = new Family(); $new_family->name = $row[1]; $new_family->save(); User::whereIn("id", $user->id)->update(["family_id" => $new_family->id]); } } else { $new_user = new User(); $new_user->name = $row[2]; $new_user->dob = $row[4]; $new_user->weddingDate = $row[5]; $new_user->baptism_taken = trim($row[6]) == "YES" ? true : false; $new_user->annointing_taken = trim($row[7]) == "YES" ? true : false; $new_user->phone_number = $row[8]; $new_user->email = $row[9]; $new_user->member_type = trim($row[10]) == "YES" ? 0 : 2; $new_user->address = $row[11] + $row[12] + $row[13] + $row[14]; switch (trim($row[15])) { case "0": $new_user->zone_id = $church->zones()->where("name", "=", "Zone 0")->first()->id; break; case "1": $new_user->zone_id = $church->zones()->where("name", "=", "Zone 1")->first()->id; break; case "2": $new_user->zone_id = $church->zones()->where("name", "=", "Zone 2")->first()->id; break; case "3": $new_user->zone_id = $church->zones()->where("name", "=", "Zone 3")->first()->id; break; case "4": $new_user->zone_id = $church->zones()->where("name", "=", "Zone 4")->first()->id; break; case "5": $new_user->zone_id = $church->zones()->where("name", "=", "Zone 5")->first()->id; break; default: $new_user->zone_id = $church->zones()->where("name", "=", "No Zone")->first()->id; } $new_user->church_id = $church_id; if ($family) { $family_id = $family->id; $new_user->family_id = $family_id; $new_user->save(); } else { $new_family = new Family(); $new_family->name = $row[1]; $new_family->save(); $new_user->family_id = $new_family->id; $new_user->save(); } } } fclose($file); }