class EntityShareTaxonomyExport in Entity Share 7
A class to export the taxonomy term.
Hierarchy
- class \EntityShareTaxonomyAbstract
- class \EntityShareTaxonomyExport
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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityShareTaxonomyAbstract:: |
protected | property | Delta of the field. | |
EntityShareTaxonomyAbstract:: |
protected | property | Entity object. | |
EntityShareTaxonomyAbstract:: |
protected | property | Entity share object. | |
EntityShareTaxonomyAbstract:: |
protected | property | Field datas. | |
EntityShareTaxonomyAbstract:: |
protected | property | Entity type of the current field. | |
EntityShareTaxonomyAbstract:: |
protected | property | Metadatas of the field. | |
EntityShareTaxonomyAbstract:: |
protected | property | Field language. | |
EntityShareTaxonomyAbstract:: |
protected | property | Field name. | |
EntityShareTaxonomyAbstract:: |
protected | property | Field type. | |
EntityShareTaxonomyAbstract:: |
protected | property | Type of field managed by the class. | |
EntityShareTaxonomyAbstract:: |
public | function | Check if the field type is managed. | |
EntityShareTaxonomyAbstract:: |
public | function | Constructor. Initialize properties. | |
EntityShareTaxonomyExport:: |
protected | function | Clean a term with unneeded datas. | |
EntityShareTaxonomyExport:: |
public | function | Manage taxonomy for the export. | |
EntityShareTaxonomyExport:: |
protected | function | Export the term. | |
EntityShareTaxonomyExport:: |
protected | function | Load a term with parent infos. | |
EntityShareTaxonomyExport:: |
protected | function | Get the parents of a term. | |
EntityShareTaxonomyExport:: |
protected | function | Load the parent tree. |