public function TripalFieldDownloader::write
3.x TripalFieldDownloader.inc | public TripalFieldDownloader::write(TripalJob $job = NULL) |
Creates the downloadable file.
Parameters
$job: If this function is run as a Tripal Job then this argument can be set to the Tripaljob object for keeping track of progress.
File
- tripal/
includes/ TripalFieldDownloaders/ TripalFieldDownloader.inc, line 323
Class
Code
public function write(TripalJob $job = NULL) {
$this->initWrite($job);
$num_handled = 0;
foreach ($this->collection_bundles as $bundle_collection) {
$collection_bundle_id = $bundle_collection->collection_bundle_id;
$bundle_name = $bundle_collection->bundle_name;
$entity_ids = $bundle_collection->ids;
$fields = $bundle_collection->fields;
$site_id = $bundle_collection->site_id;
foreach ($entity_ids as $entity_id) {
$num_handled++;
if ($job) {
$job->setItemsHandled($num_handled);
}
// if we have a site_id then we need to get the entity from the
// remote service. Otherwise create the entity from the local system.
if ($site_id) {
$entity = $this->loadRemoteEntity($entity_id, $site_id, $bundle_name);
if (!$entity) {
continue;
}
}
else {
$result = tripal_load_entity('TripalEntity', array($entity_id), FALSE, $fields, FALSE);
$entity = $result[$entity_id];
}
if (!$entity) {
continue;
}
$lines = $this->formatEntity($entity);
foreach ($lines as $line) {
fwrite($this->fh, $line . "\r\n");
}
}
}
$this->finishWrite($job);
}