Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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