It seems pretty easy from this vantage to write an calendar module expressly for users. That is, any event a user adds to the calendar is only viewable to the user who wrote the event. I don't see one, so I'm wondering if it's more difficult than I believe. Does anybody have an opinion about this?

Comments

nevets’s picture

Take the code below, place in a file called private_event.module in a directory under modules called private_event.
Make sure under administer -> settings -> content you configure the 'private event' type so it shows in the calendar.
You will also need to grant the approriate permission for people to be able to create private events. There is also a permission that can be used to granted selected roles the ability to see all private events. Please let me know if this works for you (or if you have problems) as I plan to add this to Drupal in the next few days.

For those interested in how this works, it is a copy of basicevent plus the db_rewrite_sql hook which implements the logic to keep the event s private.

<?php
// $Id: 

/**
 * @file
 * An extremly simple module to implement the event API for private events.
 */

/**
 * Implementation of hook_help().
 */
function private_event_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('A story-like node that implements the event API automatically. Depends on the event module (4.6 or later).');
    case 'node/add#event':
      return t('An event is a story which can be given a start and end date, thus appearing in the events calendar but only for the user that created it.');
  }
}

/**
 * Implementation of hook_node_info().
 */
function private_event_node_info() {
  return array('private event' => array('name' => t('private event'), 'base' => 'private_event'));
}

/**
 * Implementation of hook_perm().
 */
function private_event_perm() {
  return array('create private events', 'edit own private events', 'see all private events');
}

/**
 * Implementation of hook_access().
 */
function private_event_access($op, $node) {
  global $user;
  switch($op) {
    case 'create':
      return user_access('create private events');
      break;
    case 'update':
    case 'delete':
      if (user_access('edit own private events') && ($user->uid == $node->uid)) {
        return TRUE;
      }
      break;
  }
}

/**
 * Implementation of hook_menu().
 */
function private_event_menu($may_cache) {
  $items = array();

  if ($may_cache) {
    $items[] = array('path' => 'node/add/private event', 'title' => t('private event'),
      'access' => user_access('create private events'));
  }

  return $items;
}

/**
 * Implementation of hook_form().
 */
function private_event_form(&$node) {
  // warn them if this isn't set to appear in the calendar
  if (variable_get('private event_nodeapi_event', 'never') == 'never') {
    $link = l(t('event content-type settings page'), 'admin/settings/content-types/private event');
    drupal_set_message(t('The event node is currently set to never appear in the calendar. You will not be able to set the start and end dates until an administrator changes the content-type settings. This is done using the %link.', array('%link' => $link)));
  }

  $form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#default_value' => $node->title, '#size' => 60, '#maxlength' => 128, '#required' => TRUE);
  $form['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#required' => TRUE);

  $form = array_merge($form, filter_form($node->format));

  return $form;
}

function private_event_db_rewrite_sql($query, $primary_table, $primary_field, $args) {
	global $user;
	
	if ( $primary_field == 'nid' ) {
		
		// Super user (uid == 1) and people with 'see all private events' permission can view all reminders
		
		if ( $user->uid != 1 && !user_access('see all private events') ) {
			if ( strpos($query, '{event}') !== FALSE ) {
				$return['where'] = "(( n.type = 'private event' AND n.uid = $user->uid) OR ( n.type <> 'private event'))";
				return $return;
			}
		}
	}
}
vit137’s picture

I've run into a problem. I installed it and, I thought, configured it, but here is what happens.

Click on create content -> private event

I see this message:

The event node is currently set to never appear in the calendar. You will not be able to set the start and end dates until an administrator changes the content-type settings. This is done using the event content-type settings page.

If I hit the link to the content-type settings page (/admin/settings/content-types/private+event) here are my relevant settings:

Default options:
Published
Promoted to front page

Show in event calendar is set to All views.

However, if as a regular user I just add an event to the calendar it shows up as it should (just for that user).

If I am part of a group, it saves the event, but does not display it on the calendar.

So it *almost* works as I have it set. Let me know what info you need about my set-up.

Troy

nevets’s picture

The following will fix the error message

function private_event_form(&$node) {
  // warn them if this isn't set to appear in the calendar
  if (variable_get('event_nodeapi_private event', 'never') == 'never') {
    $link = l(t('private event content-type settings page'), 'admin/settings/content-types/private event');
    drupal_set_message(t('The event node is currently set to never appear in the calendar. You will not be able to set the start and end dates until an administrator changes the content-type settings. This is done using the %link.', array('%link' => $link)));
  }

Just replace the same lines in private_event.module for the function private_event_form (I missed type the variable name to variable_get.

As for working with groups, are you using the og_event module or just the event module?
When you add it for a group is public checked or un-checked.
And did you select zero, one or possible more groups to add it for?

Not sure how well it groups as I have not tried that yet.

vit137’s picture

Thanks for the patch. Seems in good shape.

Yes I'm using og. Here's how I got it to work.

in:

admin/settings/og

Visibility of posts:

Doesn't seem to matter. I currently have it set to:

Visibility chosen by author/editor using a checkbox on the posting form. Checkbox defaults to Private.

Audience required:

Follows the same rule: doesn't matter. I currently have it set to:

optional

Omitted content types:

Does Matter. Omit private event and groups leaves it alone, private
events show up only on your private calendar (unless you're admin, then you
see them all).

Bottom line is, it seems to work great with OG. Thanks for creating this
module and all your help. If you need help with it in the future please
contact me.

Cheers,

Troy

abqaria’s picture

what if i am having a birthday party, it is a private event..but i need only the invited guys through email (rsvp) to see the details

thanks

http://www.i-bloggers.com

hendrakieran’s picture

This is a valid question, have you got the answer? It will be very useful if the invitee can view the event without having to register as a member, maybe by using a one-time fixed password that can be given out in the invitation e-mail.

abqaria’s picture

Thanks alot
it worked, but how do you do the checkbox option ?

i did not get how do u make the vent group specific ?

solipsist’s picture

Shouldn't this be a module feature?

I think an event view should be configurable so that every user "owns" a calendar view. The event view calendar only displays events linked to that view. The user set as the owner of a view can decide who else may see it, based on roles, OGs or at user level.

--
Jakob Persson
Drupal developer, web designer and usability consultant
http://www.jakob-persson.com

--
Jakob Persson - blog
Leancept – Digital effect and innovation agency

Rick Nashleanas’s picture

I've been searching for a way to display only the events for the current user. I played with converting this code, but I'm thinking that basicevent's apparent deprecation might have made this option obsolete. Does anyone know if this is correct?

Rick Nashleanas
www.monarchdigital.com

Rick Nashleanas’s picture

Here's what worked for me: http://drupal.org/node/133341 One of my filters was author is current user.

Rick Nashleanas
www.monarchdigital.com