-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
62 lines (56 loc) · 3.3 KB
/
index.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
<?php
require_once './php/error-reporting.php';
require_once './php/Calendar.php';
require_once './php/cal-demo.php';
$calendar = new Calendar;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="./css/main.css" rel="stylesheet">
<title>Document</title>
</head>
<body>
<h1>Calendar class</h1>
<h2>Demonstration</h2>
<p>
This shows a single month, generated by the Calendar class, formatted with calDemo().
</p>
<p>
Note that calDemo takes, as its sole argument, the array generated by <em>Calendar::createMonth()</em>.
</p>
<p>
The display is simply for demonstartion. <em>calDemo()</em> is not part of the <em>Calendar class</em>. It is envisaged that the data structure generated by the <em>Calendar class</em> will be used in conjunction with other code (for example which might add events) and displayed by other code which could be PHP or JavaScript using Ajax to get the data structure, modified or not, from a server.
</p>
<?php
calDemo($calendar->createMonth());
?>
<h2>Overview</h2>
<p>
The Calendar PHP class creates an array which, as well as keys indicating which year and month it is for, includes an array called <em>days</em> which consists of 42, 35 or 28 <em>day</em> arrays. This corresponds to 4, 5 or 6 weeks. The <em>day</em> arrays simply record the day of the month (an integer from 1 to 31) and whether the day is in the current month, the previous month or the next month.
</p>
<p>
A February which starts on a Monday will only span 28 days or exactly 4 weeks so only 28 days will be represented in the <em>days</em> array. Other months will span 5 or 6 weeks depending on the day of the week they start on. Months which do not start on a Monday will show the last days of the previous month starting from the last Monday. Months which do not end on a Sunday will show the first days of the next month ending on the first Sunday.
</p>
<p>
In order to use the Calendar class, include the file in your script with <em>require_once './path/to/Calendar.php';</em>. Assign it to any variable with for example <em>$calendar = new Calendar;</em>. Now you can invoke it: <em>$calendar->createMonth();</em>. If no arguments are supplied it will default to the current year and month. With arguments, the code would look like: <em>$calendar->createMonth(2023, 1);</em> for January, 2023.
In order to supply one argument but not the other use <em>null</em> as in <em>$calendar->createMonth(null, 3);</em>, for March of the current year.
</p>
<h2>Usage</h2>
<p>
The calendar class could be used just to display months from any year. It could also be used in combination with an <em>events</em> CRUD application. An array representing an event (for example date, time, title, details, organizer etc.) could be added to any <em>day</em> array generated by Calendar based on the fact that the event date and the calendar date are the same. Then the calendar could be displayed with events using PHP or JavaScript etc.
</p>
<h2>$calendar->createMonth()</h2>
<p>
This shows the Array created by $calendar->createMonth().
</p>
<pre><code>
<?php
var_dump($calendar->createMonth());
?>
</code></pre>
</body>
</html>