public function getExtend($uid, $period)
 {
     /* @var $user User */
     $user = User::find($uid);
     if (empty($user->announcement_stream)) {
         Flash::error('Пользователь не подписан на рассылку.');
         return Redirect::to('admin/subscriptions');
     }
     // Already has an active subscription.
     if ($user->announcement_expires && $user->announcement_expires->isFuture()) {
         $user->announcement_expires = $user->announcement_expires->addDays($period);
     }
     // Subscription expired.
     if ($user->announcement_expires && $user->announcement_expires->isPast()) {
         // Start tomorrow.
         $start = new Carbon();
         $start->setTime(0, 0, 0)->addDays(1);
         $user->announcement_start = $start;
         // Expire in $period from tomorrow.
         $expires = clone $start;
         $expires->addDays($period);
         $user->announcement_expires = $expires;
     }
     $user->save();
     Flash::success('Подписка продленна.');
     return Redirect::to('admin/subscriptions');
 }
Example #2
0
 public function store()
 {
     $id = $this->request->input('id');
     $input = $this->request->only(['provider', 'text', 'link', 'image']);
     $categories = $this->request->input('categories');
     $inputSchedule = $this->request->only(['schedule_date', 'schedule_time']);
     if ($input['provider'] == 'weblink' && !$input['link']) {
         throw new Exception('The "link" argument is missing', 1);
     }
     $post = (int) $id ? Post::find($id)->fill($input) : new Post($input);
     if ($inputSchedule['schedule_date']) {
         $time = explode(':', $inputSchedule['schedule_time']);
         $date = new Carbon($inputSchedule['schedule_date']);
         if (count($time) > 1) {
             $date->setTime($time[0], $time[1]);
         }
         if ($date->timestamp > time()) {
             $post->posted_at = $date;
         }
     } else {
         $post->posted_at = new Carbon();
     }
     $post->user_id = $this->auth->id();
     $post->save();
     if (count($categories)) {
         $post->categories()->sync($categories);
     } else {
         $post->categories()->detach();
     }
     $post->provider_id = $post->id;
     $success = $post->save();
     $job = (new PublishPost($post))->onQueue('publish');
     $queued = $this->dispatch($job);
     return compact('success', 'queued');
 }
 protected function getUsers($days)
 {
     $expires = new Carbon();
     $expires->setTime(0, 0, 0)->addDays($days);
     $expires = $expires->format('Y-m-d H:i:s');
     $users = User::where('announcement_expires', '=', $expires)->get();
     return $users;
 }
Example #4
0
 /**
  *
  * Returns date (Carbon object) set to the date of the very first post
  * or to current date if there are no posts
  *
  * @return Carbon
  */
 protected static function getFirstDate()
 {
     $post = BlogPost::orderBy('published_at', 'asc')->isPublished()->first();
     if (!$post) {
         $date = new Carbon();
     } else {
         $date = new Carbon($post->published_at);
     }
     $date->setTime(0, 0);
     return $date;
 }
Example #5
0
 /**
  * Get the FY end date
  *
  * @param Carbon $dt Date to determine FY for
  *
  * @return Carbon Carbon instance set to the end of the FY for the input
  */
 public function get(Carbon $dt = NULL)
 {
     if (!$dt) {
         $dt = new Carbon();
     }
     /* Disregard times */
     $dt->setTime(0, 0, 0);
     /* FY is based on the -end- of the FY, thus we will work backward to determine if we need to 'rollup' the FY
        from the input year */
     $fyStart = Carbon::create($dt->year, $this->month, $this->day, 0, 0, 0);
     $fyEnd = clone $fyStart;
     $fyEnd->addYear()->subDay();
     if (!$dt->between($fyStart, $fyEnd, TRUE)) {
         $fyEnd->year($dt->year);
     }
     return $fyEnd;
 }
Example #6
0
 /**
  *
  * Returns with start and end dates limiting current archive output
  *
  * @return Carbon[] - [start, end]
  */
 protected function getCurrentRange()
 {
     if (!$this->year) {
         return [];
     }
     $start = new Carbon();
     $end = new Carbon();
     if (!$this->month) {
         //year archive
         $start->setDate($this->year, 1, 1);
         $end->setDate(intval($this->year) + 1, 1, 1);
     } else {
         if (!$this->day) {
             //month archive
             $start->setDate($this->year, $this->month, 1);
             $end->setDate($this->year, intval($this->month) + 1, 1);
         } else {
             //day archive
             $start->setDate($this->year, $this->month, $this->day);
             $end->setDate($this->year, $this->month, intval($this->day) + 1);
         }
     }
     $start->setTime(0, 0, 0);
     $end->setTime(0, 0, 0);
     return [$start, $end];
 }
 /**
  * Get the latest end time for an event on a particular day.
  * @param \Carbon\Carbon $date
  * @return string
  */
 public function getLatestEnd(Carbon $date)
 {
     $date->setTime(00, 00, 00);
     foreach ($this->times as $time) {
         if ($time->end->isSameDay($date) && $time->end->gt($date)) {
             $date->setTime($time->end->hour, $time->end->minute, $time->end->second);
         }
     }
     return $date->format('H:i');
 }
Example #8
0
 /**
  * Add a date to exclude as a business day
  *
  * @param $exclusion string|Carbon
  */
 public function addExclusion(Carbon $exclusion)
 {
     $exclusion->setTime(0, 0, 0);
     $this->exclusions[] = $exclusion;
 }
Example #9
0
 /**
  * Sets up pager to switch prev/next day
  */
 protected function setupDayPager()
 {
     $first_date = $this->first_date;
     $current_date = $this->current_date;
     // previous
     if ($first_date->getTimestamp() < $current_date->getTimestamp()) {
         $previous_date = $current_date->copy();
         $previous_date->subDay(1);
         $this->previous_text = $previous_date->formatLocalized('%d') . ' ' . $previous_date->formatLocalized('%B') . ', ' . $previous_date->year;
         $this->previous_url = $this->makePagerUrl(array('year' => $previous_date->year, 'month' => $previous_date->month, 'day' => $previous_date->day));
     } else {
         $this->previous_text = $current_date->formatLocalized('%d') . ' ' . $current_date->formatLocalized('%B') . ', ' . $current_date->year;
         $this->previous_url = '';
     }
     // next
     $today = new Carbon();
     $today->setTime(0, 0);
     if ($this->current_date->getTimestamp() < $today->getTimestamp()) {
         $next_date = $current_date->copy();
         $next_date->addDay(1);
         $this->next_text = $next_date->formatLocalized('%d') . ' ' . $next_date->formatLocalized('%B') . ', ' . $next_date->year;
         $this->next_url = $this->makePagerUrl(array('year' => $next_date->year, 'month' => $next_date->month, 'day' => $next_date->day));
     } else {
         $this->next_text = $current_date->formatLocalized('%d') . ' ' . $current_date->formatLocalized('%B') . ', ' . $current_date->year;
         $this->next_url = '';
     }
 }
Example #10
0
 public function findUsersByCreatedDate(Carbon $fromDate, Carbon $toDate, $userType)
 {
     $toDate->setTime(23, 59);
     $isEmpty = $userType == 'agent' ? '<>' : '=';
     return User::with('country')->whereBetween('created_at', [$fromDate, $toDate])->where('agency', $isEmpty, '')->get();
 }