You are here

function scald_user in Scald: Media Management made easy 6

Implementation of hook_user().

File

./scald.module, line 2856

Code

function scald_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'delete':
      $aid = scald_uid_to_aid($account->uid);
      if ($aid) {
        scald_unregister_author($aid);
      }
      break;
    case 'load':

      // See scald_actions() for handling of defaults for scald_actions and an
      //  explanation of why such handling is not done here.
      break;
    case 'insert':
    case 'update':
      if (variable_get('scald_register_users_as_authors', TRUE)) {

        // All Drupal users need to registered as Scald Authors
        $aid = scald_uid_to_aid($account->uid);
        $author_data = array(
          'name' => $account->name,
          'uid' => $account->uid,
        );
        if ($aid) {
          scald_update_author($aid, $author_data);
        }
        else {
          scald_register_author($author_data);
        }
      }

      // Fetch action bitstring components by User Role and then combine in
      //  in preparation for saving to db.
      $edit['scald_actions'] = 0;
      $roles = isset($edit['roles']) ? $edit['roles'] : $account->roles;
      $roles += array(
        DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID,
      );
      $actions_results = db_query("\n        SELECT\n          actions\n        FROM\n          {scald_role_actions}\n        WHERE\n          rid IN (" . implode(', ', array_keys($roles)) . ")\n      ");
      while ($actions_raw = db_fetch_array($actions_results)) {
        $edit['scald_actions'] = $edit['scald_actions'] | $actions_raw['actions'];
      }
      break;
    case 'view':

      // @@@TODO: Display Scald Actions abilities to user?  Admin only?
      break;
    default:
      break;
  }
}