Rev 16627 | Rev 16758 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
<?php
declare(strict_types=1);
namespace LeadersLinked\Controller;
use LeadersLinked\Model\User;
use Laminas\View\Model\JsonModel;
use Laminas\View\Model\ViewModel;
use LeadersLinked\Mapper\UserMapper;
use LeadersLinked\Mapper\QueryMapper;
use LeadersLinked\Mapper\DiscoveryContactMapper;
use LeadersLinked\Mapper\DiscoveryContactLogMapper;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\Hydrator\ArraySerializableHydrator;
use Laminas\Db\ResultSet\HydratingResultSet;
use Laminas\Paginator\Adapter\DbSelect;
use Laminas\Paginator\Paginator;
use LeadersLinked\Mapper\CompanyMapper;
use LeadersLinked\Model\DiscoveryContactLog;
use LeadersLinked\Model\Push;
// Create an action controller.
class DiscoveryContactProgressController extends AbstractActionController
{
/**
*
* @var AdapterInterface
*/
private $adapter;
/**
*
* @var AbstractAdapter
*/
private $cache;
/**
*
* @var LoggerInterface
*/
private $logger;
/**
*
* @var array
*/
private $config;
/**
*
* @param AdapterInterface $adapter
* @param AbstractAdapter $cache
* @param LoggerInterface $logger
* @param array $config
*/
public function __construct($adapter, $cache, $logger, $config)
{
$this->adapter = $adapter;
$this->cache = $cache;
$this->logger = $logger;
$this->config = $config;
}
public function indexAction()
{
$currentUserPlugin = $this->plugin('currentUserPlugin');
$currentUser = $currentUserPlugin->getUser();
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
$currentNetwork = $currentNetworkPlugin->getNetwork();
$request = $this->getRequest();
if ($request->isGet()) {
$headers = $request->getHeaders();
$isJson = false;
if ($headers->has('Accept')) {
$accept = $headers->get('Accept');
$prioritized = $accept->getPrioritized();
foreach ($prioritized as $key => $value) {
$raw = trim($value->getRaw());
if (!$isJson) {
$isJson = strpos($raw, 'json');
}
}
}
//Anderson
if ($isJson) {
$startDate = $this->params()->fromQuery('startDate');
if (empty($startDate)) {
$startDate = date('Y-m-d');
}
$endDate = $this->params()->fromQuery('endDate');
if (empty($endDate)) {
$endDate = date('Y-m-d');
}
$startDate = '2023-01-01';
$endDate = '2023-12-31';
$dtStartDate = \DateTime::createFromFormat('Y-n-d', $startDate);
$dtEndDate = \DateTime::createFromFormat('Y-n-d', $endDate);
if (!$dtStartDate || !$dtEndDate) {
$startDate = date('Y-m-d');
$endDate = date('Y-m-d');
} else {
if ($dtStartDate->getTimestamp() > $dtEndDate->getTimestamp()) {
$startDate = date('Y-m-d');
$endDate = date('Y-m-d');
}
}
$contactProgressRecordMapper = DiscoveryContactLogMapper::getInstance($this->adapter);
$dailyProgress = $contactProgressRecordMapper->fetchAllDataByDateRange($currentUser->id, $startDate, $endDate);
$dateByRage = $contactProgressRecordMapper->anderson($startDate, $endDate);
$items = [];
$i = 0;
foreach ($dateByRage as $key => $value) {
setlocale(LC_TIME, "es_ES");
setlocale(LC_TIME, 'es_ES.UTF-8');
$userOne = UserMapper::getInstance($this->adapter);
$users = $userOne->fetchOne($value['user_id']);
$added_on = strtoupper(date("d/F", strtotime($value['date'])));
$items[$i]["month"] = $added_on;
$items[$i]["users"] = $users->first_name . ' ' . $users->last_name;
$items[$i]["total"] = $value['total'];
$items[$i]["users_id"] = $users->id;
$i++;
}
// var_dump($items);
// die();
//var_dump($ander);
//die();
$total = count($dailyProgress);
$data = [
'total_by_day' => [],
'added_on' => [],
'total' => [],
'first_name' => [],
'last_name' => [],
'email' => []
];
//$items = [];
foreach ($dailyProgress as $record) {
$users = $record['user_id'];
$added_on = date("d-m-Y", strtotime($record['added_on']));
$total = count($dailyProgress);
$first_name = $record['first_name'];
$last_name = $record['last_name'];
$email = $record['email'];
array_push($data['total_by_day'], $users);
array_push($data['added_on'], $added_on);
array_push($data['total'], $total);
array_push($data['first_name'], $first_name);
array_push($data['last_name'], $last_name);
array_push($data['email'], $email);
// $item = [
// 'total_by_day' => $users,
// 'added_on' => $added_on,
// 'total' => $total,
// 'first_name' => $first_name,
// 'last_name' => $last_name,
// 'email' => $email,
// ];
// array_push($items, $item);
}
return new JsonModel([
'success' => true,
'data' => $data, //grafica
'items' => $items //tabla
]);
} else {
$this->layout()->setTemplate('layout/layout-backend');
$viewModel = new ViewModel();
$viewModel->setTemplate('leaders-linked/discovery-contact-progress/index.phtml');
return $viewModel;
}
}
}
}