<commit_before><?php
namespace UNL\UCBCN\Manager;

use UNL\UCBCN\Calendar as CalendarModel;
use UNL\UCBCN\User;

class Calendar {
    public $options = array();

    public $calendar;

    public function __construct($options = array()) {
        $this->options = $options + $this->options;
        $this->calendar = CalendarModel::getByShortName($this->options['calendar_shortname']);

        if ($this->calendar === FALSE) {
            throw new \Exception("That calendar could not be found.", 500);
        }

        # this function will currently run every time the page is loaded. In the future, it would be better
        # to simply decide whether an event should be archived or posted based on its dates, instead
        # of a column that we set in the database
        $this->archiveEvents();
    }

    public function getCategorizedEvents() {
        $events = $this->calendar->getEvents();

        $categories = array(
            'pending' => array(),
            'posted' => array(),
            'archived' => array(),
            'other' => array()
        );

        foreach ($events as $event) {
            $status = $event->getStatusWithCalendar($this->calendar);
            $key = array_key_exists($status, $categories) ? $status : 'other';

            $categories[$key][] = $event;
        }

        return $categories;
    }

    private function archiveEvents() {
        # find all posted (upcoming) events on the calendar
        $events = $this->calendar->getEvents('posted');

        # check each event to see if it has passed
        foreach ($events as $event) {
            # we will consider it passed if all datetimes are in the past
            $datetimes = $event->getDatetimes();
            $archive = true;
            foreach ($datetimes as $datetime) {
                if ($datetime->starttime >= date('Y-m-d 00:00:00') && ($datetime->endtime == NULL || $datetime->endtime >= date('Y-m-d 00:00:00'))) {
                    $archive = false;
                    break;
                }
            }

            # update the status with the calendar
            if ($archive) {
                $event->updateStatusWithCalendar($this->calendar, 'archived');<commit_msg>Wrong logic in time check, fixed now<commit_after><?php
namespace UNL\UCBCN\Manager;

use UNL\UCBCN\Calendar as CalendarModel;
use UNL\UCBCN\User;

class Calendar {
    public $options = array();

    public $calendar;

    public function __construct($options = array()) {
        $this->options = $options + $this->options;
        $this->calendar = CalendarModel::getByShortName($this->options['calendar_shortname']);

        if ($this->calendar === FALSE) {
            throw new \Exception("That calendar could not be found.", 500);
        }

        # this function will currently run every time the page is loaded. In the future, it would be better
        # to simply decide whether an event should be archived or posted based on its dates, instead
        # of a column that we set in the database
        $this->archiveEvents();
    }

    public function getCategorizedEvents() {
        $events = $this->calendar->getEvents();

        $categories = array(
            'pending' => array(),
            'posted' => array(),
            'archived' => array(),
            'other' => array()
        );

        foreach ($events as $event) {
            $status = $event->getStatusWithCalendar($this->calendar);
            $key = array_key_exists($status, $categories) ? $status : 'other';

            $categories[$key][] = $event;
        }

        return $categories;
    }

    private function archiveEvents() {
        # find all posted (upcoming) events on the calendar
        $events = $this->calendar->getEvents('posted');

        # check each event to see if it has passed
        foreach ($events as $event) {
            # we will consider it passed if all datetimes are in the past
            $datetimes = $event->getDatetimes();
            $archive = true;
            foreach ($datetimes as $datetime) {
                if ($datetime->starttime >= date('Y-m-d 00:00:00') || ($datetime->endtime != NULL && $datetime->endtime >= date('Y-m-d 00:00:00'))) {
                    $archive = false;
                    break;
                }
            }

            # update the status with the calendar
            if ($archive) {
                $event->updateStatusWithCalendar($this->calendar, 'archived');
{'fraction_non_alphanumeric': 0.12446736936532855, 'fraction_numerical': 0.006727965911639381, 'mean_word_length': 2.1123517096999302, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, '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': '4209395', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1138, 'n_words': 363}