Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6331 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
4235 efrain 1
<?php
5833 anderson 2
 
4235 efrain 3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Mapper;
6
 
7
 
6322 anderson 8
use Laminas\Db\Sql\Expression;
9
use LeadersLinked\Mapper\UserMapper;
10
use Laminas\Paginator\Adapter\DbSelect;
4235 efrain 11
use Laminas\Db\Adapter\AdapterInterface;
6322 anderson 12
use Laminas\Db\ResultSet\HydratingResultSet;
4235 efrain 13
use LeadersLinked\Model\DiscoveryContactLog;
6322 anderson 14
use LeadersLinked\Mapper\Common\MapperCommon;
4235 efrain 15
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
6330 efrain 16
use LeadersLinked\Model\DiscoveryContact;
4235 efrain 17
 
18
 
5840 anderson 19
 
4235 efrain 20
class DiscoveryContactLogMapper extends MapperCommon
21
{
22
    const _TABLE = 'tbl_discovery_contact_logs';
23
 
24
    /**
25
     *
26
     * @var DiscoveryContactLogMapper
27
     */
28
    private static $_instance;
5833 anderson 29
 
4235 efrain 30
    /**
31
     *
32
     * @param AdapterInterface $adapter
33
     */
34
    private function __construct($adapter)
35
    {
36
        parent::__construct($adapter);
37
    }
5833 anderson 38
 
4235 efrain 39
    /**
40
     *
41
     * @param AdapterInterface $adapter
42
     * @return DiscoveryContactLogMapper
43
     */
44
    public static function getInstance($adapter)
45
    {
5833 anderson 46
        if (self::$_instance == null) {
4235 efrain 47
            self::$_instance = new DiscoveryContactLogMapper($adapter);
48
        }
49
        return self::$_instance;
50
    }
5833 anderson 51
 
4235 efrain 52
    /**
53
     *
6330 efrain 54
     * @return DiscoveryContact[]
5836 anderson 55
     */
56
    public function fetchAll()
57
    {
58
        $prototype = new DiscoveryContactLog();
59
        $select = $this->sql->select(self::_TABLE);
60
        $select->order('id ASC');
61
 
62
        return $this->executeFetchAllObject($select, $prototype);
63
    }
64
 
5838 anderson 65
 
6314 anderson 66
    public function fetchAllDataByDateRange($user_id, $start_date, $end_date)
67
    {
68
        $select = $this->sql->select();
69
        $select->columns([
70
            'added_on',
71
            'user_id' => new Expression('COUNT(user_id)'),
72
        ]);
73
        $select->from(['dcl' => DiscoveryContactLogMapper::_TABLE]);
74
        $select->join(['u' => UserMapper::_TABLE], 'u.id = dcl.user_id', ['first_name', 'last_name', 'email']);
75
        $select->where->between('dcl.added_on', $start_date, $end_date);
76
        $select->where->equalTo('dcl.activity', 'LABEL_RECORD_CONTACT_ADDED');
77
        $select->group('dcl.added_on');
78
        $select->order('dcl.added_on ASC');
6313 anderson 79
 
6314 anderson 80
        return $this->executeFetchAllArray($select);
81
    }
6313 anderson 82
 
6314 anderson 83
    public function anderson($start_date, $end_date)
5838 anderson 84
    {
6318 anderson 85
        $select = $this->sql->select(self::_TABLE);
86
        $select->columns([
6313 anderson 87
            'user_id',
88
            'date' => new Expression('DATE(added_on)'),
89
            'total' => new Expression('COUNT(*)')
6288 anderson 90
        ]);
6321 anderson 91
 
6318 anderson 92
        $select->where->between(new Expression('DATE(added_on)'), $start_date, $end_date);
93
        $select->where->equalTo('activity', 'LABEL_RECORD_CONTACT_ADDED');
94
        $select->group([
6313 anderson 95
            'user_id',
96
            new Expression('DATE(added_on)'),
97
        ]);
6318 anderson 98
        $select->order('added_on ASC');
6313 anderson 99
 
100
        //echo $select->getSqlString($this->adapter->platform); exit;
101
 
102
 
6318 anderson 103
        return $this->executeFetchAllArray($select);
5838 anderson 104
    }
105
 
6313 anderson 106
 
5836 anderson 107
    /**
6330 efrain 108
     *
109
     * @param int $contact_id
6331 efrain 110
     * @return DiscoveryContactLog
6330 efrain 111
     */
112
    public function fetchOneFirstByContactId($contact_id)
113
    {
114
 
115
        $select = $this->sql->select(self::_TABLE);
116
        $select->where->equalTo('contact_id', $contact_id);
117
        $select->order('id ASC');
118
 
119
        $prototype = new DiscoveryContactLog();
120
        return $this->executeFetchOneObject($select, $prototype);
121
    }
122
 
123
 
124
    /**
5836 anderson 125
     *
4235 efrain 126
     * @param int $id
127
     * @return DiscoveryContactLogMapper
128
     */
129
    public function fetchOne($id)
130
    {
5833 anderson 131
 
4235 efrain 132
        $select = $this->sql->select(self::_TABLE);
133
        $select->where->equalTo('id', $id);
5833 anderson 134
 
4235 efrain 135
        $prototype = new DiscoveryContactLog();
136
        return $this->executeFetchOneObject($select, $prototype);
137
    }
5833 anderson 138
 
4235 efrain 139
    /**
140
     *
141
     * @param string $uuid
142
     * @return DiscoveryContactLogMapper
143
     */
144
    public function fetchOneByUuid($uuid)
145
    {
5833 anderson 146
 
4235 efrain 147
        $select = $this->sql->select(self::_TABLE);
148
        $select->where->equalTo('uuid', $uuid);
5833 anderson 149
 
4235 efrain 150
        $prototype = new DiscoveryContactLog();
151
        return $this->executeFetchOneObject($select, $prototype);
152
    }
5833 anderson 153
 
4235 efrain 154
    /**
155
     *
156
     * @param int $company_id
157
     * @param int $contact_id
158
     * @param int $page
159
     * @param int $records_per_page
160
     * @return Paginator
161
     */
162
    public function fetchAllDataTableForCompanyIdAndContactId($company_id, $contact_id,  $page = 1, $records_per_page = 10)
163
    {
164
        $prototype = new DiscoveryContactLog();
165
        $select = $this->sql->select(self::_TABLE);
166
        $select->where->equalTo('company_id', $company_id);
167
        $select->where->equalTo('contact_id', $contact_id);
168
        $select->order('added_on DESC');
5833 anderson 169
 
4235 efrain 170
        $hydrator   = new ObjectPropertyHydrator();
171
        $resultset  = new HydratingResultSet($hydrator, $prototype);
5833 anderson 172
 
4235 efrain 173
        $adapter = new DbSelect($select, $this->sql, $resultset);
5833 anderson 174
        $paginator = new Paginator($adapter);
4235 efrain 175
        $paginator->setItemCountPerPage($records_per_page);
176
        $paginator->setCurrentPageNumber($page);
5833 anderson 177
 
178
 
4235 efrain 179
        return $paginator;
180
    }
5833 anderson 181
 
182
 
4235 efrain 183
    /**
184
     *
185
     * @param DiscoveryContactLog $record
186
     * @return boolean
187
     */
188
    public function insert($record)
189
    {
190
        $hydrator = new ObjectPropertyHydrator();
191
        $values = $hydrator->extract($record);
192
        $values = $this->removeEmpty($values);
5833 anderson 193
 
4235 efrain 194
        $insert = $this->sql->insert(self::_TABLE);
195
        $insert->values($values);
196
        $result = $this->executeInsert($insert);
5833 anderson 197
 
198
        if ($result) {
4235 efrain 199
            $record->id = $this->lastInsertId;
200
        }
5833 anderson 201
 
4235 efrain 202
        return $result;
203
    }
204
 
5833 anderson 205
 
6388 efrain 206
    /**
207
     *
208
     * @param array $values
209
     * @return boolean
210
     */
211
    public function insertRaw($values)
212
    {
213
        $insert = $this->sql->insert(self::_TABLE);
214
        $insert->values($values);
215
        return $this->executeInsert($insert);
5833 anderson 216
 
6388 efrain 217
    }
218
 
5833 anderson 219
 
220
 
221
 
4235 efrain 222
    /**
223
     *
224
     * @param DiscoveryContactLog $record
225
     * @return boolean
226
     */
227
    public function delete($record)
228
    {
229
        $delete = $this->sql->delete(self::_TABLE);
230
        $delete->where->equalTo('id', $record->id);
5833 anderson 231
 
4235 efrain 232
        return $this->executeDelete($delete);
233
    }
5833 anderson 234
}