Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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