/** Update record based on updated aMember record * automatically fills fields from the @see getFieldsMapping() */ function refreshFromAmember(Am_Record $record, User $user, $groups) { foreach ($this->getFieldsMapping() as $a) { list($k, $v) = $a; // Do not update field if it is primary key for record. // Some plugins like drupal will set primary key on their own. if ($v == $this->_key) { continue; } switch ($k) { case self::FIELD_PASS: case self::FIELD_SALT: case self::FIELD_ADDED_SQL: case self::FIELD_ADDED_STAMP: break; case self::FIELD_NAME: $record->set($v, $user->getName()); break; case self::FIELD_LOGIN: case self::FIELD_EMAIL: $record->set($v, $user->get($k)); break; default: if (is_callable($k)) { $val = call_user_func($k, $user, $record, $this); } elseif ($k[0] == ':') { break; } elseif ($k[0] == '!') { $val = eval(substr($k, 1)); } elseif ($k[0] != '_') { $val = $user->get($k); } else { break; } $record->set($v, is_null($val) ? "" : $val); } } }
function end($tag, $attributes, $cdata) { if (!$this->table) { return; } switch ($tag) { case 'row': if ($this->record && !$this->record->isLoaded()) { $exist = false; if ($fields = $this->record->getTable()->_checkUnique) { $where = array(); foreach ($fields as $f) { $where[$f] = isset($this->record->{$f}) ? $this->record->{$f} : null; } $records = $this->record->getTable()->findBy($where); $exist = (bool) count($records); } if (!$exist) { $this->record->insert(); } } $this->record = null; break; case 'field': if (!empty($this->record)) { $this->record->set($attributes['name'], $cdata); } break; } }
/** Update record based on updated aMember record * automatically fills fields from the @see getFieldsMapping() */ function refreshFromAmember(Am_Record $record, User $user, $groups) { foreach ($this->getFieldsMapping() as $a) { list($k, $v) = $a; switch ($k) { case self::FIELD_LOGIN: case self::FIELD_EMAIL: $record->set($v, $user->get($k)); break; } } }