You are here

class RedhenNote in RedHen CRM 7

The class used for note entities.

Hierarchy

Expanded class hierarchy of RedhenNote

1 string reference to 'RedhenNote'
redhen_note_entity_info in modules/redhen_note/redhen_note.module
Implements hook_entity_info().

File

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

View source
class RedhenNote extends Entity {
  public $note_id = NULL, $author_uid = NULL, $type = '', $created = '', $updated = '';
  public function __construct(array $values = array()) {
    parent::__construct($values, 'redhen_note');

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

  /**
   * Override buildContent() to add note properties.
   */
  public function buildContent($view_mode = 'full', $langcode = NULL) {
    $wrapper = entity_metadata_wrapper('redhen_note', $this);
    $author = $wrapper->author
      ->value();
    $content['author'] = array(
      '#theme' => 'redhen_property_field',
      '#label' => t('Author'),
      '#items' => array(
        array(
          '#markup' => $author->name,
        ),
      ),
      '#classes' => 'field field-label-inline clearfix',
    );
    $content['created'] = array(
      '#theme' => 'redhen_property_field',
      '#label' => t('Created'),
      '#items' => array(
        array(
          '#markup' => redhen_format_date($this->created),
        ),
      ),
      '#classes' => 'field field-label-inline clearfix',
    );
    return entity_get_controller($this->entityType)
      ->buildContent($this, $view_mode, $langcode, $content);
  }

  /**
   * Override label() to add note label.
   */
  public function label() {
    $wrapper = entity_metadata_wrapper('redhen_note', $this);
    $entity = $wrapper->entity
      ->value();

    // Don't sanitize here as this function should produce unsanitized output.
    return t('Note !id on !label', array(
      '!id' => $this->note_id,
      '!label' => entity_label($wrapper->entity_type
        ->value(), $wrapper->entity),
    ));
  }

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

  /**
   * Specifify URI
   */
  protected function defaultUri() {
    switch ($this->entity_type) {
      case 'redhen_contact':
        $path = 'contact';
        break;
      case 'redhen_org':
        $path = 'org';
        break;
    }
    return array(
      'path' => 'redhen/' . $path . '/' . $this->entity_id . '/note/' . $this->note_id . '/view',
    );
  }

}

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::defaultLabel protected function Defines the entity label if the 'entity_class_label' callback is used. 1
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::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.
RedhenNote::$note_id public property
RedhenNote::buildContent public function Override buildContent() to add note properties. Overrides Entity::buildContent
RedhenNote::defaultUri protected function Specifify URI Overrides Entity::defaultUri
RedhenNote::label public function Override label() to add note label. Overrides Entity::label
RedhenNote::save public function Permanently saves the entity. Overrides Entity::save
RedhenNote::__construct public function Overrides Entity::__construct