You are here

class EntityShareTaxonomyExport in Entity Share 7

A class to export the taxonomy term.

Hierarchy

Expanded class hierarchy of EntityShareTaxonomyExport

File

modules/entity_share_taxonomy/includes/entity_share_taxonomy.export.inc, line 11
Class for handling taxonomy Export.

View source
class EntityShareTaxonomyExport extends EntityShareTaxonomyAbstract {

  /**
   * Manage taxonomy for the export.
   */
  public function exportDatas() {

    // Check if the field type is managed by the module.
    if (!$this
      ->isManagedFieldType()) {
      return;
    }

    // If we already come from content field walk.
    if (isset($this->fieldData['entity_type']) && $this->fieldData['entity_type'] == $this->fieldEntityType) {
      $term = (object) $this->fieldData;
    }
    else {
      $field_data = (object) $this->fieldData;
      $tid = $field_data->tid;
      $term = $this
        ->exportTerm($tid);
    }
    $this->fieldData = $term;
  }

  /**
   * Load a term with parent infos.
   *
   * @param int $tid
   *   Term Id to load.
   *
   * @return mixed
   *   The term entity.
   */
  protected function getFullyLoadedTerm($tid) {
    $term_ori = taxonomy_term_load($tid);
    $vocabulary = entity_share_taxonomy_get_tree_all_language($term_ori->vid, 0, NULL, TRUE);
    foreach ($vocabulary as $term) {
      if ($term->tid == $tid) {
        $field_export = new EntityShareEntityExport($term);
        $term = $field_export
          ->execute();
        $term = $this
          ->cleanTaxonomyTermExport($term);
        return $term;
      }
    }
  }

  /**
   * Clean a term with unneeded datas.
   *
   * @param object $term
   *   Term to clean.
   *
   * @return object
   *   Cleaned term.
   */
  protected function cleanTaxonomyTermExport($term) {
    unset($term->i18n_tsid);
    return $term;
  }

  /**
   * Get the parents of a term.
   *
   * @param object $term
   *   Term to extract parent.
   *
   * @return bool|array
   *   Array of the parent terms or FALSE if no parent.
   */
  protected function getParentsTerm($term) {
    if (!isset($term->parents)) {
      $term = $this
        ->getFullyLoadedTerm($term->tid);
    }
    return $term->parents;
  }

  /**
   * Load the parent tree.
   *
   * @param object $term
   *   Term to extract parent.
   *
   * @return object
   *   Term to with parents.
   */
  protected function loadParentTree($term) {
    if ($parents = $this
      ->getParentsTerm($term)) {
      foreach ($parents as $tid) {
        if ($tid != 0) {
          $parent = $this
            ->getFullyLoadedTerm($tid);
        }
        else {
          $parent = 0;
        }

        // For the entity save.
        $term->parent[] = $parent;
        unset($term->parents);
        if (!empty($parent->parents)) {
          $this
            ->loadParentTree($parent);
        }
      }
    }
    return $term;
  }

  /**
   * Export the term.
   *
   * @param int $tid
   *   Term Id to load.
   *
   * @return object
   *   The term with all parents loaded.
   */
  protected function exportTerm($tid) {
    $full_term = $this
      ->getFullyLoadedTerm($tid);
    return $this
      ->loadParentTree($full_term);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityShareTaxonomyAbstract::$delta protected property Delta of the field.
EntityShareTaxonomyAbstract::$entity protected property Entity object.
EntityShareTaxonomyAbstract::$entityShareEntity protected property Entity share object.
EntityShareTaxonomyAbstract::$fieldData protected property Field datas.
EntityShareTaxonomyAbstract::$fieldEntityType protected property Entity type of the current field.
EntityShareTaxonomyAbstract::$fieldInfo protected property Metadatas of the field.
EntityShareTaxonomyAbstract::$fieldLang protected property Field language.
EntityShareTaxonomyAbstract::$fieldName protected property Field name.
EntityShareTaxonomyAbstract::$fieldType protected property Field type.
EntityShareTaxonomyAbstract::$managedFieldTypes protected property Type of field managed by the class.
EntityShareTaxonomyAbstract::isManagedFieldType public function Check if the field type is managed.
EntityShareTaxonomyAbstract::__construct public function Constructor. Initialize properties.
EntityShareTaxonomyExport::cleanTaxonomyTermExport protected function Clean a term with unneeded datas.
EntityShareTaxonomyExport::exportDatas public function Manage taxonomy for the export.
EntityShareTaxonomyExport::exportTerm protected function Export the term.
EntityShareTaxonomyExport::getFullyLoadedTerm protected function Load a term with parent infos.
EntityShareTaxonomyExport::getParentsTerm protected function Get the parents of a term.
EntityShareTaxonomyExport::loadParentTree protected function Load the parent tree.