public function onBeforeWrite() { parent::onBeforeWrite(); // Make sure a valid date range is entered if (DateTime::createFromFormat('Y-m-d', $this->StartDate) > DateTime::createFromFormat('Y-m-d', $this->EndDate)) { throw new ValidationException("End date cannot occur before start date"); } // Make sure something is set... if ($this->ShortDescription === "") { $this->ShortDescription = "(No description set)"; } // Write the ics file for the event $service = new IcsGenerator($this->Title); $service->generateEventList(null, $this->ID); // Attach the file to this page $this->CalFileID = $service->getFileObject()->ID; $this->CalFileURL = $service->getFileObject()->getURL(); }