You are here

function _avatar_selection_save_avatar_info in Avatar Selection 5.2

Same name and namespace in other branches
  1. 5 avatar_selection.module \_avatar_selection_save_avatar_info()
  2. 6 avatar_selection.admin.inc \_avatar_selection_save_avatar_info()
  3. 7 avatar_selection.admin.inc \_avatar_selection_save_avatar_info()

Create the SQL queries in order to save the avatar path and data into the database, and perform them according to the SQL server type.

Parameters

$aid: The avatar id.

$image: The avatar image.

$name: The avatar name, used as the image alternative text on the forms.

$access: Array of roles - the value determines which user roles have rights to see the avatar.

$og: Array of organic groups (optional).

$weight: The weight of the avatar. Lower weighted avatars appear before higher weighted avatars in the list.

3 calls to _avatar_selection_save_avatar_info()
avatar_selection_edit_form_submit in ./avatar_selection.module
Submit the image list form in the Avatar Selection - 'Manage Avatars' page.
avatar_selection_upload_form_submit in ./avatar_selection.module
Submit the image upload form in the Avatar Selection administration page.
_avatar_selection_scan_images in ./avatar_selection.module
Scan the directory for new files.

File

./avatar_selection.module, line 1173
The Avatar Selection module allows the user to pick an avatar image from a list already loaded by an administrative user, and to the administrator to disable uploading other avatar files by the user.

Code

function _avatar_selection_save_avatar_info($aid, $image, $name, $access, $og = array(), $weight = 0) {

  // Add or update avatar_selection table.
  if ($aid) {
    $result = db_query("UPDATE {avatar_selection} SET name = '%s', weight = %d WHERE aid = %d AND avatar = '%s'", $name, $weight, $aid, $image);
    $result = db_query("DELETE FROM {avatar_selection_roles} WHERE aid = %d", $aid);
    $result = db_query("DELETE FROM {avatar_selection_og} WHERE aid = %d", $aid);
  }
  else {
    $aid = db_next_id("{avatar_selection}_aid");
    $result = db_query("INSERT INTO {avatar_selection} (aid, avatar, name, weight) VALUES(%d, '%s', '%s', %d)", $aid, $image, $name, $weight);
  }

  // Add access settings.
  if (is_array($access) && count($access)) {
    foreach ($access as $rid) {
      $result = db_query("INSERT INTO {avatar_selection_roles} (aid, rid) VALUES(%d, %d)", $aid, $rid);
    }
  }
  if (is_array($og) && count($og)) {
    foreach ($og as $ogid) {
      $result = db_query("INSERT INTO {avatar_selection_og} (aid, ogid) VALUES(%d, %d)", $aid, $ogid);
    }
  }
}