Skip to content

Instantly share code, notes, and snippets.

@clrockwell
Last active August 29, 2015 13:58
Show Gist options
  • Save clrockwell/45c2f18e1d2670dd9d09 to your computer and use it in GitHub Desktop.
Save clrockwell/45c2f18e1d2670dd9d09 to your computer and use it in GitHub Desktop.
Unfortunately, I don't remember why I didn't make exhibitor events as content types instead of managing them this way. It was originally done for D6 and I've only made the necessary updates for D7
<?php
/**
* Exhibitor Events
*
* Manage exhibitor events such as Celebrity Appearances, Give-A-Ways, etc.
**/
/**
* Implementation of hook_perm()
*/
function exhibitorevents_permission() {
return array(
'add celebrity event' => array(
'title' => t('Add Celebrity Event'),
),
'add giveaway event' => array(
'title' => t('Add Give-A-Way Event'),
),
'add press kit' => array(
'title' => t('Add Press Kit'),
),
);
}
/**
* Implementation of hook_theme
*/
function exhibitorevents_theme() {
return array(
'seminar_table' => array(
'variables' => array('seminars' => NULL),
'path' => drupal_get_path('module', 'exhibitorevents'),
'template' => 'seminar-table',
),
'presskit_table' => array(
'variables' => array('presskits' => NULL),
'path' => drupal_get_path('module', 'exhibitorevents'),
'template' => 'presskit-table',
),
'event_calendar' => array(
'variables' => array(
'calendar' => NULL,
'eventTypes' => NULL,
'eventDays' => NULL,
'importantDates' => NULL,
),
'path' => drupal_get_path('module', 'exhibitorevents'),
'template' => 'event-calendar',
),
'eventcalendar_item_detail' => array(
'variables' => array('event' => NULL),
'path' => drupal_get_path('module', 'exhibitorevents'),
'template' => 'event-calendar-item-detail',
),
);
}
/**
* Implementation of hook_menu()
*/
function exhibitorevents_menu() {
$items['add-celebrity-event'] = array(
'title' => 'Add Celebrity Appearance',
'page callback' => 'drupal_get_form',
'page arguments' => array('celebrity_event_form'),
'file' => 'exhibitorevents.forms.inc',
'access arguments' => array('add celebrity event')
);
$items['add-giveaway-event'] = array(
'title' => 'Add Give-A-Way',
'page callback' => 'drupal_get_form',
'page arguments' => array('giveaway_form'),
'file' => 'exhibitorevents.forms.inc',
'access arguments' => array('add giveaway event'),
);
$items['add-seminar'] = array(
'title' => 'Add Seminar',
'page callback' => 'drupal_get_form',
'page arguments' => array('seminar_form'),
'file' => 'exhibitorevents.forms.inc',
'access arguments' => array('administer nodes'), // right now, only admins
);
$items['add-other-event'] = array(
'title' => 'Add Other Event',
'page callback' => 'drupal_get_form',
'page arguments' => array('otherevent_form'),
'file' => 'exhibitorevents.forms.inc',
'access arguments' => array('administer nodes'), // right now, only admins
);
$items['seminar-schedule'] = array(
'title' => 'Seminar Schedule',
'page callback' => 'seminar_display_schedule',
'file' => 'exhibitorevents.seminar.inc',
'access callback' => TRUE,
);
/**
* I don't know if this should be here.
* If it becomes a full-fledged event listing,
* then it should; however, if it remains simply
* a press kit upload then it needs to be moved
* from this module
*/
$items['upload-press-kit'] = array(
'title' => 'Upload Press Kit',
'page callback' => 'drupal_get_form',
'page arguments' => array('presskit_form'),
'file' => 'exhibitorevents.presskit.inc',
'access arguments' => array('add press kit'),
'type' => MENU_CALLBACK,
);
$items['delete-press-kit/%'] = array(
'title' => 'Upload Press Kit',
'page callback' => 'presskit_delete',
'page arguments' => array(1),
'file' => 'exhibitorevents.presskit.inc',
'access arguments' => array('add press kit'),
'type' => MENU_CALLBACK,
);
/** Calendar **/
$items['event-calendar/%/detail'] = array(
'title' => 'Event Detail',
'title callback' => 'eventcalendar_detail_title',
'title arguments' => array(1),
'file' => 'exhibitorevents.eventcalendar.inc',
'page callback' => 'eventcalendar_item_detail',
'page arguments' => array(1),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['event-calendar'] = array(
'title' => 'MATS Event Schedule',
'title arguments' => array(1),
'file' => 'exhibitorevents.eventcalendar.inc',
'page callback' => 'eventcalendar_main',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['online-press-room'] = array(
'title' => 'Online Press Room',
'file' => 'exhibitorevents.presskit.inc',
'page callback' => 'online_press_room',
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
return $items;
}
function exhibitorevents_get_extras($byId = array()) {
module_load_include('inc', 'exhibitorevents', 'exhibitorevents.presskit');
if (array_key_exists('exhibitor_id', $byId)) {
$return['giveaways'] = exhibitorevents_get_giveaways(NULL, $byId['exhibitor_id']);
$return['celebrity'] = exhibitorevents_get_celeb_appearances(NULL, $byId['exhibitor_id']);
$return['presskit'] = presskit_get_kits($byId['exhibitor_id']);
}
return $return;
}
function exhibitorevents_get_event($eventId) {
$type = db_query("SELECT type FROM exhibitorevents WHERE eeid = :eventId", array(':eventId' => $eventId))->fetchField();
switch ($type) {
case 'Give-A-Way':
return current(exhibitorevents_get_giveaways($eventId));
break;
case 'Celebrity Appearance':
return current(exhibitorevents_get_celeb_appearances($eventId));
break;
}
return FALSE;
}
/**
* @return
* if both parameters are NULL, return all active give-a-ways
*/
function exhibitorevents_get_giveaways($giveaway_id = NULL, $exhibitor_id = NULL, $date = NULL) {
$select = db_select('exhibitorevents', 'ee');
$select->join('exhibitorevents_giveaway', 'eg', 'ee.eeid = eg.eeid');
$select->condition('ee.status', 1, '=');
$select->condition('ee.type', 'Give-A-Way', '=');
$select->fields('ee');
$select->fields('eg');
if (
!(is_null($giveaway_id)) &&
!(is_null($exhibitor_id))
)
{
watchdog('Exhibitor Events', __FUNCTION__ . ' was called with two non-null parameters. This is not allowed');
return FALSE;
}
if (!(is_null($giveaway_id))) {
$select->condition('eg.id', $giveaway_id, '=');
}
if (!(is_null($exhibitor_id))) {
$select->condition('ee.exhibitor_id', $exhibitor_id, '=');
}
$results = $select->execute();
$return = array();
foreach ($results as $result) {
$result->times = exhibitorevents_get_event_times($result->eeid, $date);
if (empty($result->times) && !is_null($date)) {
// a specific date was requested
// and nothing is available
// skip
} else {
$return[] = $result;
}
}
return $return;
}
function exhibitorevents_get_celeb_appearances($appearance_id = NULL, $exhibitor_id = NULL, $date = NULL) {
$select = db_select('exhibitorevents', 'ee');
$select->condition('ee.status', 1, '=');
$select->condition('ee.type', 'Celebrity Appearance', '=');
$select->fields('ee');
if (
!(is_null($appearance_id)) &&
!(is_null($exhibitor_id))
)
{
watchdog('Exhibitor Events', __FUNCTION__ . ' was called with two non-null parameters. This is not allowed');
return FALSE;
}
if (!(is_null($appearance_id))) {
$select->condition('ee.eeid', $appearance_id, '=');
}
if (!(is_null($exhibitor_id))) {
$select->condition('ee.exhibitor_id', $exhibitor_id, '=');
}
$results = $select->execute();
$return = array();
foreach ($results as $result) {
$result->times = exhibitorevents_get_event_times($result->eeid, $date);
if (empty($result->times) && !is_null($date)) {
// a specific date was requested
// and nothing is available
// skip
} else {
$return[] = $result;
}
}
return $return;
}
function exhibitorevents_get_event_times($eeid, $date = NULL) {
$select = db_select('exhibitorevents_times', 'et')
->fields('et', array('date', 'start_time', 'end_time'))
->condition('eeid', $eeid, '=');
if (!is_null($date)) {
$select->condition('date', $date, '=');
}
$results = $select->execute();
$return = array();
foreach ($results as $entry) {
$return[] = $entry;
}
return $return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment