public function overviewAction(Request $request) { $redirector = $this->checkForFirstLogin(); if ($redirector != null) { return $redirector; } $fetcher = new DQL\FetchData($this); $cPackage = $cPackage = $fetcher->getRunningDataPackage(); if ($cPackage == null) { return $this->redirect($this->generateUrl('settings_packages', array(), true)); } $pstart = $cPackage->getStart(); $pend = $cPackage->getEnd(); $clientStatusDTO = $fetcher->getClientStatusDTO($cPackage); //var_dump($clientStatusDTO); $totalUsageObj = $fetcher->getTotalUsageObj($cPackage); //var_dump($totalUsageObj); $now = new \DateTime(); // or your date as well $totDays = $pend->diff($pstart)->format("%a"); $today = $now->diff($pstart)->format("%a"); //var_dump($now,$pstart,$pend,$totDays,$today); $html = $this->render('dashboard/overview.html.twig', array('clientStatusDTO' => $clientStatusDTO, 'totalUsageObj' => $totalUsageObj, 'totalPackage' => $cPackage->getKbytes(), 'totalDays' => $totDays, 'today' => $today, 'expireDate' => $pend->format('Y-m-d'))); return $html; }
public function getStringPeriode() { $dateDebut = new DateTime($this->getDateDebutPeriod()); $dateFinale = new DateTime($this->getDateFinalePeriode()); $dateDiff = $dateDebut->diff($dateFinale); #echo 'Nombre de temp : '.$interval->format('%y ans,%m mois, %d jour, %h heures, %i minutes %s secondes') $this->periode = $dateDiff->format("%m mois"); return $this->periode; }
public function dateInterval($date, $locale) { $comment_date = new \DateTime($date); $dateNow = new \DateTime('NOW'); $interval = $dateNow->diff($comment_date); $periodes = [$interval->format('%y'), $interval->format('%m'), $interval->format('%d'), $interval->format('%h'), $interval->format('%i')]; $unity_en = [['year', 'years'], ['month', 'months'], ['day', 'days'], ['hour', 'hours'], ['minute', 'minutes']]; $unity_fr = [['an', 'ans'], ['mois', 'mois'], ['jour', 'jours'], ['heure', 'heures'], ['minute', 'minutes']]; $periodesLength = count($periodes); for ($i = 0; $i < $periodesLength; $i++) { if (intval($periodes[$i]) >= 1 && $i < count($periodes)) { $locale_unity = $locale == "fr" ? $unity_fr : $unity_en; $u = $periodes[$i] > 1 ? $locale_unity[$i][1] : $locale_unity[$i][0]; return $periodes[$i] . ' ' . $u; } } if ($locale == 'fr') { return "moins d'une minute"; } else { return 'less than a minute'; } }
/** * @param $birthday * @return string */ private function getAge($birthday) { $dateNow = new \DateTime(); $dateIntervall = $dateNow->diff($birthday); return $dateIntervall->y; }
/** * * [AJAX][jqTree] Carrega os computadores da subrede informada */ public function loadcompnodesAction(Request $request) { if (!$request->isXmlHttpRequest()) { throw $this->createNotFoundException('Página não encontrada!'); } $logger = $this->get('logger'); $agrupar = $request->get('agrupar'); $idRede = $request->get('idSubrede'); $date = new \DateTime(); # Monta um array no formato suportado pelo plugin-in jqTree (JQuery) $_tree = array(); if (!empty($agrupar)) { $comps = $this->getDoctrine()->getRepository('CacicCommonBundle:LogAcesso')->gerarRelatorioRede($filtros = null, $idRede, $dataInicio = null, $dataFim = null); foreach ($comps as $comp) { #$computadores = implode(", ", $comp['idComputador']); if (is_array($comp['nmComputador'])) { $nomes = implode(", ", $comp['nmComputador']); } else { $nomes = $comp['nmComputador']; } if (is_array($comp['teIpComputador'])) { $ips = implode(", ", $comp['teIpComputador']); } else { $ips = $comp['teIpComputador']; } if (is_array($comp['teDescSo'])) { $so = implode(", ", $comp['sgSo']); } else { $so = $comp['teDescSo']; } $_label = ($nomes ?: '###') . ' - '; $_label .= $comp['teNodeAddress'] . ' - ' . $so; // Calculate age $now = new \DateTime($comp['data']); $interval = intval($now->diff($date)->format('%R%a')); if ($interval > 60) { $color = "alert alert-danger"; } elseif ($interval > 30) { $color = "alert alert-warning"; } else { $color = null; } $_tree[] = array('id' => $comp['teNodeAddress'], 'label' => $_label, 'type' => 'computador', 'load_on_demand' => false, 'alert_class' => $color); } } else { $comps = $this->getDoctrine()->getRepository('CacicCommonBundle:Computador')->listarPorSubrede($idRede); foreach ($comps as $comp) { $_label = ($comp->getNmComputador() ?: '###') . ' - ' . $comp->getTeIpComputador(); if ($comp->getIdSo()) { $_label .= ' - ' . $comp->getIdSo()->getSgSo(); } // Calculate age $interval = intval($comp->getDtHrUltAcesso()->diff($date)->format('%R%a')); // Calculate age if ($interval > 60) { $color = "alert alert-danger"; } elseif ($interval > 30) { $color = "alert alert-warning"; } else { $color = null; } $_tree[] = array('id' => $comp->getIdComputador(), 'label' => $_label, 'type' => 'computador', 'load_on_demand' => false, 'alert_class' => $color); } } $response = new Response(json_encode($_tree)); $response->headers->set('Content-Type', 'application/json'); return $response; }
/** * @return \DateInterval */ public function getTimeRunning() { $now = new \DateTime(); return $now->diff($this->from); }
public function adminAction() { $user = $this->getUser(); if ($user != null) { $roles = $user->getRoles(); if (in_array('ROLE_ADMIN', $roles)) { //Obtener datos de las reservas $em = $this->getDoctrine()->getManager(); $reservas = $em->getRepository('LIHotelBundle:Reserva')->findAll(); $habitaciones = $em->getRepository('LIHotelBundle:Habitacion')->findAll(); $userManager = $this->get('fos_user.user_manager'); $usuarios = $userManager->findUsers(); /** BUSCAR LAS RESERVAS QUE YA CADUCARON Y EL ESTADO ES POR CONCRETAR, AGREGARLAS EN UN FLASHBAG Y MOSTRARLO EN LA VISTA LA INTERFAZ DE ESOS MENSAJES ES <span class="labelalert labelalert-primary">labelalert-primary</span> <span class="labelalert labelalert-atencion">labelalert-atencion</span> <span class="labelalert labelalert-grave">labelalert-grave</span> <span class="labelalert labelalert-normal">labelalert-normal</span> **/ $por_c = 0; $con = 0; $can = 0; $cant_usuarios = sizeof($usuarios); $session = $this->get('session'); $hoy = new \DateTime('today'); foreach ($reservas as $reserva) { $estado = $reserva->getEstadoReserva(); if ($estado == 'Por Concretar') { $por_c = $por_c + 1; /** OBTENIENDO LAS RESERVAS QUE NO SE CONCRETARON EN LA FECHA PREVISTA **/ $fecha2 = $reserva->getFechadesde(); $interval = $hoy->diff($fecha2); $off = $interval->format('%R%a'); if ($off < 0) { $off = $off * -1; $session->getFlashBag()->add('grave', array('id' => $reserva->getId(), 'codigo' => $reserva->getCodigoreserva(), 'dias' => $off)); } if ($fecha2 == $hoy) { $session->getFlashBag()->add('informacion', array('id' => $reserva->getId(), 'codigo' => $reserva->getCodigoreserva())); } } if ($estado == 'Concretada' && $reserva->getHabitacion()->getEstado() != 'Libre') { $con = $con + 1; //Liberando las habitaciones que terminaron su reserva hoy $dias_reserva = $reserva->getDiasReserva() - 1; $fecha_reserva = $reserva->getFechaDesde(); $fecha_inicio_ = new \DateTime($fecha_reserva->format('Y-m-d')); $fecha_final_ = new \DateTime($fecha_inicio_->format('Y-m-d')); $fecha_final_->add(new \DateInterval('P' . $dias_reserva . 'D')); $hoy = new \DateTime('today'); if ($hoy > $fecha_final_) { //throw $this->createNotFoundException($reserva->getId()." - ".$hoy->format('Y-m-d')." > ".$fecha_final_->format('Y-m-d')); $session->getFlashBag()->add('libre', array('id' => $reserva->getId(), 'codigo' => $reserva->getHabitacion()->getNombre())); $habitacion = $reserva->getHabitacion(); $habitacion->setEstado('Libre'); $em->persist($habitacion); $em->flush(); } } if ($estado == 'Cancelada') { $can = $can + 1; } } $admins = 0; $users = 0; foreach ($usuarios as $u) { $roles = $u->getRoles(); if (in_array('ROLE_ADMIN', $roles)) { $admins = $admins + 1; } else { $users = $users + 1; } } $libres = $reservadas = $ocupadas = 0; foreach ($habitaciones as $key) { if ($key->getEstado() == 'Libre') { $libres = $libres + 1; } if ($key->getEstado() == 'Ocupada' || $key->getEstado() == 'Indispuesta') { $ocupadas = $ocupadas + 1; } if ($key->getEstado() == 'Reservada') { $reservadas = $reservadas + 1; } } return $this->render('LIHotelBundle:Inicio:inicioAdmin.html.twig', array('session' => $session, 'user' => $user, 'por_concretar' => $por_c, 'concretadas' => $con, 'canceladas' => $can, 'admins' => $admins, 'users' => $users, 'cant_habitaciones' => sizeof($habitaciones), 'habitaciones_libres' => $libres, 'habitaciones_reservadas' => $reservadas, 'habitaciones_ocupadas' => $ocupadas)); } else { return $this->redirect($this->generateUrl('LIHotelBundle_homepage')); } } return $this->redirect($this->generateUrl('fos_user_security_login')); }