Browse Source

Fixed a bug when creating new content types that have properties set

Stephen Ficklin 7 years ago
parent
commit
f12a6ce25e

+ 53 - 85
tripal/api/tripal.entities.api.inc

@@ -312,7 +312,6 @@ function tripal_create_bundle($args, &$error = '') {
         ->execute();
     }
 
-    // Allow modules to make additions to the entity when it's created.
     $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
     $modules = module_implements('bundle_create');
     foreach ($modules as $module) {
@@ -330,49 +329,7 @@ function tripal_create_bundle($args, &$error = '') {
     // Get the bundle object.
     $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
 
-    // Allow modules to add fields to the new bundle.
-    $modules = module_implements('bundle_fields_info');
-    foreach ($modules as $module) {
-      $function = $module . '_bundle_fields_info';
-      $info = $function('TripalEntity', $bundle);
-      foreach ($info as $field_name => $details) {
-        $field_type = $details['type'];
-
-        // TODO: make sure the field term exits. If not then
-        // skip it.
-
-        // If the field already exists then skip it.
-        $field = field_info_field($details['field_name']);
-        if ($field) {
-          continue;
-        }
-
-        // Create the field.
-        $field = field_create_field($details);
-        if (!$field) {
-          tripal_set_message(t("Could not create new field: %field.",
-              array('%field' =>  $details['field_name'])), TRIPAL_ERROR);
-        }
-      }
-    }
-
-    // Allow modules to add instances to the new bundle.
-    $modules = module_implements('bundle_instances_info');
-    foreach ($modules as $module) {
-      $function = $module . '_bundle_instances_info';
-      $info = $function('TripalEntity', $bundle);
-      foreach ($info as $field_name => $details) {
-        // If the field is already attached to this bundle then skip it.
-        $field = field_info_field($details['field_name']);
-        if ($field and array_key_exists('bundles', $field) and
-            array_key_exists('TripalEntity', $field['bundles']) and
-            in_array($bundle->name, $field['bundles']['TripalEntity'])) {
-          continue;
-        }
-        // Create the field instance.
-        $instance = field_create_instance($details);
-      }
-    }
+    tripal_create_bundle_fields($bundle, $term);
 
     $modules = module_implements('bundle_postcreate');
     foreach ($modules as $module) {
@@ -547,64 +504,75 @@ function tripal_get_content_type($bundle_name) {
  *
  * @param $bundle_name
  *   The name of the bundle to refresh (e.g. bio_data_4).
+ *
+ * @return
+ *   The array of field instance names that were added.
  */
-function tripal_refresh_bundle_fields($bundle_name) {
-
-  $num_created = 0;
+function tripal_create_bundle_fields($bundle, $term) {
 
-  // Get the bundle object.
-  $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
-  if (!$bundle) {
-    tripal_report_error('tripal', TRIPAL_ERROR, "Unrecognized bundle name '%bundle'.",
-        array('%bundle' => $bundle_name));
-    return FALSE;
-  }
+  $added = array();
 
   // Allow modules to add fields to the new bundle.
   $modules = module_implements('bundle_fields_info');
+  $info = array();
   foreach ($modules as $module) {
     $function = $module . '_bundle_fields_info';
-    $info = $function('TripalEntity', $bundle);
-    foreach ($info as $field_name => $details) {
-      $field_type = $details['type'];
-
-      // If the field already exists then skip it.
-      $field = field_info_field($details['field_name']);
-      if ($field) {
-        continue;
-      }
+    $temp = $function('TripalEntity', $bundle);
+    $info = array_merge($info, $temp);
+  }
 
-      // Create the field.
-      $field = field_create_field($details);
-      if (!$field) {
-        tripal_set_message(t("Could not create new field: %field.",
-            array('%field' =>  $details['field_name'])), TRIPAL_ERROR);
-      }
+  // Allow modules to alter which fields should be attached to content
+  // types they create.
+  drupal_alter('bundle_fields_info', $info, $bundle, $term);
+
+  // Iterate through all of the fields and create them.
+  foreach ($info as $field_name => $details) {
+    $field_type = $details['type'];
+
+    // TODO: make sure the field term exits. If not then
+    // skip it.
+
+    // If the field already exists then skip it.
+    $field = field_info_field($details['field_name']);
+    if ($field) {
+      continue;
+    }
+
+    // Create the field.
+    $field = field_create_field($details);
+    if (!$field) {
+      tripal_set_message(t("Could not create new field: %field.",
+          array('%field' =>  $details['field_name'])), TRIPAL_ERROR);
     }
   }
 
   // Allow modules to add instances to the new bundle.
   $modules = module_implements('bundle_instances_info');
+  $info = array();
   foreach ($modules as $module) {
     $function = $module . '_bundle_instances_info';
-    $info = $function('TripalEntity', $bundle);
-    foreach ($info as $field_name => $details) {
-      // If the field is already attached to this bundle then skip it.
-      $field = field_info_field($details['field_name']);
-      if ($field and array_key_exists('bundles', $field) and
-          array_key_exists('TripalEntity', $field['bundles']) and
-          in_array($bundle->name, $field['bundles']['TripalEntity'])) {
-        continue;
-      }
-      // Create the field instance.
-      $instance = field_create_instance($details);
-      $num_created++;
-      drupal_set_message(t("Created field: %field", array('%field' => $info[$field_name]['label'])));
-    }
+    $temp = $function('TripalEntity', $bundle);
+    $info = array_merge($info, $temp);
   }
-  if ($num_created == 0) {
-    drupal_set_message(t("No new fields were added."));
+
+  // Allow modules to alter which fields should be attached to content
+  // types they create.
+  drupal_alter('bundle_instances_info', $info, $bundle, $term);
+
+  // Iterate through all of the field instances and create them.
+  foreach ($info as $field_name => $details) {
+    // If the field is already attached to this bundle then skip it.
+    $field = field_info_field($details['field_name']);
+    if ($field and array_key_exists('bundles', $field) and
+        array_key_exists('TripalEntity', $field['bundles']) and
+        in_array($bundle->name, $field['bundles']['TripalEntity'])) {
+      continue;
+    }
+    // Create the field instance.
+    $instance = field_create_instance($details);
+    $added[] = $field_name;
   }
+  return $added;
 }
 
 /**

+ 14 - 0
tripal/api/tripal.fields.api.inc

@@ -30,6 +30,20 @@
 function hook_field_storage_tquery($conditions, $orderBy) {
   // See the tripal_chado_field_storage_tquery() function for an example.
 }
+
+function hook_bundle_fields_info($entity_type, $bundle) {
+
+}
+function hook_bundle_instances_info($entity_type, $bundle) {
+
+}
+function hook_bundle_fields_info_alter(&$info, $bundle, $term) {
+
+}
+function hook_bundle_instances_info_alter(&$info, $bundle, $term) {
+
+}
+
 /**
  * Retrieves a list of TripalField types.
  *

+ 11 - 1
tripal/tripal.module

@@ -648,7 +648,17 @@ function tripal_form_alter(&$form, $form_state, $form_id) {
 }
 
 function tripal_check_new_fields($bundle_name) {
-  tripal_refresh_bundle_fields($bundle_name);
+  $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
+  $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
+
+  $added = tripal_create_bundle_fields($bundle, $term);
+  if (count($added) == 0) {
+    drupal_set_message('No new fields were added');
+  }
+  foreach ($added as $field_name) {
+    drupal_set_message('Added field: ' . $field_name);
+  }
+
   drupal_goto("admin/structure/bio_data/manage/$bundle_name/fields");
 }
 

+ 1 - 0
tripal_chado/api/tripal_chado.query.api.inc

@@ -1318,6 +1318,7 @@ function chado_select_record($table, $columns, $values, $options = NULL) {
 
     // Require the field be in the table description.
     if (!array_key_exists($field, $table_desc['fields'])) {
+      dpm(debug_backtrace());
       tripal_report_error('tripal_chado', TRIPAL_ERROR,
         'chado_select_record: The field "%field" does not exist for the table "%table".  Cannot perform query. Values: %array',
         array('%field' => $field, '%table' => $table, '%array' => print_r($values, 1)),

+ 18 - 5
tripal_chado/includes/TripalFields/chado_linker__prop/chado_linker__prop_widget.inc

@@ -40,7 +40,7 @@ class chado_linker__prop_widget extends ChadoFieldWidget {
     if (count($items) > 0) {
       // Check for element values that correspond to fields in the Chado table.
       $fk_value = tripal_get_field_item_keyval($items, 0, 'chado-' . $chado_table . '__' . $lfkey_field, $fk_value);
-      $type_id = tripal_get_field_item_keyval($items, 0, 'chado-' . $chado_table . '__type_id', $type_id);      
+      $type_id = tripal_get_field_item_keyval($items, 0, 'chado-' . $chado_table . '__type_id', $type_id);
       if (array_key_exists($delta, $items)) {
         $record_id = tripal_get_field_item_keyval($items, $delta, 'chado-' . $chado_table . '__' . $pkey, $record_id);
         $value = tripal_get_field_item_keyval($items, $delta, 'chado-' . $chado_table . '__value', $value);
@@ -59,9 +59,22 @@ class chado_linker__prop_widget extends ChadoFieldWidget {
 
     // Use default value for the field if it's not already set
     if (!$value && isset($instance['default_value'][$delta])) {
-      $value = $instance['default_value'][$delta]['chado-' . $chado_table . '__value'];
+      $value = $instance['default_value'][$delta]['value'];
     }
-    
+    if (!$type_id) {
+      $vocabulary = $this->instance['settings']['term_vocabulary'];
+      $accession = $this->instance['settings']['term_accession'];
+      $cvterm = tripal_get_cvterm(array(
+        'dbxref_id' => array(
+          'db_id' => array(
+            'name' => $vocabulary,
+          ),
+          'accession' => $accession,
+        ),
+      ));
+      $type_id = $cvterm->cvterm_id;
+    }
+
     $widget['value'] = array(
       '#type' => 'value',
       '#value' => array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
@@ -78,7 +91,7 @@ class chado_linker__prop_widget extends ChadoFieldWidget {
     $widget['chado-' . $chado_table . '__value'] = array(
       '#type' => 'textarea',
       '#default_value' => $value,
-      '#title' => $instance['label'] . ' value',
+      '#title' => $instance['label'],
       '#description' => $instance['description'],
     );
     $widget['chado-' . $chado_table . '__type_id'] = array(
@@ -106,7 +119,7 @@ class chado_linker__prop_widget extends ChadoFieldWidget {
 
     $value = $form_state['values'][$field_name]['und'][$delta]['chado-' . $chado_table . '__value'];
     $form_state['values'][$field_name]['und'][$delta]['value'] = $value;
-    
+
     // If the user removed the property then we want to clear out the other
     // fields so there is no insert.
     if (!$value) {

+ 3 - 3
tripal_chado/includes/TripalFields/local__source_data/local__source_data_widget.inc

@@ -47,9 +47,8 @@ class local__source_data_widget extends ChadoFieldWidget {
     );
     $widget['source_data'] = array(
       '#type' => 'fieldset',
-      '#title' => 'Source Data',
-      '#description' => t('The following fields help viewers identify the source
-          where data was obtained for this analysis.'),
+      '#title' => $this->instance['label'],
+      '#description' => $this->instance['description'],
       '#weight' => isset($element['#weight']) ? $element['#weight'] : 0,
       '#delta' => $delta,
     );
@@ -58,6 +57,7 @@ class local__source_data_widget extends ChadoFieldWidget {
       '#title' => 'Data Source Name',
       '#description' => 'The name of the source where data was obtained for this analysis.',
       '#default_value' => $sourcename,
+      '#required' => TRUE,
     );
     $widget['source_data']['chado-analysis__sourceversion'] = array(
       '#type' => 'textfield',

+ 2 - 0
tripal_chado/includes/tripal_chado.entity.inc

@@ -15,12 +15,14 @@ function tripal_chado_entity_create(&$entity, $type) {
     if (!property_exists($entity, 'chado_table')) {
       $entity->chado_table =  NULL;
       $entity->chado_column = NULL;
+      $entity->chado_linker = NULL;
 
       // Add in the Chado table information for this entity type.
       $bundle = tripal_load_bundle_entity(array('name' => $entity->bundle));
       if ($bundle->data_table) {
         $entity->chado_table = $bundle->data_table;
         $entity->chado_column = $bundle->type_column;
+        $entity->chado_linker = $bundle->type_linker_table;
       }
     }
     if (!property_exists($entity, 'chado_record')) {

+ 18 - 7
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -37,13 +37,13 @@ function tripal_chado_field_storage_write($entity_type, $entity, $op, $fields) {
   $type_field = $entity->chado_column;
   $record     = $entity->chado_record;
   $record_id  = $entity->chado_record_id;
+  $linker     = $entity->chado_linker;
   $base_schema = chado_get_schema($base_table);
   $base_pkey = $base_schema['primary key'][0];
 
   // Convert the fields into a key/value list of fields and their values.
   $field_vals = tripal_chado_field_storage_write_merge_fields($fields, $entity_type, $entity);
 
-
   // First, write the record for the base table.  If we have a record id then
   // this is an update and we need to set the primary key.  If not, then this
   // is an insert and we need to set the type_id if the table supports it.
@@ -51,10 +51,10 @@ function tripal_chado_field_storage_write($entity_type, $entity, $op, $fields) {
   if ($record_id) {
     $values[$base_pkey] = $record_id;
   }
-  elseif ($type_field) {
+  elseif ($type_field and !$linker) {
     $values[$type_field] = $cvterm->cvterm_id;
   }
-  $base_record_id = tripal_chado_field_storage_write_table($base_table, $values);
+  $base_record_id = tripal_chado_field_storage_write_table($base_table, $values, $base_table);
 
   // If this is an insert then add the chado_entity record.
   if ($op == FIELD_STORAGE_INSERT) {
@@ -77,7 +77,7 @@ function tripal_chado_field_storage_write($entity_type, $entity, $op, $fields) {
       continue;
     }
     foreach ($details as $delta => $values) {
-      $record_id = tripal_chado_field_storage_write_table($table_name, $values);
+      $record_id = tripal_chado_field_storage_write_table($table_name, $values, $base_table, $base_pkey, $base_record_id);
     }
   }
 }
@@ -106,12 +106,11 @@ function tripal_chado_field_storage_write($entity_type, $entity, $op, $fields) {
  * @return
  *   The unique record ID.
  */
-function tripal_chado_field_storage_write_table($table_name, $values) {
+function tripal_chado_field_storage_write_table($table_name, $values, $base_table, $base_pkey = NULL, $base_record_id= NULL) {
   $schema = chado_get_schema($table_name);
   $fkeys = $schema['foreign keys'];
   $pkey = $schema['primary key'][0];
 
-
   // Fields with a cardinality greater than 1 will often submit an
   // empty form.  We want to remove these empty submissions.  We can detect
   // them if all of the fields are empty.
@@ -154,13 +153,25 @@ function tripal_chado_field_storage_write_table($table_name, $values) {
       return $record[0]->$pkey;
     }
 
+    // If this table_name is a linker table then we want to be sure to add in
+    // the value for the $base_record_id it it isn't set.  This would only
+    // occur on an insert.
+    if (array_key_exists($base_table, $fkeys) and $base_table != $table_name) {
+      foreach ($fkeys[$base_table]['columns'] as $lkey => $rkey) {
+        if ($rkey == $base_pkey and !array_key_exists($lkey, $values) or empty($values[$lkey])) {
+          $values[$lkey] = $base_record_id;
+        }
+      }
+    }
+    dpm($values);
+
     // Insert the values array as a new record in the table but remove the
     // pkey as it should be set.
     $new_vals = $values;
     unset($new_vals[$pkey]);
     $record = chado_insert_record($table_name, $new_vals);
     if ($record === FALSE) {
-      throw new Exception('Could not insert Chado record into table: "' . $table_name . '".');
+      throw new Exception('Could not insert Chado record into table: "' . $table_name . '": ' . print_r($new_vals, TRUE));
     }
     return $record[$pkey];
   }

+ 7 - 0
tripal_chado/includes/tripal_chado.fields.inc

@@ -836,6 +836,9 @@ function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle,
     //
     // ANALYSIS TABLE
     //
+    elseif ($table_name == 'analysis' and $column_name == 'name') {
+      $base_info['required'] = TRUE;
+    }
     elseif ($table_name == 'analysis' and $column_name == 'program') {
       $base_info['description'] = 'The program name (e.g. blastx, blastp, sim4, genscan. If the analysis was not derived from a software package then provide a very brief description of the pipeline, workflow or method.';
       $base_info['label'] = 'Program, Pipeline, Workflow or Method Name';
@@ -848,6 +851,10 @@ function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle,
       $base_info['label'] = 'Program Version';
       $base_info['description'] = 'The version of the program used to perform this analysis. (e.g. TBLASTX 2.0MP-WashU [09-Nov-2000]. Enter "n/a" if no version is available or applicable.';
     }
+    elseif ($table_name == 'analysis' and $column_name == 'timeexecuted') {
+      $base_info['label'] = 'Date Performed';
+      $base_info['description'] = 'The date and time when the analysis was performed.';
+    }
 
     if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
         $column_name == 'sourceversion' or $column_name == 'sourcename')) {

+ 3 - 16
tripal_ws/includes/TripalWebService.inc

@@ -76,19 +76,6 @@ class TripalWebService {
     // continuing.
   }
 
-  /**
-   * Retrieves the path for the current resource.
-   *
-   * This web service class always provides a resource that fits within the
-   * type of class.  The URL for each resource is needed for building the
-   * full IRI. This path can be concatenated to the Tripal webservices path to
-   * form the complete IRI for the current resource.
-   */
-  public function getResourcePath() {
-    $class = get_class($this);
-    return $class::$type;
-  }
-
   // --------------------------------------------------------------------------
   //                     CLASS FUNCTIONS -- DO NOT OVERRIDE
   // --------------------------------------------------------------------------
@@ -192,7 +179,7 @@ class TripalWebService {
 
     // Get the data array and set the IRIs fore each ID.
     $data = $this->getData();
-    $this->setIRI($data);
+    $this->setIDs($data);
 
     return array_merge($json_ld, $data);
   }
@@ -203,7 +190,7 @@ class TripalWebService {
    * @param $data
    *   An array of data as returned by the $this->getData() function
    */
-  protected function setIRI(&$data) {
+  protected function setIDs(&$data) {
     global $base_url;
 
     if(array_key_exists('@id', $data)) {
@@ -214,7 +201,7 @@ class TripalWebService {
     }
     foreach ($data as $key => $val) {
       if (is_array($val)) {
-        $this->setIRI($data[$key]);
+        $this->setIDs($data[$key]);
       }
     }
   }

+ 11 - 25
tripal_ws/includes/TripalWebService/TripalEntityService_v0_1.inc

@@ -32,7 +32,7 @@ class TripalEntityService_v0_1 extends TripalWebService {
   /**
    * @see TripalWebService::handleRequest()
    */
-  public function handleRequest($path) {
+  public function handleRequest() {
 
     // Get the content type.
     $ctype     = (count($this->path) > 0) ? $this->path[0] : '';
@@ -40,7 +40,7 @@ class TripalEntityService_v0_1 extends TripalWebService {
 
     // If we have no content type then list all of the available content types.
     if ($ctype and !$entity_id) {
-      $this->doContentType($ctype);
+      $this->doContentTypeList($ctype);
     }
     // If we don't have an entity ID then show a paged list of entities with
     // the given type.
@@ -55,7 +55,7 @@ class TripalEntityService_v0_1 extends TripalWebService {
   /**
    * Creates a collection of resources for a given type.
    */
-  private function doContentType($ctype) {
+  private function doContentTypeList($ctype) {
     $this->resource = new TripalWebServiceCollection();
     $this->resource->addContextItem('label', 'rdfs:label');
 
@@ -65,7 +65,6 @@ class TripalEntityService_v0_1 extends TripalWebService {
     $term = reset($term);
 
     // Set the label for this collection.
-    $this->resource->addContextItem($term->name, $term->url);
     $this->resource->addProperty('label', $bundle->label . " collection");
 
     // Iterate through the fields and create a $field_mapping array that makes
@@ -82,8 +81,8 @@ class TripalEntityService_v0_1 extends TripalWebService {
             if (array_key_exists('term_accession', $instance['settings'])){
               $vocabulary = $instance['settings']['term_vocabulary'];
               $accession = $instance['settings']['term_accession'];
-              $term = tripal_get_term_details($vocabulary, $accession);
-              $key = $term['name'];
+              $fterm = tripal_get_term_details($vocabulary, $accession);
+              $key = $fterm['name'];
               $key = strtolower(preg_replace('/ /', '_', $key));
               $field_mapping[$key] = $field['field_name'];
               $field_mapping[$field['field_name']] = $field['field_name'];
@@ -98,7 +97,7 @@ class TripalEntityService_v0_1 extends TripalWebService {
     $order = array();
     $order_dir = array();
     $URL_add = array();
-    foreach ($params as $param => $value) {
+    foreach ($this->params as $param => $value) {
       $URL_add[] = "$param=$value";
 
       // Ignore non filter parameters
@@ -209,7 +208,6 @@ class TripalEntityService_v0_1 extends TripalWebService {
     $cquery = clone $query;
     $cquery->count();
     $num_records = $cquery->execute();
-    $num_records = count($num_records['TripalEntity']);
 
     if (!$num_records) {
       $num_records = 0;
@@ -217,10 +215,10 @@ class TripalEntityService_v0_1 extends TripalWebService {
 
     // Add in the pager to the response.
     $response['totalItems'] = $num_records;
-    $limit = array_key_exists('limit', $params) ? $params['limit'] : 25;
+    $limit = array_key_exists('limit', $this->params) ? $this->params['limit'] : 25;
 
     $total_pages = ceil($num_records / $limit);
-    $page = array_key_exists('page', $params) ? $params['page'] : 1;
+    $page = array_key_exists('page', $this->params) ? $this->params['page'] : 1;
 
     // Set the query order
     $order_keys = array_keys($order);
@@ -239,11 +237,7 @@ class TripalEntityService_v0_1 extends TripalWebService {
     $this->resource->initPager($num_records, 25);
 
     // Iterate through the entities and add them to the list.
-    $i = 0;
     foreach ($results['TripalEntity'] as $entity_id => $stub) {
-      $vocabulary = '';
-      $term_name = '';
-
       // We don't need all of the attached fields for an entity so, we'll
       // not use the entity_load() function.  Instead just pull it from the
       // database table.
@@ -254,16 +248,15 @@ class TripalEntityService_v0_1 extends TripalWebService {
       $query->condition('TE.id', $entity_id);
       $entity = $query->execute()->fetchObject();
 
-      //$entity = tripal_load_entity('TripalEntity', array($entity->id));
       $member = new TripalWebServiceResource();
       $member->addContextItem('label', 'rdfs:label');
       $member->addContextItem('itemPage', 'schema:itemPage');
-      $member->setID($entity->id);
+      $member->addContextItem($term->name, $term->url);
+      $member->setID(urldecode($bundle->label) . '/' . $entity->id);
+      $member->setType($term->name);
       $member->addProperty('label', $entity->title);
       $member->addProperty('itemPage', url('/bio_data/' . $entity->id, array('absolute' => TRUE)));
-
       $this->resource->addMember($member);
-      $i++;
     }
   }
 
@@ -307,11 +300,4 @@ class TripalEntityService_v0_1 extends TripalWebService {
 
     }
   }
-  /**
-   * @see TripalWebService::getResourcePath()
-   */
-  public function getResourcePath() {
-    $base_path = parent::getResourcePath();
-    return $base_path . '/' . $this->resource['@type'];
-  }
 }

+ 3 - 3
tripal_ws/includes/TripalWebServiceCollection.inc

@@ -56,7 +56,7 @@ class TripalWebServiceCollection extends TripalWebServiceResource {
    * @param $itemsPerPage
    *   The maximum number of items per page.
    */
-  public function initPager($totalItems, $itemsPerPage) {
+  public function initPager($totalItems, $itemsPerPage, $path) {
     $this->doPaging = TRUE;
     $this->totalItems = $totalItems;
     $this->itemsPerPage = $itemsPerPage;
@@ -115,10 +115,10 @@ class TripalWebServiceCollection extends TripalWebServiceResource {
         $prev = $page - 1;
         $next = $page + 1;
         if ($prev > 0) {
-          $data['view']['previous'] = $URL . '?' . implode('&', array_merge($URL_add, array("page=$prev", "limit=$limit")));
+          $data['view']['previous'] = '?' . implode('&', array_merge($URL_add, array("page=$prev", "limit=$limit")));
         }
         if ($next < $total_pages) {
-          $data['view']['next'] = $URL . '?' . implode('&', array_merge($URL_add, array("page=$next", "limit=$limit")));
+          $data['view']['next'] = '?' . implode('&', array_merge($URL_add, array("page=$next", "limit=$limit")));
         }
       }
 

+ 1 - 0
tripal_ws/includes/TripalWebServiceResource.inc

@@ -217,4 +217,5 @@ class TripalWebServiceResource {
   public function getContext() {
       return $this->context;
   }
+
 }

+ 1 - 1
tripal_ws/tripal_ws.module

@@ -170,7 +170,7 @@ function tripal_ws_get_services() {
 
     // Now call the service to handle the request.
     $service->setPath($adj_path);
-    $service->setParams($params);
+    $service->setParams($args);
     $service->handleRequest();
     $response = $service->getResponse();
     print drupal_json_encode($response);