1 | <?php |
||
16 | class Export_UserService extends BaseApplicationComponent implements IExportElementType |
||
17 | { |
||
18 | /** |
||
19 | * Return export template. |
||
20 | * |
||
21 | * @return string |
||
22 | */ |
||
23 | 1 | public function getTemplate() |
|
27 | |||
28 | /** |
||
29 | * Get user groups. |
||
30 | * |
||
31 | * @return array|bool |
||
32 | */ |
||
33 | 2 | public function getGroups() |
|
49 | |||
50 | /** |
||
51 | * Return user fields. |
||
52 | * |
||
53 | * @param array $settings |
||
54 | * @param bool $reset |
||
55 | * |
||
56 | * @return array |
||
57 | */ |
||
58 | 2 | public function getFields(array $settings, $reset) |
|
59 | { |
||
60 | // Set criteria |
||
61 | 2 | $criteria = new \CDbCriteria(); |
|
62 | 2 | $criteria->condition = 'settings = :settings'; |
|
63 | 2 | $criteria->params = array( |
|
64 | 2 | ':settings' => JsonHelper::encode($settings), |
|
65 | ); |
||
66 | |||
67 | // Check if we have a map already |
||
68 | 2 | $stored = craft()->export->findMap($criteria); |
|
69 | |||
70 | 2 | if (!count($stored) || $reset) { |
|
71 | |||
72 | // Set the static fields for this type |
||
73 | $fields = array( |
||
74 | 1 | ExportModel::HandleId => array('name' => Craft::t('ID'), 'checked' => 0), |
|
75 | 1 | ExportModel::HandleUsername => array('name' => Craft::t('Username'), 'checked' => 1), |
|
76 | 1 | ExportModel::HandleFirstName => array('name' => Craft::t('First Name'), 'checked' => 1), |
|
77 | 1 | ExportModel::HandleLastName => array('name' => Craft::t('Last Name'), 'checked' => 1), |
|
78 | 1 | ExportModel::HandleEmail => array('name' => Craft::t('Email'), 'checked' => 1), |
|
79 | 1 | ExportModel::HandlePreferredLocale => array('name' => Craft::t('Preferred Locale'), 'checked' => 0), |
|
80 | 1 | ExportModel::HandleWeekStartDay => array('name' => Craft::t('Week Start Day'), 'checked' => 0), |
|
81 | 1 | ExportModel::HandleStatus => array('name' => Craft::t('Status'), 'checked' => 0), |
|
82 | 1 | ExportModel::HandleLastLoginDate => array('name' => Craft::t('Last Login Date'), 'checked' => 0), |
|
83 | 1 | ExportModel::HandleInvalidLoginCount => array('name' => Craft::t('Invalid Login Count'), 'checked' => 0), |
|
84 | 1 | ExportModel::HandleLastInvalidLoginDate => array('name' => Craft::t('Last Invalid Login Date'), 'checked' => 0), |
|
85 | 1 | ); |
|
86 | |||
87 | // Set the dynamic fields for this type |
||
88 | 1 | foreach (craft()->fields->getLayoutByType(ElementType::User)->getFields() as $field) { |
|
89 | 1 | $data = $field->getField(); |
|
90 | 1 | $fields[$data->handle] = array('name' => $data->name, 'checked' => 1, 'fieldtype' => $data->type); |
|
91 | 1 | } |
|
92 | 1 | } else { |
|
93 | |||
94 | // Get the stored map |
||
95 | 1 | $fields = $stored->map; |
|
96 | } |
||
97 | |||
98 | // Return fields |
||
99 | 2 | return $fields; |
|
100 | } |
||
101 | |||
102 | /** |
||
103 | * Set user criteria. |
||
104 | * |
||
105 | * @param array $settings |
||
106 | * |
||
107 | * @return ElementCriteriaModel |
||
108 | */ |
||
109 | 1 | public function setCriteria(array $settings) |
|
123 | |||
124 | /** |
||
125 | * Get user attributes. |
||
126 | * |
||
127 | * @param array $map |
||
128 | * @param BaseElementModel $element |
||
129 | * |
||
130 | * @return array |
||
131 | */ |
||
132 | 1 | public function getAttributes(array $map, BaseElementModel $element) |
|
152 | } |
||
153 |