Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1545 | Rev 4113 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

<?php
namespace LeadersLinked\Helper;

use Laminas\View\Helper\AbstractHelper;
use Laminas\Db\Adapter\AdapterInterface;
use LeadersLinked\Mapper\UserMapper;
use LeadersLinked\Model\UserType;
use LeadersLinked\Mapper\ConnectionMapper;
use LeadersLinked\Mapper\LocationMapper;
use LeadersLinked\Mapper\ProfileVisitMapper;

class MenuHelper extends AbstractHelper
{
    /**
     *
     * @var AdapterInterface
     */
    private $adapter;
    
    /**
     * 
     * @var array
     */
    private $config;
    
    
    /**
     *
     * @param AdapterInterface $adapter
     * @param array $config
     */
    public function __construct($adapter, $config)
    {
        $this->adapter = $adapter;
        $this->config = $config;
    }
    
    /**
     * 
     * @param int $user_id
     * @return string
     */
    public function __invoke($user_id)
    {
        $userMapper = UserMapper::getInstance($this->adapter);
        $user = $userMapper->fetchOne($user_id);
        
        $profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
        $visits = $profileVisitMapper->getTotalByVisitedId($user->id);
        
        $connectionMapper = ConnectionMapper::getInstance($this->adapter);
        $connections = $connectionMapper->fetchTotalConnectionByUser($user->id);
        
        
        if($user->location_id) {
            $locationMapper = LocationMapper::getInstance($this->adapter);
            $location = $locationMapper->fetchOne($user->location_id);
            
            $country = $location->country;
        } else {
            $country = '';
        }
        
      
        
        $userMapper = UserMapper::getInstance($this->adapter);
        $user = $userMapper->fetchOne($user_id);
        if($user && $user->usertype_id == UserType::ADMIN) {
            $link_admin = '/backend/signin-admin';
        } else {
            $link_admin = '';
        } 
        
        $data = [
            'user_uuid' => $user->uuid,
            'fullname' => trim($user->first_name . ' ' . $user->last_name),
            'country' => $country,
            'visits' => $visits,
            'connections' => $connections,
            'link_admin' => $link_admin
        ];
        
        return $this->getView()->render('helpers/menu.phtml', $data);
    }
}