<commit_before><?php
/* @var $this SiteController */

$this->pageTitle=Yii::app()->name . ' - Fetch';
$this->breadcrumbs=array(
	'Fetch',
);
?>
<h1>Fetch</h1>


<?php

    function icsToArray($paramUrl) {
        $icsFile = file_get_contents($paramUrl);
        $icsData = explode("BEGIN:", $icsFile);
        foreach($icsData as $key => $value) {
            $icsDatesMeta[$key] = explode("\n", $value);
        }
        foreach($icsDatesMeta as $key => $value) {
            foreach($value as $subKey => $subValue) {
                if ($subValue != "") {
                    if ($key != 0 && $subKey == 0) {
                        $icsDates[$key]["BEGIN"] = $subValue;
                    } else {
                        $subValueArr = explode(":", $subValue, 2);
                        $icsDates[$key][$subValueArr[0]] = $subValueArr[1];
                    }
                }
            }
        }
        return $icsDates;
    } 

    $url='http://ov-kempten.ov-cms.thw.de/unser-thw-ortsverband/terminkalender/kalender/ics/?type=150&tx_cal_controller%5Bcalendar%5D=20';

    $temp = tempnam('/tmp', 'thw-kempten');

    file_put_contents($temp, file_get_contents($url));

    $data = icsTOArray($temp);

    echo '<br />';
    echo json_encode($data);

    unlink($temp);

?><commit_msg>Adding logic to insert / update datenabse events entries<commit_after><?php
/* @var $this SiteController */

$this->pageTitle=Yii::app()->name . ' - Fetch';
$this->breadcrumbs=array(
	'Fetch',
);
?>
<h1>Fetch</h1>


<?php

    function icsToArray($paramUrl) {
        $icsFile = file_get_contents($paramUrl);
        $icsData = explode("BEGIN:", $icsFile);
        foreach($icsData as $key => $value) {
            $icsDatesMeta[$key] = explode("\n", $value);
        }
        foreach($icsDatesMeta as $key => $value) {
            foreach($value as $subKey => $subValue) {
                if ($subValue != "") {
                    if ($key != 0 && $subKey == 0) {
                        $icsDates[$key]["BEGIN"] = $subValue;
                    } else {
                        $subValueArr = explode(":", $subValue, 2);
                        $icsDates[$key][$subValueArr[0]] = $subValueArr[1];
                    }
                }
            }
        }
        return $icsDates;
    } 

    $url='http://ov-kempten.ov-cms.thw.de/unser-thw-ortsverband/terminkalender/kalender/ics/?type=150&tx_cal_controller%5Bcalendar%5D=20';
    $temp = tempnam('/tmp', 'thw-kempten');
    file_put_contents($temp, file_get_contents($url));
    $data = icsTOArray($temp);
    foreach ($data as &$value) {
        echo '1';
        if ($value['BEGIN'] == 'VEVENT') {
            $criteria = new CDbCriteria;
            $criteria->condition = "'uid' = '".trim($value['UID'])."'";
            $models = Events::model()->findAll($criteria);
            if (count($models) > 0) {
                // Update Date to Events model

            } else {
                // Create new Events model from data
                $event = new Events();
                $event->uid = $value['UID'];

                if (array_key_exists('SUMMARY', $value)) {
                    $event->summary = $value['SUMMARY'];
                }
                if (array_key_exists('DESCRIPTION', $value)) {
                    $event->description = $value['DESCRIPTION'];
                }
                if (array_key_exists('LOCATION', $value)) {
                    $event->location = $value['LOCATION'];
                }
                $event->save();
            }
            echo 'laber <br />';
        }
    }
    unlink($temp);
    unset($url);
    unset($temp);
    unset($data);
?>
{'fraction_non_alphanumeric': 0.17326057298772168, 'fraction_numerical': 0.008185538881309686, 'mean_word_length': 1.7751703255109765, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3935907', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1123, 'n_words': 188}