You are here

function node_registration_metadata_entity_get_properties in Node registration 7

Callback for getting properties of an entity.

1 string reference to 'node_registration_metadata_entity_get_properties'
node_registration_entity_property_info_alter in includes/node_registration.entity.inc
Implements hook_entity_property_info_alter().

File

includes/node_registration.entity.inc, line 559
Entity hooks and callbacks for registrations.

Code

function node_registration_metadata_entity_get_properties($entity, array $options, $name, $entity_type) {
  switch ($entity_type) {

    // REGISTRATION properties.
    case 'node_registration':
      switch ($name) {

        // User name.
        case 'user_name':
          $account = $entity->uid ? user_load($entity->uid) : NULL;
          return $account && $account->uid ? $account->name : '';

        // User mail.
        case 'user_mail':
          $account = $entity->uid ? user_load($entity->uid) : NULL;
          return $account && $account->uid ? $account->mail : '';

        // View URL.
        case 'url':
          $return = entity_uri($entity_type, $entity);
          return url($return['path'], $return['options'] + $options);

        // Edit URL.
        case 'edit_url':
          $return = entity_uri($entity_type, $entity);
          $return['path'] .= '/edit';
          if (!$entity->uid) {
            $return['options']['query'] = array(
              'secret' => $entity->secret,
            );
          }
          return url($return['path'], $return['options'] + $options);

        // Cancel URL.
        case 'cancel_url':
          $return = entity_uri($entity_type, $entity);
          $return['path'] .= '/cancel';
          if (!$entity->uid) {
            $return['options']['query'] = array(
              'secret' => $entity->secret,
            );
          }
          return url($return['path'], $return['options'] + $options);
      }
      break;
    case 'node':
      switch ($name) {

        // Event start.
        case 'event_start':
          $utc = $entity->registration
            ->site_utc();
          return $utc;

        // Time left.
        case 'time_left':
          $utc = $entity->registration
            ->site_utc();
          if ($utc) {
            $time_left = $utc - REQUEST_TIME;
            $time_left = format_interval($time_left);
            return $time_left;
          }

        // Capacity.
        case 'capacity':
          $capacity = $entity->registration
            ->capacity();
          return $capacity;

        // Slots taken.
        case 'slots_taken':
          return node_registration_event_count($entity);

        // Slots left.
        case 'slots_left':
          $capacity = $entity->registration
            ->capacity();
          return max(0, $capacity - node_registration_event_count($entity));
      }
      break;
  }
}