Last active
August 29, 2015 14:14
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>"; | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Props to deggertsen here: https://www.drupal.org/node/2098779