You are here

function _photos_access_usersave in Album Photos 7.3

Same name and namespace in other branches
  1. 8.5 photos_access/photos_access.module \_photos_access_usersave()
  2. 8.4 photos_access/photos_access.module \_photos_access_usersave()
  3. 6.0.x photos_access/photos_access.module \_photos_access_usersave()

Save users to access album list.

1 call to _photos_access_usersave()
photos_access_update_access in photos_access/photos_access.module
Update access to album.

File

photos_access/photos_access.module, line 417

Code

function _photos_access_usersave($value, $id, $collaborate = TRUE) {
  $t = preg_split('/,|,/', $value);
  if ($t) {
    $values = array();
    foreach ($t as $a) {
      $a = trim($a);

      // Check {users}.name
      if ($u = _photos_access_user(array(
        'name' => $a,
      ))) {
        $values[] = array(
          'id' => $id,
          'uid' => $u->uid,
          'collaborate' => $collaborate ? 1 : 0,
        );
      }
    }
    if (isset($values[0])) {

      // Insert users into photos access table.
      $query = db_insert('photos_access_user')
        ->fields(array(
        'id',
        'uid',
        'collaborate',
      ));
      foreach ($values as $record) {
        $query
          ->values($record);
      }
      $query
        ->execute();
    }
  }
}