/
User.php
75 lines (63 loc) · 2.26 KB
/
User.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace Concrete\Core\Export\Item;
use Concrete\Core\Attribute\Key\Category;
use Concrete\Core\Export\Item\ItemInterface;
use Concrete\Core\User\Group\Group;
use Concrete\Core\User\Group\GroupList;
use Concrete\Core\User\UserInfo;
defined('C5_EXECUTE') or die("Access Denied.");
class User implements ItemInterface
{
/**
* @param $user UserInfo
* @param \SimpleXMLElement $xml
* @return \SimpleXMLElement
*/
public function export($user, \SimpleXMLElement $xml)
{
$node = $xml->addChild('user');
// basic information
$node->addAttribute('username', $user->getUserName());
$node->addAttribute('email', $user->getUserEmail());
if (!$user->isActive()) {
$node->addAttribute('inactive', 1);
}
if (!$user->isValidated()) {
$node->addAttribute('unvalidated', 1);
}
if ($timezone = $user->getUserObject()->getUserTimezone()) {
$node->addAttribute('timezone', $timezone);
}
if ($language = $user->getUserDefaultLanguage()) {
$node->addAttribute('language', $language);
}
// attributes
$category = Category::getByHandle('user');
$attributes = $category->getController()->getAttributeValues($user->getEntityObject());
if (count($attributes) > 0) {
$child = $node->addChild('attributes');
foreach ($attributes as $av) {
$ak = $av->getAttributeKey();
$cnt = $ak->getController();
$cnt->setAttributeValue($av);
$attributeKey = $child->addChild('attributekey');
$attributeKey->addAttribute('handle', $ak->getAttributeKeyHandle());
$cnt->exportValue($attributeKey);
}
}
// groups
$list = new GroupList();
$list->filterByUserID($user->getUserID());
$groups = $list->getResults();
if (count($groups)) {
$child = $node->addChild('groups');
foreach($groups as $groupObject) {
$group = $child->addChild('group');
$group->addAttribute('path', $groupObject->getGroupPath());
}
}
unset($user);
unset($category);
return $node;
}
}