Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16817 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

<?php
declare(strict_types=1);

namespace LeadersLinked\Controller;

use Laminas\Db\Adapter\AdapterInterface;

use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\Log\LoggerInterface;
use Laminas\View\Model\JsonModel;
use Laminas\View\Model\ViewModel;
use LeadersLinked\Library\Functions;
use LeadersLinked\Mapper\PerformanceEvaluationTestMapper;
use LeadersLinked\Mapper\PerformanceEvaluationFormMapper;
use LeadersLinked\Mapper\QueryMapper;
use LeadersLinked\Mapper\UserMapper;
use LeadersLinked\Model\PerformanceEvaluationTest;
use Laminas\Hydrator\ArraySerializableHydrator;
use Laminas\Db\ResultSet\HydratingResultSet;
use Laminas\Paginator\Adapter\DbSelect;
use Laminas\Paginator\Paginator;
use LeadersLinked\Form\PerformanceEvaluation\PerformanceEvaluationTakeAnTestForm;
use Laminas\Mvc\I18n\Translator;
use LeadersLinked\Library\PerformanceEvaluationInterviewPDF;
use LeadersLinked\Cache\CacheInterface;
use LeadersLinked\Cache\CacheImpl;

class ActivityCenterPerformanceEvaluationController extends AbstractActionController
{
    /**
     *
     * @var \Laminas\Db\Adapter\AdapterInterface
     */
    private $adapter;
    
    /**
     *
     * @var \LeadersLinked\Cache\CacheInterface
     */
    private $cache;
    
    
    /**
     *
     * @var \Laminas\Log\LoggerInterface
     */
    private $logger;
    
    /**
     *
     * @var array
     */
    private $config;
    
    
    /**
     *
     * @var \Laminas\Mvc\I18n\Translator
     */
    private $translator;
    
    
    /**
     *
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
     * @param \LeadersLinked\Cache\CacheInterface $cache
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
     * @param array $config
     * @param \Laminas\Mvc\I18n\Translator $translator
     */
    public function __construct($adapter, $cache, $logger, $config, $translator)
    {
        $this->adapter      = $adapter;
        $this->cache        = $cache;
        $this->logger       = $logger;
        $this->config       = $config;
        $this->translator   = $translator;
    }
    
    public function indexAction()
    {
        $currentUserPlugin = $this->plugin('currentUserPlugin');
        $currentUser = $currentUserPlugin->getUser();
        $currentCompany = $currentUserPlugin->getCompany();
        
        
        
        
        
        $request = $this->getRequest();
        
        if ($request->isGet()) {
            
            $headers = $request->getHeaders();
            
            $isJson = false;
            if ($headers->has('Accept')) {
                $accept = $headers->get('Accept');
                
                $prioritized = $accept->getPrioritized();
                
                foreach ($prioritized as $key => $value) {
                    $raw = trim($value->getRaw());
                    
                    if (!$isJson) {
                        $isJson = strpos($raw, 'json');
                    }
                }
            }
            

            if ($isJson) {
                
                
                $data = [
                    'items' => [],
                    'total' => 0,
                ];
                
                
                $search = $this->params()->fromQuery('search');
                $search = empty($search['value']) ? '' :  Functions::sanitizeFilterString($search['value']);
                
                $start = intval($this->params()->fromQuery('start', 0), 10);
                $records_x_page = intval($this->params()->fromQuery('length', 10), 10);
                $page =  intval($start / $records_x_page);
                $page++;
                
                $order = $this->params()->fromQuery('order', []);
                $order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
                $order_direction = empty($order[0]['dir']) ? 'ASC' : Functions::sanitizeFilterString(filter_var($order[0]['dir']));
                
                $fields = ['max_date'];
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'first_name';
                
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
                    $order_direction = 'ASC';
                }
                
                
                
                
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
                //$allowDelete = $acl->isAllowed($currentUser->usertype_id, 'performance-evaluation/evaluations/delete');
                
                
                
                $queryMapper = QueryMapper::getInstance($this->adapter);
                $sql = $queryMapper->getSql();
                $select = $sql->select();
                $select->columns([
                    'id',
                    'uuid',
                    'last_date',
                    'status',
                    'type',
                    'added_on',
                    'updated_on'
                    
                ]);

                
                
                $select->from(['tb1' => PerformanceEvaluationTestMapper::_TABLE]);
                $select->join(['tb2' => PerformanceEvaluationFormMapper::_TABLE], 'tb1.form_id = tb2.id ', ['form' => 'name']);
                $select->join(['tb3' => UserMapper::_TABLE], 'tb1.supervisor_id = tb3.id ', ['supervisor_first_name' => 'first_name', 'supervisor_last_name' => 'last_name', 'supervisor_email' => 'email']);
                $select->join(['tb4' => UserMapper::_TABLE], 'tb1.employee_id = tb4.id ', ['employee_first_name' => 'first_name', 'employee_last_name' => 'last_name', 'employee_email' => 'email']);
                $select->where->equalTo('tb1.company_id', $currentCompany->id);
                $select->where->nest()
                    ->nest()
                        ->equalTo('tb1.supervisor_id', $currentUser->id)
                        ->and->equalTo('tb1.type', PerformanceEvaluationTest::TYPE_SUPERVISOR)
                    ->unnest()
                    ->or->nest()
                        ->equalTo('tb1.supervisor_id', $currentUser->id)
                        ->and->equalTo('tb1.type', PerformanceEvaluationTest::TYPE_BOTH)
                    ->unnest()
                    ->or->nest()
                    ->equalTo('tb1.employee_id', $currentUser->id)
                    ->and->equalTo('tb1.type', PerformanceEvaluationTest::TYPE_EMPLOYEE)
                    ->unnest()
                ->unnest();
                
                if ($search) {
                    $select->where->nest() 
                        ->like('tb2.name', '%' . $search . '%')
                        ->or->like('tb1.uuid', '%' . $search . '%')
                        ->unnest();
                }
                
                
                $select->order('tb1.last_date DESC, tb2.name ASC');
                

                
                $hydrator = new ArraySerializableHydrator();
                $resultset = new HydratingResultSet($hydrator);
                
                $adapter = new DbSelect($select, $sql, $resultset);
                $paginator = new Paginator($adapter);
                $paginator->setItemCountPerPage($records_x_page);
                $paginator->setCurrentPageNumber($page);
                

                
                $items = [];
                $records = $paginator->getCurrentItems();
                foreach ($records as $record)
                {
                    
                    $dt = \DateTime::createFromFormat('Y-m-d', $record['last_date']);
                    $last_date = $dt->format('d/m/Y');
                    
                    switch($record['status'])
                    {
                        case PerformanceEvaluationTest::STATUS_PENDING :
                            $status = 'LABEL_PENDING';
                            break;
                            
                        case PerformanceEvaluationTest::STATUS_COMPLETED :
                            $status = 'LABEL_COMPLETED';
                            break;
                            
                        default :
                            $status = 'LABEL_UNKNOW';
                            break;
                    }
                    
                    switch($record['type'])
                    {
                        case PerformanceEvaluationTest::TYPE_BOTH : 
                            $type = 'LABEL_PERFORMANCE_EVALUATION_TYPE_BOTH';
                            break;
                            
                        case PerformanceEvaluationTest::TYPE_SUPERVISOR : 
                            $type = 'LABEL_PERFORMANCE_EVALUATION_TYPE_SUPERVISOR';
                            break;
                            
                        case PerformanceEvaluationTest::TYPE_EMPLOYEE :
                            $type = 'LABEL_PERFORMANCE_EVALUATION_TYPE_EMPLOYEE';
                            break;
                            
                        default :
                            $type = 'LABEL_UNKNOWN';
                            break;
                    }
                    
                    
                    
                    if($record['status'] == PerformanceEvaluationTest::STATUS_COMPLETED) {
                        $link_pdf = $this->url()->fromRoute('activities-center/performance-evaluation/report', ['id' => $record['uuid']]);
                        $link_take_a_test = '';
                        

                    } else {
                        $link_pdf = '';
                        $link_take_a_test = $this->url()->fromRoute('activities-center/performance-evaluation/take-a-test', ['id' => $record['uuid']]);
                    }

                    
                    $item = [
                        'last_date' => $last_date,
                        'form' => $record['form'],
                        'type' => $type,
                        'supervisor_first_name' => $record['supervisor_first_name'],
                        'supervisor_last_name' => $record['supervisor_last_name'],
                        'supervisor_email' => $record['supervisor_email'],
                        'employee_first_name' => $record['employee_first_name'],
                        'employee_last_name' => $record['employee_last_name'],
                        'employee_email' => $record['employee_email'],
                        'status' => $status,
                        'actions' => [
                            'link_pdf' => $link_pdf,
                            'link_take_a_test' => $link_take_a_test,
                        ]
                    ];
                    /*
                     if($testSelf) {
                     $item['actions']['link_report_self'] = $this->url()->fromRoute('performance-evaluation/evaluations/report-self', ['id' => $record['uuid'] ]);
                     } else{
                     $item['actions']['link_self'] = $this->url()->fromRoute('performance-evaluation/evaluations/self', ['id' => $record['uuid'] ]);
                     }
                     if($testBoth) {
                     $item['actions']['link_report_both'] = $this->url()->fromRoute('performance-evaluation/evaluations/report-both', ['id' => $record['uuid'] ]);
                     } else{
                     $item['actions']['link_both'] = $this->url()->fromRoute('performance-evaluation/evaluations/both', ['id' => $record['uuid'] ]);
                     }
                     if($testSupervisor) {
                     $item['actions']['link_report_superviser'] = $this->url()->fromRoute('performance-evaluation/evaluations/report-superviser', ['id' => $record['uuid'] ]);
                     } else{
                     $item['actions']['link_superviser'] = $this->url()->fromRoute('performance-evaluation/evaluations/superviser', ['id' => $record['uuid'] ]);
                     }*/
                    
                    array_push($items, $item);
                }
                
                $data['items'] = $items;
                $data['total'] = $paginator->getTotalItemCount();
                
                
                return new JsonModel([
                    'success' => true,
                    'data' => $data
                ]);
            } else {
                
                if($this->cache->hasItem('ACTIVITY_CENTER_RELATIONAL')) {
                    $search =  $this->cache->getItem('ACTIVITY_CENTER_RELATIONAL');
                    $this->cache->removeItem('ACTIVITY_CENTER_RELATIONAL');
                } else {
                    $search = '';
                }

    
                

                $form = new PerformanceEvaluationTakeAnTestForm();

                $this->layout()->setTemplate('layout/layout-backend');
                $viewModel = new ViewModel();
                $viewModel->setTemplate('leaders-linked/activity-center-performance-evaluation/index.phtml');
                $viewModel->setVariables([
                    'search' => $search, 
                    'form' => $form
                ]);
                return $viewModel;
            }
        } else {
            return new JsonModel([
                'success' => false,
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
            ]);
            
        }
    }
    

    public function takeaTestAction()
    {
        $request = $this->getRequest();
        $currentUserPlugin = $this->plugin('currentUserPlugin');
        $currentCompany = $currentUserPlugin->getCompany();
        $currentUser = $currentUserPlugin->getUser();
        
        $request = $this->getRequest();
        $uuid = $this->params()->fromRoute('id');
        
        
        if (!$uuid) {
            $data = [
                'success' => false,
                'data' => 'ERROR_INVALID_PARAMETER'
            ];
            
            return new JsonModel($data);
        }
        
        $performanceEvaluationTestMapper = PerformanceEvaluationTestMapper::getInstance($this->adapter);
        $performanceEvaluationTest = $performanceEvaluationTestMapper->fetchOneByUuid($uuid);
        
        
        


        if (!$performanceEvaluationTest) {
            $data = [
                'success' => false,
                'data' => 'ERROR_RECORD_NOT_FOUND'
            ];
            
            return new JsonModel($data);
        }
        
        if ($performanceEvaluationTest->company_id == $currentCompany->id) {
            switch ($performanceEvaluationTest->type) 
            {
                case PerformanceEvaluationTest::TYPE_BOTH : 
                    $ok = $performanceEvaluationTest->supervisor_id == $currentUser->id
                    || $performanceEvaluationTest->employee_id == $currentUser->id;
                    break;
                    
                case PerformanceEvaluationTest::TYPE_SUPERVISOR :
                    $ok = $performanceEvaluationTest->supervisor_id == $currentUser->id;
                    break;
                    
                case PerformanceEvaluationTest::TYPE_EMPLOYEE :
                    $ok =  $performanceEvaluationTest->employee_id == $currentUser->id;
                    break;
                    
                default : 
                    $ok = false;
                    break;
                    
            }
        } else {
            $ok = false;
        }
        
        if(!$ok) {
            return new JsonModel([
                'success' => false,
                'data' => 'ERROR_UNAUTHORIZED'
            ]);
        }
        
        
        
        if ($request->isPost()) {
         
   
            
            $dataPost = $request->getPost()->toArray();
            
            $form = new PerformanceEvaluationTakeAnTestForm($this->adapter, $currentCompany->id);
            $form->setData($dataPost);
            
            if ($form->isValid()) {
        
                switch( $performanceEvaluationTest->type)
                {
                    case PerformanceEvaluationTest::TYPE_BOTH :
                        $type = 'LABEL_PERFORMANCE_EVALUATION_TYPE_BOTH';
                        break;
                        
                    case PerformanceEvaluationTest::TYPE_SUPERVISOR :
                        $type = 'LABEL_PERFORMANCE_EVALUATION_TYPE_SUPERVISOR';
                        break;
                        
                    case PerformanceEvaluationTest::TYPE_EMPLOYEE :
                        $type = 'LABEL_PERFORMANCE_EVALUATION_TYPE_EMPLOYEE';
                        break;
                        
                    default :
                        $type = 'LABEL_UNKNOWN';
                        break;
                }
                
                
                $type = $this->translator->translate($type);
        
                
                $performanceEvaluationFormMapper = PerformanceEvaluationFormMapper::getInstance($this->adapter);
                $performanceEvaluationForm = $performanceEvaluationFormMapper->fetchOne($performanceEvaluationTest->form_id);
                
                $dataPost = (array) $form->getData();

                $content = json_decode($performanceEvaluationTest->content);
                
            
                
                $content->points = $dataPost['points'];
                $content->comment = $dataPost['comment'];
                $content->evaluation = [];
                
                foreach($content->competencies_selected as $competency)
                {
               
                    
                    
                    foreach($competency->behaviors as $behavior)
                    {
                  
                        $key_comment = $competency->uuid . '-' . $behavior->uuid . '-comment';
                        $key_points = $competency->uuid . '-' . $behavior->uuid . '-points';

                        $value_comment = $this->params()->fromPost($key_comment);
                        $value_comment = Functions::sanitizeFilterString($value_comment);
                        $value_comment = empty($value_comment) ? '' : $value_comment;
                        
                        
               
                        $value_points = intval($this->params()->fromPost($key_points), 10);
                        
                        array_push($content->evaluation, [
                            'competency' => $competency->uuid, 
                            'behavior' => $behavior->uuid, 
                            'comment' => $value_comment, 
                            'points' => $value_points
                        ]);
                        
                        
                        
                        
                    }
                }
                

                $performanceEvaluationTest->status = PerformanceEvaluationTest::STATUS_COMPLETED;
                $performanceEvaluationTest->content = json_encode($content);
                
                $result = $performanceEvaluationTestMapper->update($performanceEvaluationTest);
                
                if ($result) {
                    $this->logger->info('Se agrego la prueba de tipo '  . $type . ' de la Evaluación de  Desempeño : ' . $performanceEvaluationTest->uuid, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
                    $data = [
                        'success' => true,
                        'data' => 'LABEL_RECORD_UPDATED'
                    ];
                } else {
                    $data = [
                        'success' => false,
                        'data' => $performanceEvaluationTestMapper->getError()
                    ];
                }
                
                return new JsonModel($data);
            } else {
                $messages = [];
                $form_messages = (array) $form->getMessages();
                foreach ($form_messages as $fieldname => $field_messages) {
                    $messages[$fieldname] = array_values($field_messages);
                }
                
                return new JsonModel([
                    'success' => false,
                    'data' => $messages
                ]);
            }
        } else if ($request->isGet()) {
            switch( $performanceEvaluationTest->type)
            {
                case PerformanceEvaluationTest::TYPE_BOTH :
                    $type = 'LABEL_PERFORMANCE_EVALUATION_TYPE_BOTH';
                    break;
                    
                case PerformanceEvaluationTest::TYPE_SUPERVISOR :
                    $type = 'LABEL_PERFORMANCE_EVALUATION_TYPE_SUPERVISOR';
                    break;
                    
                case PerformanceEvaluationTest::TYPE_EMPLOYEE :
                    $type = 'LABEL_PERFORMANCE_EVALUATION_TYPE_EMPLOYEE';
                    break;
                    
                default :
                    $type = 'LABEL_UNKNOWN';
                    break;
            }
            
            
            $performanceEvaluationFormMapper = PerformanceEvaluationFormMapper::getInstance($this->adapter);
            $performanceEvaluationForm = $performanceEvaluationFormMapper->fetchOne($performanceEvaluationTest->form_id);
            
            
            $content = json_decode($performanceEvaluationTest->content);
            foreach($content->competencies_selected as &$competency)
            {
                foreach($competency->behaviors as &$behavior)
                {
                    $behavior->competency_uuid = $competency->uuid;
                }
            }
            
            $userMapper = UserMapper::getInstance($this->adapter);
            
            if($performanceEvaluationTest->supervisor_id) {
                $user = $userMapper->fetchOne($performanceEvaluationTest->supervisor_id);
                $supervisor = $user->first_name . ' ' . $user->last_name;
            } else {
                $supervisor = '';
            }
            
            if($performanceEvaluationTest->employee_id) {
                $user = $userMapper->fetchOne($performanceEvaluationTest->employee_id);
                $employee = $user->first_name . ' ' . $user->last_name;
            } else {
                $employee = '';
            }
            
            $dt = \DateTime::createFromFormat('Y-m-d', $performanceEvaluationTest->last_date);
            if($dt) {
                $last_date = $dt->format('d/m/Y');
            } else {
                $last_date = '';
            }
            
            
            $data = [
               // 'uuid' =>  $content->uuid,
                'name' =>  $content->name,
                'functions' =>  $content->functions,
                'objectives' =>  $content->objectives,
                'form' => $performanceEvaluationForm->name,
                'type' => $type,
                'supervisor' => $supervisor,
                'employee' => $employee,
                'last_date' => $last_date,
                //'job_description_id_boss' =>  $content->job_description_id_boss,
                'competency_types' => [], 
                'competencies' => [],
                'behaviors' => [],
                'competencies_selected' => [],
                'subordinates_selected' => [],
            ]; 
            
            foreach($content->competency_types as $record) 
            {
               array_push($data['competency_types'], $record);
            }
            
            foreach($content->competencies as $record)
            {
                array_push($data['competencies'], $record);
            }
            
            foreach($content->behaviors as $record)
            {
                array_push($data['behaviors'], $record);
            }
            
            foreach($content->competencies_selected as $record)
            {
                array_push($data['competencies_selected'], $record);
            }
            
            foreach($content->subordinates_selected as $record)
            {
                array_push($data['subordinates_selected'], $record);
            }


            
            $data = [
                'success' => true,
                'data' => $data
            ];

            
            return new JsonModel($data);
        } else {
            $data = [
                'success' => false,
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
            ];
            
            return new JsonModel($data);
        }
        
        return new JsonModel($data);
    }
    
    public function reportAction()
    {
        $request = $this->getRequest();
        $currentUserPlugin = $this->plugin('currentUserPlugin');
        $currentCompany = $currentUserPlugin->getCompany();
        $currentUser = $currentUserPlugin->getUser();
        
        $request = $this->getRequest();
        $uuid = $this->params()->fromRoute('id');
        
        if (!$uuid) {
            $data = [
                'success' => false,
                'data' => 'ERROR_INVALID_PARAMETER'
            ];
            
            return new JsonModel($data);
        }
        
        $performanceEvaluationTestMapper = PerformanceEvaluationTestMapper::getInstance($this->adapter);
        $performanceEvaluationTest = $performanceEvaluationTestMapper->fetchOneByUuid($uuid);
        if (!$performanceEvaluationTest) {
            $data = [
                'success' => false,
                'data' => 'ERROR_RECORD_NOT_FOUND'
            ];
            
            return new JsonModel($data);
        }

        
        if ($performanceEvaluationTest->company_id != $currentCompany->id) {
            return new JsonModel([
                'success' => false,
                'data' => 'ERROR_UNAUTHORIZED'
            ]);
        }
        
        if ($performanceEvaluationTest->employee_id != $currentUser->id 
            && $performanceEvaluationTest->supervisor_id != $currentUser->id ) {
            return new JsonModel([
                'success' => false,
                'data' => 'ERROR_UNAUTHORIZED'
            ]);
        }
        
        if($performanceEvaluationTest->status ==PerformanceEvaluationTest::STATUS_PENDING) {
            return new JsonModel([
                'success' => false,
                'data' =>   'ERROR_RECORD_IS_PENDING'
            ]);
            
        }
        

        
        $request = $this->getRequest();
        if ($request->isGet()) {
            
            switch( $performanceEvaluationTest->type)
            {
                case PerformanceEvaluationTest::TYPE_BOTH :
                    $type = $this->translator->translate('LABEL_PERFORMANCE_EVALUATION_TYPE_BOTH');
                    break;
                    
                case PerformanceEvaluationTest::TYPE_SUPERVISOR :
                    $type = $this->translator->translate('LABEL_PERFORMANCE_EVALUATION_TYPE_SUPERVISOR');
                    break;
                    
                case PerformanceEvaluationTest::TYPE_EMPLOYEE :
                    $type = $this->translator->translate('LABEL_PERFORMANCE_EVALUATION_TYPE_EMPLOYEE');
                    break;
                    
                default :
                    $type = $this->translator->translate('LABEL_UNKNOWN');
                    break;
            }
            
            
            $performanceEvaluationFormMapper = PerformanceEvaluationFormMapper::getInstance($this->adapter);
            $performanceEvaluationForm = $performanceEvaluationFormMapper->fetchOne($performanceEvaluationTest->form_id);
            
            $userMapper = UserMapper::getInstance($this->adapter);
            $employee = $userMapper->fetchOne($performanceEvaluationTest->employee_id);
            
            $filename = $performanceEvaluationForm->name . '-' . trim($employee->first_name) . '-' . trim($employee->last_name)  . '-' . $type . '-' . date('Y-m-d H:i a') . '.pdf';
            
            $filename = Functions::normalizeStringFilename( $filename );
            
            
            
            
            $content = base64_encode($this->renderPDF($performanceEvaluationTest));
            $data = [
                'success' => true,
                'data' => [
                    'basename' => $filename,
                    'content' => $content
                ]
            ];
            
            return new JsonModel($data);
            
            /*
            
            $content = $this->renderPdf($currentCompany, $jobDescription);
            $response = new Response();
            $response->setStatusCode(200);
            $response->setContent($content);
            
            
            
            $headers = $response->getHeaders();
            $headers->clearHeaders();
            
            $headers->addHeaderLine('Content-Description: File Transfer');
            $headers->addHeaderLine('Content-Type: application/pdf');
            //$headers->addHeaderLine('Content-Disposition: attachment; filename=' . $filename);
            $headers->addHeaderLine('Content-Transfer-Encoding: binary');
            $headers->addHeaderLine('Expires: 0');
            $headers->addHeaderLine('Cache-Control: must-revalidate');
            $headers->addHeaderLine('Pragma: public');
            return $response;
            */
            
            
            
            
            return ;
        } else {
            
            
            return new JsonModel([
                'success' => false,
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
            ]);
        }
    }
    
    /**
     * Render PDF
     * @param PerformanceEvaluationTest $performanceEvaluationTest
     
     * @return mixed
     */
    private function renderPDF($performanceEvaluationTest)
    {
        $request = $this->getRequest();
        $currentUserPlugin = $this->plugin('currentUserPlugin');
        $currentCompany = $currentUserPlugin->getCompany();
        $currentUser = $currentUserPlugin->getUser();
        
        
        //Generate New PDF
        $pdf = new PerformanceEvaluationInterviewPDF();
        
        $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $currentCompany->uuid;
        $header = $currentCompany->header ? $target_path . DIRECTORY_SEPARATOR . $currentCompany->header : '';
        if (empty($header) || !file_exists($header)) {
            $header = $this->config['leaderslinked.images_default.company_pdf_header'];
        }
        
        $footer = $currentCompany->footer ? $target_path . DIRECTORY_SEPARATOR . $currentCompany->footer : '';
        if (empty($footer) || !file_exists($footer)) {
            $footer = $this->config['leaderslinked.images_default.company_pdf_footer'];
        }
        
        $content = json_decode($performanceEvaluationTest->content);
        
        $pdf->header = $header;
        $pdf->footer = $footer;
        $pdf->translator = $this->translator;
        
        $pdf->SetMargins(10, 0, 10);
        
        $pdf->AliasNbPages();
        $pdf->AddPage();
        
        switch( $performanceEvaluationTest->type)
        {
            case PerformanceEvaluationTest::TYPE_BOTH :
                $type = $this->translator->translate('LABEL_PERFORMANCE_EVALUATION_TYPE_BOTH');
                break;
                
            case PerformanceEvaluationTest::TYPE_SUPERVISOR :
                $type = $this->translator->translate('LABEL_PERFORMANCE_EVALUATION_TYPE_SUPERVISOR');
                break;
                
            case PerformanceEvaluationTest::TYPE_EMPLOYEE :
                $type = $this->translator->translate('LABEL_PERFORMANCE_EVALUATION_TYPE_EMPLOYEE');
                break;
                
            default :
                $type = $this->translator->translate('LABEL_UNKNOWN');
                break;
        }
        
        $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $performanceEvaluationTest->updated_on);
        
        $evaluated = '';
        $evaluator = '';
        
        $userMapper = UserMapper::getInstance($this->adapter);
        if($performanceEvaluationTest->employee_id) {
            $user = $userMapper->fetchOne($performanceEvaluationTest->employee_id);
            if($user) {
                $evaluated = ucwords(strtolower(trim($user->first_name . ' ' . $user->last_name)));
            }
        }
        if($performanceEvaluationTest->supervisor_id) {
            $user = $userMapper->fetchOne($performanceEvaluationTest->supervisor_id);
            if($user) {
                $evaluator = ucwords(strtolower(trim($user->first_name . ' ' . $user->last_name)));
            }
        }
        
        $rows = [
            [
                'title' => $this->translator->translate('LABEL_TYPE') . ' : ',
                'content' => $type,
            ],
            [
                'title' => $this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_POSITION') . ' : ',
                'content' => $content->name,
            ],
            [
                'title' => $this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_EVALUATED')  . ' : ',
                'content' => Functions::utf8_decode($evaluated),
            ],
            
            [
                'title' => $this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_EVALUATE_SIGNATURE') . ' : ',
                'content' => ''
            ],
            [
                'title' => $this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_EVALUATOR') . ' : ',
                'content' => Functions::utf8_decode($evaluator),
            ],
            [
                'title' => $this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_EVALUATOR_SIGNATURE') . ' : ',
                'content' => ''
            ],
            [
                'title' => $this->translator->translate( 'LABEL_PDF_PERFORMANCE_EVALUATION_MANAGER_SIGNATURE') . ' : ',
                'content' => ''
            ],
            [
                'title' => $this->translator->translate('LABEL_DATE'),
                'content' => $dt->format('d/m/Y H:i a')
            ]
        ];
        
        
        
        $pdf->borderTable($this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_TITLE'), $rows);
        
        $pdf->evaluationTable($content->comment, $content->points);
        
        
    
        // Competencies
        if ($content->competencies_selected) {
            $pdf->AddPage();
            
            $i = 0;
            
            $max = count($content->competencies_selected);
            for($i = 0; $i < $max; $i++)
            {
                $competency_selected = $content->competencies_selected[$i];
                
                $j = $i + 1;
                $last = $j == $max;
                $pdf->competencyTable($i, $competency_selected, $content->competencies, $content->competency_types, $content->behaviors, $content->evaluation, $last);
            }
            
        }
        
        return $pdf->Output('S');
    }
}