示例#1
0
 public function updateCommentary()
 {
     /* @var $user User */
     $uid = Input::get('uid');
     $user = User::find($uid);
     $user->commentary = Input::get('user_commentary');
     $user->monitored = Input::get('monitored');
     if (Input::get('password') == Input::get('re-password') && Input::get('re-password') != '') {
         $user->password = Hash::make(Input::get('re-password'));
     }
     // Update announcement info.
     $oldAnnouncement = $user->announcement_stream;
     $user->announcement_stream = Input::get('announcement_stream');
     // New announcements will start next day.
     if ($oldAnnouncement != $user->announcement_stream) {
         $start = new Carbon\Carbon();
         $start->setTime(0, 0, 0)->addDay();
         $user->announcement_start = $start;
         $user->announcement_expires = $start->addDays(Config::get('announcements.duration'));
     }
     if (Input::get('showRegion') == 1) {
         $user->show_continent = 1;
     }
     if (Input::get('showDot') == 1) {
         $user->show_dot = 1;
     }
     if (Input::get('showRegion') == 0) {
         $user->show_continent = 0;
     }
     if (Input::get('showDot') == 0) {
         $user->show_dot = 0;
     }
     $user->save();
     return Redirect::back();
 }
示例#2
0
 public function getExpiredAttribute()
 {
     $duration = $this->attributes['post_duration'];
     $createdAt = new \Carbon\Carbon($this->attributes['created_at'], 'Asia/Kolkata');
     $expireAt = $createdAt->addDays($duration);
     $currentDate = \Carbon\Carbon::now(new \DateTimeZone('Asia/Kolkata'));
     if ($currentDate >= $expireAt) {
         // $expired = 1;
         return 1;
     } else {
         // $expired = 0;
         return 0;
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     /*$validator = $this->validate();
     
     		if($validator->fails()){
     			return Redirect::back()
     					->withErrors($validator->messages())
     					->withInput(Input::all());	
     		}*/
     $validator = $this->validate();
     if ($validator->fails()) {
         if (Request::ajax()) {
             return Response::json(array('success' => false, 'messages' => $validator->messages()));
         } else {
             return Redirect::back()->withErrors($validator->messages())->withInput(Input::all());
         }
     }
     $donor = Donor::find(Input::get('donor_id'));
     $product = Product::find(Input::get('product_id'));
     // Donor can only give blood of it's own blood type
     if (strtolower($product->category->name) == 'blood') {
         if (strtolower($donor->blood_group->name) != strtolower($product->name)) {
             //apply ajax
             if (Request::ajax()) {
                 return Response::json(array('success' => false, 'messages' => ['This donor is only able to donate blood of type ' . $donor->blood_group->name . ' only.']));
             } else {
                 return Redirect::back()->withErrors(['This donor is only able to donate blood of type ' . $donor->blood_group->name . ' only.'])->withInput(Input::all());
             }
         }
     }
     // Check if donor is eligible to make the donation
     if (count($donor->donations)) {
         // Check if donor is donating within the validity period
         $validity_days = $product->validity_period;
         $last_donated_at = new Carbon\Carbon($donor->donations->last()->donated_at);
         $next_possible_donation_date = $last_donated_at->addDays($validity_days);
         $today = Carbon\Carbon::now();
         if ($next_possible_donation_date->gt($today)) {
             //if ajax request nam return response.
             if (Request::ajax()) {
                 return Response::json(array('success' => false, 'messages' => ['This donor is not able to donate untill ' . $next_possible_donation_date->format('Y-m-d') . '.']));
             } else {
                 return Redirect::back()->withErrors(['This donor is not able to donate untill ' . $next_possible_donation_date->format('Y-m-d') . '.'])->withInput(Input::all());
             }
         }
     }
     DB::beginTransaction();
     $donation = new Donation();
     $donation->donor_id = Input::get('donor_id');
     $donation->product_id = Input::get('product_id');
     $donation->location_id = Input::get('location_id');
     $donation->quantity = Input::get('quantity');
     $donation->donated_at = Input::get('donated_at');
     $donation->save();
     /*if (Request::ajax()){
     			return Response::json(array(
     				'success' => true,
     				'donors' => [''] + Donor::all()->lists('name_with_blood_group', 'id'),
     				'donor_id' => $donor->id,
     			));
     		}*/
     // Increment product quantity
     /*$product = $donation->product;
     		$product->quantity = $product->quantity + $donation->quantity;
     		$product->save();*/
     // increment count in item_in table
     // increment count in location_products table
     $response = Event::fire('donation.create', array($donation));
     DB::commit();
     if (Request::ajax()) {
         return Response::json(array('success' => true, 'donors' => [''] + Donor::all()->lists('name_with_blood_group', 'id'), 'donor_id' => $donor->id));
     } else {
         Session::flash('success', 'Successfully created donation!');
         return Redirect::route('donation.index');
     }
 }