public function setup($guid, $type, $subtype, array $attributes = [])
{
while (!isset($guid)) {
$this->iterator++;
if (!isset($this->row[$this->iterator])) {
$guid = $this->iterator;
}
}
if ($subtype) {
$subtype_id = get_subtype_id($type, $subtype);
if (!$subtype_id) {
$subtype_id = add_subtype($type, $subtype);
}
} else {
if (isset($attributes['subtype_id'])) {
$subtype_id = $attributes['subtype_id'];
$subtype = get_subtype_from_id($subtype_id);
}
}
$attributes['guid'] = $guid;
$attributes['type'] = $type;
$attributes['subtype'] = $subtype_id;
$time = $this->getCurrentTime()->getTimestamp();
$primary_attributes = array('owner_guid' => 0, 'container_guid' => 0, 'access_id' => ACCESS_PUBLIC, 'time_created' => $time, 'time_updated' => $time, 'last_action' => $time, 'enabled' => 'yes');
switch ($type) {
case 'object':
$external_attributes = ['title' => null, 'description' => null];
break;
case 'user':
$external_attributes = ['name' => "John Doe {$guid}", 'username' => "john_doe_{$guid}", 'password_hash' => null, 'email' => "john_doe_{$guid}@example.com", 'language' => 'en', 'banned' => "no", 'admin' => 'no', 'prev_last_action' => null, 'last_login' => null, 'prev_last_login' => null];
break;
case 'group':
$external_attributes = ['name' => null, 'description' => null];
break;
}
$map = array_merge($primary_attributes, $external_attributes, $attributes);
$attrs = (object) $map;
$this->rows[$guid] = $attrs;
$this->addQuerySpecs($attrs);
$entity = $this->rowToElggStar($this->rows[$guid]);
foreach ($attrs as $name => $value) {
if (!isset($entity->{$name}) || $entity->{$name} != $value) {
// not an attribute, so needs to be set again
$entity->{$name} = $value;
}
}
return $entity;
}