Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16951 | Ir a la última revisión | 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\ViewModel;
use Laminas\View\Model\JsonModel;
use Laminas\Db\Sql\Expression;
use LeadersLinked\Model\Job;
use LeadersLinked\Mapper\JobSkillMapper;
use LeadersLinked\Mapper\SkillMapper;
use LeadersLinked\Mapper\UserMapper;
use LeadersLinked\Model\User;
use LeadersLinked\Mapper\CompanyLocationMapper;
use LeadersLinked\Mapper\CompanySizeMapper;
use LeadersLinked\Mapper\CompanyFollowerMapper;
use LeadersLinked\Model\Company;
use LeadersLinked\Mapper\GroupMapper;
use LeadersLinked\Mapper\GroupMemberMapper;
use LeadersLinked\Mapper\GroupTypeMapper;
use LeadersLinked\Model\Group;
use LeadersLinked\Model\Notification;
use LeadersLinked\Mapper\NotificationMapper;
use LeadersLinked\Mapper\UserProfileMapper;
use LeadersLinked\Mapper\ProfileVisitMapper;
use LeadersLinked\Mapper\ConnectionMapper;
use LeadersLinked\Model\CompanyFollower;
use LeadersLinked\Mapper\MicrolearningUserProgressMapper;
use LeadersLinked\Mapper\MicrolearningUserLogMapper;
use LeadersLinked\Mapper\DailyPulseRecordMapper;
use LeadersLinked\Model\DailyPulseRecord;
use LeadersLinked\Mapper\SurveyCampaignMapper;
use LeadersLinked\Mapper\RecruitmentSelectionApplicationMapper;
use LeadersLinked\Mapper\RecruitmentSelectionVacancyMapper;
use LeadersLinked\Mapper\PerformanceEvaluationTestMapper;



class DashboardController 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();
        
        
        $request = $this->getRequest();
        if($request->isGet()) {
            
            
            
            
            
            $this->layout()->setTemplate('layout/layout-backend.phtml');
            $viewModel = new ViewModel();
 
            $company = $currentUserPlugin->getCompany();
            if($company) {
                
                $microlearningUserLogMapepr = MicrolearningUserLogMapper::getInstance($this->adapter);
                $end_date = $microlearningUserLogMapepr->fetchOneMaxDateActivityFromCompanyId($company->id);
                if($end_date) {
                
                
                    $t = strtotime($end_date);
                    $start_date = date('Y-m-d', strtotime('-30 days', $t));
                    
                    $closed_capsules_x_days = $microlearningUserLogMapepr->fetchAllCountClosedCapsulesDailyByCompanyIdAndStartDateAndEndDate($company->id, $start_date, $end_date);
                    $users_with_closed_capsules_x_days = $microlearningUserLogMapepr->fetchAllCountUsersWithClosedCapsulesDailyByCompanyIdAndStartDateAndEndDate($company->id, $start_date, $end_date);

                
                } else {
                    $closed_capsules_x_days = [];
                    $users_with_closed_capsules_x_days = [];
                    
                }
                
                $average_closed_capsules_x_days = 0;
                $average_users_with_closed_capsules_x_day = 0;
               
                
                $max = count($closed_capsules_x_days);
                if($max) {
                    for($i = 0; $i < $max; $i++)
                    {
                        $average_closed_capsules_x_days += $closed_capsules_x_days[$i]['total'];
                    }
                    $average_closed_capsules_x_days = $average_closed_capsules_x_days / $max;
                    
                }
                
                
                $max = count($users_with_closed_capsules_x_days);
                if($max) {
                    for($i = 0; $i < $max; $i++)
                    {
                        $average_users_with_closed_capsules_x_day += $users_with_closed_capsules_x_days[$i]['total'];
                    }
                    $average_users_with_closed_capsules_x_day = $average_users_with_closed_capsules_x_day / $max;
                    
                }
                
                
                $users_with_daily_pulse_x_days = [];
                $average_users_with_daily_pulse_x_days = 0;
                
                $dailyPulseRecordMapper = DailyPulseRecordMapper::getInstance($this->adapter);
                $end_date = $dailyPulseRecordMapper->fetchOneMaxDateActivityFromCompanyId($company->id);
                if($end_date) {
                    
                    
                    $t = strtotime($end_date);
                    $start_date = date('Y-m-d', strtotime('-30 days', $t));
                    
                    $users_with_daily_pulse_x_days = $dailyPulseRecordMapper->fetchAllCountUsersWithClosedCapsulesDailyByCompanyIdAndStartDateAndEndDate($company->id, $start_date, $end_date);
                    $average_users_with_daily_pulse_x_days = 0;
                    
                    $max = count($users_with_daily_pulse_x_days);
                    if($max) {
   
                        for($i = 0; $i < $max; $i++)
                        {
                            $average_users_with_daily_pulse_x_days += $users_with_daily_pulse_x_days[$i]['total'];
                        }
                        $average_users_with_daily_pulse_x_days = $average_users_with_daily_pulse_x_days / $max;
                        
                    }
                    
                    
                } 
                
                $followerMapper = CompanyFollowerMapper::getInstance($this->adapter);
                $total_followers = $followerMapper->fetchCountByCompanyId($company->id);
                
         
                $surveyCampaignMapper = SurveyCampaignMapper::getInstance($this->adapter);
                $total_surveys = $surveyCampaignMapper->fetchCountByCompanyId($company->id);
                
                $recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
                $total_recruitment_selection_vacancies = $recruitmentSelectionVacancyMapper->fetchCountByCompanyId($company->id);
                
                $performanceEvaluationTestMapper = PerformanceEvaluationTestMapper::getInstance($this->adapter);
                $total_performance_evaluation_tests = $performanceEvaluationTestMapper->fetchCountByCompanyId($company->id);
                
                
                $viewModel->setTemplate('leaders-linked/dashboard/company.phtml');
                $viewModel->setVariables([
                    'average_closed_capsules_x_days'            => $average_closed_capsules_x_days,
                    'average_users_with_closed_capsules_x_day'  => $average_users_with_closed_capsules_x_day,
                    'closed_capsules_x_days'                    => $closed_capsules_x_days,
                    'users_with_closed_capsules_x_days'         => $users_with_closed_capsules_x_days,
                    'users_with_daily_pulse_x_days'             => $users_with_daily_pulse_x_days,
                    'average_users_with_daily_pulse_x_days'     => $average_users_with_daily_pulse_x_days,
                    'total_followers'                           => $total_followers,
                    'total_surveys'                             => $total_surveys,
                    'total_recruitment_selection_vacancies'     => $total_recruitment_selection_vacancies,
                    'total_performance_evaluation_tests'        => $total_performance_evaluation_tests,
                ]); 
                
            } else {
                $viewModel->setTemplate('leaders-linked/dashboard/index.phtml');
            }
       
  

            return $viewModel ;
        }
        
        return new JsonModel([
           'success' => false,
           'data' => 'ERROR_METHOD_NOT_ALLOWED'
        ]);
    }
    
    public function notificationActions()
    {
        
    }
    
    public function csrfAction()
    {
        $request = $this->getRequest();
        if($request->isGet()) {
            
            $token = md5(uniqid('CSFR-' . mt_rand(), true));
            $_SESSION['token'] = $token;
            
            
            return new JsonModel([
                'success' => true,
                'data' => $token
            ]);
            
            
        } else {
            return new JsonModel([
                'success' => false,
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
            ]);
        }
        
        
    }
    
    public function chatAction()
    {
    }
    
    
    
    public function inMailPersonalAction()
    {
    }
    
    public function inMailCompanyAction()
    {
    }
   
}