Proyectos de Subversion LeadersLinked - Backend

Rev

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