I am trying to setup my node template page so that when somebody who has already registered visits the registration page again they will get different information. Something similar to what is discussed in this issue, but not using views(#1685058: You Are Already Registered - Need Default Message to User).

This is what I have so far. It is pulling all the registration entities for the currently accessed registration page (note that I am using commerce_registration):

<?php $query = new EntityFieldQuery();
    $query
      ->entityCondition('entity_type', 'registration')
      ->propertyCondition('entity_id', $node->field_registration_product_refer['und'][0]['product_id']);

    $result = $query->execute();
  
    $ids = array_keys($result['registration']);
	$registrations = entity_load('registration', $ids);
	?>

Now that I have all the registration entities loaded for this particular registration page, I need something that will allow me to determine from the list of existing registrations if the current user is registered. I'm sure this is a simple task to someone who is a php pro, but I'm still just learning.

I thought I would use something like the registration_is_registered() function to determine if someone is registered, but it keeps telling me "Argument 1 passed to registration_is_registered() must be an instance of Registration". I assume that because my $registrations is an array of registrations this isn't working? Maybe I need to run a foreach? Is there a better way to do this?

Thanks for any help here.

Comments

deggertsen’s picture

Status: Active » Fixed

I did it! Here's the full code that will output "You are already registered for this event." if the current user is indeed already registered.

<?php 
$query = new EntityFieldQuery();
    $query
      ->entityCondition('entity_type', 'registration')
      ->propertyCondition('entity_id', $node->field_registration_product_refer['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)): ?><p>You are already registered for this event.</p>
<?php endif;
?>

Note that you would have to change the $node->field_registration_product_refer['und'][0]['product_id'] to whatever the value of the entity id is for the registration page in question.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.