Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15683 | Rev 15685 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
15670 anderson 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Controller;
6
 
15682 anderson 7
use Laminas\View\Model\JsonModel;
8
use Laminas\View\Model\ViewModel;
9
use LeadersLinked\Mapper\DiscoveryContactLogMapper;
15670 anderson 10
use Laminas\Mvc\Controller\AbstractActionController;
11
 
12
// Create an action controller.
13
class DiscoveryContactProgressController extends AbstractActionController
14
{
15682 anderson 15
    /**
16
     *
17
     * @var AdapterInterface
18
     */
19
    private $adapter;
20
 
21
 
22
    /**
23
     *
24
     * @var AbstractAdapter
25
     */
26
    private $cache;
27
 
28
    /**
29
     *
30
     * @var  LoggerInterface
31
     */
32
    private $logger;
33
 
34
    /**
35
     *
36
     * @var array
37
     */
38
    private $config;
39
 
40
    /**
41
     *
42
     * @param AdapterInterface $adapter
43
     * @param AbstractAdapter $cache
44
     * @param LoggerInterface $logger
45
     * @param array $config
46
     */
47
    public function __construct($adapter, $cache, $logger, $config)
48
    {
49
        $this->adapter      = $adapter;
50
        $this->cache        = $cache;
51
        $this->logger       = $logger;
52
        $this->config       = $config;
53
    }
54
 
15670 anderson 55
    // Define an action "world".
56
    public function indexAction()
57
    {
15674 anderson 58
        $currentUserPlugin = $this->plugin('currentUserPlugin');
59
        $currentUser = $currentUserPlugin->getUser();
60
        $currentCompany = $currentUserPlugin->getCompany();
15670 anderson 61
 
15674 anderson 62
        $request = $this->getRequest();
63
        if ($request->isGet()) {
15677 anderson 64
            $headers  = $request->getHeaders();
65
            $isJson = false;
15678 anderson 66
 
15680 anderson 67
            if ($headers->has('Accept')) {
68
                $accept = $headers->get('Accept');
69
                $prioritized = $accept->getPrioritized();
15679 anderson 70
 
15680 anderson 71
                foreach ($prioritized as $key => $value) {
72
                    $raw = trim($value->getRaw());
15679 anderson 73
 
15680 anderson 74
                    if (!$isJson) {
75
                        $isJson = strpos($raw, 'json');
76
                    }
15679 anderson 77
                }
78
            }
79
 
15681 anderson 80
            if ($isJson) {
15683 anderson 81
                $search = $this->params()->fromQuery('search');
15682 anderson 82
                $search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
83
                $page               = intval($this->params()->fromQuery('start', 1), 10);
84
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
85
                $order =  $this->params()->fromQuery('order', []);
86
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
87
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var($order[0]['dir'], FILTER_SANITIZE_STRING));
88
                $fields =  ['first_name', 'last_name', 'corporate_email', 'activity'];
89
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'first_name';
90
 
91
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
92
                    $order_direction = 'ASC';
93
                }
94
 
95
                //Quede aqui en el mapper
96
                $discoveryContactMapper = DiscoveryContactLogMapper::getInstance($this->adapter);
97
                $paginator = $discoveryContactMapper->fetchAllDataTableForCompanyIdAndContactId($search, $currentCompany->id, $page, $records_x_page, $order_field, $order_direction);
15681 anderson 98
            } else {
99
            }
15679 anderson 100
 
15681 anderson 101
 
15677 anderson 102
            return new JsonModel([
103
                'success' => true,
15684 anderson 104
                'message' => $currentUser
15677 anderson 105
            ]);
15675 anderson 106
        }
15673 anderson 107
        return new JsonModel([
108
            'success' => true,
15676 anderson 109
            'message' => $currentUser
15673 anderson 110
        ]);
15670 anderson 111
    }
112
}