Ik probeer een simpel kalendertje te maken. Ik stop per geselecteerde maand alle data per week in een array. Alleen alles wat ik in deze array stop komt niet overeen met welkeweek.nl (dit gebruikte ik eens als indicatie). Toch geeft de PHP date functie wel het goede week nummer terug en alles word daarin netjes geplaatst. Is er een mogelijkheid dat er een tijdzone of i.d. geset moet worden hiervoor?
Mijn return array:
Array
(
[5] => Array
(
[0] => 27
[1] => 28
[2] => 29
[3] => 30
[4] => 31
[5] => 1
[6] => 2
)
[6] => Array
(
[0] => 3
[1] => 4
[2] => 5
[3] => 6
[4] => 7
[5] => 8
[6] => 9
)
[7] => Array
(
[0] => 10
[1] => 11
[2] => 12
[3] => 13
[4] => 14
[5] => 15
[6] => 16
)
[8] => Array
(
[0] => 17
[1] => 18
[2] => 19
[3] => 20
[4] => 21
[5] => 22
[6] => 23
)
[9] => Array
(
[0] => 24
[1] => 25
[2] => 26
[3] => 27
[4] => 28
[5] => 1
[6] => 2
)
)Mijn script die alles erin zet.
<?php
public function setCalDayWeeks()
{
// Put every day in array
for($i = 1; $this->getNumDays($this->calmonth, $this->calyear) >= $i; $i++)
{
$this->caldays[$i] = date('l', strtotime($i.'-'.$this->calmonth.'-'.$this->calyear));
}
// For every day put the week nr in array if not exists
foreach($this->caldays as $day => $value)
{
if(!in_array(date('W', strtotime($day.'-'.$this->calmonth.'-'.$this->calyear)), $this->calweeks))
{
$this->calweeks[] = intval(date('W', strtotime($day.'-'.$this->calmonth.'-'.$this->calyear)));
}
}
// For every week the days of that week in array
foreach($this->calweeks as $key => $week)
{
// For first week add last days of previous month if needed
if($key == 1)
{
for($i = 0; (7 - count($tmpadd)) > $i; $i++)
{
$useweek = $week - 1;
$newday = $this->getNumDays($useweek, $this->calmonth) - $i;
array_unshift($this->calcontent[$useweek], $newday);
}
}
// Tmp array to add
$tmpadd = array();
foreach($this->caldays as $day => $value)
{
if(date('W', strtotime($day.'-'.$this->calmonth.'-'.$this->calyear)) == $week)
{
// For the last day of last week add rest of days if needed
if($day == $this->getNumDays($this->calmonth, $this->calyear))
{
$tmpadd[] = $day;
$cnt = count($tmpadd);
for($i = 1; (7 - $cnt) >= $i; $i++)
{
$tmpadd[] = $i;
}
}
else
{
$tmpadd[] = $day;
}
}
}
$this->calcontent[$week] = $tmpadd;
}
}
?>
[size=xsmall]Toevoeging op 30/01/2014 10:28:36:[/size]
Bump