Upcoming Events
in Project codes
This CodeLet displays a user's upcoming events. A visitor, visiting a user's profile would be able to see those events that user has subscribed to. In this CodeLet, for subscription, "Attendance" flag is used. You can alter the code to meet your requirements.
<?php
//$Id$
/**
* @file
*
* Display upcoming events of a user
*
* @author Joshi Consultancy Services <info@joshics.in>
*/
/**
* Implementation of hook_block
*
* @param unknown_type $op
* @param unknown_type $delta
* @param unknown_type $edit
* @author Joshi Consultancy Services <info@joshics.in>
*/
function upcoming_events_block($op = 'list', $delta = 0, $edit = array()) {
unset($block);
switch ($op) {
case 'list':
$block[1] = array(
'info' => t('Upcoming Event block (Upcoming Events module)'),
'status' => 1,
);
return $block;
case 'configure':
switch ($delta) {
case 1:
$form['upcoming_event_count'] = array(
'#type' => 'textfield',
'#title' => t('Events to dispay'),
'#description' => t('Provide the number of upcoming events that should be shown in the block'),
'#default_value' => variable_get('upcoming_event_count', 3),
'#weight' => -5,
);
$form['upcoming_event_path'] = array(
'#type' => 'textfield',
'#title' => t('Path'),
'#description' => t('Provide the path to the full page view where all the events are listed. i.e. myevents'),
'#default_value' => variable_get('upcoming_event_path', ''),
'#weight' => -4,
);
return $form;
}
case 'save':
switch ($delta) {
case 1:
variable_set('upcoming_event_count', $edit['upcoming_event_count']);
variable_set('upcoming_event_path', $edit['upcoming_event_path']);
break;
}
case 'view';
switch($delta) {
case 1:
$ss__username = _get_username(arg(1));
$block = array(
'subject' => t("@user's Upcoming Events", array('@user' => $ss__username)),
'content' => _get_user_events(),
);
break;
}
return $block;
}
}
/**
* _get_username
*
* Return username related to a user id
* @param integer $sn__uid
* @author Joshi Consultancy Services <info@joshics.in>
*/
function _get_username($sn__uid) {
if (is_numeric($sn__uid)) {
$query = "SELECT name FROM {users} WHERE uid = %d";
}
else {
$query = "SELECT uid FROM {users} WHERE name = 's'";
}
return db_result(db_query($query, $sn__uid));
}
/**
* _get_user_events
*
* Return upcoming events of the user
*
* @author Joshi Consultancy Services <info@joshics.in>
*/
function _get_user_events() {
$header = array(t("Event"), t('Starts'), t('Ends'), t('Attendees'));
$output = '';
$raw = array();
$om__result = '';
$r__result = '';
$sn__uid = is_numeric(arg(1)) ? arg(1) : _get_username(arg(1));
$ss__query = "SELECT node.title, node.nid, cte.field_event_time_value, cte.field_event_time_value2, cte.field_attendees_value
FROM {node} node LEFT JOIN {content_type_event} cte ON node.nid = cte.nid LEFT JOIN {flag_content} fc ON cte.nid = fc.content_id
WHERE fc.uid = %d AND fc.fid = 2 AND node.type ='event' AND node.status = 1
AND (DATE_FORMAT(cte.field_event_time_value, '%Y-%m-%d') >= '". format_date(time(), 'custom', "Y-m-d") ."')
ORDER BY field_event_time_value ASC LIMIT 0, ". variable_get('upcoming_event_count', 3);
$r__result = db_query(db_rewrite_sql($ss__query), $sn__uid);
while($om__result = db_fetch_object($r__result)) {
$row[] = array(
l($om__result->title, "node/". $om__result->nid),
format_date(strtotime($om__result->field_event_time_value), 'medium'),
format_date(strtotime($om__result->field_event_time_value2), 'medium'),
$om__result->field_attendees_value
);
}
if (variable_get('upcoming_event_path')) {
$output = "<div style='clear:both;float:right:margin-top:5px;'>". l(t('More'),variable_get('upcoming_event_path')) ."</div>";
}
unset($om__result, $r__result);
return theme('table', $header, $row) . $output;
}
?> (3 votes)
- Login or register to post comments
- 1661 reads
-
Your feedback


Recent comments
- I have contributed a module
20 weeks 6 days ago - Improved Image menu
39 weeks 3 days ago - Great code!
41 weeks 1 day ago - Code Search is ready
50 weeks 4 days ago - I would love to see an
1 year 2 weeks ago - Thank you very much for your
1 year 3 weeks ago - Commented code
1 year 3 weeks ago - We are glad to know that the
1 year 3 weeks ago - Enhancements to codes
1 year 3 weeks ago - We have developed a module
1 year 4 weeks ago



Comments
This is something that can not be achieved using views. I use this CodeLet with minot alteration to meet my requiremnets and it worked like a charm.
Thank you very much for sharing the CodeLet.
Regards.
We are glad to know that the code helped you.
Thank you for using the code.
[url=http://joshics.in]JoshicsIN[/url]