Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15715 | Rev 15717 | 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
 
15699 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
 
15699 anderson 91
            if (!in_array($order_direction, ['ASC', 'DESC'])) {
92
                $order_direction = 'ASC';
93
            }
15682 anderson 94
 
15687 anderson 95
 
15699 anderson 96
            //Quede aqui en el mapper
97
            $discoveryContactMapper = DiscoveryContactLogMapper::getInstance($this->adapter);
15710 anderson 98
            $records = $discoveryContactMapper->fetchAll();
15699 anderson 99
            $items = [];
15710 anderson 100
            //$records = $paginator->getCurrentItems();
15716 anderson 101
            return new JsonModel([
102
                'success' => true,
103
                'records' => $records
104
            ]);
15711 anderson 105
            foreach ($records as $record) {
15713 anderson 106
 
15714 anderson 107
                // $item = [
108
                //     'first_name' => $record->first_name,
109
                //     'last_name' => $record->last_name,
110
                //     'corporate_email' => $record->corporate_email,
111
                //     'company' => $record->company,
112
                //     'country' => $record->country,
113
                //     'sector' => $record->sector,
114
                //     'actions' => [
115
                //         'link_edit' => $this->url()->fromRoute('discovery-contacts/edit', ['id' => $record->uuid]),
116
                //         'link_delete' => $this->url()->fromRoute('discovery-contacts/delete', ['id' => $record->uuid]),
117
                //         'link_view' => $this->url()->fromRoute('discovery-contacts/view', ['id' => $record->uuid]),
118
                //     ],
119
                // ];
15713 anderson 120
 
15715 anderson 121
                //array_push($items, $item);
15716 anderson 122
 
15711 anderson 123
            }
124
 
15699 anderson 125
            // } else {
126
            // }
15675 anderson 127
        }
15690 anderson 128
 
129
 
15701 anderson 130
        return new JsonModel([
131
            'success' => true,
132
            'message' => $currentCompany->id
133
        ]);
15670 anderson 134
    }
135
}