How can I design my classes to include calendar events stored in a database?

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 getCalendarCellList() {}

    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 calendar events (such as appointments or schedules) stored in a database.
My question is: which is the best way to manage these calendar 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!

2

to add a eventList property in CalendarCell and populate it with an array of CalendarEvent objects fetched by the database.

Note: This is not a PHP solution, instead its a solution based on a RDBMS approach.

Yes you can do what you suggested above. Other developers who don’t want to use the events could just not call the method that loads the events. A calendar cell and an event are 2 separate things. Hence, I see them as 2 separate classes.

The associations between a cell and an event (as I would think of it) may be something like:

  • A calenderCell has 0,1 or more Events.

  • An Event belongs to one or more calendarCells (for example, in case of a conference or a task spanning many days).

The above represent a Many-To-Many association.

You need a third class “calendarEvnet-MM” that holds the PK of calendarCell and calendarEvents.

So you’d have:

calendarCell Table:

claendarCell_ID (Primary Key)

calendarEvent Table:

calendarEvent_ID (Primary Key)

calendarEvnet-MM Table:

calendarEvnet-MM_ID (Primary Key)

calendarCell_ID_FK (Foreign Key)

calendarEvent_ID_FK (Foreign Key)

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật