You are here

function hosting_client_validate_suggest in Hosting 7.4

Same name and namespace in other branches
  1. 6.2 client/hosting_client.module \hosting_client_validate_suggest()
  2. 7.3 client/hosting_client.module \hosting_client_validate_suggest()

Helper for hosting_client_validate to suggest a new client name.

Parameters

string $name: The client name being validated.

bool $internal: Whether this is an internal client name.

Return value

string Suggested client name.

See also

hosting_client_validate()

1 call to hosting_client_validate_suggest()
hosting_client_validate in client/hosting_client.module
Implements hook_validate().

File

client/hosting_client.module, line 355

Code

function hosting_client_validate_suggest($name, $internal = FALSE) {
  $suggestion = FALSE;
  $table = $internal ? 'hosting_client' : 'node';
  $field = $internal ? 'uname' : 'title';
  $name = $internal ? hosting_client_sanitize($name) : $name;
  for ($i = 0; $i < 20; $i++) {

    // @todo convert this statement to DBTNG syntax.
    $nid = db_query("SELECT nid\n                     FROM {:table}\n                     WHERE uname\n                     LIKE '%:name%'\n                    ", array(
      ':table' => $table,
      ':field' => $field,
      ':name' => $name . $i,
    ))
      ->fetchField();
    if (!$nid) {
      return $name . $i;
    }
  }
}