Skip to content

Instantly share code, notes, and snippets.

@drogers98
Last active August 29, 2015 14:14
Show Gist options
  • Save drogers98/7d0eebabaf90a84c3d95 to your computer and use it in GitHub Desktop.
Save drogers98/7d0eebabaf90a84c3d95 to your computer and use it in GitHub Desktop.
Drupal entity registration, see if user is already registered in order to hide/display stuff. use in the node.tpl.php. Modify line 6 to reference the particular product reference you are using.
<?php
// Hide/display stuff for users who are already registered
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'registration')
->propertyCondition('entity_id', $node->field_product_ref['und'][0]['product_id']);
$result = $query->execute();
//print_r($result['registration'][10]);
$ids = array_keys($result['registration']);
$registrations = entity_load('registration', $ids);
global $user;
$currentUser = $user->uid;
foreach ($registrations as $registration) {
$registeredUser = $registration->user_uid;
if($currentUser == $registeredUser){
$registered = 'yes';
}
}
if ($registered == 'yes'){
echo "<div class='alert alert-success' role='alert'>You are already registered for this course</div>";
} else {
echo "<div class='alert alert-success' role='alert'>You are not yet registered</div>";
}
?>
<?php
// Older version. May still work for your application. Hide/display stuff for users who are already registered
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'registration')
->propertyCondition('entity_id', $node->field_product_ref['und'][0]['product_id']);
$result = $query->execute();
$ids = array_keys($result['registration']);
$registrations = entity_load('registration', $ids);
global $user;
foreach ($registrations as $registration) {
$registered = registration_is_registered($registration, NULL, $user->uid);
}
if (!empty($registered)):
echo "<p>You are already registered for this event.</p>";
endif;
?>
@drogers98
Copy link
Author

Props to deggertsen here: https://www.drupal.org/node/2098779

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment