Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15697 | Rev 15699 | 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
 
15697 anderson 80
            if ($isJson) {
81
                $search = $this->params()->fromQuery('search');
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';
15682 anderson 90
 
15697 anderson 91
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
92
                    $order_direction = 'ASC';
93
                }
15682 anderson 94
 
15687 anderson 95
 
15697 anderson 96
                //Quede aqui en el mapper
97
                $discoveryContactMapper = DiscoveryContactLogMapper::getInstance($this->adapter);
15698 anderson 98
                $paginator = $discoveryContactMapper->fetchAll($currentCompany->id, $currentUser->id,  $page, $records_x_page);
15697 anderson 99
                $items = [];
100
                $records = $paginator->getCurrentItems();
101
                return new JsonModel([
102
                    'success' => true,
103
                    'records' => $records
104
                ]);
105
            } else {
106
            }
15679 anderson 107
 
15681 anderson 108
 
15689 anderson 109
            // return new JsonModel([
110
            //     'success' => true,
111
            //     'message' => $currentUser
112
            // ]);
15675 anderson 113
        }
15690 anderson 114
 
115
 
15694 anderson 116
        return new JsonModel([
117
            'success' => true,
118
            'message' => $currentCompany->id
119
        ]);
15670 anderson 120
    }
121
}