Kronolith_FreeBusy_View::render PHP Method

render() public method

Renders the fb view
public render ( Horde_Date $day = null ) : string
$day Horde_Date The day to render
return string The html of the rendered fb view.
    public function render(Horde_Date $day = null)
    {
        global $prefs;
        $this->_startHour = floor($prefs->getValue('day_hour_start') / 2);
        $this->_endHour = floor(($prefs->getValue('day_hour_end') + 1) / 2);
        $this->_render($day);
        $vCal = new Horde_Icalendar();
        /* Required members */
        $required = Horde_Icalendar::newComponent('vfreebusy', $vCal);
        foreach ($this->_requiredMembers as $member) {
            $required->merge($member, false);
        }
        foreach ($this->_requiredResourceMembers as $member) {
            $required->merge($member, false);
        }
        $required->simplify();
        /* Optional members */
        $optional = Horde_Icalendar::newComponent('vfreebusy', $vCal);
        foreach ($this->_optionalMembers as $member) {
            $optional->merge($member, false);
        }
        foreach ($this->_optionalResourceMembers as $member) {
            $optional->merge($member, false);
        }
        $optional->simplify();
        /* Optimal time calculation */
        $optimal = Horde_Icalendar::newComponent('vfreebusy', $vCal);
        $optimal->merge($required, false);
        $optimal->merge($optional);
        $template = $GLOBALS['injector']->createInstance('Horde_Template');
        $template->set('title', $this->_title());
        $html = $template->fetch(KRONOLITH_TEMPLATES . '/fbview/header.html');
        $hours_html = $this->_hours();
        // Set C locale to avoid localized decimal separators during CSS width
        // calculation.
        $lc = setlocale(LC_NUMERIC, 0);
        setlocale(LC_NUMERIC, 'C');
        // Required to attend.
        if (count($this->_requiredMembers) > 0) {
            $rows = '';
            foreach ($this->_requiredMembers as $member) {
                $member->simplify();
                $blocks = $this->_getBlocks($member, $member->getBusyPeriods(), 'busyblock.html', _("Busy"));
                $template = $GLOBALS['injector']->createInstance('Horde_Template');
                $template->set('blocks', $blocks);
                $template->set('name', htmlspecialchars($member->getName()));
                $rows .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html');
            }
            $template = $GLOBALS['injector']->createInstance('Horde_Template');
            $template->set('title', _("Required Attendees"));
            $template->set('rows', $rows);
            $template->set('span', count($this->_timeBlocks));
            $template->set('hours', $hours_html);
            $html .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/section.html');
        }
        // Optional to attend.
        if (count($this->_optionalMembers) > 0) {
            $rows = '';
            foreach ($this->_optionalMembers as $member) {
                $member->simplify();
                $blocks = $this->_getBlocks($member, $member->getBusyPeriods(), 'busyblock.html', _("Busy"));
                $template = $GLOBALS['injector']->createInstance('Horde_Template');
                $template->set('blocks', $blocks);
                $template->set('name', htmlspecialchars($member->getName()));
                $rows .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html');
            }
            $template = $GLOBALS['injector']->createInstance('Horde_Template');
            $template->set('title', _("Optional Attendees"));
            $template->set('rows', $rows);
            $template->set('span', count($this->_timeBlocks));
            $template->set('hours', $hours_html);
            $html .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/section.html');
        }
        // Resources
        if (count($this->_requiredResourceMembers) > 0 || count($this->_optionalResourceMembers) > 0) {
            $template = $GLOBALS['injector']->createInstance('Horde_Template');
            $rows = '';
            foreach ($this->_requiredResourceMembers as $member) {
                $member->simplify();
                $blocks = $this->_getBlocks($member, $member->getBusyPeriods(), 'busyblock.html', _("Busy"));
                $template = $GLOBALS['injector']->createInstance('Horde_Template');
                $template->set('blocks', $blocks);
                $template->set('name', htmlspecialchars($member->getName()));
                $rows .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html');
            }
            foreach ($this->_optionalResourceMembers as $member) {
                $member->simplify();
                $blocks = $this->_getBlocks($member, $member->getBusyPeriods(), 'busyblock.html', _("Busy"));
                $template = $GLOBALS['injector']->createInstance('Horde_Template');
                $template->set('blocks', $blocks);
                $template->set('name', htmlspecialchars($member->getName()));
                $rows .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html');
            }
            $template = $GLOBALS['injector']->createInstance('Horde_Template');
            $template->set('title', _("Required Resources"));
            $template->set('rows', $rows);
            $template->set('span', count($this->_timeBlocks));
            $template->set('hours', $hours_html);
            $html .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/section.html');
        }
        // Possible meeting times.
        $optimal->setAttribute('ORGANIZER', _("All Attendees"));
        $blocks = $this->_getBlocks($optimal, $optimal->getFreePeriods($this->_start->timestamp(), $this->_end->timestamp()), 'meetingblock.html', _("All Attendees"));
        $template = $GLOBALS['injector']->createInstance('Horde_Template');
        $template->set('name', _("All Attendees"));
        $template->set('blocks', $blocks);
        $rows = $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html');
        // Possible meeting times.
        $required->setAttribute('ORGANIZER', _("Required Attendees"));
        $blocks = $this->_getBlocks($required, $required->getFreePeriods($this->_start->timestamp(), $this->_end->timestamp()), 'meetingblock.html', _("Required Attendees"));
        $template = $GLOBALS['injector']->createInstance('Horde_Template');
        $template->set('name', _("Required Attendees"));
        $template->set('blocks', $blocks);
        $rows .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html');
        // Reset locale.
        setlocale(LC_NUMERIC, $lc);
        $template = $GLOBALS['injector']->createInstance('Horde_Template');
        $template->set('rows', $rows);
        $template->set('title', _("Overview"));
        $template->set('span', count($this->_timeBlocks));
        $template->set('hours', $hours_html);
        $html .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/section.html');
        $template = $GLOBALS['injector']->createInstance('Horde_Template');
        if ($prefs->getValue('show_fb_legend')) {
            $template->setOption('gettext', true);
            $template->set('span', count($this->_timeBlocks));
            $template->set('legend', $template->fetch(KRONOLITH_TEMPLATES . '/fbview/legend.html'));
        } else {
            $template->set('legend', '');
        }
        $html .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/footer.html');
        return $html;
    }