Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6324 | Rev 6326 | 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
    {
6325 anderson 107
        var_dump($id);
108
        die();
6323 anderson 109
        $select = $this->sql->select();
6324 anderson 110
        // $select->columns([
111
        //     'first_name',
112
        //     'last_name',
113
        // ]);
6322 anderson 114
        $select->from(UserMapper::_TABLE);
115
        $select->where->equalTo('id', $id);
6313 anderson 116
 
6322 anderson 117
        $prototype = new UserMapper();
118
        return $this->executeFetchOneObject($select, $prototype);
119
    }
6313 anderson 120
 
5836 anderson 121
    /**
122
     *
4235 efrain 123
     * @param int $id
124
     * @return DiscoveryContactLogMapper
125
     */
126
    public function fetchOne($id)
127
    {
5833 anderson 128
 
4235 efrain 129
        $select = $this->sql->select(self::_TABLE);
130
        $select->where->equalTo('id', $id);
5833 anderson 131
 
4235 efrain 132
        $prototype = new DiscoveryContactLog();
133
        return $this->executeFetchOneObject($select, $prototype);
134
    }
5833 anderson 135
 
4235 efrain 136
    /**
137
     *
138
     * @param string $uuid
139
     * @return DiscoveryContactLogMapper
140
     */
141
    public function fetchOneByUuid($uuid)
142
    {
5833 anderson 143
 
4235 efrain 144
        $select = $this->sql->select(self::_TABLE);
145
        $select->where->equalTo('uuid', $uuid);
5833 anderson 146
 
4235 efrain 147
        $prototype = new DiscoveryContactLog();
148
        return $this->executeFetchOneObject($select, $prototype);
149
    }
5833 anderson 150
 
4235 efrain 151
    /**
152
     *
153
     * @param int $company_id
154
     * @param int $contact_id
155
     * @param int $page
156
     * @param int $records_per_page
157
     * @return Paginator
158
     */
159
    public function fetchAllDataTableForCompanyIdAndContactId($company_id, $contact_id,  $page = 1, $records_per_page = 10)
160
    {
161
        $prototype = new DiscoveryContactLog();
162
        $select = $this->sql->select(self::_TABLE);
163
        $select->where->equalTo('company_id', $company_id);
164
        $select->where->equalTo('contact_id', $contact_id);
165
        $select->order('added_on DESC');
5833 anderson 166
 
4235 efrain 167
        $hydrator   = new ObjectPropertyHydrator();
168
        $resultset  = new HydratingResultSet($hydrator, $prototype);
5833 anderson 169
 
4235 efrain 170
        $adapter = new DbSelect($select, $this->sql, $resultset);
5833 anderson 171
        $paginator = new Paginator($adapter);
4235 efrain 172
        $paginator->setItemCountPerPage($records_per_page);
173
        $paginator->setCurrentPageNumber($page);
5833 anderson 174
 
175
 
4235 efrain 176
        return $paginator;
177
    }
5833 anderson 178
 
179
 
4235 efrain 180
    /**
181
     *
182
     * @param DiscoveryContactLog $record
183
     * @return boolean
184
     */
185
    public function insert($record)
186
    {
187
        $hydrator = new ObjectPropertyHydrator();
188
        $values = $hydrator->extract($record);
189
        $values = $this->removeEmpty($values);
5833 anderson 190
 
4235 efrain 191
        $insert = $this->sql->insert(self::_TABLE);
192
        $insert->values($values);
193
        $result = $this->executeInsert($insert);
5833 anderson 194
 
195
        if ($result) {
4235 efrain 196
            $record->id = $this->lastInsertId;
197
        }
5833 anderson 198
 
4235 efrain 199
        return $result;
200
    }
201
 
5833 anderson 202
 
203
 
204
 
205
 
206
 
4235 efrain 207
    /**
208
     *
209
     * @param DiscoveryContactLog $record
210
     * @return boolean
211
     */
212
    public function delete($record)
213
    {
214
        $delete = $this->sql->delete(self::_TABLE);
215
        $delete->where->equalTo('id', $record->id);
5833 anderson 216
 
4235 efrain 217
        return $this->executeDelete($delete);
218
    }
5833 anderson 219
}