Add IUser::getAvatarImage() for easy access
This commit is contained in:
parent
c91192fb73
commit
dad6470baa
|
@ -70,20 +70,25 @@ class SyncSystemAddressBook extends Command {
|
|||
$name = $user->getBackendClassName();
|
||||
$userId = $user->getUID();
|
||||
$displayName = $user->getDisplayName();
|
||||
//$emailAddress = $user->getEMailAddress();
|
||||
$image = $user->getAvatarImage(-1);
|
||||
|
||||
$cardId = "$name:$userId.vcf";
|
||||
$card = $this->backend->getCard($systemAddressBook['id'], $cardId);
|
||||
if ($card === false) {
|
||||
$vCard = new VCard();
|
||||
$vCard->add(new Text($vCard, 'UID', $user->getUID()));
|
||||
$vCard->add(new Text($vCard, 'UID', $userId));
|
||||
$vCard->add(new Text($vCard, 'FN', $displayName));
|
||||
// $vCard->add(new Text($vCard, 'EMAIL', $user->getEMailAddress()));
|
||||
//$vCard->add(new Binary($vCard, 'PHOTO', $user->getAvatar()));
|
||||
// $vCard->add(new Text($vCard, 'EMAIL', $emailAddress));
|
||||
if ($image) {
|
||||
$vCard->add('PHOTO', $image->data(), ['ENCODING' => 'b', 'TYPE' => $image->mimeType()]);
|
||||
}
|
||||
$vCard->validate();
|
||||
$this->backend->createCard($systemAddressBook['id'], $cardId, $vCard->serialize());
|
||||
} else {
|
||||
$updated = false;
|
||||
$vCard = Reader::read($card['carddata']);
|
||||
if($vCard->FN !== $user->getDisplayName()) {
|
||||
if($vCard->FN !== $displayName) {
|
||||
$vCard->FN = new Text($vCard, 'FN', $displayName);
|
||||
$updated = true;
|
||||
}
|
||||
|
|
|
@ -79,7 +79,9 @@ class Avatar implements \OCP\IAvatar {
|
|||
/** @var File $node */
|
||||
$node = $this->folder->get('avatar.' . $ext);
|
||||
$avatar->loadFromData($node->getContent());
|
||||
$avatar->resize($size);
|
||||
if ($size > 0) {
|
||||
$avatar->resize($size);
|
||||
}
|
||||
$this->folder->newFile('avatar.' . $size . '.' . $ext)->putContent($avatar->data());
|
||||
}
|
||||
return $avatar;
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
namespace OC\User;
|
||||
|
||||
use OC\Hooks\Emitter;
|
||||
use OCP\IAvatarManager;
|
||||
use OCP\IImage;
|
||||
use OCP\IUser;
|
||||
use OCP\IConfig;
|
||||
|
||||
|
@ -74,17 +76,21 @@ class User implements IUser {
|
|||
*/
|
||||
private $config;
|
||||
|
||||
/** @var IAvatarManager */
|
||||
private $avatarManager;
|
||||
|
||||
/**
|
||||
* @param string $uid
|
||||
* @param \OC_User_Interface $backend
|
||||
* @param \OC\Hooks\Emitter $emitter
|
||||
* @param \OCP\IConfig $config
|
||||
*/
|
||||
public function __construct($uid, $backend, $emitter = null, IConfig $config = null) {
|
||||
public function __construct($uid, $backend, $emitter = null, IConfig $config = null, $avatarManager = null) {
|
||||
$this->uid = $uid;
|
||||
$this->backend = $backend;
|
||||
$this->emitter = $emitter;
|
||||
$this->config = $config;
|
||||
$this->avatarManager = $avatarManager;
|
||||
if ($this->config) {
|
||||
$enabled = $this->config->getUserValue($uid, 'core', 'enabled', 'true');
|
||||
$this->enabled = ($enabled === 'true');
|
||||
|
@ -93,6 +99,9 @@ class User implements IUser {
|
|||
$this->enabled = true;
|
||||
$this->lastLogin = \OC::$server->getConfig()->getUserValue($uid, 'login', 'lastLogin', 0);
|
||||
}
|
||||
if (is_null($this->avatarManager)) {
|
||||
$this->avatarManager = \OC::$server->getAvatarManager();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -316,4 +325,21 @@ class User implements IUser {
|
|||
public function getEMailAddress() {
|
||||
return $this->config->getUserValue($this->uid, 'settings', 'email');
|
||||
}
|
||||
|
||||
/**
|
||||
* get the avatar image if it exists
|
||||
*
|
||||
* @param int $size
|
||||
* @return IImage|null
|
||||
* @since 9.0.0
|
||||
*/
|
||||
public function getAvatarImage($size) {
|
||||
$avatar = $this->avatarManager->getAvatar($this->uid);
|
||||
$image = $avatar->get(-1);
|
||||
if ($image) {
|
||||
return $image;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -152,4 +152,13 @@ interface IUser {
|
|||
* @since 9.0.0
|
||||
*/
|
||||
public function getEMailAddress();
|
||||
|
||||
/**
|
||||
* get the avatar image if it exists
|
||||
*
|
||||
* @param int $size
|
||||
* @return IImage|null
|
||||
* @since 9.0.0
|
||||
*/
|
||||
public function getAvatarImage($size);
|
||||
}
|
||||
|
|
|
@ -98,6 +98,8 @@ class SimpleUserForTesting implements IUser {
|
|||
}
|
||||
|
||||
public function getEMailAddress() {
|
||||
// TODO: Implement getEMailAddress() method.
|
||||
}
|
||||
|
||||
public function getAvatarImage($size) {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue