-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMiniCalendar.php
97 lines (89 loc) · 2.29 KB
/
MiniCalendar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?
/**
* This file is part of the NRomiixCMS
*
* Copyright (c) 2012 Roman Mátyus ([email protected])
*/
namespace NRomiix\Components;
use Nette\Application\Control,
NRomiix\Components\MiniCalendar\MiniCalendarCsv;
/**
* MiniCalendar
* component for fast creating mini calendar
*
* @author Roman Mátyus
* @license MIT
*/
class MiniCalendar extends Control
{
/** @var string */
private $result="";
/** @var array */
private $item=array();
/**
* add text string to the result
* @param string $text
* @return MiniCalendar
*/
public function addText($text)
{
if (is_string($text))
$this->result .= $text;
return $this;
}
/**
* add day of the week to the result
* @param string $patern
* @param string $lang
* @param string $date
* @return MiniCalendar
*/
public function addDayOfTheWeek($pattern = "%s",$lang="",$date="now")
{
$data_from_file = new MiniCalendarCsv("dayoftheweek.$lang.csv");
$day_translate = $data_from_file->getData();
if(strtotime($date))
$this->result .= str_replace("%s",\Nette\String::lower($day_translate[date("l",strtotime($date))]),$pattern);
return $this;
}
/**
* add date to the result
* @param string $patern
* @param string $format
* @param string $date
* @return MiniCalendar
*/
public function addDate($pattern="%s",$format="d.m.Y",$date="now")
{
if(strtotime($date)&&is_string($format))
$this->result .= str_replace("%s",date($format,strtotime($date)),$pattern);
return $this;
}
/**
* add day holyday to the result from arbitrary source
* @param string $source
* @param string $pattern
* @param string $con
* @param string $date
* @return MiniCalendar
*/
public function addDayFrom($source="Csv",$pattern="%s",$con="", $date="now")
{
$source = '\\NRomiix\\Components\\MiniCalendar\\MiniCalendar'.$source;
$data_from_file = new $source($con);
$data_from_file = $data_from_file->getData();
if (isset($data_from_file[date("m-d",strtotime($date))]))
$this->result .= str_replace("%s",$data_from_file[date("m-d",strtotime($date))],$pattern);
return $this;
}
/**
* render MiniCalendar
*/
public function render()
{
$template = parent::createTemplate();
$template->setFile(__DIR__ . '/minicalendar.latte');
$template->result = $this->result;
$template->render();
}
}