Exemple #1
0
 public function toDateTime()
 {
     $dateTime = new \Datetime();
     $dateTime->setDate($this->year, $this->month, $this->day);
     $dateTime->setTime(0, 0, 0);
     return $dateTime;
 }
 /**
  * @return array
  */
 public function findAllPerMonth()
 {
     $sql = 'SELECT DISTINCT CONCAT(MONTH(`created`), \' \', YEAR(`created`)) as month, avg(`usage`) as average, username FROM oc_uc_storageusage WHERE `usage` > 0 GROUP BY username, month';
     $query = $this->db->prepareQuery($sql);
     $result = $query->execute();
     $entities = array();
     while ($row = $result->fetch()) {
         if (!isset($entities[$row['username']])) {
             $entities[$row['username']] = array();
         }
         $date = explode(' ', $row['month']);
         $dateTime = new \Datetime();
         $dateTime->setDate($date[1], $date[0], 1);
         $entities[$row['username']] = array_merge($entities[$row['username']], array(new StorageUsage($dateTime, $row['average'], $row['username'])));
     }
     return $entities;
 }
 /**
  * Parse the results from the per month entities found
  *
  * @param \OC_DB_StatementWrapper $result
  * @return array
  */
 private function parsePerMonthEntities($result)
 {
     $entities = array();
     while ($row = $result->fetch()) {
         if (!isset($entities[$row['username']])) {
             $entities[$row['username']] = array();
         }
         $date = explode(' ', $row['month']);
         $dateTime = new \Datetime();
         $dateTime->setDate($date[1], $date[0], 1);
         $entities[$row['username']] = array_merge($entities[$row['username']], array(new StorageUsage($dateTime, $row['average'], $row['username'], $row['maximumusage'])));
     }
     return $entities;
 }
 public function updateAction($id, Request $request)
 {
     $session = $request->getSession();
     if (!$session->get('AdminAuth')) {
         return $this->redirect($this->generateUrl("login"));
     }
     $ArticleRepository = $this->getDoctrine()->getManager()->getRepository('EntityBundle:Article');
     $articleOLD = $ArticleRepository->find($id);
     $arraydatedebut = array('day' => $articleOLD->getDateDebut()->format('d'), 'month' => $articleOLD->getDateDebut()->format('m'), 'year' => $articleOLD->getDateDebut()->format('Y'));
     // var_dump($arraydatedebut);
     $arraydatefin = array('day' => $articleOLD->getDateFin()->format('d'), 'month' => $articleOLD->getDateDebut()->format('m'), 'year' => $articleOLD->getDateDebut()->format('Y'));
     // var_dump($arraydatefin);
     $em = $this->getDoctrine()->getManager();
     $build['article'] = $articleOLD;
     $build['datedebut'] = $arraydatedebut;
     $build['datefin'] = $arraydatefin;
     $build['years'] = range(1331, 1407);
     $localisation = $articleOLD->getLocalisation($articleOLD);
     $image = $articleOLD->getImage($articleOLD);
     if (!$articleOLD) {
         throw $this->createNotFoundException('No news found by id ' . $id);
     }
     if ($request->isMethod('POST')) {
         $datedebut = new \Datetime();
         $dateDebutFrom = $request->request->all()['form']['dateDebut'];
         $datedebut->setDate($dateDebutFrom['year'], $dateDebutFrom['day'], $dateDebutFrom['month']);
         $datefin = new \Datetime();
         $dateFinFrom = $request->request->all()['form']['dateFin'];
         $datefin->setDate($dateFinFrom['year'], $dateFinFrom['day'], $dateFinFrom['month']);
         /**/
         $articleOLD = new Article();
         $articleOLD->setId($id);
         $articleOLD->setDateDebut($datedebut);
         $articleOLD->setDateFin($datefin);
         $articleOLD->setIsDelete('0');
         $articleOLD->setLocalisation($localisation);
         $articleOLD->setImage($image);
         $articleOLD->setTitre($request->request->all()['form']['titre']);
         $articleOLD->setSource($request->request->all()['form']['source']);
         $articleOLD->setDescription($request->request->all()['form']['description']);
         $em->persist($articleOLD);
         $em->flush();
         return $this->redirect($this->generateUrl("admin_article_list"));
     }
     return $this->render('AdminBundle:Article:update.html.twig', $build);
 }
Exemple #5
0
 /**
  * Get datetime object from YYYYMMDDHHIISS number
  *
  * @param $idate
  * @return \Datetime
  */
 public static function YYYYMMDDHHIISStoDate($idate)
 {
     $idate = trim($idate);
     $date = $idate . "";
     $y = (int) substr($date, 0, 4);
     $m = (int) substr($date, 4, 2);
     $d = (int) substr($date, 6, 2);
     $h = (int) substr($date, 8, 2);
     $i = (int) substr($date, 10, 2);
     $s = (int) substr($date, 12, 2);
     $return = new \Datetime();
     $return->setDate($y, $m, $d);
     $return->setTime($h, $i, $s);
     return $return;
 }