Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16245 | Rev 16305 | 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;
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;
15806 anderson 20
use LeadersLinked\Model\DiscoveryContactLog;
15970 anderson 21
use LeadersLinked\Model\Push;
15670 anderson 22
 
23
// Create an action controller.
24
class DiscoveryContactProgressController extends AbstractActionController
25
{
15682 anderson 26
    /**
27
     *
28
     * @var AdapterInterface
29
     */
30
    private $adapter;
31
 
32
 
33
    /**
34
     *
35
     * @var AbstractAdapter
36
     */
37
    private $cache;
38
 
39
    /**
40
     *
41
     * @var  LoggerInterface
42
     */
43
    private $logger;
44
 
45
    /**
46
     *
47
     * @var array
48
     */
49
    private $config;
50
 
51
    /**
52
     *
53
     * @param AdapterInterface $adapter
54
     * @param AbstractAdapter $cache
55
     * @param LoggerInterface $logger
56
     * @param array $config
57
     */
58
    public function __construct($adapter, $cache, $logger, $config)
59
    {
60
        $this->adapter      = $adapter;
61
        $this->cache        = $cache;
62
        $this->logger       = $logger;
63
        $this->config       = $config;
64
    }
65
 
15670 anderson 66
 
15678 anderson 67
 
15679 anderson 68
 
15788 anderson 69
    public function indexAction()
70
    {
15792 anderson 71
        $currentUserPlugin = $this->plugin('currentUserPlugin');
72
        $currentUser = $currentUserPlugin->getUser();
15793 anderson 73
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
74
        $currentNetwork = $currentNetworkPlugin->getNetwork();
15796 anderson 75
        $request = $this->getRequest();
15793 anderson 76
 
16238 anderson 77
 
16239 anderson 78
 
16304 anderson 79
        //if ($request->isGet()) {
80
        $headers  = $request->getHeaders();
81
        $isJson = false;
15795 anderson 82
 
16304 anderson 83
        if ($headers->has('Accept')) {
84
            $accept = $headers->get('Accept');
15796 anderson 85
 
16304 anderson 86
            $prioritized = $accept->getPrioritized();
15796 anderson 87
 
16304 anderson 88
            foreach ($prioritized as $key => $value) {
89
                $raw = trim($value->getRaw());
15796 anderson 90
 
16304 anderson 91
                if (!$isJson) {
92
                    $isJson = strpos($raw, 'json');
15796 anderson 93
                }
94
            }
16304 anderson 95
        }
96
        //Anderson
97
        //if ($isJson) {
16241 anderson 98
 
16304 anderson 99
        $startDate = $this->params()->fromQuery('startDate');
100
        if (empty($startDate)) {
101
            $startDate = date('Y-m-d');
102
        }
15798 anderson 103
 
16304 anderson 104
        $endDate = $this->params()->fromQuery('endDate');
105
        if (empty($endDate)) {
106
            $endDate = date('Y-m-d');
107
        }
15800 anderson 108
 
16304 anderson 109
        $startDate = '2023-01-01';
110
        $endDate = '2023-05-16';
15800 anderson 111
 
16304 anderson 112
        $dtStartDate = \DateTime::createFromFormat('Y-n-d', $startDate);
113
        $dtEndDate = \DateTime::createFromFormat('Y-n-d', $endDate);
15800 anderson 114
 
16304 anderson 115
        if (!$dtStartDate || !$dtEndDate) {
116
            $startDate = date('Y-m-d');
117
            $endDate = date('Y-m-d');
118
        } else {
16125 anderson 119
 
16304 anderson 120
            if ($dtStartDate->getTimestamp() > $dtEndDate->getTimestamp()) {
121
                $startDate = date('Y-m-d');
122
                $endDate = date('Y-m-d');
123
            }
124
        }
15806 anderson 125
 
16304 anderson 126
        $contactProgressRecordMapper = DiscoveryContactLogMapper::getInstance($this->adapter);
127
        $dailyProgress = $contactProgressRecordMapper->fetchAllDataByDateRange($currentUser->id, $startDate, $endDate);
15806 anderson 128
 
15970 anderson 129
 
16304 anderson 130
        $total = count($dailyProgress);
131
        $data = [
132
            'total_by_day' => [],
133
            'added_on' => [],
134
            'total' => []
135
        ];
16125 anderson 136
 
16304 anderson 137
        foreach ($dailyProgress as $record) {
138
            $users = $record['user_id'];
139
            $added_on = date("d-m-Y", strtotime($record['added_on']));
140
            $total = count($dailyProgress);
141
            array_push($data['total_by_day'], $users);
142
            array_push($data['added_on'], $added_on);
143
            array_push($data['total'], $total);
144
        }
15842 anderson 145
 
16143 anderson 146
 
16304 anderson 147
        return new JsonModel([
148
            'success' => true,
149
            'data' => $data
150
        ]);
151
        // } else {
152
        //     $this->layout()->setTemplate('layout/layout-backend');
153
        //     $viewModel = new ViewModel();
154
        //     $viewModel->setTemplate('leaders-linked/discovery-contact-progress/index.phtml');
155
        //     return $viewModel;
156
        // }
157
        //}
15670 anderson 158
    }
159
}