You are here

function scald_register_author in Scald: Media Management made easy 6

Register an Author with Scald Core.

Parameters

$data: A keyed array with the following possible keys: 'name', the full name; no first/last/etc. distinction. (required) 'uid', A Drupal User ID. (optional) 'url', A URL by which to find out more about the Author. (optional) NOTE: If this element is omitted for an array which has 'uid' set, the path 'user/<uid>' is assumed and supplied. Set 'url' to an empty string to avoid this behavior.

Return value

The Author ID upon success. FALSE upon failure

2 calls to scald_register_author()
scald_enable_batch in ./scald.install
Batch addition of all Users as Scald Authors.
scald_user in ./scald.module
Implementation of hook_user().

File

./scald.module, line 1668

Code

function scald_register_author($data = array()) {

  // Validate arguments
  if (empty($data) || empty($data['name'])) {
    return FALSE;
  }

  // Build SQL conditions
  $sets = array();
  $sql_data = array();
  foreach ($data as $field => $value) {
    switch ($field) {
      case 'name':
        $sets[] = 'name = \'%s\'';
        $sql_data[] = $value;
        break;

      // end 'name'
      case 'uid':
        $sets[] = 'uid = %d';
        $sql_data[] = $value;
        if (!isset($data['url'])) {
          $sets[] = 'url = \'' . url('user') . '/%d\'';
          $sql_data[] = $value;
        }
        break;

      // end 'uid'
      case 'url':
        $sets[] = 'url = \'%s\'';
        $sql_data[] = $value;
        break;

      // end 'url'
      default:
        continue;
    }
  }
  if (!db_query("\n      INSERT INTO\n        {scald_authors}\n      SET " . implode(', ', $sets), $sql_data)) {
    return FALSE;
  }
  return db_last_insert_id('scald_authors', 'aid');
}