summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2017-05-16 02:46:42 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2017-06-23 12:36:37 +0200
commit045f652ef2844e3917b4ae7f3bbb5abb3422d02b (patch)
treebc4dc49e5d83d7f2bd7220f55db6fa7b498df686 /lib
parent039ee7e3aa33284999526a15231ddd0b676c81bd (diff)
downloadnextcloud-server-045f652ef2844e3917b4ae7f3bbb5abb3422d02b.tar.gz
nextcloud-server-045f652ef2844e3917b4ae7f3bbb5abb3422d02b.zip
completing PersonalInfo
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Server.php7
-rw-r--r--lib/private/Settings/Manager.php26
-rw-r--r--lib/private/Settings/Mapper.php8
-rw-r--r--lib/private/Settings/Personal/PersonalInfo.php149
4 files changed, 182 insertions, 8 deletions
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 489683aa127..262f9f00a71 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -42,6 +42,7 @@
namespace OC;
use bantu\IniGetWrapper\IniGetWrapper;
+use OC\Accounts\AccountManager;
use OC\App\AppManager;
use OC\App\AppStore\Bundles\BundleFetcher;
use OC\App\AppStore\Fetcher\AppFetcher;
@@ -970,7 +971,11 @@ class Server extends ServerContainer implements IServerContainer {
$c->getLockingProvider(),
$c->getRequest(),
new \OC\Settings\Mapper($c->getDatabaseConnection()),
- $c->getURLGenerator()
+ $c->getURLGenerator(),
+ $c->query(AccountManager::class),
+ $c->getGroupManager(),
+ $c->getL10NFactory(),
+ $c->getThemingDefaults()
);
return $manager;
});
diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php
index a307261c83f..d6b3398d0fc 100644
--- a/lib/private/Settings/Manager.php
+++ b/lib/private/Settings/Manager.php
@@ -23,15 +23,18 @@
namespace OC\Settings;
+use OC\Accounts\AccountManager;
use OCP\AppFramework\QueryException;
use OCP\Encryption\IManager as EncryptionManager;
use OCP\IConfig;
use OCP\IDBConnection;
+use OCP\IGroupManager;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserManager;
+use OCP\L10N\IFactory;
use OCP\Lock\ILockingProvider;
use OCP\Settings\ISettings;
use OCP\Settings\IManager;
@@ -61,6 +64,14 @@ class Manager implements IManager {
private $request;
/** @var IURLGenerator */
private $url;
+ /** @var AccountManager */
+ private $accountManager;
+ /** @var IGroupManager */
+ private $groupManager;
+ /** @var IFactory */
+ private $l10nFactory;
+ /** @var \OC_Defaults */
+ private $defaults;
/**
* @param ILogger $log
@@ -73,6 +84,9 @@ class Manager implements IManager {
* @param IRequest $request
* @param Mapper $mapper
* @param IURLGenerator $url
+ * @param AccountManager $accountManager
+ * @param IGroupManager $groupManager
+ * @param IFactory $l10nFactory
*/
public function __construct(
ILogger $log,
@@ -84,7 +98,11 @@ class Manager implements IManager {
ILockingProvider $lockingProvider,
IRequest $request,
Mapper $mapper,
- IURLGenerator $url
+ IURLGenerator $url,
+ AccountManager $accountManager,
+ IGroupManager $groupManager,
+ IFactory $l10nFactory,
+ \OC_Defaults $defaults
) {
$this->log = $log;
$this->dbc = $dbc;
@@ -96,6 +114,10 @@ class Manager implements IManager {
$this->lockingProvider = $lockingProvider;
$this->request = $request;
$this->url = $url;
+ $this->accountManager = $accountManager;
+ $this->groupManager = $groupManager;
+ $this->l10nFactory = $l10nFactory;
+ $this->defaults = $defaults;
}
/**
@@ -346,7 +368,7 @@ class Manager implements IManager {
try {
if ($section === 'personal-info') {
/** @var ISettings $form */
- $form = new Personal\PersonalInfo();
+ $form = new Personal\PersonalInfo($this->config, $this->userManager, $this->groupManager, $this->accountManager, $this->l10nFactory, $this->defaults);
$forms[$form->getPriority()] = [$form];
}
} catch (QueryException $e) {
diff --git a/lib/private/Settings/Mapper.php b/lib/private/Settings/Mapper.php
index 2525f2c9854..7dea1fe3d81 100644
--- a/lib/private/Settings/Mapper.php
+++ b/lib/private/Settings/Mapper.php
@@ -143,10 +143,10 @@ class Mapper {
}
/**
- * @param $table Mapper::TABLE_ADMIN_SECTIONS or Mapper::TABLE_ADMIN_SETTINGS
- * @param $idCol
- * @param $id
- * @param $values
+ * @param string $table Mapper::TABLE_ADMIN_SECTIONS or Mapper::TABLE_ADMIN_SETTINGS
+ * @param string $idCol
+ * @param string $id
+ * @param array $values
*/
public function update($table, $idCol, $id, $values) {
$query = $this->dbc->getQueryBuilder();
diff --git a/lib/private/Settings/Personal/PersonalInfo.php b/lib/private/Settings/Personal/PersonalInfo.php
index 6815b7390b6..c1b2e8acc70 100644
--- a/lib/private/Settings/Personal/PersonalInfo.php
+++ b/lib/private/Settings/Personal/PersonalInfo.php
@@ -24,17 +24,108 @@
namespace OC\Settings\Personal;
+use OC\Accounts\AccountManager;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IConfig;
+use OCP\IGroupManager;
+use OCP\IUser;
+use OCP\IUserManager;
+use OCP\L10N\IFactory;
use OCP\Settings\ISettings;
class PersonalInfo implements ISettings {
+ /** @var IConfig */
+ private $config;
+ /** @var IUserManager */
+ private $userManager;
+ /** @var AccountManager */
+ private $accountManager;
+ /** @var IGroupManager */
+ private $groupManager;
+ /** @var IFactory */
+ private $l10nFactory;
+
+ const COMMON_LANGUAGE_CODES = [
+ 'en', 'es', 'fr', 'de', 'de_DE', 'ja', 'ar', 'ru', 'nl', 'it',
+ 'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko'
+ ];
+ /** @var \OC_Defaults */
+ private $defaults;
+
+ /**
+ * @param IConfig $config
+ * @param IUserManager $userManager
+ * @param IGroupManager $groupManager
+ * @param AccountManager $accountManager
+ * @param IFactory $l10nFactory
+ */
+ public function __construct(
+ IConfig $config,
+ IUserManager $userManager,
+ IGroupManager $groupManager,
+ AccountManager $accountManager,
+ IFactory $l10nFactory,
+ \OC_Defaults $defaults
+ ) {
+ $this->config = $config;
+ $this->userManager = $userManager;
+ $this->accountManager = $accountManager;
+ $this->groupManager = $groupManager;
+ $this->l10nFactory = $l10nFactory;
+ $this->defaults = $defaults;
+ }
/**
* @return TemplateResponse returns the instance with all parameters set, ready to be rendered
* @since 9.1
*/
public function getForm() {
- return new TemplateResponse('settings', 'settings/personal/personal.info');
+ $lookupServerUploadEnabled = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes');
+ $lookupServerUploadEnabled = $lookupServerUploadEnabled === 'yes';
+
+ $uid = \OC_User::getUser();
+ $user = $this->userManager->get($uid);
+
+ $userData = $this->accountManager->getUser($user);
+ list($activeLanguage, $commonLanguages, $languages) = $this->getLanguages($user);
+
+ //links to clients
+ $clients = [
+ 'desktop' => $this->config->getSystemValue('customclient_desktop', $this->defaults->getSyncClientUrl()),
+ 'android' => $this->config->getSystemValue('customclient_android', $this->defaults->getAndroidClientUrl()),
+ 'ios' => $this->config->getSystemValue('customclient_ios', $this->defaults->getiOSClientUrl())
+ ];
+
+ $parameters = [
+ 'avatarChangeSupported' => \OC_User::canUserChangeAvatar($uid),
+ 'lookupServerUploadEnabled' => $lookupServerUploadEnabled,
+ 'avatar_scope' => $userData[AccountManager::PROPERTY_AVATAR]['scope'],
+ 'displayNameChangeSupported' => \OC_User::canUserChangeDisplayName($uid),
+ 'displayName' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'],
+ 'email' => $userData[AccountManager::PROPERTY_EMAIL]['value'],
+ 'emailScope' => $userData[AccountManager::PROPERTY_EMAIL]['scope'],
+ 'emailMesage' => '',
+ 'emailVerification' => $userData[AccountManager::PROPERTY_EMAIL]['verified'],
+ 'phone' => $userData[AccountManager::PROPERTY_PHONE]['value'],
+ 'phoneScope' => $userData[AccountManager::PROPERTY_PHONE]['scope'],
+ 'address', $userData[AccountManager::PROPERTY_ADDRESS]['value'],
+ 'addressScope', $userData[AccountManager::PROPERTY_ADDRESS]['scope'],
+ 'website' => $userData[AccountManager::PROPERTY_WEBSITE]['value'],
+ 'websiteScope' => $userData[AccountManager::PROPERTY_WEBSITE]['scope'],
+ 'websiteVerification' => $userData[AccountManager::PROPERTY_WEBSITE]['verified'],
+ 'twitter' => $userData[AccountManager::PROPERTY_TWITTER]['value'],
+ 'twitterScope' => $userData[AccountManager::PROPERTY_TWITTER]['scope'],
+ 'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'],
+ 'groups' => $this->groupManager->getUserGroups($user),
+ 'passwordChangeSupported' => \OC_User::canUserChangePassword($uid),
+ 'activelanguage' => $activeLanguage,
+ 'commonlanguages' => $commonLanguages,
+ 'languages' => $languages,
+ 'clients' => $clients,
+ ];
+
+
+ return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, '');
}
/**
@@ -56,4 +147,60 @@ class PersonalInfo implements ISettings {
public function getPriority() {
return 10;
}
+
+ private function getLanguages(IUser $user) {
+ $uid = $user->getUID();
+
+ $commonLanguages = [];
+ $userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage());
+ $languageCodes = $this->l10nFactory->findAvailableLanguages();
+ foreach($languageCodes as $lang) {
+ $l = \OC::$server->getL10N('settings', $lang);
+ // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version
+ $potentialName = (string) $l->t('__language_name__');
+ if($l->getLanguageCode() === $lang && substr($potentialName, 0, 1) !== '_') {//first check if the language name is in the translation file
+ $ln = array('code' => $lang, 'name' => $potentialName);
+ } elseif ($lang === 'en') {
+ $ln = ['code' => $lang, 'name' => 'English (US)'];
+ }else{//fallback to language code
+ $ln=array('code'=>$lang, 'name'=>$lang);
+ }
+
+ // put appropriate languages into appropriate arrays, to print them sorted
+ // used language -> common languages -> divider -> other languages
+ if ($lang === $userLang) {
+ $userLang = $ln;
+ } elseif (in_array($lang, self::COMMON_LANGUAGE_CODES)) {
+ $commonLanguages[array_search($lang, self::COMMON_LANGUAGE_CODES)]=$ln;
+ } else {
+ $languages[]=$ln;
+ }
+ }
+
+ // if user language is not available but set somehow: show the actual code as name
+ if (!is_array($userLang)) {
+ $userLang = [
+ 'code' => $userLang,
+ 'name' => $userLang,
+ ];
+ }
+
+ ksort($commonLanguages);
+
+ // sort now by displayed language not the iso-code
+ usort( $languages, function ($a, $b) {
+ if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) {
+ // If a doesn't have a name, but b does, list b before a
+ return 1;
+ }
+ if ($a['code'] !== $a['name'] && $b['code'] === $b['name']) {
+ // If a does have a name, but b doesn't, list a before b
+ return -1;
+ }
+ // Otherwise compare the names
+ return strcmp($a['name'], $b['name']);
+ });
+
+ return [$userLang, $commonLanguages, $languages];
+ }
}