How can I design my classes for a calendar based on database events?

Posted by Gianluca78 on Programmers See other posts from Programmers or by Gianluca78
Published on 2012-10-10T06:45:47Z Indexed on 2012/10/10 9:51 UTC
Read the original article Hit count: 189

I'm developing a web calendar in php (using Symfony2) inspired by iCal for a project of mine. At this moment, I have two classes: a class "Calendar" and a class "CalendarCell".

Here you are the two classes properties and method declarations.

class Calendar
{
    private $month;
    private $monthName;
    private $year;
    private $calendarCellList = array();
    private $translator;

    public function __construct($month, $year, $translator) {}               

    public function getCalendarCells() {}

    public function getMonth() {}

    public function getMonthName() {}

    public function getNextMonth() {}

    public function getNextYear() {}

    public function getPreviousMonth() {}

    public function getPreviousYear() {}

    public function getYear() {}

    private function calculateDaysPreviousMonth() {}

    private function calculateNumericDayOfTheFirstDayOfTheWeek() {}

    private function isCurrentDay(\DateTime $dateTime) {}

    private function isDifferentMonth(\DateTime $dateTime) {}
}

class CalendarCell 
{
    private $day;
    private $month;
    private $dayNameAbbreviation;
    private $numericDayOfTheWeek;
    private $isCurrentDay;
    private $isDifferentMonth;
    private $translator;

    public function __construct(array $parameters) {}

    public function getDay() {}

    public function getMonth() {}

    public function getDayNameAbbreviation() {}

    public function isCurrentDay() {}

    public function isDifferentMonth() {}
}

Each calendar day can includes many events stored in a database. My question is: which is the best way to manage these events in my classes? I think to add a eventList property in CalendarCell and populate it with an array of CalendarEvent objects fetched by the database.

This kind of solution doesn't allow other coders to reuse the classes without db (because I should inject at least a repository services also) just to create and visualize a calendar... so maybe it could be better to extend CalendarCell (for instance in CalendarCellEvent) and add the database features?

I feel like I'm missing some crucial design pattern!

Any suggestion will be very appreciated!

© Programmers or respective owner

Related posts about php

Related posts about design-patterns