Kronolith_Event_Sql::toProperties PHP Method

toProperties() public method

Prepares this event to be saved to the backend.
public toProperties ( boolean $full = false ) : array
$full boolean Return full data, including uid and id.
return array The event properties.
    public function toProperties($full = false)
    {
        $driver = $this->getDriver();
        $properties = array();
        if ($full) {
            $properties['event_id'] = $this->id;
            $properties['event_uid'] = $this->uid;
        }
        /* Basic fields. */
        $properties['event_creator_id'] = $driver->convertToDriver($this->creator);
        $properties['event_title'] = $driver->convertToDriver($this->title);
        $properties['event_description'] = $driver->convertToDriver($this->description);
        $properties['event_location'] = $driver->convertToDriver($this->location);
        $properties['event_timezone'] = $this->timezone;
        $properties['event_url'] = (string) $this->url;
        $properties['event_private'] = (int) $this->private;
        $properties['event_status'] = $this->status;
        $properties['event_attendees'] = serialize($this->attendees);
        $properties['event_resources'] = serialize($driver->convertToDriver($this->getResources()));
        $properties['event_modified'] = $_SERVER['REQUEST_TIME'];
        $properties['event_organizer'] = $this->organizer;
        if ($this->isAllDay()) {
            $properties['event_start'] = $this->start->strftime('%Y-%m-%d %H:%M:%S');
            $properties['event_end'] = $this->end->strftime('%Y-%m-%d %H:%M:%S');
            $properties['event_allday'] = 1;
        } else {
            if ($driver->getParam('utc')) {
                $start = clone $this->start;
                $end = clone $this->end;
                $start->setTimezone('UTC');
                $end->setTimezone('UTC');
            } else {
                $start = $this->start;
                $end = $this->end;
            }
            $properties['event_start'] = $start->strftime('%Y-%m-%d %H:%M:%S');
            $properties['event_end'] = $end->strftime('%Y-%m-%d %H:%M:%S');
            $properties['event_allday'] = 0;
        }
        /* Alarm. */
        $properties['event_alarm'] = (int) $this->alarm;
        /* Alarm Notification Methods. */
        $properties['event_alarm_methods'] = serialize($driver->convertToDriver($this->methods));
        /* Recurrence. */
        if (!$this->recurs()) {
            $properties['event_recurtype'] = 0;
        } else {
            $recur = $this->recurrence->getRecurType();
            if ($this->recurrence->hasRecurEnd()) {
                if ($driver->getParam('utc')) {
                    $recur_end = clone $this->recurrence->recurEnd;
                    $recur_end->setTimezone('UTC');
                } else {
                    $recur_end = $this->recurrence->recurEnd;
                }
            } else {
                $recur_end = new Horde_Date(array('year' => 9999, 'month' => 12, 'mday' => 31, 'hour' => 23, 'min' => 59, 'sec' => 59));
            }
            $properties['event_recurtype'] = $recur;
            $properties['event_recurinterval'] = $this->recurrence->getRecurInterval();
            $properties['event_recurenddate'] = $recur_end->format('Y-m-d H:i:s');
            $properties['event_recurcount'] = $this->recurrence->getRecurCount();
            switch ($recur) {
                case Horde_Date_Recurrence::RECUR_WEEKLY:
                    $properties['event_recurdays'] = $this->recurrence->getRecurOnDays();
                    break;
            }
            $properties['event_exceptions'] = implode(',', $this->recurrence->getExceptions());
        }
        /* Exception information */
        if (!empty($this->baseid)) {
            $properties['event_baseid'] = $this->baseid;
            if ($driver->getParam('utc')) {
                $eod = clone $this->exceptionoriginaldate;
                $eod->setTimezone('UTC');
            } else {
                $eod = $this->exceptionoriginaldate;
            }
            $properties['event_exceptionoriginaldate'] = $eod->strftime('%Y-%m-%d %H:%M:%S');
        } else {
            /* This must be an empty string. */
            $properties['event_baseid'] = '';
            $properties['event_exceptionoriginaldate'] = null;
        }
        return $properties;
    }