diff --git a/main/inc/lib/formvalidator/Element/InputUser.php b/main/inc/lib/formvalidator/Element/InputUser.php index 87bc39d75f..b35513050d 100644 --- a/main/inc/lib/formvalidator/Element/InputUser.php +++ b/main/inc/lib/formvalidator/Element/InputUser.php @@ -1,56 +1,72 @@ user = $user; - $this->imageSize = 'small'; - $this->subTitle = null; - if (isset($attributes['image_size'])) { $this->imageSize = $attributes['image_size']; unset($attributes['image_size']); } + if (isset($attributes['sub_title'])) { + $this->subTitle = $attributes['sub_title']; + unset($attributes['sub_title']); + } + parent::__construct($name, $label, $attributes); $this->setType('hidden'); + } - if ($this->user) { - $this->subTitle = $this->user->getUsername(); - $this->setValue($this->user->getId()); - } + /** + * @inheritDoc + */ + public function setValue($value) + { + $this->user = !is_a($value, 'Chamilo\UserBundle\Entity\User') + ? UserManager::getManager()->find($value) + : $value; - if (isset($attributes['sub_title'])) { - $this->subTitle = $attributes['sub_title']; - unset($attributes['sub_title']); - } + parent::setValue($this->user->getId()); } public function toHtml() { + if (!$this->user) { + return ''; + } + + $userInfo = api_get_user_info($this->user->getId()); + $userPicture = isset($userInfo["avatar_{$this->imageSize}"]) + ? $userInfo["avatar_{$this->imageSize}"] + : $userInfo["avatar"]; + + if (!$this->subTitle) { + $this->subTitle = $this->user->getUsername(); + } + $html = parent::toHtml(); $html .= '