-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMiniCalendarCsv.php
87 lines (79 loc) · 1.78 KB
/
MiniCalendarCsv.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
<?
/**
* This file is part of the NRomiixCMS
*
* Copyright (c) 2012 Roman Mátyus ([email protected])
*/
namespace NRomiix\Components\MiniCalendar;
use Nette\Object,
NRomiix\Components\MiniCalendar\IMiniCalendarStorage;
/**
* MiniCalendarCsv
* Class for get data from CSV file for component MiniCalendar
*
* @author Roman Mátyus
* @license MIT
*/
class MiniCalendarCsv extends Object implements IMiniCalendarStorage
{
/** @var array */
public $result=array();
/**
* get $arr for connection to DB or file and parse
* @param string|array $arr
*/
function __construct($arr)
{
$file = __DIR__."/$arr";
if (file_exists($file)) {
$data = file_get_contents($file);
//Debug::bardump($data);
if ($data) {
$data = explode("\r\n\r\n",$data);
foreach (explode("\r\n",$data[0]) as $item) {
$item = explode(":",$item);
if ($item[1]!=="")
$config[$item[0]]=$item[1];
}
$this->result['config']=$config;
if (isset($this->result['config']['year']))
if ($this->result['config']['year']!=date("Y")) {
return FALSE;
}
$data = explode("\r\n",$data[1]);
foreach ($data as $item) {
$item = explode("|",$item);
if (isset($item[1]))
if ($item[1]!="")
$name_day[$item[0]]=$item[1];
}
$this->result['data']=$name_day;
}
}
return ($this->result)?TRUE:FALSE;
}
/**
* get only data
* @return NULL|array
*/
public function getData()
{
return ($this->result['data'])?$this->result['data']:NULL;
}
/**
* get only configuration
* @return NULL|array
*/
function getConfig()
{
return ($this->result['config'])?$this->result['config']:NULL;
}
/**
* get all data from storage
* @return NULL|array
*/
function getResult()
{
return ($this->result)?$this->result:NULL;
}
}