当前位置: 首页>>代码示例>>PHP>>正文


PHP Datetime::setISODate方法代码示例

本文整理汇总了PHP中Datetime::setISODate方法的典型用法代码示例。如果您正苦于以下问题:PHP Datetime::setISODate方法的具体用法?PHP Datetime::setISODate怎么用?PHP Datetime::setISODate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Datetime的用法示例。


在下文中一共展示了Datetime::setISODate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: indexAction

 /**
  * Lists all Emission entities.
  */
 public function indexAction()
 {
     $breadcrumbs = $this->get("white_october_breadcrumbs");
     $breadcrumbs->addItem('Les émissions');
     $breadcrumbs->addItem('Grille des programmes');
     $format = $this->get('request')->get('_format');
     $timestampDay = 60 * 60 * 24;
     $timestampWeek = $timestampDay * 7;
     if (!empty($_GET['date'])) {
         $start = new \Datetime($_GET['date']);
         if ($start->format('W') != 1) {
             $start->setISODate($start->format('Y'), $start->format('W'), 1);
         }
     } elseif (!empty($_GET['week'])) {
         $start = new \Datetime();
         $start->setISODate($start->format('Y'), $_GET['week'], 1);
     }
     if (empty($start)) {
         $start = new \Datetime('now');
         $start->setTime(0, 0);
     }
     $weekNumber = $start->format('W');
     // find programs on current week
     $dayNumber = $start->format('w');
     if ($dayNumber === 0) {
         $start->modify('-6 days');
     } elseif ($dayNumber > 1) {
         $start->modify('-' . ($dayNumber - 1) . ' days');
     }
     $stop = clone $start;
     $stop->modify('+7 days');
     $em = $this->getDoctrine()->getManager();
     $query = $em->createQuery("SELECT p FROM ProgramBundle:Program p WHERE p.time_stop < :stop AND p.time_start >= :start AND p.time_start < p.time_stop  ORDER BY p.time_start ASC, p.time_stop DESC")->setParameters(array('start' => $start, 'stop' => $stop));
     $results = $query->getResult();
     $entities = array();
     for ($i = 0; $i < 7; $i++) {
         $day = clone $start;
         $day->modify("+{$i} days");
         $entities[] = array('date' => $day, 'tot' => array('label' => 'Tôt', 'desc' => 'Avant 7h00', 'entities' => array()), 'am' => array('label' => 'Matinée', 'desc' => '7h00 - 12h00', 'entities' => array()), 'pm' => array('label' => 'Après-midi', 'desc' => '12h00 - 18h00', 'entities' => array()), 'soir' => array('label' => 'Soirée', 'desc' => '18h00 - 21h00', 'entities' => array()), 'nuit' => array('label' => 'Nuit', 'desc' => 'Après 21h00', 'entities' => array()));
     }
     foreach ($results as $result) {
         $weekDay = $result->getTimeStart()->format('N') - 1;
         if ($result->getTimeStart()->format('H:i:s') < '07:00:00') {
             $entities[$weekDay]['tot']['entities'][] = $result;
         } elseif ($result->getTimeStart()->format('H:i:s') < '12:00:00') {
             $entities[$weekDay]['am']['entities'][] = $result;
         } elseif ($result->getTimeStart()->format('H:i:s') < '18:00:00') {
             $entities[$weekDay]['pm']['entities'][] = $result;
         } elseif ($result->getTimeStart()->format('H:i:s') < '21:00:00') {
             $entities[$weekDay]['soir']['entities'][] = $result;
         } else {
             $entities[$weekDay]['nuit']['entities'][] = $result;
         }
     }
     return $this->render(sprintf('ProgramBundle:Program:index.%s.twig', $format), array('entities' => $entities, 'count' => count($results), 'weekNumber' => $weekNumber, 'start' => $start, 'stop' => $stop));
 }
开发者ID:polypodes,项目名称:EuradioNantes.eu,代码行数:59,代码来源:ProgramController.php


注:本文中的Datetime::setISODate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。