Welcome Guest, Not a member yet? Register   Sign In
.ics, .ical export script
#1

[eluser]codepotato[/eluser]
Hi all,

First post! Woop!

I just wanted to add something that may have already been done in the community but i couldn't find anything, so here goes.

I've created a very basic (but working) script that exports data into an ics file format.

This is very basic, but should give you enough to get started. Feel free to message me if you need a hand.

Code:
class Ics_model extends Model {

    var $name   = '' // THIS WILL BE THE FILENAME;

    function Ics_model()
    {
        // Call the Model constructor
        parent::Model();
        
        $this->load->helper('file');
        $this->load->helper('date');
    }
    
    
    function create($name, $operator_id)
    {
    
        // get all incomplete reminders
        
        $data = $this->db->get_where()) // AT THIS POINT, GET THE DATA YOU WANT IN YOUR ICS;
        
        if($data->num_rows() > 0)
        {
            // data exists
            
            $ics =
'BEGIN:VCALENDAR
CALSCALE:GREGORIAN
X-WR-TIMEZONE;VALUE=TEXT:US/Pacific
METHOD:PUBLISH
PRODID:-//Codepotato //iCal 1.0//EN
X-WR-CALNAME;VALUE=TEXT:Example
VERSION:2.0';            
            
            foreach($data->result() as $row)
            {
                $datestring = "%Y%m%d";
                $date = mdate($datestring, $row->reminder);
                
                $ics .=
'
BEGIN:VEVENT
SEQUENCE:5
DTSTART;TZID=Europe/London:'.$date.'T120000 // THIS LINE DECLARES THE START TIME / DATE
SUMMARY:'.$row->task.' THIS LINE DECLARES THE TASK LABEL
DTEND;TZID=Europe/London:'.$date.'T121500 // THIS LINE DECLARES THE FINISH TIME / DATE
BEGIN:VALARM
TRIGGER;VALUE=DURATION:-P1D
ACTION:DISPLAY
DESCRIPTION:Event reminder
END:VALARM
END:VEVENT';
                
            }
            
            $ics .=
'
END:VCALENDAR';
            
        }
          

        if (!write_file('./ics/'.$name.'.ics', $ics)) // AT THIS PART, WRITE THE FILE TO THE SERVER
        {
             return('error');
        }
        else
        {
             return('success');
        }
    }
    
}
#2

[eluser]Unknown[/eluser]
You could also use some existing iCal etc. PHP Class you find via google and then use that in either a CI wrapper or Just include it.
Might be more versatile.
#3

[eluser]Jamie Rumbelow[/eluser]
Hey Gareth,

Thanks for contributing this model to the community - it's a small (dare I say it contrived) little example, but it's a nice working script and could definitely be used and improved upon. If you want to promote it a bit more and make it a bit more findable, I encourage you to add it to the CodeIgniter Wiki. If you're serious about developing it, create a GitHub repo and chuck the code in there - it'll make it much easier to update in the future!

Jamie




Theme © iAndrew 2016 - Forum software by © MyBB