function tripal_is_bulk_loader_record_name_unique

2.x tripal_bulk_loader.api.templates.inc tripal_is_bulk_loader_record_name_unique($new_record_name, $template_id, $template_array = NULL, $current_priority = NULL)

Meant to be called from a form_validate function to ensure a newly added bulk loader record name is unique and not empty.

Parameters

$new_record_name: The record name to check for uniqueness

$template_id: The template_id of the template to add the record to

$template_array: The array describing the template. Optional -will be loaded using template_id if not provided

$current_priority: The priority of the already existing record -checks that the name only occurs on this particular record

Return value

TRUE if the record name is not empty and not already in the template_array; FALSE otherwise

Related topics

3 calls to tripal_is_bulk_loader_record_name_unique()
1 string reference to 'tripal_is_bulk_loader_record_name_unique'

File

tripal_bulk_loader/api/tripal_bulk_loader.api.templates.inc, line 198
Provides functions for hooking into bulk loader functionality.

Code

function tripal_is_bulk_loader_record_name_unique($new_record_name, $template_id, $template_array = NULL, $current_priority = NULL) {

  // get the template array if it's not supplied
  if (empty($template_array)) {
    $template = db_query("SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=:template", array(':template' => $template_id))->fetchObject();
    $template_array = unserialize($template->template_array);
    if (!is_array($template_array)) {
      return TRUE;
    }
  }

  // Check that the new record name is not empty
  if (empty($new_record_name)) {
    return FALSE;
  }

  // Check the new record name is unique
  foreach ($template_array as $priority => $t) {
    if (strcmp($t['record_id'], $new_record_name) == 0) {
      if (($priority != $current_priority) AND ($current_priority !== NULL)) {
        return FALSE;
      }
    }
  }
  return TRUE;
}