user24793
user24793

Reputation: 344

how to initialize a variables from another function in php

I am building a custom Rule for Drupal to send an email when the capacity hits it limit. Yes I did ask this in Drupal Stackexchange however they say it is a php issue. And since I am stuck having to figure this out, not being a developer, I need to ask for help. Hopefully, I will explain it correctly.

My problem is I am not sure how to pull the value, of the total capacity of an event, into my variable $registration from the event.

I will attach my rule to show you that code. I have the variable initialize, however, I know I need to somehow pull that value into the variable in my rule or into the script/file I have for the rule. Once I get the value into there I should be able to determine True or False.

function registration_capacity_rules_condition_info() {
  $conditions = array(
  'registration_capacity_event_is_at_capacity' => array(
       'label' => t('Event has reached maximum registrations'),
       'group' => t('MY MODULE'),
       'parameters' => array(
         'registration' => array(
            'type' => 'registration',
            'label' => t('The registration event capacity'),
           ),         
         ),
       ),
     );

  return $conditions;
}

function registration_capacity_event_is_at_capacity($registration) {
  if ($registration == registration_event_count()) {    
      return TRUE;
  }
}

I really think I need to connect to the event so it knows how to pull that value. However, I not entirely sure what to look up to get this. I have read about setting variables but nothing I find helps me pull it from another location outside the script/file I am building.

Hopefully I was clear enough for some helpful direction. Thank you!

EDIT********** Adding registration_event_count() function

function registration_event_count($entity_type, $entity_id, $registration_id = NULL, $reset = FALSE) {
  $count = &drupal_static(__FUNCTION__ . '_' . $entity_type . '_' . $entity_id . '_' . $registration_id, FALSE);
  if (!$count || $reset) {
    $query = db_select('registration', 'r');
    $query->addExpression('sum(count)', 'count');
    $query->condition('entity_id', $entity_id);
    $query->condition('entity_type', $entity_type);
    if ($registration_id != NULL) {
      $query->condition('registration_id', $registration_id, '<>');
    }
    $query->condition('state', registration_get_active_states(), 'IN');
    $result = $query->execute();
    $count = $result->fetchField();
    $count = ($count == '') ? 0 : $count;
  }

  // Allow other mods to override count.
  $settings = registration_entity_settings($entity_type, $entity_id);
  $context = array(
    'entity_type' => $entity_type,
    'entity_id' => $entity_id,
    'registration_id' => $registration_id,
    'settings' => $settings,
  );

  drupal_alter('registration_event_count', $count, $context);

  return $count;
}

IF anyone ever looks at this I am able to get the value to return as '1' or true. I now just need to get the if statement to trigger the rules action. I will post once I figure it out.

Upvotes: 1

Views: 156

Answers (0)

Related Questions