| 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;
|
| 15727 |
anderson |
15 |
use Laminas\Hydrator\ArraySerializableHydrator;
|
|
|
16 |
use Laminas\Db\ResultSet\HydratingResultSet;
|
|
|
17 |
use Laminas\Paginator\Adapter\DbSelect;
|
|
|
18 |
use Laminas\Paginator\Paginator;
|
| 15732 |
anderson |
19 |
use LeadersLinked\Mapper\CompanyMapper;
|
| 15670 |
anderson |
20 |
|
|
|
21 |
// Create an action controller.
|
|
|
22 |
class DiscoveryContactProgressController extends AbstractActionController
|
|
|
23 |
{
|
| 15682 |
anderson |
24 |
/**
|
|
|
25 |
*
|
|
|
26 |
* @var AdapterInterface
|
|
|
27 |
*/
|
|
|
28 |
private $adapter;
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
*
|
|
|
33 |
* @var AbstractAdapter
|
|
|
34 |
*/
|
|
|
35 |
private $cache;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
*
|
|
|
39 |
* @var LoggerInterface
|
|
|
40 |
*/
|
|
|
41 |
private $logger;
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
*
|
|
|
45 |
* @var array
|
|
|
46 |
*/
|
|
|
47 |
private $config;
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
*
|
|
|
51 |
* @param AdapterInterface $adapter
|
|
|
52 |
* @param AbstractAdapter $cache
|
|
|
53 |
* @param LoggerInterface $logger
|
|
|
54 |
* @param array $config
|
|
|
55 |
*/
|
|
|
56 |
public function __construct($adapter, $cache, $logger, $config)
|
|
|
57 |
{
|
|
|
58 |
$this->adapter = $adapter;
|
|
|
59 |
$this->cache = $cache;
|
|
|
60 |
$this->logger = $logger;
|
|
|
61 |
$this->config = $config;
|
|
|
62 |
}
|
|
|
63 |
|
| 15670 |
anderson |
64 |
// Define an action "world".
|
|
|
65 |
public function indexAction()
|
|
|
66 |
{
|
| 15674 |
anderson |
67 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
68 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
69 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 15670 |
anderson |
70 |
|
| 15674 |
anderson |
71 |
$request = $this->getRequest();
|
|
|
72 |
if ($request->isGet()) {
|
| 15677 |
anderson |
73 |
$headers = $request->getHeaders();
|
|
|
74 |
$isJson = false;
|
| 15678 |
anderson |
75 |
|
| 15680 |
anderson |
76 |
if ($headers->has('Accept')) {
|
|
|
77 |
$accept = $headers->get('Accept');
|
|
|
78 |
$prioritized = $accept->getPrioritized();
|
| 15679 |
anderson |
79 |
|
| 15680 |
anderson |
80 |
foreach ($prioritized as $key => $value) {
|
|
|
81 |
$raw = trim($value->getRaw());
|
| 15679 |
anderson |
82 |
|
| 15680 |
anderson |
83 |
if (!$isJson) {
|
|
|
84 |
$isJson = strpos($raw, 'json');
|
|
|
85 |
}
|
| 15679 |
anderson |
86 |
}
|
|
|
87 |
}
|
|
|
88 |
|
| 15755 |
anderson |
89 |
if ($isJson) {
|
| 15745 |
anderson |
90 |
|
| 15755 |
anderson |
91 |
$data = [
|
|
|
92 |
'items' => [],
|
|
|
93 |
'total' => 0,
|
| 15745 |
anderson |
94 |
|
| 15755 |
anderson |
95 |
];
|
| 15745 |
anderson |
96 |
|
| 15755 |
anderson |
97 |
$search = $this->params()->fromQuery('search');
|
|
|
98 |
$search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
|
|
|
99 |
$page = intval($this->params()->fromQuery('start', 1), 10);
|
|
|
100 |
$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
|
|
101 |
$order = $this->params()->fromQuery('order', []);
|
|
|
102 |
$order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
|
|
|
103 |
$order_direction = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var($order[0]['dir'], FILTER_SANITIZE_STRING));
|
|
|
104 |
$fields = ['first_name', 'last_name', 'corporate_email', 'activity'];
|
|
|
105 |
$order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'first_name';
|
| 15682 |
anderson |
106 |
|
| 15755 |
anderson |
107 |
if (!in_array($order_direction, ['ASC', 'DESC'])) {
|
|
|
108 |
$order_direction = 'ASC';
|
|
|
109 |
}
|
| 15682 |
anderson |
110 |
|
| 15687 |
anderson |
111 |
|
| 15755 |
anderson |
112 |
//Quede aqui en el mapper
|
|
|
113 |
$discoveryContactLogMapper = DiscoveryContactLogMapper::getInstance($this->adapter);
|
|
|
114 |
$contactLogMappers = $discoveryContactLogMapper->fetchAll();
|
| 15717 |
anderson |
115 |
|
| 15755 |
anderson |
116 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
117 |
$sql = $queryMapper->getSql();
|
|
|
118 |
$select = $sql->select();
|
|
|
119 |
$select->columns(['user_id', 'activity', 'details', 'added_on']);
|
|
|
120 |
$select->from(['tb1' => DiscoveryContactLogMapper::_TABLE], ['activity', 'details', 'added_on']);
|
|
|
121 |
$select->join(['tb2' => UserMapper::_TABLE], 'tb1.user_id = tb2.id', ['uuid', 'first_name', 'last_name', 'email']);
|
|
|
122 |
$select->join(['tb3' => CompanyMapper::_TABLE], 'tb1.company_id = tb3.id', ['name']);
|
| 15727 |
anderson |
123 |
|
| 15755 |
anderson |
124 |
if ($search) {
|
|
|
125 |
$select->where->nest()
|
|
|
126 |
->like('first_name', '%' . $search . '%')
|
|
|
127 |
->or->like('last_name', '%' . $search . '%')
|
|
|
128 |
->or->like('email', '%' . $search . '%')
|
|
|
129 |
->unnest();
|
|
|
130 |
}
|
| 15727 |
anderson |
131 |
|
| 15755 |
anderson |
132 |
$select->order($order_field . ' ' . $order_direction);
|
|
|
133 |
$hydrator = new ArraySerializableHydrator();
|
|
|
134 |
$resultset = new HydratingResultSet($hydrator);
|
|
|
135 |
$adapter = new DbSelect($select, $sql, $resultset);
|
|
|
136 |
$paginator = new Paginator($adapter);
|
|
|
137 |
$paginator->setItemCountPerPage($records_x_page);
|
|
|
138 |
$paginator->setCurrentPageNumber($page);
|
| 15727 |
anderson |
139 |
|
|
|
140 |
|
| 15755 |
anderson |
141 |
$items = [];
|
|
|
142 |
$records = $paginator->getCurrentItems();
|
|
|
143 |
foreach ($records as $record) {
|
| 15733 |
anderson |
144 |
|
| 15755 |
anderson |
145 |
$dt_added_on = \DateTime::createFromFormat('Y-m-d H:i:s', $record['added_on']);
|
|
|
146 |
$added_on = $dt_added_on->format('d/m/Y h:i a');
|
|
|
147 |
$item = [
|
|
|
148 |
'uuid' => $record['uuid'],
|
|
|
149 |
'first_name' => ucwords(strtolower($record['first_name'])),
|
|
|
150 |
'last_name' => ucwords(strtolower($record['last_name'])),
|
|
|
151 |
'email' => strtolower($record['email']),
|
|
|
152 |
'company' => $record['name'],
|
|
|
153 |
'activity' => $record['activity'],
|
|
|
154 |
'details' => $record['details'],
|
|
|
155 |
'added_on' => $added_on,
|
|
|
156 |
];
|
| 15733 |
anderson |
157 |
|
|
|
158 |
|
| 15755 |
anderson |
159 |
array_push($items, $item);
|
|
|
160 |
}
|
| 15745 |
anderson |
161 |
|
| 15755 |
anderson |
162 |
$data['items'] = $items;
|
|
|
163 |
$data['total'] = $paginator->getTotalItemCount();
|
| 15746 |
anderson |
164 |
|
| 15755 |
anderson |
165 |
return new JsonModel([
|
|
|
166 |
'success' => true,
|
|
|
167 |
'data' => $data
|
|
|
168 |
]);
|
|
|
169 |
} else {
|
| 15780 |
anderson |
170 |
// $this->layout()->setTemplate('layout/layout-backend');
|
|
|
171 |
// $viewModel = new ViewModel();
|
|
|
172 |
// $viewModel->setTemplate('leaders-linked/discovery-contact-progress/index.phtml');
|
|
|
173 |
// return $viewModel;
|
|
|
174 |
// return new JsonModel([
|
|
|
175 |
// 'success' => true,
|
|
|
176 |
// 'message' => $currentCompany->id
|
|
|
177 |
// ]);
|
| 15755 |
anderson |
178 |
}
|
| 15675 |
anderson |
179 |
}
|
| 15670 |
anderson |
180 |
}
|
|
|
181 |
}
|