Tripal v1.0 (6.x-1.0)
tripal_bulk_loader.api.templates.inc
Go to the documentation of this file.
00001 <?php
00023 function tripal_bulk_loader_is_record_name_unique($new_record_name, $template_id, $template_array = NULL, $current_priority = NULL) {
00024 
00025   // get the template array if it's not supplied
00026   if (empty($template_array)) {
00027     $template = db_fetch_object(db_query("SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d", $template_id));
00028     $template_array = unserialize($template->template_array);
00029     if (!is_array($template_array)) {
00030       watchdog(
00031         'tripal_bulk_loader',
00032         'Unable to retrieve template array from database where template_id=%template_id',
00033         array('%template_id' => $template_id),
00034         WATCHDOG_WARNING
00035       );
00036       return FALSE;
00037     }
00038   }
00039 
00040   // Check that the new record name is not empty
00041   if (empty($new_record_name)) {
00042     return FALSE;
00043   }
00044 
00045   // Check the new record name is unique
00046   foreach ($template_array as $priority => $t) {
00047     if (strcmp($t['record_id'], $new_record_name) == 0) {
00048         if (($priority != $current_priority) AND ($current_priority !== NULL)) {
00049               return FALSE;
00050             }
00051     }
00052   }
00053   return TRUE;
00054 }
00055 
00067 function tripal_bulk_loader_delete_record($delete_priority, $template_array) {
00068 
00069         if (empty($template_array)) {
00070                 drupal_set_message("Unable to delete record with a priority of $priority since the template was not supplied",'error');
00071                 return FALSE;
00072         }
00073 
00074         $new_template_array = array();
00075         $i=0;
00076         foreach ($template_array as $priority => $record) {
00077                 if ($priority != $delete_priority) {
00078                         $new_template_array[$i] = $record;
00079                         $i++;
00080                 }
00081         }
00082 
00083         return $new_template_array;
00084 }
00085 
00099 function tripal_bulk_loader_delete_field($priority, $delete_field_index, $template_array) {
00100 
00101         if (empty($template_array)) {
00102                 drupal_set_message("Unable to delete record with a priority of $priority since the template was not supplied",'error');
00103                 return FALSE;
00104         }
00105 
00106         // Re-order the remaining fields of the same record to ensure that the indicies are
00107         // 0 to size and. If this is not done, weird behaviour may result
00108         $new_template_array = $template_array;
00109         $new_template_array[$priority]['fields'] = array();
00110         $i=0;
00111         foreach ($template_array[$priority]['fields'] as $field_index => $field_details) {
00112                 if ($field_index != $delete_field_index) {
00113                         $new_template_array[$priority]['fields'][$i] = $field_details;
00114                         $i++;
00115                 }
00116         }
00117 
00118         // If this field was the only one in the current record, also delete the record
00119         if (empty($new_template_array[$priority]['fields'])) {
00120                 $new_template_array = tripal_bulk_loader_delete_record($priority, $new_template_array);
00121         }
00122 
00123         return $new_template_array;
00124 }
 All Classes Files Functions Variables