Proyectos de Subversion LeadersLinked - Backend

Rev

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