System description

UML and about the controller

 

Cal-UML

A class diagram of cal
A class diagram of cal

Controller

The controller folder contains the heart of the cal-extension:

  • tx_cal_controller,
  • tx_cal_modelcontroller &
  • tx_cal_viewcontroller.

tx_cal_controller:

The tx_cal_controller is the main entry point of the plugin. It contains the main() function which is called from TYPO3 to retrieve content. Therefore it makes usage of the tx_cal_modelcontroller to fetch model-objects and the tx_cal_viewcontroller to process the model-objects for the desired view.

The configuration of the flexform gets merrged with the typoscript(TS)-setup for tx_cal_controller. If a flexform value is filled the TS-option gets overwritten.

Additionally the tx_cal_controller instanciates the tx_cal_rightsservice which is in charge of checking all rights.

According to the desired->allowed->default view a function is called to handle the request, e.g. month(-view): month(). Inside each of these functions a request is made to the tx_cal_modelcontroller to hand over the according set of models. In the month-example: findEventsForMonth(). Afterwards the returned models are handed over to the tx_cal_viewcontroller which takes care of the according content: renderEventsForMonth().

The received content from the tx_cal_viewcontroller will be wraped through the TYPO3 piBase function pi_wrapInBaseClass() and returned afterwards.

tx_cal_modelcontroller:

The tx_cal_modelcontroller offers services to find and deal with certain models, e.g.: findEvent(), saveEvent(), removeEvent(), findLocation(), findOrganizer(), searchEvents(), searchLocation(), searchOrganizer(), findEventsForDay(), findEventsForWeek(), findEventsForMonth(), findEventsForYear(), findEventsForList(), findEventsForIcs(), findEventsForRss(). The findEventsForX-Functions all (except: ics and rss) calculate a start- and endtime and hand over the request to the findAllWithin() function.

Besides the find() function for a single event the most important and most used function in the tx_cal_modelcontroller is the findAllWithin() function. First the function checks if a type has been specified and if true it searches for a service according to the given type. But mostly there is no type and the function runs into a loop in which it searches for all services according to the handed over service-name like: 'cal_event_model'. There should be at least one service: the default tx_cal_event_service.

The service is being asked the same question as the function: 'findAllWithin()' and hopefully it returns some model-objects. In case of the default tx_cal_event_service the model-objects will be of the type tx_cal_phpicalendar_model.

In case we have more services returning more model-objects we have to sort them. The array storing the model-objects will sort them by day and time: $events[$eventdaykey][$eventtimekey] = $event. This is now the master-array which will follow us through the whole process. Additionally each service adds a legend-description into the master-array['legend'].

Finally the master-array will be returned.

tx_cal_viewcontroller:

Similar to the tx_cal_modelcontroller the tx_cal_viewcontroller offers services to render model-objects: drawDay(), drawWeek(), drawMonth(), drawYear(), drawEvent(), drawSearchEventResults(), drawLocation(), drawOrganizer() and many many more.

Lets stick to the month example and have a look at the drawMonth() function:

The tx_cal_viewcontroller searches for a service according to the view: service-name 'cal_view' and type 'month'. This should return a view-service. The default service for the month view is the tx_cal_monthview. This service is asked to drawMonth() using the master-array and return the content result.

Finally the content will be returned.