createFromFormat() public static method

Create a Carbon instance from a specific format.
public static createFromFormat ( string $format, string $time, DateTimeZon\DateTimeZone | string $timezone = null ) : static
$format string
$time string
$timezone DateTimeZon\DateTimeZone | string
return static
 /**
  * Handle the report incident command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(ReportIncidentCommand $command)
 {
     $data = ['name' => $command->name, 'status' => $command->status, 'message' => $command->message, 'visible' => $command->visible];
     // Link with the component.
     if ($command->component_id) {
         $data['component_id'] = $command->component_id;
     }
     // The incident occurred at a different time.
     if ($command->incident_date) {
         $incidentDate = Date::createFromFormat('d/m/Y H:i', $command->incident_date, config('cachet.timezone'))->setTimezone(Config::get('app.timezone'));
         $data['created_at'] = $incidentDate;
         $data['updated_at'] = $incidentDate;
     }
     // Create the incident
     $incident = Incident::create($data);
     // Update the component.
     if ($command->component_id) {
         Component::find($command->component_id)->update(['status' => $command->component_status]);
     }
     // Notify subscribers.
     if ($command->notify) {
         event(new IncidentWasReportedEvent($incident));
     }
     return $incident;
 }
 public function getInsert()
 {
     //if(Input::old('tanggal')!="" and Input::old('nis')!="") {
     $siswa = \DB::table('t_siswa_tingkat')->where('nis', Input::old('nis'))->first();
     if ($siswa == null) {
         \Session::flash('siswa_ilang', 'NIS tidak ditemukan');
         return redirect('/home');
     }
     $date = Date::createFromFormat('Y-m-d', Input::old('tanggal'));
     $tapel = AbsencesController::checkPeriode($date);
     $tapel['kd_tapel'] = \DB::table('t_tahun_ajaran')->where('tahun_ajaran', $tapel['tahun_ajaran'])->first()->kd_tahun_ajaran;
     $siswa_tingkat = \DB::table('t_siswa_tingkat')->where('nis', $siswa->nis)->where('kd_tahun_ajaran', $tapel['kd_tapel'])->where('kd_periode_belajar', $tapel['periode'])->first();
     if ($siswa_tingkat == null) {
         \Session::flash('tahun_ajaran', 'Tahun ajaran belum dimulai');
         return redirect('/home');
     }
     $siswa = \DB::table('t_siswa')->where('nis', $siswa->nis)->first();
     $pikets = \DB::table('t_piket')->where('hari', $date->format('l'))->first();
     $piket = \DB::table('t_guru')->where('kd_guru', $pikets->kd_guru)->first();
     $jam_masuk = Date::createFromFormat('H:i:s', $pikets->jam_masuk, Date::now()->tzName);
     return view('absences.insert', compact('date', 'jam_masuk', 'siswa', 'siswa_tingkat', 'piket', 'tapel'));
     //}
     //else
     //    return redirect('home');
 }
 /**
  * Handle the report maintenance command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\ReportMaintenanceCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(ReportMaintenanceCommand $command)
 {
     $scheduledAt = Date::createFromFormat('d/m/Y H:i', $command->timestamp, config('cachet.timezone'))->setTimezone(Config::get('app.timezone'));
     $maintenanceEvent = Incident::create(['name' => $command->name, 'message' => $command->message, 'scheduled_at' => $scheduledAt, 'status' => 0, 'visible' => 1]);
     // Notify subscribers.
     event(new MaintenanceWasScheduledEvent($maintenanceEvent));
     return $maintenanceEvent;
 }
 /**
  * Handle the report maintenance command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\ReportMaintenanceCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(ReportMaintenanceCommand $command)
 {
     // TODO: Add validation to scheduledAt
     $scheduledAt = Date::createFromFormat('d/m/Y H:i', $command->timestamp, Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
     $maintenanceEvent = Incident::create(['name' => $command->name, 'message' => $command->message, 'scheduled_at' => $scheduledAt, 'status' => 0, 'visible' => 1]);
     // Notify subscribers.
     if ($command->notify) {
         event(new MaintenanceWasScheduledEvent($maintenanceEvent));
     }
     return $maintenanceEvent;
 }
Example #5
0
 protected function asDateTime($value)
 {
     if (is_numeric($value)) {
         return Date::createFromTimestamp($value);
     } elseif (preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})$/', $value)) {
         return Date::createFromFormat('Y-m-d', $value)->startOfDay();
     } elseif (!$value instanceof DateTime) {
         $format = $this->getDateFormat();
         return Date::createFromFormat($format, $value);
     }
     return Date::instance($value);
 }
Example #6
0
 /**
  * Returns the rendered Blade templates.
  *
  * @return \Illuminate\View\View
  */
 public function showIndex()
 {
     $today = Date::now();
     $startDate = Date::now();
     segment_page('Status Page');
     // Check if we have another starting date
     if (Binput::has('start_date')) {
         try {
             // If date provided is valid
             $oldDate = Date::createFromFormat('Y-m-d', Binput::get('start_date'));
             segment_track('Status Page', ['start_date' => $oldDate->format('Y-m-d')]);
             // If trying to get a future date fallback to today
             if ($today->gt($oldDate)) {
                 $startDate = $oldDate;
             }
         } catch (Exception $e) {
             // Fallback to today
         }
     }
     $metrics = null;
     if ($displayMetrics = Setting::get('display_graphs')) {
         $metrics = Metric::where('display_chart', 1)->get();
     }
     $daysToShow = Setting::get('app_incident_days') ?: 7;
     $incidentDays = range(0, $daysToShow - 1);
     $dateTimeZone = Setting::get('app_timezone');
     $incidentVisiblity = Auth::check() ? 0 : 1;
     $allIncidents = Incident::notScheduled()->where('visible', '>=', $incidentVisiblity)->whereBetween('created_at', [$startDate->copy()->subDays($daysToShow)->format('Y-m-d') . ' 00:00:00', $startDate->format('Y-m-d') . ' 23:59:59'])->orderBy('created_at', 'desc')->get()->groupBy(function (Incident $incident) use($dateTimeZone) {
         return (new Date($incident->created_at))->setTimezone($dateTimeZone)->toDateString();
     });
     // Add in days that have no incidents
     foreach ($incidentDays as $i) {
         $date = (new Date($startDate))->setTimezone($dateTimeZone)->subDays($i);
         if (!isset($allIncidents[$date->toDateString()])) {
             $allIncidents[$date->toDateString()] = [];
         }
     }
     // Sort the array so it takes into account the added days
     $allIncidents = $allIncidents->sortBy(function ($value, $key) {
         return strtotime($key);
     }, SORT_REGULAR, true)->all();
     // Scheduled maintenance code.
     $scheduledMaintenance = Incident::scheduled()->orderBy('scheduled_at')->get();
     // Component & Component Group lists.
     $usedComponentGroups = Component::where('group_id', '>', 0)->groupBy('group_id')->lists('group_id');
     $componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->orderBy('order')->get();
     $ungroupedComponents = Component::where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
     $canPageBackward = Incident::notScheduled()->where('created_at', '<', $startDate->format('Y-m-d'))->count() != 0;
     return View::make('index', ['componentGroups' => $componentGroups, 'ungroupedComponents' => $ungroupedComponents, 'displayMetrics' => $displayMetrics, 'metrics' => $metrics, 'allIncidents' => $allIncidents, 'scheduledMaintenance' => $scheduledMaintenance, 'aboutApp' => Markdown::convertToHtml(Setting::get('app_about')), 'canPageForward' => (bool) $today->gt($startDate), 'canPageBackward' => $canPageBackward, 'previousDate' => $startDate->copy()->subDays($daysToShow)->toDateString(), 'nextDate' => $startDate->copy()->addDays($daysToShow)->toDateString(), 'pageTitle' => Setting::get('app_name') . ' Status']);
 }
 /**
  * Return a timestamp as DateTime object.
  *
  * @param  mixed  $value
  * @return \Jenssegers\Date\Date
  */
 protected function asDateTime($value)
 {
     // If this value is an integer, we will assume it is a UNIX timestamp's value
     // and format a Carbon object from this timestamp. This allows flexibility
     // when defining your date fields as they might be UNIX timestamps here.
     if (is_numeric($value)) {
         return Date::createFromTimestamp($value);
     } elseif (preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})$/', $value)) {
         return Date::createFromFormat('Y-m-d', $value)->startOfDay();
     } elseif (!$value instanceof DateTime) {
         $format = $this->getDateFormat();
         return Date::createFromFormat($format, $value);
     }
     return Date::instance($value);
 }
Example #8
0
 /**
  * Displays the explore page.
  *
  * @return \Illuminate\View\View
  */
 public function showIndex()
 {
     $today = Date::now();
     $startDate = Date::now();
     // Check if we have another starting date
     if (Binput::has('start_date')) {
         try {
             // If date provided is valid
             $oldDate = Date::createFromFormat('Y-m-d', Binput::get('start_date'));
             // If trying to get a future date fallback to today
             if ($today->gt($oldDate)) {
                 $startDate = $oldDate;
             }
         } catch (Exception $e) {
             // Fallback to today
         }
     }
     $daysToShow = Setting::get('app_issue_days', 0) - 1;
     if ($daysToShow < 0) {
         $daysToShow = 0;
         $issueDays = [];
     } else {
         $issueDays = range(0, $daysToShow);
     }
     $dateTimeZone = Setting::get('app_timezone');
     $issueVisiblity = Auth::check() ? 0 : 1;
     $allIssues = Issue::where('visible', '>=', $issueVisiblity)->whereBetween('created_at', [$startDate->copy()->subDays($daysToShow)->format('Y-m-d') . ' 00:00:00', $startDate->format('Y-m-d') . ' 23:59:59'])->orderBy('scheduled_at', 'desc')->orderBy('created_at', 'desc')->get()->groupBy(function (Issue $issue) use($dateTimeZone) {
         // If it's scheduled, get the scheduled at date.
         if ($issue->is_scheduled) {
             return (new Date($issue->scheduled_at))->setTimezone($dateTimeZone)->toDateString();
         }
         return (new Date($issue->created_at))->setTimezone($dateTimeZone)->toDateString();
     });
     // Add in days that have no issues
     foreach ($issueDays as $i) {
         $date = (new Date($startDate))->setTimezone($dateTimeZone)->subDays($i);
         if (!isset($allIssues[$date->toDateString()])) {
             $allIssues[$date->toDateString()] = [];
         }
     }
     // Sort the array so it takes into account the added days
     $allIssues = $allIssues->sortBy(function ($value, $key) {
         return strtotime($key);
     }, SORT_REGULAR, true)->all();
     return View::make('index')->withDaysToShow($daysToShow)->withAllIssues($allIssues)->withCanPageForward((bool) $today->gt($startDate))->withCanPageBackward(Issue::where('created_at', '<', $startDate->format('Y-m-d'))->count() > 0)->withPreviousDate($startDate->copy()->subDays($daysToShow)->toDateString())->withNextDate($startDate->copy()->addDays($daysToShow)->toDateString());
 }
 /**
  * Handle the update incident command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\UpdateIncidentCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(UpdateIncidentCommand $command)
 {
     $incident = $command->incident;
     $incident->update($this->filterIncidentData($command));
     // The incident occurred at a different time.
     if ($command->incident_date) {
         $incidentDate = Date::createFromFormat('d/m/Y H:i', $command->incident_date, config('cachet.timezone'))->setTimezone(Config::get('app.timezone'));
         $incident->update(['created_at' => $incidentDate, 'updated_at' => $incidentDate]);
     }
     // Update the component.
     if ($command->component_id) {
         Component::find($command->component_id)->update(['status' => $command->component_status]);
     }
     // Notify subscribers.
     event(new IncidentWasUpdatedEvent($incident));
     return $incident;
 }
 /**
  * Return a timestamp as DateTime object.
  *
  * @param  mixed  $value
  * @return \Carbon\Carbon
  */
 protected function asDateTime($value)
 {
     Date::setLocale('it');
     // If the value is already a DateTime instance, we will just skip the rest of
     // these checks since they will be a waste of time, and hinder performance
     // when checking the field. We will just return the DateTime right away.
     if ($value instanceof DateTime) {
         //
     } elseif (is_numeric($value)) {
         return Date::createFromTimestamp($value);
     } elseif (preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})$/', $value)) {
         return Date::createFromFormat('Y-m-d', $value)->startOfDay();
     } elseif (!$value instanceof DateTime) {
         $format = $this->getDateFormat();
         return Date::createFromFormat($format, $value);
     }
     return Date::instance($value);
 }
Example #11
0
 /**
  * Displays the explore page.
  *
  * @return \Illuminate\View\View
  */
 public function indexAction()
 {
     $this->subMenu['explore']['active'] = true;
     $today = Date::now();
     $startDate = Date::now();
     // Check if we have another starting date
     if (Request::has('start_date')) {
         try {
             // If date provided is valid
             $oldDate = Date::createFromFormat('Y-m-d', Request::get('start_date'));
             // If trying to get a future date fallback to today
             if ($today->gt($oldDate)) {
                 $startDate = $oldDate;
             }
         } catch (Exception $e) {
             // Fallback to today
         }
     }
     $daysToShow = Setting::get('app_issue_days', 0) - 1;
     if ($daysToShow < 0) {
         $daysToShow = 0;
         $issueDays = [];
     } else {
         $issueDays = range(0, $daysToShow);
     }
     $dateTimeZone = Setting::get('app_timezone');
     $allIssues = Issue::whereBetween('created_at', [$startDate->copy()->subDays($daysToShow)->format('Y-m-d') . ' 00:00:00', $startDate->format('Y-m-d') . ' 23:59:59'])->orderBy('created_at', 'desc')->get()->groupBy(function (Issue $issue) use($dateTimeZone) {
         return (new Date($issue->created_at))->setTimezone($dateTimeZone)->toDateString();
     });
     // Add in days that have no issues
     foreach ($issueDays as $i) {
         $date = (new Date($startDate))->setTimezone($dateTimeZone)->subDays($i);
         if (!isset($allIssues[$date->toDateString()])) {
             $allIssues[$date->toDateString()] = [];
         }
     }
     // Sort the array so it takes into account the added days
     $allIssues = $allIssues->sortBy(function ($value, $key) {
         return strtotime($key);
     }, SORT_REGULAR, true)->all();
     return View::make('explore.index')->withPageTitle(trans('dashboard.explore'))->withProjects([])->withSubMenu($this->subMenu)->withDaysToShow($daysToShow)->withAllIssues($allIssues)->withCanPageForward((bool) $today->gt($startDate))->withCanPageBackward(Issue::where('created_at', '<', $startDate->format('Y-m-d'))->count() > 0)->withPreviousDate($startDate->copy()->subDays($daysToShow)->toDateString())->withNextDate($startDate->copy()->addDays($daysToShow)->toDateString());
 }
 /**
  * Handle various type conversions that should be supported natively by Doctrine (like DateTime)
  *
  * @param  mixed $value
  * @param  string $typeOfField
  * @return Date
  */
 protected function handleTypeConversions($value, $typeOfField)
 {
     switch ($typeOfField) {
         case 'datetimetz':
         case 'datetime':
         case 'time':
         case 'date':
             if ('' === $value) {
                 return null;
             }
             if (is_int($value)) {
                 $value = Date::createFromTimestamp($value);
             } elseif (is_string($value)) {
                 $value = Date::createFromFormat('d/M/Y', $value);
             }
             break;
         default:
     }
     return $value;
 }
Example #13
0
 function hdate($date)
 {
     $obj = \Jenssegers\Date\Date::createFromFormat('Y-m-d H:i:s', $date);
     return $obj->ago();
 }
Example #14
0
 /**
  * Updates the given incident.
  *
  * @param \CachetHQ\Cachet\Models\Incident $schedule
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function editScheduleAction(Incident $schedule)
 {
     $scheduleData = Binput::get('incident');
     // Parse the schedule date.
     $scheduledAt = Date::createFromFormat('d/m/Y H:i', $scheduleData['scheduled_at'], config('cachet.timezone'))->setTimezone(Config::get('app.timezone'));
     if ($scheduledAt->isPast()) {
         $messageBag = new MessageBag();
         $messageBag->add('scheduled_at', trans('validation.date', ['attribute' => 'scheduled time you supplied']));
         return Redirect::route('dashboard.schedule.edit', ['id' => $schedule->id])->withErrors($messageBag);
     }
     $scheduleData['scheduled_at'] = $scheduledAt;
     // Bypass the incident.status field.
     $scheduleData['status'] = 0;
     try {
         $schedule->update($scheduleData);
     } catch (ValidationException $e) {
         return Redirect::route('dashboard.schedule.edit', ['id' => $schedule->id])->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.schedule.edit.failure')))->withErrors($e->getMessageBag());
     }
     return Redirect::route('dashboard.schedule.edit', ['id' => $schedule->id])->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.schedule.edit.success')));
 }
Example #15
0
 /**
  * Updates the given incident.
  *
  * @param \CachetHQ\Cachet\Models\Incident $schedule
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function editScheduleAction(Incident $schedule)
 {
     $scheduleData = Binput::get('incident');
     // Parse the schedule date.
     $scheduledAt = Date::createFromFormat('d/m/Y H:i', $scheduleData['scheduled_at'], Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
     if ($scheduledAt->isPast()) {
         $messageBag = new MessageBag();
         $messageBag->add('scheduled_at', trans('validation.date', ['attribute' => 'scheduled time you supplied']));
         return Redirect::back()->withErrors($messageBag);
     }
     $scheduleData['scheduled_at'] = $scheduledAt;
     // Bypass the incident.status field.
     $scheduleData['status'] = 0;
     $schedule->update($scheduleData);
     if (!$schedule->isValid()) {
         segment_track('Dashboard', ['event' => 'Edited Schedule', 'success' => false]);
         return Redirect::back()->withInput(Binput::all())->with('title', sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.schedule.edit.failure')))->with('errors', $schedule->getErrors());
     }
     segment_track('Dashboard', ['event' => 'Edited Schedule', 'success' => true]);
     $successMsg = sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.schedule.edit.success'));
     return Redirect::to('dashboard/schedule')->with('success', $successMsg);
 }
Example #16
0
 /**
  * Create a Carbon instance from a specific format.
  *
  * @param string $format
  * @param string $time
  *
  * @throws \InvalidArgumentException
  *
  * @return \Carbon\Carbon
  */
 public function create($format, $time)
 {
     return Date::createFromFormat($format, $time, $this->gitaminTimezone)->setTimezone($this->appTimezone);
 }
Example #17
0
 public function ago($date)
 {
     return date_ago(Date::createFromFormat('Y-m-d', $date));
 }
Example #18
0
 /**
  * Edit an incident.
  *
  * @param \CachetHQ\Cachet\Models\Incident $incident
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function editIncidentAction(Incident $incident)
 {
     $incidentData = Binput::get('incident');
     if (array_has($incidentData, 'created_at') && $incidentData['created_at']) {
         $incidentDate = Date::createFromFormat('d/m/Y H:i', $incidentData['created_at'], Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
         $incidentData['created_at'] = $incidentDate;
         $incidentData['updated_at'] = $incidentDate;
     } else {
         unset($incidentData['created_at']);
     }
     try {
         $incident->update($incidentData);
     } catch (ValidationException $e) {
         return Redirect::route('dashboard.incidents.edit', ['id' => $incident->id])->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.templates.edit.failure')))->withErrors($e->getMessageBag());
     }
     $componentStatus = array_pull($incidentData, 'component_status');
     if ($incident->component) {
         $incident->component->update(['status' => $componentStatus]);
     }
     return Redirect::route('dashboard.incidents.edit', ['id' => $incident->id])->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.edit.success')));
 }
 /**
  * Edit an incident.
  *
  * @param \CachetHQ\Cachet\Models\Incident $incident
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function editIncidentAction(Incident $incident)
 {
     $incidentData = Binput::get('incident');
     if (array_has($incidentData, 'created_at') && $incidentData['created_at']) {
         $incidentDate = Date::createFromFormat('d/m/Y H:i', $incidentData['created_at'], Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
         $incidentData['created_at'] = $incidentDate;
         $incidentData['updated_at'] = $incidentDate;
     } else {
         unset($incidentData['created_at']);
     }
     $incident->update($incidentData);
     if (!$incident->isValid()) {
         segment_track('Dashboard', ['event' => 'Edited Incident', 'success' => false]);
         return Redirect::back()->withInput(Binput::all())->with('title', sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.templates.edit.failure')))->with('errors', $incident->getErrors());
     }
     $componentStatus = array_pull($incidentData, 'component_status');
     if ($incident->component) {
         $incident->component->update(['status' => $componentStatus]);
     }
     segment_track('Dashboard', ['event' => 'Edited Incident', 'success' => true]);
     $successMsg = sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.edit.success'));
     return Redirect::to('dashboard/incidents')->with('success', $successMsg);
 }
Example #20
0
 private function makeTimelineData($timeline)
 {
     Carbon::setLocale('pt_BR');
     foreach ($timeline as $key => $item) {
         $now = Carbon::now();
         $start = Carbon::createFromFormat('Y-m-d H:i:s', $item['start']);
         $end = Carbon::createFromFormat('Y-m-d H:i:s', $item['end']);
         $startW3c = Carbon::createFromFormat('Y-m-d H:i:s', $item['start'])->addSeconds(env('TIME_OFFSET_ADD'));
         $endW3c = Carbon::createFromFormat('Y-m-d H:i:s', $item['end'])->addSeconds(env('TIME_OFFSET_ADD'));
         $timeline[$key]['startW3c'] = $startW3c->toW3cString();
         $timeline[$key]['endW3c'] = $endW3c->toW3cString();
         $end->addSeconds(2);
         $diff = $start->diffInDays($end);
         if ($diff <= 1) {
             $period = $start->format('d \\d\\e F');
         } else {
             if ($start->month == $end->month) {
                 $period = $start->format('d') . ' a ' . $end->format('d \\d\\e F');
             } else {
                 $period = $start->format('d \\d\\e F') . ' a ' . $end->format('d \\d\\e F');
             }
         }
         $timeline[$key]['period'] = $period;
         $timeline[$key]['past'] = $start->diffInSeconds($now) > 0;
     }
     return ['lines' => $timeline, 'now' => $now->toW3cString()];
 }
Example #21
0
    function _display_log($mode)
    {
        $setting = $this->mode_settings[$mode];
        $this->load->vars('setting', $setting);
        $log_path = $this->config->item('log_path');
        if (!$log_path) {
            $log_path = APPPATH . 'logs/';
        }
        $prefix = $setting['prefix'];
        $log_files = array();
        if (is_dir($log_path)) {
            foreach (glob($log_path . $prefix . "-*.php") as $filename) {
                $datestr = substr($filename, -14, 10);
                $log_files[$datestr] = Date::createFromFormat('Y-m-d', $datestr)->format('d F Y');
            }
        }
        $this->load->vars('log_files', array_reverse($log_files));
        $selected_log = $this->input->get('log_date', FALSE);
        if (!$selected_log || empty($selected_log)) {
            $values = array_keys($this->load->get_var('log_files'));
            if (is_array($values) && isset($values[0])) {
                $selected_log = $values[0];
            }
        }
        $this->load->vars('selected_log', $selected_log);
        $rows = array();
        $filename = $log_path . $prefix . '-' . $selected_log . '.php';
        if (file_exists($filename)) {
            $fh = fopen($filename, 'r');
            $row = array();
            while ($line = fgets($fh)) {
                $match = array();
                if (preg_match($setting['pattern'], trim($line), $match)) {
                    if (!empty($row)) {
                        $rows[] = $row;
                    }
                    $row = array();
                    foreach ($setting['columns'] as $index => $column) {
                        if ($column == 'time') {
                            $row[$column] = substr($match[$index + 1], -8);
                        } else {
                            $row[$column] = nl2br($match[$index + 1]);
                        }
                        if ($column == 'username') {
                            $user = $this->user_model->get_by_username($row['username']);
                            if ($user) {
                                $row['full_name'] = $user->full_name;
                            } else {
                                $row['full_name'] = '-';
                            }
                        }
                    }
                } elseif (!empty($row) && isset($row['message'])) {
                    $row['message'] .= '<br />' . $line;
                }
            }
            if (!empty($row)) {
                $rows[] = $row;
            }
            fclose($fh);
        }
        $this->load->vars('rows', $rows);
        $this->template->set_js_script('
$(document).ready(function() {
	$(\'[name=log_files]\').change(function() {
		location.href = \'' . site_url('utils/logs/' . $mode) . '?log_date=\' + $(this).val();
	});
});
', 'log', TRUE)->build('utils/logs');
    }
Example #22
0
 /**
  * Create a Carbon instance from a specific format.
  *
  * We're also going to make sure the timezone information is correct.
  *
  * @param string $format
  * @param string $time
  *
  * @throws \InvalidArgumentException
  *
  * @return \Carbon\Carbon
  */
 public function createNormalized($format, $time)
 {
     return Date::createFromFormat($format, $time)->setTimezone($this->appTimezone);
 }
 /**
  *
  * @return array|string|static[]
  */
 public function LiveMatch()
 {
     $getMatchId = $this->footballMatches->whereNotIn('status', ['FT', 'Postp.'])->whereDate('formatted_date', '>=', Date::yesterday()->format('Y-m-d'))->orderBy('formatted_date', 'asc')->first();
     $request = 'matches/' . $getMatchId['match_id'] . '?';
     $match = $this->connector($request);
     $match['match_id'] = $match['id'];
     unset($match['id']);
     $mergeDateTime = Date::createFromFormat('d.m.Y H:i', $match['formatted_date'] . ' ' . $match['time'], 'UTC')->tz('Asia/Bangkok')->toDateTimeString();
     $date = Date::createFromFormat('Y-m-d H:i:s', $mergeDateTime)->format('Y-m-d');
     $match['formatted_date'] = $date;
     $time = Date::createFromFormat('Y-m-d H:i:s', $mergeDateTime)->format('H:i');
     $matchStatus = $match['status'];
     $match['status'] === $match['time'] ? $match['status'] = $time : ($match['status'] = $matchStatus);
     $match['time'] = $time;
     if ($match['localteam_score'] === '?' and $match['visitorteam_score'] === '?' or $match['localteam_score'] === '' and $match['visitorteam_score'] === '') {
         if ($match['status'] !== 'FT' or $match['status'] !== 'AET') {
             $match['localteam_score'] = '-';
             $match['visitorteam_score'] = '-';
         }
     }
     $this->footballMatches->updateOrCreate(['match_id' => $match['match_id']], $match);
     if (!empty($match['events'])) {
         $matchEvents = $match['events'];
         $matchId = $match['match_id'];
         foreach ($matchEvents as $matchEvent) {
             $matchEvent['match_id'] = $matchId;
             $matchEvent['event_id'] = $matchEvent['id'];
             unset($matchEvent['id']);
             $this->footballMatchEvents->updateOrCreate(['event_id' => $matchEvent['event_id']], $matchEvent) ? Log::info('Event of ' . $matchId . ' update completed!.') : Log::error('Event update process of ' . $matchId . ' failed');
         }
     }
     Event::fire(new FootballMatchUpdated($this->footballMatches));
     return Log::info('All data of ' . $match['match_id'] . ' update completed!');
 }