CodeIgniter Forums
.ics, .ical export script - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forum-22.html)
+--- Thread: .ics, .ical export script (/thread-25927.html)



.ics, .ical export script - El Forum - 12-31-2009

[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');
        }
    }
    
}



.ics, .ical export script - El Forum - 01-02-2010

[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.


.ics, .ical export script - El Forum - 01-03-2010

[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