/** * Import userdata from a csv file and update crowd * * Structure has to similiar to this: * * username;neos_googleplus;neos_email;neos_twitter;... * xyz;xyz;xyz@example.org;@xyz;... * ... * * "username" is the only required field and has to contain the usernames from crowd. * The other columns are optional and only the ones which match the "additionalAttributes" in the * Settings.yaml are read. * * @param string $csvPath the path to a csv file with userdata */ public function importUserAttributesCommand($csvPath, $delimiter = ';') { $validAttributes = $this->settings['additionalAttributes']['user']; $validAttributes[] = 'username'; $columns = []; $fieldCount = 0; if (($handle = fopen($csvPath, "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE) { // First line are the column headers if (empty($columns)) { $columns = $data; $fieldCount = count($columns); echo "Columns: " . join(', ', $columns) . "\n"; } $attributes = []; for ($i = 0; $i < $fieldCount; $i++) { $columnName = $columns[$i]; if (in_array($columnName, $validAttributes)) { $attributes[$columnName] = $data[$i]; } } echo "Updating data: " . join(', ', $data) . "\n"; $this->crowdApiConnector->setUserAttributes($attributes['username'], $attributes); } fclose($handle); } }
/** * @param FlowQuery $flowQuery the FlowQuery object * @param array $arguments the arguments for this operation * @return void */ public function evaluate(FlowQuery $flowQuery, array $arguments) { $user = false; if (count($arguments) > 0 && is_string($arguments[0])) { $user = $this->apiConnector->fetchUser($arguments[0]); } if ($user) { $groups = $this->apiConnector->fetchGroups(); $user['memberships'] = array_filter($groups, function ($group) use($user) { return in_array($user['name'], $group['members']) && isset($group['neos_group_type']) && !empty($group['neos_group_type']); }); $user['additionalProperties'] = array_filter($user, function ($key) { return strpos($key, 'neos_') === 0; }, ARRAY_FILTER_USE_KEY); } $flowQuery->setContext($user); }
/** * @param FlowQuery $flowQuery the FlowQuery object * @param array $arguments the arguments for this operation * @return void */ public function evaluate(FlowQuery $flowQuery, array $arguments) { $groups = $this->apiConnector->fetchGroups(); $flowQuery->setContext($groups); }