You are here

class RedhenOrg in RedHen CRM 7

The class used for group entities.

Hierarchy

Expanded class hierarchy of RedhenOrg

1 string reference to 'RedhenOrg'
redhen_org_entity_info in modules/redhen_org/redhen_org.module
Implements hook_entity_info().

File

modules/redhen_org/lib/redhen_org.entity.inc, line 10
Redhen Group entity classes

View source
class RedhenOrg extends Entity {

  // @codingStandardsIgnoreStart
  public $label = '', $org_id = NULL, $primary_contact_id = NULL, $author_uid = NULL, $redhen_state = REDHEN_STATE_ACTIVE, $type = '', $created = '', $updated = '';

  // @codingStandardsIgnoreEnd

  /**
   * Override parent constructor.
   */
  public function __construct(array $values = array()) {
    global $user;
    parent::__construct($values, 'redhen_org');

    // New organization. is_new might not be set so check for id.
    if (!$this->org_id) {
      $this->author_uid = $user->uid;
      $this->redhen_state = REDHEN_STATE_ACTIVE;
      $this->created = REQUEST_TIME;
    }
  }

  /**
   * Override buildContent() to add organization properties.
   */
  public function buildContent($view_mode = 'full', $langcode = NULL) {
    $wrapper = entity_metadata_wrapper('redhen_org', $this);
    $primary_contact = $wrapper->primary_contact
      ->value();
    $content['redhen_state'] = array(
      '#theme' => 'redhen_property_field',
      '#label' => t('State'),
      '#items' => array(
        array(
          '#markup' => $this->redhen_state == REDHEN_STATE_ACTIVE ? t('Active') : t('Inactive'),
        ),
      ),
      '#classes' => 'field field-label-inline clearfix',
    );
    if (isset($primary_contact->contact_id)) {
      $contact_array = $primary_contact
        ->view('teaser');
      $content['primary_contact'] = array(
        '#theme' => 'fieldset',
        '#title' => t('Primary Contact'),
        '#children' => drupal_render($contact_array),
      );
    }
    return entity_get_controller($this->entityType)
      ->buildContent($this, $view_mode, $langcode, $content);
  }

  /**
   * Permanently saves the entity.
   *
   * @return bool
   *   Returns FALSE if entity was not saved.
   */
  public function save() {
    $this->updated = REQUEST_TIME;
    return parent::save();
  }

  /**
   * Set the primary contact for an organization.
   *
   * @param RedhenContact $contact
   *   The RedhenContact to use as the primary contact
   *
   * @return bool
   *   Return FALSE if we are unable to set the primary contact
   */
  public function setPrimaryContact(RedhenContact $contact) {

    // @TODO Check that $contact has a relationship with $this.
    $this->primary_contact_id = $contact->contact_id;
    return $this
      ->save();
  }

  /**
   * Set the redhen_state for an organization.
   *
   * @param string $state
   *   The REDHEN_STATE_* value to use.
   */
  public function setState($state) {
    $this->redhen_state = $state;
    return $this
      ->save();
  }

  /**
   * Specifies the default label, which is picked up by label() by default.
   */
  protected function defaultLabel() {
    $type = redhen_org_get_types($this->type);
    return $this->label . ' (' . $type->label . ')';
  }

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

}

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::__sleep public function Magic method to only serialize what's necessary.
Entity::__wakeup public function Magic method to invoke setUp() on unserialization.
RedhenOrg::$label public property
RedhenOrg::buildContent public function Override buildContent() to add organization properties. Overrides Entity::buildContent
RedhenOrg::defaultLabel protected function Specifies the default label, which is picked up by label() by default. Overrides Entity::defaultLabel
RedhenOrg::defaultUri protected function Specify URI. Overrides Entity::defaultUri
RedhenOrg::save public function Permanently saves the entity. Overrides Entity::save
RedhenOrg::setPrimaryContact public function Set the primary contact for an organization.
RedhenOrg::setState public function Set the redhen_state for an organization.
RedhenOrg::__construct public function Override parent constructor. Overrides Entity::__construct