소스 검색

changes for the collections before adding the web services api hooks

Shawna Spoor 7 년 전
부모
커밋
1987d5580f

+ 23 - 20
tripal/includes/TripalEntityCollection.inc

@@ -473,7 +473,7 @@ class TripalEntityCollection {
    * @throws Exception
    */
   public function writeAll() {
-    foreach ($this->downloaders as $class_name => $lable) {
+    foreach ($this->downloaders as $class_name => $label) {
       $this->write($class_name);
     }
   }
@@ -524,7 +524,6 @@ class TripalEntityCollection {
    * @throws Exception
    */
   public function write($formatter) {
-    dpm($formatter);
     if (!$this->isFormatterCompatible($formatter)) {
       throw new Exception(t('The formatter, "@formatter", is not compatible with this data collection.', array('@formatter' => $formatter)));
 
@@ -538,33 +537,37 @@ class TripalEntityCollection {
 
     // Filter out fields that aren't supported by the formatter.
     $supported_fields = array();
-    foreach ($this->fields as $field_id) {
-      // If the formatter is TripalTabDownloader or TripalCSVDownloader then
-      // we always want to support the field.
-      if ($formatter == 'TripalTabDownloader' or $formatter == 'TripalCSVDownloader') {
-        if (!in_array($field_id, $supported_fields)) {
-          $supported_fields[] = $field_id;
+    foreach ($this->fields as $field_group) {
+      foreach ($field_group as $field_id) {
+        // If the formatter is TripalTabDownloader or TripalCSVDownloader then
+        // we always want to support the field.
+        if ($formatter == 'TripalTabDownloader' or $formatter == 'TripalCSVDownloader') {
+          if (!in_array($field_id, $supported_fields)) {
+            $supported_fields[] = $field_id;
+          }
+          continue;
         }
-        continue;
-      }
 
-      // Otherwise, find out if the formatter specified is supporte by the
-      // field and if so then add it to our list of supported fields.
-      $field = field_info_field_by_id($field_id);
-      $field_name = $field['field_name'];
-      $field_type = $field['type'];
-      if (tripal_load_include_field_class($field_type)) {
-        $settings = $field_type::$default_instance_settings;
-        if (array_key_exists('download_formatters', $settings)) {
-          if (in_array($formatter, $settings['download_formatters'])) {
-            $supported_fields[] = $field_id;
+        // Otherwise, find out if the formatter specified is supporte by the
+        // field and if so then add it to our list of supported fields.
+        $field = field_info_field_by_id($field_id);
+        $field_name = $field['field_name'];
+        $field_type = $field['type'];
+        if (tripal_load_include_field_class($field_type)) {
+          $settings = $field_type::$default_instance_settings;
+          if (array_key_exists('download_formatters', $settings)) {
+            if (in_array($formatter, $settings['download_formatters'])) {
+              $supported_fields[] = $field_id;
+            }
           }
         }
       }
     }
 
     $downloader = new $formatter($this->bundles, $this->ids, $supported_fields, $outfile, $this->user->uid);
+    //print_r($downloader);
     $downloader->write();
 
   }
+
 }

+ 18 - 8
tripal/includes/TripalFieldDownloaders/TripalFieldDownloader.inc

@@ -19,7 +19,7 @@ abstract class TripalFieldDownloader {
   protected $bundle_name = '';
 
   /**
-   * A set of entity IDs. The entities must all be of the same bundle type.
+   * A set of entity IDs. 
    */
   protected $entity_ids = array();
 
@@ -119,14 +119,24 @@ abstract class TripalFieldDownloader {
         fwrite($fh, $line . "\r\n");
       }
     }
-
     foreach ($this->entity_ids as $entity_id) {
-      $result = tripal_load_entity('TripalEntity', array($entity_id), FALSE, $this->fields);
-      reset($result);
-      $entity = $result[$entity_id];
-      $lines = $this->formatEntity($entity);
-      foreach ($lines as $line) {
-        fwrite($fh, $line . "\r\n");
+      if (is_array($entity_id)) {
+        foreach ($entity_id as $single_entity) {
+          $result = tripal_load_entity('TripalEntity', array($single_entity), FALSE, $this->fields);
+          $entity = $result[$single_entity];
+          $lines = $this->formatEntity($entity);
+          foreach ($lines as $line) {
+            fwrite($fh, $line . "\r\n");
+          }
+        }
+      }
+      else {
+        $result = tripal_load_entity('TripalEntity', array($entity_id), FALSE, $this->fields);
+        $entity = $result[$entity_id];
+        $lines = $this->formatEntity($entity);
+        foreach ($lines as $line) {
+          fwrite($fh, $line . "\r\n");
+        }
       }
     }
     fclose($fh);

+ 11 - 2
tripal/includes/TripalFieldDownloaders/TripalTabDownloader.inc

@@ -54,11 +54,20 @@ class TripalTabDownloader extends TripalFieldDownloader {
    */
   protected function getHeader() {
     $row = array();
+
     foreach ($this->fields as $field_id) {
       $field = field_info_field_by_id($field_id);
       $field_name = $field['field_name'];
-      $instance = field_info_instance('TripalEntity', $field_name, $this->bundle_name);
-      $row[] = $instance['label'];
+      if (is_array($this->bundle_name)) {
+        foreach ($this->bundle_name as $bundle) {
+          $instance = field_info_instance('TripalEntity', $field_name, $bundle->bundle_name);
+          $row[] = $instance['label'];
+        }
+      }
+      else {
+        $instance = field_info_instance('TripalEntity', $field_name, $this->bundle_name);
+        $row[] = $instance['label'];
+      }
     }
     return array(implode("\t", $row));
   }