I'm writing a PHP based Directory Browser that allows users to browse their files, and have 14 days worth of archives.
What I'm currently working on is developing a calendar that will read the hard drive, pull the archives into an array (archives are folders formatted as 20060526 - yyyymmdd), and output a calendar based around those 14 archives. All dates on the calendar would be greyed out except the 14 archives which would be links. If this is a new user, they may have less than 14 archives.
I have everything done except the calendar, and need some guidance with the logic (keep in mind this is my first time writing a calendar).
What I was initially planning as far as logic is to grab the first and last archive, and compare them. If they are in the same month, the entire calendar will be that month. If they are in different months, I will make the calendar in the month that has the most archives in it, and include the archives of the other month either before or after (ie 30 31 1 2 3 4 5 6 7) etc. I started writing my class for this and stopped there to get some feedback on where to go next, or if I should revise to make this more effective. My class so far is below. Any feedback would be greatly appreciated.
<?php
require("class.php");
class CreateCalendar
{
/******
* List of all Archives for user
*
*/
var $ArchiveList;
/******
* The array key for the oldest archive
*
*/
var $LastKey;
/******
* Array containing the month I will use in calendar
* as $this->Official["month"]
* along with date, year, and other info
*
*/
var $Official;
function CreateCalendar()
{
// Start Class from class.php
// Grab the Archives
$db = new DirectoryBrowse;
$db->SetUser("cgraz");
$db->setArchive();
$db->setBaseDir();
$db->GrabArchives();
$archives = $db->ArchiveList;
// $archives[0] is most recent backup
for($i=0; $i<count($archives); $i++)
{
$this->ArchiveList[$i]["day"] = substr($archives[$i], 6, 2);
$this->ArchiveList[$i]["month"] = substr($archives[$i], 4, 2);
$this->ArchiveList[$i]["year"] = substr($archives[$i], 0, 4);
}
// Array key for oldest archive
$this->LastKey = (count($this->ArchiveList) - 1);
}
function MoreDaysWhichMonth($month1, $month2)
{
$a = 0;
$b = 0;
for($i=0; $i<count($this->ArchiveList); $i++)
{
if($this->ArchiveList[$i]["month"] == $month1)
{
$a += 1;
}
else
{
if($this->ArchiveList[$i]["month"] == $month2)
{
$b += 1;
}
}
}
if($a > $b)
{
return $month1;
}
else
{
if($a == $b)
{
return $month1;
}
else
{
return $month2;
}
}
}
function ChooseMonth()
{
if($this->ArchiveList[0]["month"] == $this->ArchiveList[$this->LastKey]["month"])
{
$this->Official["month"] = $this->ArchiveList[0]["month"];
}
else
{
// Count Which Month has more Archives in it
// Then that will be official month
$this->Official["month"] = $this->MoreDaysWhichMonth($this->ArchiveList[0]["month"], $this->ArchiveList[$this->LastKey]["month"]);
}
}
}
?>