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