Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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