All pastes #206512 Raw Edit

Unnamed

public text v1 · immutable
#206512 ·published 2006-10-17 13:08 UTC
rendered paste body
<?php


define('INC_LIB_ARG', 'lib/Arg.php');
define('INC_LIB_STORAGE', 'lib/Storage.php');
define('INC_SCHEDULE_VAR_SCHEDULE', 'var/schedule');

include_once(INC_LIB_ARG);
include_once(INC_LIB_STORAGE);

class Schedule extends Storage_ARRAY {
    function Schedule() {
        $location = INC_SCHEDULE_VAR_SCHEDULE;
        parent::Storage_ARRAY($location);
    }

    function handle_field($id, $field) {
        $result = $field;
        if (preg_match('/^(\d{2})\.(\d{2})\.(\d{4})$/', $field['date'], $match)
        &&  preg_match('/^\d{2}:\d{2}$/', $field['time'])) {
            $date_info = getdate(mktime(0,0,0,$match[2],$match[1],$match[3]));
            $result['day'] = ($date_info['wday'] == 0 ? 6 : $date_info['wday'] - 1 );
            $id = $id_new;
            $participant_number = 0;
            $points = 0;
            if (!empty($result['participant_new'])) {
                if (empty($result['participant'])) {
                    $result['participant'] = array();
                }
                foreach($result['participant_new'] as $key => $value) {
                    $result['participant'][$key] = $value;
                }
            }
            if (!empty($result['participant'])) {
                foreach ($result['participant'] as $key => $value) {
                    if ($value == 0) {
                        unset($result['participant'][$key]);
                    } else {
                        $participant_number++;
                        $points += $value;
                    }
                }
            }
            $result['participant_number'] = $participant_number;
            $result['points'] = $points;
            $result['date_match'] = $match;
        }
        if (empty($result['id'])) {
            if (empty($id)) {
                $result['id'] = $match[3].$match[2].$match[1];
            } else {
                $result = $id;
            }
        }
        return $result;
    }

    function add($id, $field) {
        $field = $this->handle_field($id, $field);
        $id = $field['id'];
        unset($field['date_match']);
        parent::add($id, $field);
    }

    function set($id, $field) {
        $field =  $this->handle_field($id, $field);
        $id_new = $field['date_match'][3].$field['date_match'][2].$field['date_match'][1];
        if ($id != $id_new) {
            if (!empty($id)) {
                $this->container[$id_new] = & $this->container[$id];
                unset($this->container[$id]);
                $id = $id_new;
            }
            ksort(&$this->container);
        }
        unset($field['date_match']);
        parent::set($id, $field);
    }
}

?>