Generator dnu v mesici pro kalendar

zery
Člen | 5
+
0
-

Ahoj,
nevite o nejake komponente, ktera umi generovat kalendar? Potrebuji vugenerovat cely mesic a pak si prepinat mezi mesicema v danem roce – to uz si nejak udelam. Potrebuji jen nejaky generator dnu kazdeho mesice.

Pavel Kravčík
Člen | 1195
+
+3
-

Můj nejoblíbenější: https://fullcalendar.io/

Nebo klasicky třeba BoostrapDatePicker – je jich tuny.

Václav Pávek
Backer | 100
+
+1
-

Kalendář má být v PHP nebo JS?

dehtak
Člen | 113
+
-2
-

kalendar je celkem jednoducha zalezitost malej priklad

<?php declare(strict_types=1);

namespace Component;

use Nette;
use Nette\Application\UI;

class Calendar extends UI\Control{


    private $month;
    private $year;


         public function setMonth($month = null, $year = null):void{

            $this->month = $month? (int) $month : (int)date("n");
            $this->year = $year? (int) $year : (int)date("Y");

        }


        public function handleGet($month, $year):void{
             if($this->parent->isAjax()){
                $this->redrawControl('calendar');
                $this->setMonth($month, $year);
             }
        }


	public function render() {

            if (!$this->month && !$this->year){ $this->setMonth(); }

            $timestamp = mktime(0, 0, 0, $this->month, 1, $this->year);

            // current date
            $this->template->currentDay = date("j");
            $this->template->currentMonth = date("n");
            $this->template->currentYear = date("Y");

            // days
            $this->template->day = date("j", $timestamp);
            $this->template->firstDay = date("N", $timestamp) - 1;
            $this->template->daysInMonth = date("t", $timestamp);

            // month
            $this->template->month = $this->month;
            $this->template->prevMonth = $this->month === 1 ? 12 : $this->month - 1;
            $this->template->nextMonth = $this->month === 12 ? 1 : $this->month + 1;

            // year
            $this->template->year = $this->year;
            $this->template->prevYear = $this->month === 1 ? $this->year - 1 : $this->year;
            $this->template->nextYear = $this->month === 12 ? $this->year + 1 : $this->year;

            $this->template->render(__DIR__.'/calendar.latte');
	}
}

A sablona

{snippet calendar}

<p><a class="ajax" n:href="get!, $prevMonth,$prevYear">Prev</a> |
	<strong>{$month} / {$year}</strong>
| <a class="ajax" n:href="get!, $nextMonth,$nextYear">Next</a></p>


<table>
<tr>
	<th>Po</th>
	<th>Út</th>
	<th>St</th>
	<th>Čt</th>
	<th>Pá</th>
	<th>So</th>
	<th>Ne</th>
</tr>
<tr>
	{for $weekDay = 0; $weekDay < $firstDay; $weekDay++}
		<td>&nbsp;</td>
	{/for}

	{for $day = 1; $day <= $daysInMonth; $day++}
		{if $weekDay % 7 == 0}
			</tr><tr>
		{/if}

		<td>
			{if $day == $currentDay && $month == $currentMonth && $year == $currentYear}
				<strong>{$day}</strong>
			{else}
				{$day}
			{/if}
		</td>

		{var $weekDay=$weekDay+1}
	{/for}

	{for $i = $weekDay; $i % 7 !== 0; $i++}
		<td>&nbsp;</td>
	{/for}
</tr>
</table>
{/snippet}

Editoval dehtak (16. 10. 2020 11:54)