Esempio n. 1
0
 public function update()
 {
     if (!Auth::user()) {
         return Response::json(array('success' => false))->setCallback(Input::get('callback'));
     }
     $user = Auth::user();
     $member = Member::where('user_id', '=', $user->id)->first();
     $members_interests = MembersInterests::where('current_id', '=', $member->id)->get();
     $members_destinations = MembersDestinations::where('current_id', '=', $member->id)->get();
     foreach ($members_interests as $int) {
         $int->delete();
     }
     foreach ($members_destinations as $dest) {
         $dest->delete();
     }
     try {
         $member->firstname = Input::get('firstname');
         $member->lastname = Input::get('lastname');
         $member->address = Input::get('address');
         $member->suburb = Input::get('suburb');
         $member->postcode = Input::get('postcode');
         $member->gender = Input::get('gender');
         // Make sure DOB is of format dd-mm-yyyy
         $dM = Input::get('dob-month');
         $dD = Input::get('dob-day');
         if (strlen($dM) === 1) {
             $dM = '0' . $dM;
         }
         if (strlen($dD) === 1) {
             $dD = '0' . $dD;
         }
         $member->dob = Input::get('dob-year') . '-' . $dM . '-' . $dD;
         $member->phone = Input::get('phone');
         $member->state = Input::get('state');
         $member->hasflown = Input::has('hasflown') ? 'y' : 'n';
         $member->flightsperyear = Input::get('flight-count');
         $member->member_type = Input::get('member_type') != '' ? Input::get('member_type') : '0';
         $member->signup_marketing = Input::has('terms') ? 1 : 0;
         $member->points = 0;
         $member->audit = $user->audit;
         // Save member so we have access to their ID
         $member->save();
         // Save member destinations
         if (Input::has('favourite-dest')) {
             $dest = Input::get('favourite-dest');
             for ($i = 0; $i < count($dest); $i++) {
                 $newDest = new MembersDestinations();
                 $newDest->current_id = $member->id;
                 $newDest->destination_id = $dest[$i];
                 $newDest->save();
             }
         }
         // Save member interests
         if (Input::has('interests')) {
             $intr = Input::get('interests');
             for ($i = 0; $i < count($intr); $i++) {
                 $newIntr = new MembersInterests();
                 $newIntr->current_id = $member->id;
                 $newIntr->interest_id = $intr[$i];
                 $newIntr->save();
             }
         }
     } catch (Exception $e) {
         // Return an error
         return Response::json(array('message' => 'Invalid data sent', 'success' => false))->setCallback(Input::get('callback'));
     }
     // Sign them up for email spam
     try {
         $this->crmSignup($user, $member);
     } catch (Exception $e) {
         // Just in case,
     }
     // Return success
     return Response::json(array('success' => true, 'data' => $member, 'cards' => Member::getCards()))->setCallback(Input::get('callback'));
 }
Esempio n. 2
0
 public function edit()
 {
     if (!Auth::user()) {
         return Redirect::to('/login');
     }
     // Get interest and destination choice data
     $data = array('interests' => Interests::all()->sortBy('orderIndex'), 'interests_categories' => InterestsCategories::all()->sortBy('orderIndex'), 'destinations' => Destinations::where('publish', '=', 1)->get()->sortBy('orderIndex'), 'member_cards' => Member::getCards(), 'member' => Member::where('user_id', '=', Auth::user()->id)->first(), 'user' => Auth::user());
     // populate members destinations into easily emutable array
     $data['members_destinations'] = array();
     $m_dest = MembersDestinations::where('current_id', '=', $data['member']->id)->get();
     foreach ($m_dest as $dest) {
         $data['members_destinations'][] = $dest->destination_id;
     }
     // populate members interests into easily emutable array
     $data['members_interests'] = array();
     $m_int = MembersInterests::where('current_id', '=', $data['member']->id)->get();
     foreach ($m_int as $int) {
         $data['members_interests'][] = $int->interest_id;
     }
     // Convert object to array so it can be chunked for signup list
     $tmpdest = array();
     foreach ($data['destinations'] as $dest) {
         $tmpdest[] = $dest;
     }
     $data['destinations_chunks'] = array_chunk($tmpdest, ceil(count($data['destinations']) / 3));
     // Push view to content
     $this->layout->content = View::make('pages.edit', $data);
 }