<commit_before><?php
/**
 * Litus is a project by a group of students from the KU Leuven. The goal is to create
 * various applications to support the IT needs of student unions.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 *
 * @license http://litus.cc/LICENSE
 */

namespace BrBundle\Component\Document\Generator\Pdf;

use BrBundle\Entity\Cv\Entry,
    BrBundle\Entity\Cv\Util,
    CommonBundle\Component\Util\File\TmpFile,
    CommonBundle\Component\Util\Xml\Generator,
    CommonBundle\Component\Util\Xml\Object,
    CommonBundle\Entity\General\AcademicYear,
    Doctrine\ORM\EntityManager,
    Zend\Mvc\I18n\Translator;

/**
 * Generates the CV Book for one academic year.
 *
 * @author <NAME> <<EMAIL>>
 */
class CvBook extends \CommonBundle\Component\Document\Generator\Pdf
{
    /**
     * @var AcademicYear
     */
    private $year;

    /**
     * @var Translator
     */
    private $translator;

    /**
     * @param EntityManager $entityManager The EntityManager instance
     * @param AcademicYear  $year          The academic year for which to generate the book.
     * @param TmpFile       $file          The file to write to
     * @param Translator    $translator    The translator
     */
    public function __construct(EntityManager $entityManager, AcademicYear $year, TmpFile $file, Translator $translator)
    {
        $filePath = $entityManager
            ->getRepository('CommonBundle\Entity\General\Config')
            ->getConfigValue('br.pdf_generator_path');

        parent::__construct(
            $entityManager,
            $filePath . '/cv/cvbook.xsl',
            $file->getFilename()
        );

        $this->year = $year;
        $this->translator = $translator;
    }

    protected function generateXml(TmpFile $tmpFile)
    {
        $xml = new Generator($tmpFile);

        $data = Util::getGrouped($this->getEntityManager(), $this->year);

        $groups = array();

        foreach ($data as $studyData) {
            $groups[] = $this->generateGroup($studyData['name'], $studyData['entries']);
        }

        $organization_logo = $this->getEntityManager()
            ->getRepository('CommonBundle\Entity\General\Config')
            ->getConfigValue('organization_logo');

        $foreword = $this->getEntityManager()
            ->getRepository('CommonBundle\Entity\General\Config')
            ->getConfigValue('br.cv_book_foreword');

        $xml->append(
            new Object(
                'cvbook',
                array(
                    'logo' => $organization_logo,
                    'index' => $this->translator->translate('Alphabetical Index'),
                    'toc' => $this->translator->translate('Table of Contents'),
                ),
                array(
                    new Object(
                        'foreword',
                        array(
                            'title' => $this->translator->translate('Foreword'),
                        ),
                        Object::fromString($foreword)
                    ),
                    new Object(
                        'cvs',
                        null,
                        $groups
                    ),
                )
            )
        );
    }

    private function generateGroup($groupName, $entries)
    {
        $cvs = array();
        foreach ($entries as $entry) {
            $cvs[] = $this->generateCv($entry);
        }

        return new Object(
            'cvgroup',
            array(
                'name' => $groupName,
            ),
            $cvs
        );
    }

    private function generateCv(Entry $cv)
    {
        $picturePath = 'public' . $this->getEntityManager()
            ->getRepository('CommonBundle\Entity\General\Config')
            ->getConfigValue('common.profile_path');

        return new Object(
            'cv',
            array(
                'id'        => $cv->getId(),
                'firstname' => $cv->getFirstName(),
                'lastname'  => $cv->getLastName(),
                'birthday'  => $cv->getBirthDay()->format('d/m/Y'),
                'email'     => $cv->getEmail(),
                'phone'     => $cv->getPhoneNumber(),
                'img'       => $picturePath . '/' . $cv->getAcademic()->getPhotoPath(),
            ),
            $this->getSections($cv)
        );
    }

    private function getSections(Entry $cv)
    {
        $result = array();

        $result[] = new Object(
            'address',<commit_msg>update the CvBook: new date and GSM format<commit_after><?php
/**
 * Litus is a project by a group of students from the KU Leuven. The goal is to create
 * various applications to support the IT needs of student unions.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 *
 * @license http://litus.cc/LICENSE
 */

namespace BrBundle\Component\Document\Generator\Pdf;

use BrBundle\Entity\Cv\Entry,
    BrBundle\Entity\Cv\Util,
    CommonBundle\Component\Util\File\TmpFile,
    CommonBundle\Component\Util\Xml\Generator,
    CommonBundle\Component\Util\Xml\Object,
    CommonBundle\Entity\General\AcademicYear,
    Doctrine\ORM\EntityManager,
    Zend\Mvc\I18n\Translator;

/**
 * Generates the CV Book for one academic year.
 *
 * @author <NAME> <<EMAIL>>
 */
class CvBook extends \CommonBundle\Component\Document\Generator\Pdf
{
    /**
     * @var AcademicYear
     */
    private $year;

    /**
     * @var Translator
     */
    private $translator;

    /**
     * @param EntityManager $entityManager The EntityManager instance
     * @param AcademicYear  $year          The academic year for which to generate the book.
     * @param TmpFile       $file          The file to write to
     * @param Translator    $translator    The translator
     */
    public function __construct(EntityManager $entityManager, AcademicYear $year, TmpFile $file, Translator $translator)
    {
        $filePath = $entityManager
            ->getRepository('CommonBundle\Entity\General\Config')
            ->getConfigValue('br.pdf_generator_path');

        parent::__construct(
            $entityManager,
            $filePath . '/cv/cvbook.xsl',
            $file->getFilename()
        );

        $this->year = $year;
        $this->translator = $translator;
    }

    protected function generateXml(TmpFile $tmpFile)
    {
        $xml = new Generator($tmpFile);

        $data = Util::getGrouped($this->getEntityManager(), $this->year);

        $groups = array();

        foreach ($data as $studyData) {
            $groups[] = $this->generateGroup($studyData['name'], $studyData['entries']);
        }

        $organization_logo = $this->getEntityManager()
            ->getRepository('CommonBundle\Entity\General\Config')
            ->getConfigValue('organization_logo');

        $foreword = $this->getEntityManager()
            ->getRepository('CommonBundle\Entity\General\Config')
            ->getConfigValue('br.cv_book_foreword');

        $xml->append(
            new Object(
                'cvbook',
                array(
                    'logo' => $organization_logo,
                    'index' => $this->translator->translate('Alphabetical Index'),
                    'toc' => $this->translator->translate('Table of Contents'),
                ),
                array(
                    new Object(
                        'foreword',
                        array(
                            'title' => $this->translator->translate('Foreword'),
                        ),
                        Object::fromString($foreword)
                    ),
                    new Object(
                        'cvs',
                        null,
                        $groups
                    ),
                )
            )
        );
    }

    private function generateGroup($groupName, $entries)
    {
        $cvs = array();
        foreach ($entries as $entry) {
            $cvs[] = $this->generateCv($entry);
        }

        return new Object(
            'cvgroup',
            array(
                'name' => $groupName,
            ),
            $cvs
        );
    }

    private function generateCv(Entry $cv)
    {
        $picturePath = 'public' . $this->getEntityManager()
            ->getRepository('CommonBundle\Entity\General\Config')
            ->getConfigValue('common.profile_path');
        $phoneNumber =$cv->getPhoneNumber();
        
        $monthsEnglish = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' );
        $monthsDutch = array('Januari', 'Februari', 'Maart', 'April', 'Mei', 'Juni', 'Juli', 'Augustus', 'September', 'Oktober', 'November', 'December' );
        $birthday = $cv->getBirthDay()->format('d F Y');
        $birthday = str_ireplace($monthsEnglish, $monthsDutch, $birthday);

        return new Object(
            'cv',
            array(
                'id'        => $cv->getId(),
                'firstname' => $cv->getFirstName(),
                'lastname'  => $cv->getLastName(),
                'birthday'  => $birthday,
                'email'     => $cv->getEmail(),
                'phone'     => substr($phoneNumber, 0,3)." (0)".substr($phoneNumber, 3,3)." ".substr($phoneNumber, 6,2)." ".substr($phoneNumber, 8,2)." ".substr($phoneNumber, 10,2),
                'img'       => $picturePath . '/' . $cv->getAcademic()->getPhotoPath(),
            ),
            $this->getSections($cv)
        );
    }

    private function getSections(Entry $cv)
    {
        $result = array();

        $result[] = new Object(
            'address',
{'fraction_non_alphanumeric': 0.14248627059410884, 'fraction_numerical': 0.0015976035946080878, 'mean_word_length': 1.8056022408963586, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 157, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3748094', 'n_tokens_mistral': 2889, 'n_tokens_neox': 2728, 'n_words': 571}