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 .= '
- ' . $this->user->getCompleteName() . ' + '.$this->user->getCompleteName().'
-

' . $this->user->getCompleteName() . '

- ' . $this->subTitle . ' +

'.$this->user->getCompleteName().'

+ '.$this->subTitle.'
'; return $html; } -} \ No newline at end of file +} diff --git a/main/inc/lib/formvalidator/FormValidator.class.php b/main/inc/lib/formvalidator/FormValidator.class.php index 7bbd43a218..52eead3af7 100755 --- a/main/inc/lib/formvalidator/FormValidator.class.php +++ b/main/inc/lib/formvalidator/FormValidator.class.php @@ -1751,6 +1751,21 @@ EOT; } } } + + /** + * Add a \InputUser element to the form. + * It needs a Chamilo\UserBundle\Entity\User as value. + * The exported value is the Chamilo\UserBundle\Entity\User ID + * @param string $name + * @param string $label + * @param string $imageSize Optional. Small, medium or large image + * @param string $subtitle Optional. The subtitle for the field + * @return \InputUser + */ + public function addInputUser($name, $label, $imageSize = 'small', $subtitle = '') + { + return $this->addElement('InputUser', $name, $label, ['image_size' => $imageSize, 'sub_title' => $subtitle]); + } } /**