本文整理汇总了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));
}