public function admincreateusers($user_data) { // Check that the user is not already on the system $users = new LoveUser(); $userlist = $users->getUserList(); $newUsers = array(); $returnUsers = array(); foreach ($user_data as $user) { if (!$this->searchMultiArray($userlist, 'username', $user['username'])) { $counter = 1; $user_nick = $user['nickname']; while ($this->searchMultiArray($userlist, 'nickname', $user['nickname'])) { $user['nickname'] = $user_nick . "+" . (string) $counter; $counter++; } $newUsers[] = $user; } else { // Check if the user was removed, and if so, readd him foreach ($userlist as $singleUser) { if ($singleUser['username'] == $user['username']) { if ($singleUser['removed'] == 1) { // Unset removed flag $user['removed'] = 0; $user_obj = new LoveUser(); $user_obj->loadByUsername($user['username']); $user_obj->setPassword($user['password']); $user_obj->setRemoved(0); $user_obj->save(); // And add it to the create list $returnUsers[] = array('uid' => $user_obj->id, 'user_data' => $user); } } } } } if (count($newUsers) > 0) { return array_merge($returnUsers, $users->insertUsers($newUsers)); } else { return $returnUsers; } }
/** * Get users from DB and compare it with the supplied * array, return the users that are present in both. */ function userCreationSucceded($newUsers = array()) { $user = new LoveUser(); $currentUsers = $user->getUserList(); $existingUsers = array(); $found = false; foreach ($newUsers as $newUser) { foreach ($currentUsers as $currentUser) { // If we can find the entry's username on the Db take it as the user exists if (searchMultiArray($currentUser, 'username', $newUser['username'])) { // Set the found flag as true $found = true; } } // If the user has not been found we add it if (!$found) { // Add it to the existing users array $existingUsers[] = $newUser; } } return $existingUsers; }