addOneYear() public method

Add one year.
public addOneYear ( ) : ExpressiveDate
return ExpressiveDate
Beispiel #1
0
function eme_create_year_scope($count)
{
    global $eme_timezone;
    $scope = array();
    $scope[0] = __('Select Year', 'eme');
    $eme_date_obj = new ExpressiveDate(null, $eme_timezone);
    for ($i = 0; $i < $count; $i++) {
        $year = $eme_date_obj->getYear();
        $limit_start = "{$year}-01-01";
        $limit_end = "{$year}-12-31";
        $this_scope = "{$limit_start}--{$limit_end}";
        $scope_text = eme_localised_date($limit_start . " " . $eme_timezone, get_option('eme_show_period_yearly_dateformat'));
        $scope[$this_scope] = $scope_text;
        $eme_date_obj->addOneYear();
    }
    return $scope;
}
function eme_create_events_table($charset, $collate)
{
    global $wpdb, $eme_timezone;
    $db_version = get_option('eme_version');
    $table_name = $wpdb->prefix . EVENTS_TBNAME;
    if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name) {
        // Creating the events table
        $sql = "CREATE TABLE " . $table_name . " (\n         event_id mediumint(9) NOT NULL AUTO_INCREMENT,\n         event_status mediumint(9) DEFAULT 1,\n         event_author mediumint(9) DEFAULT 0,\n         event_name text NOT NULL,\n         event_slug text default NULL,\n         event_url text default NULL,\n         event_start_time time NOT NULL,\n         event_end_time time NOT NULL,\n         event_start_date date NOT NULL,\n         event_end_date date NULL, \n         creation_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00', \n         creation_date_gmt datetime NOT NULL DEFAULT '0000-00-00 00:00:00', \n         modif_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00', \n         modif_date_gmt datetime NOT NULL DEFAULT '0000-00-00 00:00:00', \n         event_notes longtext DEFAULT NULL,\n         event_rsvp bool DEFAULT 0,\n         use_paypal bool DEFAULT 0,\n         use_2co bool DEFAULT 0,\n         use_webmoney bool DEFAULT 0,\n         use_fdgg bool DEFAULT 0,\n         use_mollie bool DEFAULT 0,\n         use_sagepay bool DEFAULT 0,\n         price text DEFAULT NULL,\n         currency text DEFAULT NULL,\n         rsvp_number_days tinyint unsigned DEFAULT 0,\n         rsvp_number_hours tinyint unsigned DEFAULT 0,\n         event_seats text DEFAULT NULL,\n         event_contactperson_id mediumint(9) DEFAULT 0,\n         location_id mediumint(9) DEFAULT 0,\n         recurrence_id mediumint(9) DEFAULT 0,\n         event_category_ids text default NULL,\n         event_attributes text NULL, \n         event_properties text NULL, \n         event_page_title_format text NULL, \n         event_single_event_format text NULL, \n         event_contactperson_email_body text NULL, \n         event_respondent_email_body text NULL, \n         event_registration_recorded_ok_html text NULL, \n         event_registration_pending_email_body text NULL, \n         event_registration_updated_email_body text NULL, \n         event_registration_cancelled_email_body text NULL, \n         event_registration_denied_email_body text NULL, \n         event_registration_form_format text NULL, \n         event_cancel_form_format text NULL, \n         registration_requires_approval bool DEFAULT 0,\n         registration_wp_users_only bool DEFAULT 0,\n         event_image_url text NULL,\n         event_image_id mediumint(9) DEFAULT 0 NOT NULL,\n         event_external_ref text NULL, \n         UNIQUE KEY (event_id)\n         ) {$charset} {$collate};";
        maybe_create_table($table_name, $sql);
        // insert a few events in the new table
        // get the current timestamp into an array
        $eme_date_obj = new ExpressiveDate(null, $eme_timezone);
        $eme_date_obj->addDays(7);
        $in_one_week = $eme_date_obj->getDate();
        $eme_date_obj->minusDays(7);
        $eme_date_obj->addWeeks(4);
        $in_four_weeks = $eme_date_obj->getDate();
        $eme_date_obj->minusWeeks(4);
        $eme_date_obj->addOneYear();
        $in_one_year = $eme_date_obj->getDate();
        $wpdb->query("INSERT INTO " . $table_name . " (event_name, event_start_date, event_start_time, event_end_time, location_id)\n            VALUES ('Orality in James Joyce Conference', '{$in_one_week}', '16:00:00', '18:00:00', 1)");
        $wpdb->query("INSERT INTO " . $table_name . " (event_name, event_start_date, event_start_time, event_end_time, location_id)\n            VALUES ('Traditional music session', '{$in_four_weeks}', '20:00:00', '22:00:00', 2)");
        $wpdb->query("INSERT INTO " . $table_name . " (event_name, event_start_date, event_start_time, event_end_time, location_id)\n               VALUES ('6 Nations, Italy VS Ireland', '{$in_one_year}','22:00:00', '24:00:00', 3)");
    } else {
        // eventual maybe_add_column() for later versions
        maybe_add_column($table_name, 'event_status', "alter table {$table_name} add event_status mediumint(9) DEFAULT 1;");
        maybe_add_column($table_name, 'event_start_date', "alter table {$table_name} add event_start_date date NOT NULL;");
        maybe_add_column($table_name, 'event_end_date', "alter table {$table_name} add event_end_date date NULL;");
        maybe_add_column($table_name, 'event_start_time', "alter table {$table_name} add event_start_time time NOT NULL;");
        maybe_add_column($table_name, 'event_end_time', "alter table {$table_name} add event_end_time time NOT NULL;");
        maybe_add_column($table_name, 'event_rsvp', "alter table {$table_name} add event_rsvp bool DEFAULT 0;");
        maybe_add_column($table_name, 'use_paypal', "alter table {$table_name} add use_paypal bool DEFAULT 0;");
        maybe_add_column($table_name, 'use_2co', "alter table {$table_name} add use_2co bool DEFAULT 0;");
        maybe_add_column($table_name, 'use_webmoney', "alter table {$table_name} add use_webmoney bool DEFAULT 0;");
        maybe_add_column($table_name, 'use_fdgg', "alter table {$table_name} add use_fdgg bool DEFAULT 0;");
        maybe_add_column($table_name, 'use_mollie', "alter table {$table_name} add use_mollie bool DEFAULT 0;");
        maybe_add_column($table_name, 'use_sagepay', "alter table {$table_name} add use_sagepay bool DEFAULT 0;");
        maybe_add_column($table_name, 'rsvp_number_days', "alter table {$table_name} add rsvp_number_days tinyint DEFAULT 0;");
        maybe_add_column($table_name, 'rsvp_number_hours', "alter table {$table_name} add rsvp_number_hours tinyint DEFAULT 0;");
        maybe_add_column($table_name, 'price', "alter table {$table_name} add price text DEFAULT NULL;");
        maybe_add_column($table_name, 'currency', "alter table {$table_name} add currency text DEFAULT NULL;");
        maybe_add_column($table_name, 'event_seats', "alter table {$table_name} add event_seats text DEFAULT NULL;");
        maybe_add_column($table_name, 'location_id', "alter table {$table_name} add location_id mediumint(9) DEFAULT 0;");
        maybe_add_column($table_name, 'recurrence_id', "alter table {$table_name} add recurrence_id mediumint(9) DEFAULT 0;");
        maybe_add_column($table_name, 'event_contactperson_id', "alter table {$table_name} add event_contactperson_id mediumint(9) DEFAULT 0;");
        maybe_add_column($table_name, 'event_attributes', "alter table {$table_name} add event_attributes text NULL;");
        maybe_add_column($table_name, 'event_properties', "alter table {$table_name} add event_properties text NULL;");
        maybe_add_column($table_name, 'event_url', "alter table {$table_name} add event_url text DEFAULT NULL;");
        maybe_add_column($table_name, 'event_slug', "alter table {$table_name} add event_slug text DEFAULT NULL;");
        maybe_add_column($table_name, 'event_category_ids', "alter table {$table_name} add event_category_ids text DEFAULT NULL;");
        maybe_add_column($table_name, 'event_page_title_format', "alter table {$table_name} add event_page_title_format text NULL;");
        maybe_add_column($table_name, 'event_single_event_format', "alter table {$table_name} add event_single_event_format text NULL;");
        maybe_add_column($table_name, 'event_contactperson_email_body', "alter table {$table_name} add event_contactperson_email_body text NULL;");
        maybe_add_column($table_name, 'event_respondent_email_body', "alter table {$table_name} add event_respondent_email_body text NULL;");
        maybe_add_column($table_name, 'event_registration_pending_email_body', "alter table {$table_name} add event_registration_pending_email_body text NULL;");
        maybe_add_column($table_name, 'event_registration_updated_email_body', "alter table {$table_name} add event_registration_updated_email_body text NULL;");
        maybe_add_column($table_name, 'event_registration_cancelled_email_body', "alter table {$table_name} add event_registration_cancelled_email_body text NULL;");
        maybe_add_column($table_name, 'event_registration_denied_email_body', "alter table {$table_name} add event_registration_denied_email_body text NULL;");
        maybe_add_column($table_name, 'event_registration_recorded_ok_html', "alter table {$table_name} add event_registration_recorded_ok_html text NULL;");
        maybe_add_column($table_name, 'registration_requires_approval', "alter table {$table_name} add registration_requires_approval bool DEFAULT 0;");
        $registration_wp_users_only = get_option('eme_rsvp_registered_users_only');
        maybe_add_column($table_name, 'registration_wp_users_only', "alter table {$table_name} add registration_wp_users_only bool DEFAULT {$registration_wp_users_only};");
        maybe_add_column($table_name, 'event_author', "alter table {$table_name} add event_author mediumint(9) DEFAULT 0;");
        maybe_add_column($table_name, 'creation_date', "alter table {$table_name} add creation_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00';");
        maybe_add_column($table_name, 'creation_date_gmt', "alter table {$table_name} add creation_date_gmt datetime NOT NULL DEFAULT '0000-00-00 00:00:00';");
        maybe_add_column($table_name, 'modif_date', "alter table {$table_name} add modif_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00';");
        maybe_add_column($table_name, 'modif_date_gmt', "alter table {$table_name} add modif_date_gmt datetime NOT NULL DEFAULT '0000-00-00 00:00:00';");
        maybe_add_column($table_name, 'event_registration_form_format', "alter table {$table_name} add event_registration_form_format text NULL;");
        maybe_add_column($table_name, 'event_cancel_form_format', "alter table {$table_name} add event_cancel_form_format text NULL;");
        maybe_add_column($table_name, 'event_image_url', "alter table {$table_name} add event_image_url text NULL;");
        maybe_add_column($table_name, 'event_image_id', "alter table {$table_name} add event_image_id mediumint(9) DEFAULT 0 NOT NULL;");
        maybe_add_column($table_name, 'event_external_ref', "alter table {$table_name} add event_external_ref text NULL;");
        if ($db_version < 3) {
            $wpdb->query("ALTER TABLE {$table_name} MODIFY event_name text;");
            $wpdb->query("ALTER TABLE {$table_name} MODIFY event_notes longtext;");
        }
        if ($db_version < 4) {
            $wpdb->query("ALTER TABLE {$table_name} CHANGE event_category_id event_category_ids text default NULL;");
            $wpdb->query("ALTER TABLE {$table_name} MODIFY event_author mediumint(9) DEFAULT 0;");
            $wpdb->query("ALTER TABLE {$table_name} MODIFY event_contactperson_id mediumint(9) DEFAULT 0;");
            $wpdb->query("ALTER TABLE {$table_name} MODIFY event_seats mediumint(9) DEFAULT 0;");
            $wpdb->query("ALTER TABLE {$table_name} MODIFY location_id mediumint(9) DEFAULT 0;");
            $wpdb->query("ALTER TABLE {$table_name} MODIFY recurrence_id mediumint(9) DEFAULT 0;");
            $wpdb->query("ALTER TABLE {$table_name} MODIFY event_rsvp bool DEFAULT 0;");
        }
        if ($db_version < 5) {
            $wpdb->query("ALTER TABLE {$table_name} MODIFY event_rsvp bool DEFAULT 0;");
        }
        if ($db_version < 11) {
            $wpdb->query("ALTER TABLE {$table_name} DROP COLUMN event_author;");
            $wpdb->query("ALTER TABLE {$table_name} CHANGE event_creator_id event_author mediumint(9) DEFAULT 0;");
        }
        if ($db_version < 29) {
            $wpdb->query("ALTER TABLE {$table_name} MODIFY price text default NULL;");
        }
        if ($db_version < 33) {
            $post_table_name = $wpdb->prefix . "posts";
            $wpdb->query("UPDATE {$table_name} SET event_image_id = (select ID from {$post_table_name} where post_type = 'attachment' AND guid = {$table_name}.event_image_url);");
        }
        if ($db_version < 38) {
            $wpdb->query("ALTER TABLE {$table_name} MODIFY event_seats text default NULL;");
        }
        if ($db_version < 68) {
            $wpdb->query("ALTER TABLE {$table_name} MODIFY rsvp_number_days tinyint DEFAULT 0;");
            $wpdb->query("ALTER TABLE {$table_name} MODIFY rsvp_number_hours tinyint DEFAULT 0;");
        }
        if ($db_version < 70) {
            $wpdb->query("ALTER TABLE {$table_name} DROP COLUMN use_google;");
        }
    }
}