Proyectos de Subversion LeadersLinked - Backend

Rev

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