entity_share_taxonomy.export.inc in Entity Share 7
Class for handling taxonomy Export.
File
modules/entity_share_taxonomy/includes/entity_share_taxonomy.export.incView source
<?php
/**
* @file
* Class for handling taxonomy Export.
*/
/**
* A class to export the taxonomy term.
*/
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);
}
}
Classes
Name | Description |
---|---|
EntityShareTaxonomyExport | A class to export the taxonomy term. |