Commit 32d2c3bc authored by Eric Bremner's avatar Eric Bremner
Browse files

FDSU-596: Added all sites to taxonomy listing.

parent c8264dec
......@@ -252,6 +252,37 @@ function uw_ct_event_field_default_field_bases() {
'type' => 'link_field',
);
// Exported field_base: 'field_site'
$field_bases['field_site'] = array(
'active' => 1,
'cardinality' => -1,
'deleted' => 0,
'entity_types' => array(),
'field_name' => 'field_site',
'field_permissions' => array(
'type' => 0,
),
'indexes' => array(
'tid' => array(
0 => 'tid',
),
),
'locked' => 0,
'module' => 'taxonomy',
'settings' => array(
'allowed_values' => array(
0 => array(
'vocabulary' => 'site',
'parent' => 0,
),
),
'entity_translation_sync' => FALSE,
'options_list_callback' => 'title_taxonomy_allowed_values',
),
'translatable' => 0,
'type' => 'taxonomy_term_reference',
);
// Exported field_base: 'field_uw_event_tag'
$field_bases['field_uw_event_tag'] = array(
'active' => 1,
......
......@@ -1089,6 +1089,67 @@ https://uwaterloo.ca/<event details web page>).',
),
);
// Exported field_instance: 'node-uw_event-field_site'
$field_instances['node-uw_event-field_site'] = array(
'bundle' => 'uw_event',
'default_value' => NULL,
'deleted' => 0,
'description' => '',
'display' => array(
'default' => array(
'label' => 'above',
'module' => 'taxonomy',
'settings' => array(),
'type' => 'taxonomy_term_reference_link',
'weight' => 12,
),
'entity_teaser' => array(
'label' => 'above',
'settings' => array(),
'type' => 'hidden',
'weight' => 0,
),
'ical' => array(
'label' => 'above',
'settings' => array(),
'type' => 'hidden',
'weight' => 0,
),
'teaser' => array(
'label' => 'above',
'settings' => array(),
'type' => 'hidden',
'weight' => 0,
),
),
'entity_type' => 'node',
'field_name' => 'field_site',
'label' => 'Site',
'required' => 0,
'settings' => array(
'entity_translation_sync' => FALSE,
'user_register_form' => FALSE,
),
'widget' => array(
'active' => 1,
'module' => 'term_reference_tree',
'settings' => array(
'cascading_selection' => 0,
'filter_view' => '',
'label_help_description' => '',
'leaves_only' => 1,
'max_depth' => '',
'parent_term_id' => '',
'select_parents' => 0,
'start_minimized' => 1,
'token_display' => '',
'track_list' => 0,
),
'type' => 'term_reference_tree',
'weight' => 13,
),
);
// Exported field_instance: 'node-uw_event-field_uw_event_tag'
$field_instances['node-uw_event-field_uw_event_tag'] = array(
'bundle' => 'uw_event',
......@@ -1140,7 +1201,7 @@ https://uwaterloo.ca/<event details web page>).',
'size' => 60,
),
'type' => 'taxonomy_autocomplete',
'weight' => 13,
'weight' => 14,
),
);
......@@ -1269,6 +1330,7 @@ https://uwaterloo.ca/<event details web page>).',
t('Optional: provide the name of the event website and a link to a website with more information specific to this event (e.g.
https://uwaterloo.ca/<event details web page>).');
t('Optional: provide the name of the host and a link to the host\'s website (e.g. https://uwaterloo.ca/<host website>).');
t('Site');
t('The listing page image is used on the event listing pages. You can re-use this image by inserting it into the event description.');
t('Title');
t('Type');
......
......@@ -9,6 +9,29 @@
*/
function uw_ct_event_taxonomy_default_vocabularies() {
return array(
'site' => array(
'name' => 'Site',
'machine_name' => 'site',
'description' => 'List of all active WCMS sites',
'hierarchy' => 0,
'module' => 'taxonomy',
'weight' => 0,
'rdf_mapping' => array(
'rdftype' => array(
0 => 'skos:ConceptScheme',
),
'name' => array(
'predicates' => array(
0 => 'dc:title',
),
),
'description' => array(
'predicates' => array(
0 => 'rdfs:comment',
),
),
),
),
'uw_event_tags' => array(
'name' => 'Event Tags',
'machine_name' => 'uw_event_tags',
......
......@@ -141,6 +141,7 @@ function uw_ct_event_field_group_info() {
0 => 'field_audience',
1 => 'field_uw_event_tag',
2 => 'field_uw_event_type',
3 => 'field_site',
),
'format_type' => 'fieldset',
'format_settings' => array(
......
......@@ -65,6 +65,7 @@ features[field_base][] = field_event_host_link
features[field_base][] = field_event_location
features[field_base][] = field_event_map_link
features[field_base][] = field_event_moreinfo_link
features[field_base][] = field_site
features[field_base][] = field_uw_event_tag
features[field_base][] = field_uw_event_type
features[field_group][] = group_links|node|uw_event|form
......@@ -83,12 +84,14 @@ features[field_instance][] = node-uw_event-field_event_map_link
features[field_instance][] = node-uw_event-field_event_moreinfo_link
features[field_instance][] = node-uw_event-field_file
features[field_instance][] = node-uw_event-field_image
features[field_instance][] = node-uw_event-field_site
features[field_instance][] = node-uw_event-field_uw_event_tag
features[field_instance][] = node-uw_event-field_uw_event_type
features[field_instance][] = node-uw_event-title_field
features[menu_links][] = menu-site-manager-vocabularies_events-tags:admin/structure/taxonomy/uw_event_tags
features[node][] = uw_event
features[services_endpoint][] = uwaterloo_events_v1
features[taxonomy][] = site
features[taxonomy][] = uw_event_tags
features[taxonomy][] = uw_event_type
features[user_permission][] = create uw_event content
......
......@@ -81,6 +81,185 @@ function uw_ct_event_install() {
// Do one variable_set for every content type using workbench moderation
variable_set('node_options_uw_event', array(0 => 'moderation', 1 => 'revision'));
// Array to store the breakup of all wmcs site by first letter.
$sub_sites[0]['name'] = 'A - C';
$sub_sites[0]['description'] = 'WCMS site names that start with letters A through C.';
$sub_sites[0]['weight'] = 0;
$sub_sites[0]['letters'][0] = 'A';
$sub_sites[0]['letters'][1] = 'B';
$sub_sites[0]['letters'][2] = 'C';
$sub_sites[0]['letters'][3] = 'a';
$sub_sites[0]['letters'][4] = 'b';
$sub_sites[0]['letters'][5] = 'c';
$sub_sites[1]['name'] = 'D - F';
$sub_sites[1]['description'] = 'WCMS site names that start with letters D through F.';
$sub_sites[1]['weight'] = 1;
$sub_sites[1]['letters'][0] = 'D';
$sub_sites[1]['letters'][1] = 'E';
$sub_sites[1]['letters'][2] = 'F';
$sub_sites[1]['letters'][3] = 'd';
$sub_sites[1]['letters'][4] = 'e';
$sub_sites[1]['letters'][5] = 'f';
$sub_sites[2]['name'] = 'G - I';
$sub_sites[2]['description'] = 'WCMS site names that start with letters G through I.';
$sub_sites[2]['weight'] = 2;
$sub_sites[2]['letters'][0] = 'G';
$sub_sites[2]['letters'][1] = 'H';
$sub_sites[2]['letters'][2] = 'I';
$sub_sites[2]['letters'][3] = 'g';
$sub_sites[2]['letters'][4] = 'h';
$sub_sites[2]['letters'][5] = 'i';
$sub_sites[3]['name'] = 'J - L';
$sub_sites[3]['description'] = 'WCMS site names that start with letters J through L.';
$sub_sites[3]['weight'] = 3;
$sub_sites[3]['letters'][0] = 'J';
$sub_sites[3]['letters'][1] = 'K';
$sub_sites[3]['letters'][2] = 'L';
$sub_sites[3]['letters'][3] = 'j';
$sub_sites[3]['letters'][4] = 'k';
$sub_sites[3]['letters'][5] = 'l';
$sub_sites[4]['name'] = 'M - O';
$sub_sites[4]['description'] = 'WCMS site names that start with letters M through O.';
$sub_sites[4]['weight'] = 4;
$sub_sites[4]['letters'][0] = 'M';
$sub_sites[4]['letters'][1] = 'N';
$sub_sites[4]['letters'][2] = 'O';
$sub_sites[4]['letters'][3] = 'm';
$sub_sites[4]['letters'][4] = 'n';
$sub_sites[4]['letters'][5] = 'o';
$sub_sites[5]['name'] = 'P - R';
$sub_sites[5]['description'] = 'WCMS site names that start with letters P through R.';
$sub_sites[5]['weight'] = 5;
$sub_sites[5]['letters'][0] = 'P';
$sub_sites[5]['letters'][1] = 'Q';
$sub_sites[5]['letters'][2] = 'R';
$sub_sites[5]['letters'][3] = 'p';
$sub_sites[5]['letters'][4] = 'q';
$sub_sites[5]['letters'][5] = 'r';
$sub_sites[6]['name'] = 'S - U';
$sub_sites[6]['description'] = 'WCMS site names that start with letters S through U.';
$sub_sites[6]['weight'] = 6;
$sub_sites[6]['letters'][0] = 'S';
$sub_sites[6]['letters'][1] = 'T';
$sub_sites[6]['letters'][2] = 'U';
$sub_sites[6]['letters'][3] = 's';
$sub_sites[6]['letters'][4] = 't';
$sub_sites[6]['letters'][5] = 'u';
$sub_sites[7]['name'] = 'V - Z';
$sub_sites[7]['description'] = 'WCMS site names that start with letters V through Z.';
$sub_sites[7]['weight'] = 7;
$sub_sites[7]['letters'][0] = 'V';
$sub_sites[7]['letters'][1] = 'W';
$sub_sites[7]['letters'][2] = 'X';
$sub_sites[7]['letters'][3] = 'Y';
$sub_sites[7]['letters'][4] = 'Z';
$sub_sites[7]['letters'][5] = 'v';
$sub_sites[7]['letters'][6] = 'w';
$sub_sites[7]['letters'][7] = 'x';
$sub_sites[7]['letters'][8] = 'y';
$sub_sites[7]['letters'][9] = 'z';
$sub_sites[8]['name'] = 'Other';
$sub_sites[8]['description'] = 'WCMS site names that start with no letters';
$sub_sites[8]['weight'] = 8;
// Get the vocabulary id (vid) of the Sites taxonomy.
$vid = db_select('taxonomy_vocabulary', 'tv')
->fields('tv', array('vid'))
->condition('tv.machine_name', 'site')
->execute()
->fetchAssoc();
$vid_id = $vid['vid'];
// Get the term id (tid) of the site breakups, if not present insert.
$count = 0;
foreach($sub_sites as $ss) {
$tid = db_select('taxonomy_term_data', 'ttd')
->fields('ttd', array('tid'))
->condition('ttd.name', $ss['name'])
->execute()
->fetchAssoc();
if(!isset($tid['tid'])) {
$term = new stdClass();
$term->name = $ss['name'];
$term->description = $ss['description'];
$term->vid = $vid_id;
taxonomy_term_save($term);
$tid = db_select('taxonomy_term_data', 'ttd')
->fields('ttd', array('tid'))
->condition('ttd.name', $ss['name'])
->execute()
->fetchAssoc();
}
$sub_sites[$count]['tid'] = $tid['tid'];
$count++;
}
// Grab all the sites form the table of sites.
$data = file_get_contents('https://uwaterloo.ca/tos.html');
$regex = '/<li[^>]*>(.*?)<\/li>/';
preg_match_all($regex,$data,$rows);
// Step through each of from the table of sites. Add breakup (parent).
$count = 0;
foreach($rows[0] as $row) {
$regex = '/<a[^>]*>(.*?)<\/a>/';
preg_match_all($regex, $row, $cols);
if(isset($cols[1][0])) {
$sites[$count]['site_name'] = $cols[1][0];
$letter_found = FALSE;
foreach($sub_sites as $sub) {
if($sub['name'] !== 'Other') {
foreach($sub['letters'] as $letter) {
if($sites[$count]['site_name'][0] == $letter) {
$letter_found = TRUE;
$sites[$count]['parent'] = $sub['tid'];
break;
}
}
}
}
if($letter_found == FALSE) {
$sites[$count]['parent'] = $sub_sites[8]['tid'];
}
$count++;
}
}
// Step through each site and check if in database, if not present then insert.
foreach($sites as $site) {
$tid = db_select('taxonomy_term_data', 'ttd')
->fields('ttd', array('tid'))
->condition('ttd.name', $site['site_name'])
->condition('ttd.vid', $vid_id)
->execute()
->fetchAssoc();
if(!isset($tid['tid'])) {
$term = new stdClass();
$term->name = $site['site_name'];
$term->vid = $vid_id;
$term->parent = $site['parent'];
taxonomy_term_save($term);
}
}
}
/**
......@@ -165,6 +344,186 @@ function uw_ct_event_update_7102() {
}
}
function uw_ct_event_update_7103() {
// Array to store the breakup of all wmcs site by first letter.
$sub_sites[0]['name'] = 'A - C';
$sub_sites[0]['description'] = 'WCMS site names that start with letters A through C.';
$sub_sites[0]['weight'] = 0;
$sub_sites[0]['letters'][0] = 'A';
$sub_sites[0]['letters'][1] = 'B';
$sub_sites[0]['letters'][2] = 'C';
$sub_sites[0]['letters'][3] = 'a';
$sub_sites[0]['letters'][4] = 'b';
$sub_sites[0]['letters'][5] = 'c';
$sub_sites[1]['name'] = 'D - F';
$sub_sites[1]['description'] = 'WCMS site names that start with letters D through F.';
$sub_sites[1]['weight'] = 1;
$sub_sites[1]['letters'][0] = 'D';
$sub_sites[1]['letters'][1] = 'E';
$sub_sites[1]['letters'][2] = 'F';
$sub_sites[1]['letters'][3] = 'd';
$sub_sites[1]['letters'][4] = 'e';
$sub_sites[1]['letters'][5] = 'f';
$sub_sites[2]['name'] = 'G - I';
$sub_sites[2]['description'] = 'WCMS site names that start with letters G through I.';
$sub_sites[2]['weight'] = 2;
$sub_sites[2]['letters'][0] = 'G';
$sub_sites[2]['letters'][1] = 'H';
$sub_sites[2]['letters'][2] = 'I';
$sub_sites[2]['letters'][3] = 'g';
$sub_sites[2]['letters'][4] = 'h';
$sub_sites[2]['letters'][5] = 'i';
$sub_sites[3]['name'] = 'J - L';
$sub_sites[3]['description'] = 'WCMS site names that start with letters J through L.';
$sub_sites[3]['weight'] = 3;
$sub_sites[3]['letters'][0] = 'J';
$sub_sites[3]['letters'][1] = 'K';
$sub_sites[3]['letters'][2] = 'L';
$sub_sites[3]['letters'][3] = 'j';
$sub_sites[3]['letters'][4] = 'k';
$sub_sites[3]['letters'][5] = 'l';
$sub_sites[4]['name'] = 'M - O';
$sub_sites[4]['description'] = 'WCMS site names that start with letters M through O.';
$sub_sites[4]['weight'] = 4;
$sub_sites[4]['letters'][0] = 'M';
$sub_sites[4]['letters'][1] = 'N';
$sub_sites[4]['letters'][2] = 'O';
$sub_sites[4]['letters'][3] = 'm';
$sub_sites[4]['letters'][4] = 'n';
$sub_sites[4]['letters'][5] = 'o';
$sub_sites[5]['name'] = 'P - R';
$sub_sites[5]['description'] = 'WCMS site names that start with letters P through R.';
$sub_sites[5]['weight'] = 5;
$sub_sites[5]['letters'][0] = 'P';
$sub_sites[5]['letters'][1] = 'Q';
$sub_sites[5]['letters'][2] = 'R';
$sub_sites[5]['letters'][3] = 'p';
$sub_sites[5]['letters'][4] = 'q';
$sub_sites[5]['letters'][5] = 'r';
$sub_sites[6]['name'] = 'S - U';
$sub_sites[6]['description'] = 'WCMS site names that start with letters S through U.';
$sub_sites[6]['weight'] = 6;
$sub_sites[6]['letters'][0] = 'S';
$sub_sites[6]['letters'][1] = 'T';
$sub_sites[6]['letters'][2] = 'U';
$sub_sites[6]['letters'][3] = 's';
$sub_sites[6]['letters'][4] = 't';
$sub_sites[6]['letters'][5] = 'u';
$sub_sites[7]['name'] = 'V - Z';
$sub_sites[7]['description'] = 'WCMS site names that start with letters V through Z.';
$sub_sites[7]['weight'] = 7;
$sub_sites[7]['letters'][0] = 'V';
$sub_sites[7]['letters'][1] = 'W';
$sub_sites[7]['letters'][2] = 'X';
$sub_sites[7]['letters'][3] = 'Y';
$sub_sites[7]['letters'][4] = 'Z';
$sub_sites[7]['letters'][5] = 'v';
$sub_sites[7]['letters'][6] = 'w';
$sub_sites[7]['letters'][7] = 'x';
$sub_sites[7]['letters'][8] = 'y';
$sub_sites[7]['letters'][9] = 'z';
$sub_sites[8]['name'] = 'Other';
$sub_sites[8]['description'] = 'WCMS site names that start with no letters';
$sub_sites[8]['weight'] = 8;
// Get the vocabulary id (vid) of the Sites taxonomy.
$vid = db_select('taxonomy_vocabulary', 'tv')
->fields('tv', array('vid'))
->condition('tv.machine_name', 'site')
->execute()
->fetchAssoc();
$vid_id = $vid['vid'];
// Get the term id (tid) of the site breakups, if not present insert.
$count = 0;
foreach($sub_sites as $ss) {
$tid = db_select('taxonomy_term_data', 'ttd')
->fields('ttd', array('tid'))
->condition('ttd.name', $ss['name'])
->execute()
->fetchAssoc();
if(!isset($tid['tid'])) {
$term = new stdClass();
$term->name = $ss['name'];
$term->description = $ss['description'];
$term->vid = $vid_id;
taxonomy_term_save($term);
$tid = db_select('taxonomy_term_data', 'ttd')
->fields('ttd', array('tid'))
->condition('ttd.name', $ss['name'])
->execute()
->fetchAssoc();
}
$sub_sites[$count]['tid'] = $tid['tid'];
$count++;
}
// Grab all the sites form the table of sites.
$data = file_get_contents('https://uwaterloo.ca/tos.html');
$regex = '/<li[^>]*>(.*?)<\/li>/';
preg_match_all($regex,$data,$rows);
// Step through each of from the table of sites. Add breakup (parent).
$count = 0;
foreach($rows[0] as $row) {
$regex = '/<a[^>]*>(.*?)<\/a>/';
preg_match_all($regex, $row, $cols);
if(isset($cols[1][0])) {
$sites[$count]['site_name'] = $cols[1][0];
$letter_found = FALSE;
foreach($sub_sites as $sub) {
if($sub['name'] !== 'Other') {
foreach($sub['letters'] as $letter) {
if($sites[$count]['site_name'][0] == $letter) {
$letter_found = TRUE;
$sites[$count]['parent'] = $sub['tid'];
break;
}
}
}
}
if($letter_found == FALSE) {
$sites[$count]['parent'] = $sub_sites[8]['tid'];
}
$count++;
}
}
// Step through each site and check if in database, if not present then insert.
foreach($sites as $site) {
$tid = db_select('taxonomy_term_data', 'ttd')
->fields('ttd', array('tid'))
->condition('ttd.name', $site['site_name'])
->condition('ttd.vid', $vid_id)
->execute()
->fetchAssoc();
if(!isset($tid['tid'])) {
$term = new stdClass();
$term->name = $site['site_name'];
$term->vid = $vid_id;
$term->parent = $site['parent'];
taxonomy_term_save($term);
}
}
}
/**
* Implements hook_uninstall().
*/
......
......@@ -6,6 +6,175 @@
include_once('uw_ct_event.features.inc');
/**
* Implements hook_cron().
*/
function uw_ct_event_cron() {
// Run this job at 0200 everyday
if( date('Gi') >= 0200 && date('Gi') <= 0215){
$sub_sites[0]['name'] = 'A - C';
$sub_sites[0]['description'] = 'WCMS site names that start with letters A through C.';
$sub_sites[0]['weight'] = 0;
$sub_sites[0]['letters'][0] = 'A';
$sub_sites[0]['letters'][1] = 'B';
$sub_sites[0]['letters'][2] = 'C';
$sub_sites[0]['letters'][3] = 'a';
$sub_sites[0]['letters'][4] = 'b';
$sub_sites[0]['letters'][5] = 'c';
$sub_sites[1]['name'] = 'D - F';
$sub_sites[1]['description'] = 'WCMS site names that start with letters D through F.';
$sub_sites[1]['weight'] = 1;
$sub_sites[1]['letters'][0] = 'D';
$sub_sites[1]['letters'][1] = 'E';
$sub_sites[1]['letters'][2] = 'F';
$sub_sites[1]['letters'][3] = 'd';
$sub_sites[1]['letters'][4] = 'e';
$sub_sites[1]['letters'][5] = 'f';
$sub_sites[2]['name'] = 'G - I';
$sub_sites[2]['description'] = 'WCMS site names that start with letters G through I.';
$sub_sites[2]['weight'] = 2;
$sub_sites[2]['letters'][0] = 'G';
$sub_sites[2]['letters'][1] = 'H';
$sub_sites[2]['letters'][2] = 'I';
$sub_sites[2]['letters'][3] = 'g';
$sub_sites[2]['letters'][4] = 'h';
$sub_sites[2]['letters'][5] = 'i';
$sub_sites[3]['name'] = 'J - L';
$sub_sites[3]['description'] = 'WCMS site names that start with letters J through L.';
$sub_sites[3]['weight'] = 3;
$sub_sites[3]['letters'][0] = 'J';