<commit_before><?php

namespace Etu\Core\UserBundle\Api\Transformer;

use Etu\Core\ApiBundle\Framework\Embed\EmbedBag;
use Etu\Core\ApiBundle\Framework\Transformer\AbstractTransformer;
use Etu\Core\UserBundle\Entity\User;

class UserTransformer extends AbstractTransformer
{
    /**
     * @var BadgeTransformer
     */
    protected $badgeTransformer;

    /**
     * @var KernelRootDir
     */
    protected $kernelRootDir;

    /**
     * @param BadgeTransformer $badgeTransformer
     * @param string           $kernelRootDir    path to app directory
     */
    public function __construct(BadgeTransformer $badgeTransformer, $kernelRootDir)
    {
        $this->badgeTransformer = $badgeTransformer;
        $this->kernelRootDir = $kernelRootDir;
    }

    /**
     * @param $user
     * @param EmbedBag $includes
     *
     * @return array
     */
    public function transformUnique($user, EmbedBag $includes)
    {
        return array_merge($this->getData($user), $this->getIncludes($user, $includes), $this->getLinks($user));
    }

    /**
     * @param User $user
     *
     * @return array
     */
    private function getData(User $user)
    {
        return [
            'login' => $user->getLogin(),
            'studentId' => $user->getStudentId(),
            'email' => $user->getMail(),
            'firstName' => $user->getFirstName(),
            'lastName' => $user->getLastName(),
            'fullName' => $user->getFullName(),
            'personalMail' => $user->getPersonnalMailPrivacy() == User::PRIVACY_PUBLIC ? $user->getPersonnalMail() : null,
            'phone' => $user->getPhoneNumberPrivacy() == User::PRIVACY_PUBLIC ? $user->getPhoneNumber() : null,
            'nationality' => $user->getNationalityPrivacy() == User::PRIVACY_PUBLIC ? $user->getNationality() : null,
            'address' => $user->getAddressPrivacy() == User::PRIVACY_PUBLIC ? $user->getAddress() : null,
            'postalCode' => $user->getPostalCodePrivacy() == User::PRIVACY_PUBLIC ? $user->getPostalCode() : null,
            'city' => $user->getCityPrivacy() == User::PRIVACY_PUBLIC ? $user->getCity() : null,
            'sex' => $user->getSexPrivacy() == User::PRIVACY_PUBLIC ? $user->getSex() : null,
            'branch' => $user->getBranch(),
            'level' => $user->getNiveau(),
            'speciality' => $user->getFiliere(),
            'surname' => $user->getSurnom(),
            'jadis' => $user->getJadis(),
            'passions' => $user->getPassions(),
            'birthday' => ($user->getBirthdayPrivacy() == User::PRIVACY_PUBLIC && $user->getBirthday()) ? $user->getBirthday()->format(\DateTime::ISO8601) : null,
            'website' => $user->getWebsite(),
            'facebook' => $user->getFacebook(),
            'twitter' => $user->getTwitter(),
            'linkedin' => $user->getLinkedin(),
            'viadeo' => $user->getViadeo(),
            'isStudent' => $user->getIsStudent(),
            'bdeMember' => $user->isBdeMember(),
            'bdeMembershipEnd' => $user->getBdeMembershipEnd(),
        ];
    }

    /**
     * @param User $user
     *
     * @return array
     */
    private function getLinks(User $user)
    {
        $links = [
            [
                'rel' => 'self',
                'uri' => '/api/public/users/'.$user->getLogin(),
            ],
            [
                'rel' => 'user.badges',
                'uri' => '/api/public/users/'.$user->getLogin().'/badges',
            ],
            [
                'rel' => 'user.image',
                'uri' => '/uploads/photos/'.$user->getAvatar(),
            ],
        ];<commit_msg>added ue list and country to public data<commit_after><?php

namespace Etu\Core\UserBundle\Api\Transformer;

use Etu\Core\ApiBundle\Framework\Embed\EmbedBag;
use Etu\Core\ApiBundle\Framework\Transformer\AbstractTransformer;
use Etu\Core\UserBundle\Entity\User;

class UserTransformer extends AbstractTransformer
{
    /**
     * @var BadgeTransformer
     */
    protected $badgeTransformer;

    /**
     * @var KernelRootDir
     */
    protected $kernelRootDir;

    /**
     * @param BadgeTransformer $badgeTransformer
     * @param string           $kernelRootDir    path to app directory
     */
    public function __construct(BadgeTransformer $badgeTransformer, $kernelRootDir)
    {
        $this->badgeTransformer = $badgeTransformer;
        $this->kernelRootDir = $kernelRootDir;
    }

    /**
     * @param $user
     * @param EmbedBag $includes
     *
     * @return array
     */
    public function transformUnique($user, EmbedBag $includes)
    {
        return array_merge($this->getData($user), $this->getIncludes($user, $includes), $this->getLinks($user));
    }

    /**
     * @param User $user
     *
     * @return array
     */
    private function getData(User $user)
    {
        return [
            'login' => $user->getLogin(),
            'studentId' => $user->getStudentId(),
            'email' => $user->getMail(),
            'firstName' => $user->getFirstName(),
            'lastName' => $user->getLastName(),
            'fullName' => $user->getFullName(),
            'personalMail' => $user->getPersonnalMailPrivacy() == User::PRIVACY_PUBLIC ? $user->getPersonnalMail() : null,
            'phone' => $user->getPhoneNumberPrivacy() == User::PRIVACY_PUBLIC ? $user->getPhoneNumber() : null,
            'nationality' => $user->getNationalityPrivacy() == User::PRIVACY_PUBLIC ? $user->getNationality() : null,
            'address' => $user->getAddressPrivacy() == User::PRIVACY_PUBLIC ? $user->getAddress() : null,
            'country' => $user->getCountryPrivacy() == User::PRIVACY_PUBLIC ? $user->getCountry() : null,
            'postalCode' => $user->getPostalCodePrivacy() == User::PRIVACY_PUBLIC ? $user->getPostalCode() : null,
            'city' => $user->getCityPrivacy() == User::PRIVACY_PUBLIC ? $user->getCity() : null,
            'sex' => $user->getSexPrivacy() == User::PRIVACY_PUBLIC ? $user->getSex() : null,
            'branch' => $user->getBranch(),
            'level' => $user->getNiveau(),
            'speciality' => $user->getFiliere(),
            'surname' => $user->getSurnom(),
            'jadis' => $user->getJadis(),
            'passions' => $user->getPassions(),
            'birthday' => ($user->getBirthdayPrivacy() == User::PRIVACY_PUBLIC && $user->getBirthday()) ? $user->getBirthday()->format(\DateTime::ISO8601) : null,
            'website' => $user->getWebsite(),
            'facebook' => $user->getFacebook(),
            'uvs' => $user->getUvsList(),
            'twitter' => $user->getTwitter(),
            'linkedin' => $user->getLinkedin(),
            'viadeo' => $user->getViadeo(),
            'isStudent' => $user->getIsStudent(),
            'bdeMember' => $user->isBdeMember(),
            'bdeMembershipEnd' => $user->getBdeMembershipEnd(),
        ];
    }

    /**
     * @param User $user
     *
     * @return array
     */
    private function getLinks(User $user)
    {
        $links = [
            [
                'rel' => 'self',
                'uri' => '/api/public/users/'.$user->getLogin(),
            ],
            [
                'rel' => 'user.badges',
                'uri' => '/api/public/users/'.$user->getLogin().'/badges',
            ],
            [
                'rel' => 'user.image',
                'uri' => '/uploads/photos/'.$user->getAvatar(),
            ],
        ];
{'fraction_non_alphanumeric': 0.17386042759177087, 'fraction_numerical': 0.0010757025682398816, 'mean_word_length': 2.232507605388961, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 168, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '529714', 'n_tokens_mistral': 2332, 'n_tokens_neox': 2291, 'n_words': 354}