You are here

class TMGMTLocalTaskItem in Translation Management Tool 7

Entity class for the local task item entity.

Hierarchy

Expanded class hierarchy of TMGMTLocalTaskItem

Related topics

1 string reference to 'TMGMTLocalTaskItem'
tmgmt_local_entity_info in translators/tmgmt_local/tmgmt_local.module
Implements hook_entity_info().

File

translators/tmgmt_local/entity/tmgmt_local.entity.task_item.inc, line 13

View source
class TMGMTLocalTaskItem extends Entity {

  /**
   * Translation local task item identifier.
   *
   * @var int
   */
  public $tltiid;

  /**
   * The task identifier.
   *
   * @var int
   */
  public $tltid;

  /**
   * Translation job item.
   *
   * @var int
   */
  public $tjiid;

  /**
   * Current status of the task.
   *
   * @var int
   */
  public $status;

  /**
   * Translated data and data item status.
   *
   * @var array
   */
  public $data = array();

  /**
   * Counter for all untranslated data items.
   *
   * @var integer
   */
  public $count_untranslated = 0;

  /**
   * Counter for all translated data items.
   *
   * @var integer
   */
  public $count_translated = 0;

  /**
   * Counter for all completed data items.
   *
   * @var integer
   */
  public $count_completed = 0;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $values = array(), $entity_type = 'tmgmt_local_task_item') {
    parent::__construct($values, $entity_type);
  }

  /*
   * {@inheritdoc}
   */
  public function defaultUri() {
    return array(
      'path' => 'translate/' . $this->tltid . '/item/' . $this->tltiid,
    );
  }

  /**
   * {@inheritdoc}
   */
  protected function defaultLabel() {
    if ($job_item = $this
      ->getJobItem()) {
      return $job_item
        ->label();
    }
    return t('Missing job item');
  }

  /**
   * Returns the translation task.
   *
   * @return TMGMTLocalTask
   */
  public function getTask() {
    return entity_load_single('tmgmt_local_task', $this->tltid);
  }

  /**
   * Returns the translation job item.
   *
   * @return TMGMTJobItem
   */
  public function getJobItem() {
    return entity_load_single('tmgmt_job_item', $this->tjiid);
  }

  /**
   * {@inheritdoc}
   */
  public function buildContent($view_mode = 'full', $langcode = NULL) {
    $content = drupal_get_form('tmgmt_local_translation_form', $this);
    return entity_get_controller($this->entityType)
      ->buildContent($this, $view_mode, $langcode, $content);
  }

  /**
   * Returns TRUE if the local task is pending.
   *
   * @return bool
   *   TRUE if the local task item is untranslated.
   */
  public function isPending() {
    return $this->status == TMGMT_LOCAL_TASK_ITEM_STATUS_PENDING;
  }

  /**
   * Returns TRUE if the local task is translated (fully translated).
   *
   * @return bool
   *   TRUE if the local task item is translated.
   */
  public function isCompleted() {
    return $this->status == TMGMT_LOCAL_TASK_ITEM_STATUS_COMPLETED;
  }

  /**
   * Rreturns TRUE if the local task is closed (translated and accepted).
   *
   * @return bool
   *   TRUE if the local task item is translated and accepted.
   */
  public function isClosed() {
    return $this->status == TMGMT_LOCAL_TASK_ITEM_STATUS_CLOSED;
  }

  /**
   * Sets the task item status to completed.
   */
  public function completed() {
    $this->status = TMGMT_LOCAL_TASK_ITEM_STATUS_COMPLETED;
  }

  /**
   * Sets the task item status to closed.
   */
  public function closed() {
    $this->status = TMGMT_LOCAL_TASK_ITEM_STATUS_CLOSED;
  }

  /**
   * Updates the values for a specific substructure in the data array.
   *
   * The values are either set or updated but never deleted.
   *
   * @param $key
   *   Key pointing to the item the values should be applied.
   *   The key can be either be an array containing the keys of a nested array
   *   hierarchy path or a string with '][' or '|' as delimiter.
   * @param $values
   *   Nested array of values to set.
   */
  public function updateData($key, $values = array()) {
    foreach ($values as $index => $value) {

      // In order to preserve existing values, we can not aplly the values array
      // at once. We need to apply each containing value on its own.
      // If $value is an array we need to advance the hierarchy level.
      if (is_array($value)) {
        $this
          ->updateData(array_merge(tmgmt_ensure_keys_array($key), array(
          $index,
        )), $value);
      }
      else {
        drupal_array_set_nested_value($this->data, array_merge(tmgmt_ensure_keys_array($key), array(
          $index,
        )), $value);
      }
    }
  }

  /**
   * Array of translations.
   *
   * The structure is similar to the form API in the way that it is a possibly
   * nested array with the following properties whose presence indicate that the
   * current element is a text that might need to be translated.
   *
   * - #text: The translated text of the corresponding entry in the job item.
   * - #status: The status of the translation.
   *
   * The key can be an alphanumeric string.
   *
   * @param array $key
   *   If present, only the subarray identified by key is returned.
   * @param string $index
   *   Optional index of an attribute below $key.
   *
   * @return array
   *   A structured data array.
   */
  public function getData(array $key = array(), $index = NULL) {
    if (empty($key)) {
      return $this->data;
    }
    if ($index) {
      $key = array_merge($key, array(
        $index,
      ));
    }
    return drupal_array_get_nested_value($this->data, $key);
  }

  /**
   * Count of all translated data items.
   *
   * @return
   *   Translated count
   */
  public function getCountTranslated() {
    return $this->count_translated;
  }

  /**
   * Count of all untranslated data items.
   *
   * @return
   *   Translated count
   */
  public function getCountUntranslated() {
    return $this->count_untranslated;
  }

  /**
   * Count of all completed data items.
   *
   * @return
   *   Translated count
   */
  public function getCountCompleted() {
    return $this->count_completed;
  }

}

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::save public function Permanently saves the entity. Overrides EntityInterface::save
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.
TMGMTLocalTaskItem::$count_completed public property Counter for all completed data items.
TMGMTLocalTaskItem::$count_translated public property Counter for all translated data items.
TMGMTLocalTaskItem::$count_untranslated public property Counter for all untranslated data items.
TMGMTLocalTaskItem::$data public property Translated data and data item status.
TMGMTLocalTaskItem::$status public property Current status of the task.
TMGMTLocalTaskItem::$tjiid public property Translation job item.
TMGMTLocalTaskItem::$tltid public property The task identifier.
TMGMTLocalTaskItem::$tltiid public property Translation local task item identifier.
TMGMTLocalTaskItem::buildContent public function Builds a structured array representing the entity's content. Overrides Entity::buildContent
TMGMTLocalTaskItem::closed public function Sets the task item status to closed.
TMGMTLocalTaskItem::completed public function Sets the task item status to completed.
TMGMTLocalTaskItem::defaultLabel protected function Defines the entity label if the 'entity_class_label' callback is used. Overrides Entity::defaultLabel
TMGMTLocalTaskItem::defaultUri public function Override this in order to implement a custom default URI and specify 'entity_class_uri' as 'uri callback' hook_entity_info(). Overrides Entity::defaultUri
TMGMTLocalTaskItem::getCountCompleted public function Count of all completed data items.
TMGMTLocalTaskItem::getCountTranslated public function Count of all translated data items.
TMGMTLocalTaskItem::getCountUntranslated public function Count of all untranslated data items.
TMGMTLocalTaskItem::getData public function Array of translations.
TMGMTLocalTaskItem::getJobItem public function Returns the translation job item.
TMGMTLocalTaskItem::getTask public function Returns the translation task.
TMGMTLocalTaskItem::isClosed public function Rreturns TRUE if the local task is closed (translated and accepted).
TMGMTLocalTaskItem::isCompleted public function Returns TRUE if the local task is translated (fully translated).
TMGMTLocalTaskItem::isPending public function Returns TRUE if the local task is pending.
TMGMTLocalTaskItem::updateData public function Updates the values for a specific substructure in the data array.
TMGMTLocalTaskItem::__construct public function Overrides Entity::__construct