You are here

class Registration in Entity Registration 7

Same name and namespace in other branches
  1. 8.2 lib/registration.entity.inc \Registration
  2. 7.2 lib/registration.entity.inc \Registration

Main class for Registration entities.

Hierarchy

Expanded class hierarchy of Registration

20 string references to 'Registration'
RegistrationAPITestCase::getInfo in tests/registration.test
RegistrationAPITestCase::testHookAccess in tests/registration.test
Test hook_registration_access().
RegistrationAPITestCase::testHookStatus in tests/registration.test
Test hook_registration_status().
RegistrationStandardTestCase::getInfo in tests/registration.test
RegistrationStandardTestCase::testHostEntityBroadcastForm in tests/registration.test
Tests email broadcast functionality.

... See full list

File

lib/registration.entity.inc, line 11
Entity hooks and callbacks for registrations.

View source
class Registration extends Entity {
  public $registration_id, $type, $entity_id, $entity_type, $anon_mail = NULL, $user_uid = NULL, $count, $author_uid, $state, $created, $updated;

  /**
   * Specifies the default label, which is picked up by label() by default.
   */
  protected function defaultLabel() {
    $wrapper = entity_metadata_wrapper('registration', $this);
    $host = $wrapper->entity
      ->value();
    if ($host) {
      return t('Registration for !title', array(
        '!title' => entity_label($this->entity_type, $host),
      ));
    }
    return '';
  }

  /**
   * Build content for Registration.
   *
   * @return array
   *   Render array for a registration entity.
   */
  public function buildContent($view_mode = 'full', $langcode = NULL) {
    $build = parent::buildContent($view_mode, $langcode);
    $wrapper = entity_metadata_wrapper('registration', $this);
    $host_entity_type_info = entity_get_info($this->entity_type);
    $host_entity = $wrapper->entity
      ->value();
    $state = $wrapper->state
      ->value();
    $author = $wrapper->author
      ->value();
    $user = $wrapper->user
      ->value();
    list(, , $host_entity_bundle) = entity_extract_ids($this->entity_type, $host_entity);
    $host_label = entity_label($this->entity_type, $host_entity);
    $host_uri = $host_entity ? entity_uri($this->entity_type, $host_entity) : NULL;
    $build['mail'] = array(
      '#theme' => 'registration_property_field',
      '#label' => t('Email Address'),
      '#items' => array(
        array(
          '#markup' => $wrapper->mail
            ->value(),
        ),
      ),
      '#classes' => 'field field-label-inline clearfix',
    );

    // Link to host entity.
    if (isset($host_uri['path'])) {
      $host_entity_link_label = isset($host_entity_type_info['bundles'][$host_entity_bundle]['label']) ? '<div class="field-label">' . $host_entity_type_info['bundles'][$host_entity_bundle]['label'] . '</div>' : '';
      $build['host_entity_link'] = array(
        '#theme' => 'registration_property_field',
        '#label' => $host_entity_link_label,
        '#items' => array(
          array(
            '#markup' => l($host_label, $host_uri['path']),
          ),
        ),
        '#classes' => 'field field-label-inline clearfix',
      );
    }
    $build['created'] = array(
      '#theme' => 'registration_property_field',
      '#label' => t('Created'),
      '#items' => array(
        array(
          '#markup' => format_date($this->created),
        ),
      ),
      '#classes' => 'field field-label-inline clearfix',
    );
    $build['updated'] = array(
      '#theme' => 'registration_property_field',
      '#label' => t('Updated'),
      '#items' => array(
        array(
          '#markup' => format_date($this->updated),
        ),
      ),
      '#classes' => 'field field-label-inline clearfix',
    );
    $build['spaces'] = array(
      '#theme' => 'registration_property_field',
      '#label' => t('Slots Used'),
      '#items' => array(
        array(
          '#markup' => $this->count,
        ),
      ),
      '#classes' => 'field field-label-inline clearfix',
    );
    if ($author) {
      $build['author'] = array(
        '#theme' => 'registration_property_field',
        '#label' => t('Author'),
        '#items' => array(
          array(
            '#markup' => theme('username', array(
              'account' => $author,
            )),
          ),
        ),
        '#classes' => 'field field-label-inline clearfix',
        '#attributes' => '',
      );
    }
    if ($user) {
      $build['user'] = array(
        '#theme' => 'registration_property_field',
        '#label' => t('User'),
        '#items' => array(
          array(
            '#markup' => theme('username', array(
              'account' => $user,
            )),
          ),
        ),
        '#classes' => 'field field-label-inline clearfix',
        '#attributes' => '',
      );
    }
    $build['state'] = array(
      '#theme' => 'registration_property_field',
      '#label' => t('State'),
      '#items' => array(
        array(
          '#markup' => $state ? filter_xss_admin(entity_label('registration_state', $state)) : '',
        ),
      ),
      '#classes' => 'field field-label-inline clearfix',
    );
    return $build;
  }

  /**
   * Save registration.
   *
   * @see entity_save()
   */
  public function save() {

    // Set a default state if not provided.
    $wrapper = entity_metadata_wrapper('registration', $this);
    $state = $wrapper->state
      ->value();
    if (!$state) {
      $default_state = registration_get_default_state($wrapper
        ->getBundle());
      if ($default_state) {
        $this->state = $default_state
          ->identifier();
      }
    }
    $this->updated = REQUEST_TIME;
    if (!$this->registration_id && empty($this->created)) {
      $this->created = REQUEST_TIME;
    }
    return parent::save();
  }

  /**
   * Specify URI.
   */
  protected function defaultUri() {
    return array(
      'path' => 'registration/' . $this
        ->internalIdentifier(),
    );
  }

  /**
   * Determine registrant type relative to a given account.
   *
   * @object $account
   *   A Drupal user
   *
   * @return string|NULL
   *   Can be me, user, anon or NULL if account is empty and no anon email set.
   */
  public function registrant_type($account) {
    $reg_type = NULL;
    if (!empty($account)) {
      if ($account->uid && $account->uid === $this->user_uid) {
        $reg_type = REGISTRATION_REGISTRANT_TYPE_ME;
      }
      elseif ($this->user_uid) {
        $reg_type = REGISTRATION_REGISTRANT_TYPE_USER;
      }
    }
    if (!empty($this->anon_mail)) {
      $reg_type = REGISTRATION_REGISTRANT_TYPE_ANON;
    }
    return $reg_type;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Entity::$defaultLabel protected property 1
Entity::$entityInfo protected property
Entity::$entityType protected property
Entity::$idKey protected property
Entity::$wrapper protected property
Entity::bundle public function Returns the bundle of the entity. Overrides EntityInterface::bundle
Entity::delete public function Permanently deletes the entity. Overrides EntityInterface::delete
Entity::entityInfo public function Returns the info of the type of the entity. Overrides EntityInterface::entityInfo
Entity::entityType public function Returns the type of the entity. Overrides EntityInterface::entityType
Entity::export public function Exports the entity. Overrides EntityInterface::export
Entity::getTranslation public function Gets the raw, translated value of a property or field. Overrides EntityInterface::getTranslation
Entity::hasStatus public function Checks if the entity has a certain exportable status. Overrides EntityInterface::hasStatus
Entity::identifier public function Returns the entity identifier, i.e. the entities name or numeric id. Overrides EntityInterface::identifier
Entity::internalIdentifier public function Returns the internal, numeric identifier. Overrides EntityInterface::internalIdentifier
Entity::isDefaultRevision public function Checks whether the entity is the default revision. Overrides EntityInterface::isDefaultRevision
Entity::label public function Returns the label of the entity. Overrides EntityInterface::label
Entity::setUp protected function Set up the object instance on construction or unserializiation.
Entity::uri public function Returns the uri of the entity just as entity_uri(). Overrides EntityInterface::uri
Entity::view public function Generate an array for rendering the entity. Overrides EntityInterface::view
Entity::wrapper public function Returns the EntityMetadataWrapper of the entity. Overrides EntityInterface::wrapper
Entity::__construct public function 1
Entity::__sleep public function Magic method to only serialize what's necessary.
Entity::__wakeup public function Magic method to invoke setUp() on unserialization.
Registration::$registration_id public property
Registration::buildContent public function Build content for Registration. Overrides Entity::buildContent
Registration::defaultLabel protected function Specifies the default label, which is picked up by label() by default. Overrides Entity::defaultLabel
Registration::defaultUri protected function Specify URI. Overrides Entity::defaultUri
Registration::registrant_type public function Determine registrant type relative to a given account.
Registration::save public function Save registration. Overrides Entity::save