witajcie,
mam kalendarz na dany miesiąc

Napisałem to w taki sposób

Kontroler:
  1. $this->view->timestamp = time();
  2. $this->view->curTimestamp = time();
  3. list($month, $day, $year) = explode('-', date('m-d-Y', time()));
  4. $this->view->day = $day;
  5. $this->view->month = $month;
  6. $this->view->year = $year;
  7. $this->view->firstDayOfMonth = date('w', mktime(0, 0, 0, $month, 1, $year));
  8. $this->view->dayNameArray = array('Nd', 'Pn', 'Wt', 'Sr', 'Czw', 'Pt', 'Sb');
  9. $this->view->totalDay = date('t', time());


Widok:
  1. <?php $curDay =1;?>
  2. <table class="mini_calendar">
  3. <thead class="mini_calendar_head">
  4. <tr>
  5. <th><a href="<?php echo $this->url(array('controller'=>'terminy', 't'=>strtotime('-1 month', $this->timestamp)));?>"><img src="/SYSTEM/public/img/arrow_left.png" /></a></th>
  6. <th colspan='5' ><a href="<?php echo $this->url(array('controller'=>'terminy', 't'=>$this->curTimestamp));?>">cur day</a></th>
  7. <th><a href="<?php echo $this->url(array('controller'=>'terminy', 't'=>strtotime('+1 month', $this->timestamp)));?>"><img src="/SYSTEM/public/img/arrow_right.png" /></a></th>
  8. </tr>
  9. <tr class="mini_calendar_head_dname">
  10. <td><?php echo implode('</td><td>', $this->dayNameArray);?></td>
  11. </tr>
  12. </thead>
  13. <tfoot class="mini_calendar_foot">
  14. <tr>
  15. <th><a href='#'></a></th>
  16. <th colspan='5' ></th>
  17. <th><a href='#'></a></th>
  18. </tr>
  19. </tfoot>
  20. <tbody id="mini_calendar_body">
  21. <?php while($curDay <= $this->totalDay): ?>
  22. <tr>
  23. <?php for($i=0; $i<7; $i++):?>
  24. <?php if(($curDay == 1 && $i < $this->firstDayOfMonth) || ($curDay > $this->totalDay)): ?>
  25. <td class="mini_calendar_body_blank"> </td>
  26. <?php continue; ?>
  27. <?php endif; ?>
  28. <td class="mini_calendar_body_data"><a href='<?php echo $this->url(array('controller'=>'terminy', 't'=>mktime(0, 0, 0, $this->month, $curDay, $this->year)));?>'><?php echo $curDay; ?></a></td>
  29. <?php $curDay++; ?>
  30. <?php endfor; ?>
  31. </tr>
  32. <?php endwhile; ?>
  33. </tbody>
  34. </table>


Chcę uprościć widok w kalendarzu.
Wzorując się na mojej wcześniejszej wersji
stworzyłem model:

  1. public function miniCalendar($totalDay, $firstDayOfMonth, $month, $year)
  2. {
  3. $curDay = 1;
  4. $dayArray = array();
  5.  
  6. while($curDay <= $totalDay)
  7. {
  8. $dayArray[] = array(
  9. 'mktime' => mktime(0, 0, 0, $month, $curDay, $year),
  10. 'day' => $curDay,
  11. 'blank_day' => 0
  12. );
  13. $curDay++;
  14. }
  15. return $dayArray;
  16. }


W kontrolerze:
  1. // Te parametry co wyżej w kontrolerze +
  2. $this->view->miniCalendar = $term->miniCalendar($this->view->totalDay, $this->view->firstDayOfMonth, $this->view->month, $this->view->year);


Widok(Z tym mam problem):
  1. <table>
  2. <tr><td>Nd</td><td>Pn</td><td>Wt</td><td>Sr</td><td>Czw</td><td>Pt</td><td>Sb</td></tr>
  3. <?php foreach ($this->miniCalendar as $i=>$calendar):?>
  4. <td><?php echo $calendar['day']; ?></td>
  5. <?php if($i==6 || $i==13 || $i==20 || $i==27):?>
  6. <tr>
  7. <?php endif;?>
  8. <?php endforeach;?>
  9. </table>



Nie umiem sobie poradzić z rozpoczęciem dnia od danego dnia tygodnia.
Np w następnym miesiącu zaczynamy miesiąc od środy, czyli Nd, Pn, Wt musi być <td> </td>

Proszę o pomoc w widoku, już sam się zapętlam i nie umiem iść z tym do przodu.

Pozdrawiam,
Tomasz Solik