Example #1
1
 public function change_password($tmp_code = null)
 {
     $tmp_check = false;
     if (!Auth::check()) {
         $code_created = new Carbon($this->tmp_code_created);
         $tmp_check = !empty($this->tmp_code) && $this->tmp_code == $tmp_code && $code_created->diff(new Carbon())->days <= 7;
         if (!$tmp_check) {
             FormMessage::add('tmp_code', 'The code was incorrect');
             return false;
         }
     }
     $details = Request::all();
     $rules = array('new_password' => 'required|confirmed|min:4');
     if (!($tmp_check || Auth::check() && Auth::action('user.edit') && Auth::user()->id != $this->id)) {
         $rules['current_password'] = '******';
     }
     $v = Validator::make($details, $rules);
     if ($v->passes()) {
         // check password
         if (!empty($rules['current_password']) && !Hash::check($details['current_password'], $this->password)) {
             FormMessage::add('current_password', 'The current password was incorrect');
             return false;
         }
         // if user can change his password then change it
         if (Auth::action('account.password', ['user_id' => $this->id]) || Auth::check() && Auth::action('user.edit')) {
             $this->password = Hash::make($details['new_password']);
             $this->tmp_code = '';
             $this->save();
             return true;
         }
     } else {
         FormMessage::set($v->messages());
     }
     return false;
 }
Example #2
1
 public function getDateDiff()
 {
     $created = new Carbon($this->created_at);
     $now = Carbon::now();
     $difference = $created->diff($now)->days < 1 ? 'today' : $created->diffForHumans($now, true);
     if ($difference == 'today') {
         return $difference;
     }
     return $difference . " ago";
     //$cDate->diffInDays() . " days ago";
 }
Example #3
1
 public function date($date)
 {
     $created = new Carbon($date);
     $now = Carbon::now();
     $difference = $created->diff($now)->days < 1 ? 'today' : $created->diffForHumans($now);
     $dates = explode(" ", $difference);
     if (count($dates) > 1) {
         if ($dates[1] == "month" or $dates[1] == "months") {
             if ($dates[0] >= 1) {
                 return true;
             }
         } else {
             return false;
         }
     }
     return false;
 }
Example #4
0
 public function getView(Pirep $pirep)
 {
     // Calculate some data bits (keep it out of the view)
     $extras = [];
     // Airborne Time
     $takeoff = new Carbon($pirep->departure_time);
     $landing = new Carbon($pirep->landing_time);
     $extras['airborneTime'] = $takeoff->diff($landing);
     // Blocks Time
     $offBlocks = new Carbon($pirep->off_blocks_time);
     $onBlocks = new Carbon($pirep->on_blocks_time);
     $extras['blocksTime'] = $offBlocks->diff($onBlocks);
     // Total Time
     $start = new Carbon($pirep->pirep_start_time);
     $finish = new Carbon($pirep->pirep_end_time);
     $extras['totalTime'] = $start->diff($finish);
     // Planned Route
     $routeService = new Route();
     $extras['routePoints'] = $routeService->getAllPointsForRoute($pirep->booking->route);
     // Format Text Log (ugly, I know!)
     $extras['log'] = str_replace('[', '
     [', $pirep->log);
     // Display the PIREP!
     return view('pireps/single', ['pirep' => $pirep, 'extras' => $extras, 'staffBar' => true]);
 }
Example #5
0
    public function getSinglePirep(Pirep $pirep)
    {
        // Do we have access to this PIREP?
        if ($pirep->booking->pilot->id !== PilotRepository::getCurrentPilot()->id) {
            return redirect('/pireps');
        }
        // Calculate some data bits (keep it out of the view)
        $extras = [];
        // Airborne Time
        $takeoff = new Carbon($pirep->departure_time);
        $landing = new Carbon($pirep->landing_time);
        $extras['airborneTime'] = $takeoff->diff($landing);
        // Blocks Time
        $offBlocks = new Carbon($pirep->off_blocks_time);
        $onBlocks = new Carbon($pirep->on_blocks_time);
        $extras['blocksTime'] = $offBlocks->diff($onBlocks);
        // Total Time
        $start = new Carbon($pirep->pirep_start_time);
        $finish = new Carbon($pirep->pirep_end_time);
        $extras['totalTime'] = $start->diff($finish);
        // Planned Route
        $routeService = new Route();
        $extras['routePoints'] = $routeService->getAllPointsForRoute($pirep->booking->route);
        // Format Text Log (ugly, I know!)
        $extras['log'] = str_replace('[', '
[', $pirep->log);
        // Display the PIREP!
        return view('pireps/single', ['pirep' => $pirep, 'extras' => $extras]);
    }
Example #6
0
function get_days(Carbon $begin, Carbon $end = null) : array
{
    $end = $end ?? $begin;
    $diff = $begin->diff($end);
    $one_day = new DateInterval('P1D');
    $days = [];
    for ($i = 1; $i <= $diff->days; $i++) {
        $days[] = $begin->add($one_day)->getTimestamp();
    }
    return $days;
}
Example #7
0
 public function scopeCalcDaysOpen($query, $created)
 {
     $created = new Carbon($created);
     $now = Carbon::now();
     if ($created->diff($now, false)->days < 0) {
         return 1;
     } else {
         //return "?";
         //return $created->diffInDays($now, false);
         return $created->diff($now, false)->days < 1 ? '1' : $created->diffInDays($now);
     }
     //return ($created->diff($now, false)->days < 0)	? '1' : $created->diffInDays($now);
 }
Example #8
0
 /**
  * Returns delivery progress.
  *
  * @return {string} void
  */
 public function progress()
 {
     $events = $this->event->where('type', 'progress-event');
     if ($events->count() < 1) {
         return ['progress' => '0%', 'duration' => '0'];
     }
     $started = new Carbon($events->first()->created_at);
     $last = new Carbon($events->last()->created_at);
     $difference = $started->diff($last);
     $duration = implode([$difference->h, $difference->i, $difference->s], ':');
     $lastEvent = json_decode($events->last()['payload']);
     return ['progress' => $lastEvent->progress, 'duration' => $duration];
 }
Example #9
0
 public function HasAccessAlbum($idAlbum)
 {
     // return false;
     if (!$this->isAdmin()) {
         if ($this->profileD != null) {
             $IsActived = $this->profileD->actived;
             $created = new Carbon($this->profileD->FchVencimiento);
             $now = Carbon::now();
             $difference = $created->diff($now)->days;
             $profileAccessFull = $IsActived && $difference >= 0;
             if ($profileAccessFull) {
                 return true;
             }
         }
         return false;
     }
     return true;
 }
 private function _change_password_checks($code)
 {
     $this->layoutData['title'] = 'Forgotten Password';
     if (empty($code)) {
         $this->layoutData['content'] = 'Invalid Code!';
     } else {
         if (!($user = User::where('tmp_code', '=', $code)->first())) {
             $this->layoutData['content'] = 'Invalid Code!';
         } else {
             $code_created = new Carbon($user->tmp_code_created);
             $di = $code_created->diff(new Carbon('now'));
             if ($di->days > 7) {
                 $this->layoutData['content'] = 'This code has expired!';
             } else {
                 return $user;
             }
         }
     }
     return null;
 }
Example #11
0
 /**
  * Handles confirmation of the link
  * @param $request_link
  * @return int
  */
 public function confirm($request_link)
 {
     if (Bongo_request::where('request_link', '=', $request_link)->first() == null) {
         return 0;
     } elseif (Bongo_request::where('request_link', '=', $request_link)->first()->request_status != 1) {
         return 0;
     } else {
         $request = Bongo_request::where('request_link', '=', $request_link)->first();
         $created = new Carbon($request->created_at);
         $now = Carbon::now();
         $difference = $created->diff($now)->days > 7 ? $request->update(['request_status' => 2]) : $request->update(['request_status' => 1]);
         if ($request = Bongo_request::where('request_link', '=', $request_link)->first()) {
             if (\Md\User::where('email', '=', $request->bongo_email)->first() != null) {
                 return 1;
             } else {
                 return 2;
             }
         }
     }
 }
Example #12
0
 /**
  * Calculate the date length it took to solve a ticket
  * @param Ticket $ticket
  * @return integer|false
  */
 public function ticketPerformance($ticket)
 {
     if ($ticket->completed_at == null) {
         return false;
     }
     $created = new Carbon($ticket->created_at);
     $completed = new Carbon($ticket->completed_at);
     $length = $created->diff($completed)->days;
     return $length;
 }
Example #13
0
 public function date($date)
 {
     $created = new Carbon($date);
     $now = Carbon::now();
     $difference = $created->diff($now)->days < 1 ? 'today' : $created->diffForHumans($now);
     $dates = explode(" ", $difference);
     if (count($dates) == 1) {
         return false;
     }
     return true;
 }
Example #14
0
 private function getDiff(Carbon $time1, Carbon $time2)
 {
     return $time2->diff($time1);
 }
Example #15
0
 public function index($filter = 'soon', $param = "")
 {
     $auctions = Auction::All();
     if ($param == "") {
         switch ($filter) {
             case 'soon':
                 $sorted = $auctions->sortBy('end');
                 break;
             case 'late':
                 $sorted = $auctions->sortByDesc('end');
                 break;
             case 'new':
                 $sorted = $auctions->sortByDesc('start');
                 break;
             case 'pop':
                 //have to add clicks on auctions table
                 break;
         }
         $auctions = $sorted->values()->all();
     } else {
         switch ($filter) {
             case 'price':
                 switch ($param) {
                     case '5000':
                         $filtered = $auctions->filter(function ($auction) {
                             return $auction->price <= 5000;
                         });
                         break;
                     case '10000':
                         $filtered = $auctions->filter(function ($auction) {
                             return $auction->price <= 10000 && $auction->price >= 5000;
                         });
                         break;
                     case '25000':
                         $filtered = $auctions->filter(function ($auction) {
                             return $auction->price <= 25000 && $auction->price >= 10000;
                         });
                         break;
                     case '50000':
                         $filtered = $auctions->filter(function ($auction) {
                             return $auction->price <= 50000 && $auction->price >= 25000;
                         });
                         break;
                     case '100000':
                         $filtered = $auctions->filter(function ($auction) {
                             return $auction->price <= 100000 && $auction->price >= 50000;
                         });
                         break;
                     case 'more':
                         $filtered = $auctions->filter(function ($auction) {
                             return $auction->price >= 100000;
                         });
                         break;
                 }
                 break;
             case 'end':
                 switch ($param) {
                     case 'week':
                         $filtered = $auctions->filter(function ($auction) {
                             $end = new Carbon($auction->end);
                             return $end->diff(Carbon::now(), true)->d <= 7;
                         });
                         break;
                     case 'new':
                         $filtered = $auctions->filter(function ($auction) {
                             $start = new Carbon($auction->start);
                             return $start->diff(Carbon::now(), true)->d < 1;
                         });
                         break;
                     case 'now':
                         $filtered = $auctions->filter(function ($auction) {
                             $end = new Carbon($auction->end);
                             return $end->diff(Carbon::now(), true)->d < 1 && $auction->end->diff(Carbon::now(), true)->h < 6;
                         });
                         break;
                 }
                 break;
             case 'era':
                 switch ($param) {
                     case 'pre':
                         $filtered = $auctions->filter(function ($auction) {
                             return $auction->artwork->year < 1940;
                         });
                         break;
                     case '4060':
                         $filtered = $auctions->filter(function ($auction) {
                             return $auction->artwork->year > 1940 && $auction->artwork->year < 1960;
                         });
                         break;
                     case '6080':
                         $filtered = $auctions->filter(function ($auction) {
                             return $auction->artwork->year > 1960 && $auction->artwork->year < 1980;
                         });
                         break;
                     case 'now':
                         $filtered = $auctions->filter(function ($auction) {
                             return $auction->artwork->year > 1980;
                         });
                         break;
                 }
                 break;
         }
         $a = $filtered->all();
         $auctions = array_values($a);
     }
     $timeArray = timecalc::calculate($auctions);
     return view('art.index', ['auctions' => $auctions, 'timediff' => $timeArray]);
 }
Example #16
-3
 public function getProfile($userid)
 {
     $user = User::find($userid);
     if (count($user) >= 1) {
         $updated = new Carbon($user->updated_at);
         $now = Carbon::now();
         if ($updated->diff($now)->m < 1) {
             $lastOnline = "Last seen less than a minute ago";
         } elseif ($updated->diff($now)->h < 1) {
             $lastOnline = $updated->diffInMinutes($now) > 1 ? sprintf("Last seen %d minutes ago", $updated->diffInMinutes($now)) : sprintf("Last seen %d minute ago", $updated->diffInMinutes($now));
         } elseif ($updated->diff($now)->d < 1) {
             $lastOnline = $updated->diffInHours($now) > 1 ? sprintf("Last seen %d hours ago", $updated->diffInHours($now)) : sprintf("Last seen %d hour ago", $updated->diffInHours($now));
         } elseif ($updated->diff($now)->d < 7) {
             $lastOnline = $updated->diffInDays($now) > 1 ? sprintf("Last seen %d days ago", $updated->diffInDays($now)) : sprintf("Last seen %d day ago", $updated->diffInDays($now));
         } elseif ($updated->diff($now)->m < 1) {
             $lastOnline = $updated->diffInWeeks($now) > 1 ? sprintf("Last seen %d weeks ago", $updated->diffInWeeks($now)) : sprintf("Last seen %d week ago", $updated->diffInWeeks($now));
         } elseif ($updated->diff($now)->y < 1) {
             $lastOnline = $updated->diffInMonths($now) > 1 ? sprintf("Last seen %d months ago", $updated->diffInMonths($now)) : sprintf("Last seen %d month ago", $updated->diffInMonths($now));
         } else {
             $lastOnline = $updated->diffInYears($now) > 1 ? sprintf("Last seen %d years ago", $updated->diffInYears($now)) : sprintf("Last seen %d year ago", $updated->diffInYears($now));
         }
         return view('dashboard.userProfile', ['user' => $user, 'lastOnline' => $lastOnline]);
     } else {
         return view('dashboard.userProfile');
     }
 }