Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16234 | Rev 16238 | 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
 
16144 anderson 77
        if ($request->isGet()) {
78
            $headers  = $request->getHeaders();
79
            $isJson = false;
15795 anderson 80
 
16144 anderson 81
            if ($headers->has('Accept')) {
82
                $accept = $headers->get('Accept');
15796 anderson 83
 
16144 anderson 84
                $prioritized = $accept->getPrioritized();
15796 anderson 85
 
16144 anderson 86
                foreach ($prioritized as $key => $value) {
87
                    $raw = trim($value->getRaw());
15796 anderson 88
 
16144 anderson 89
                    if (!$isJson) {
90
                        $isJson = strpos($raw, 'json');
91
                    }
15796 anderson 92
                }
93
            }
94
 
16144 anderson 95
            if ($isJson) {
96
                $startDate = $this->params()->fromQuery('startDate');
97
                if (empty($startDate)) {
98
                    $startDate = date('Y-m-d');
99
                }
15798 anderson 100
 
16144 anderson 101
                $endDate = $this->params()->fromQuery('endDate');
102
                if (empty($endDate)) {
103
                    $endDate = date('Y-m-d');
104
                }
15800 anderson 105
 
16235 anderson 106
                $startDate = '2023-01-01';
107
                $endDate = '2023-05-16';
15800 anderson 108
 
16144 anderson 109
                $dtStartDate = \DateTime::createFromFormat('Y-n-d', $startDate);
110
                $dtEndDate = \DateTime::createFromFormat('Y-n-d', $endDate);
15800 anderson 111
 
16144 anderson 112
                if (!$dtStartDate || !$dtEndDate) {
113
                    $startDate = date('Y-m-d');
114
                    $endDate = date('Y-m-d');
115
                } else {
16125 anderson 116
 
16144 anderson 117
                    if ($dtStartDate->getTimestamp() > $dtEndDate->getTimestamp()) {
118
                        $startDate = date('Y-m-d');
119
                        $endDate = date('Y-m-d');
120
                    }
121
                }
15806 anderson 122
 
16144 anderson 123
                $contactProgressRecordMapper = DiscoveryContactLogMapper::getInstance($this->adapter);
124
                $dailyProgress = $contactProgressRecordMapper->fetchAllDataByDateRange($currentUser->id, $startDate, $endDate);
15806 anderson 125
 
15970 anderson 126
 
16172 anderson 127
                $total = count($dailyProgress);
16144 anderson 128
                $data = [
16160 anderson 129
                    'total_by_day' => [],
130
                    'added_on' => [],
16172 anderson 131
                    'total' => []
16144 anderson 132
                ];
16125 anderson 133
 
16144 anderson 134
                foreach ($dailyProgress as $record) {
135
                    $users = $record['user_id'];
16222 anderson 136
                    $added_on = date("d-m-Y", strtotime($record['added_on']));
16172 anderson 137
                    $total = count($dailyProgress);
16160 anderson 138
                    array_push($data['total_by_day'], $users);
139
                    array_push($data['added_on'], $added_on);
16172 anderson 140
                    array_push($data['total'], $total);
16144 anderson 141
                }
15842 anderson 142
 
16143 anderson 143
 
16144 anderson 144
                return new JsonModel([
145
                    'success' => true,
146
                    'data' => $data
147
                ]);
148
            } else {
149
                $this->layout()->setTemplate('layout/layout-backend');
150
                $viewModel = new ViewModel();
151
                $viewModel->setTemplate('leaders-linked/discovery-contact-progress/index.phtml');
152
                return $viewModel;
153
            }
154
        }
15670 anderson 155
    }
156
}