Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6287 | Rev 6289 | 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
 
64
    public function fetchAllDataByDateRange($user_id, $start_date, $end_date)
65
    {
6284 anderson 66
        // $select = $this->sql->select(self::_TABLE);
67
        // $select->columns([
68
        //     'added_on',
69
        //     //'activity' => new Expression('SUM(LABEL_RECORD_CONTACT_ADDED)'),
70
        //     'user_id' => new Expression('COUNT(user_id)')
71
        // ]);
6288 anderson 72
        // //$select->where->equalTo('user_id', $user_id);
73
        // $select->where->between('added_on', $start_date, $end_date);
74
        // $select->where->equalTo('activity', 'LABEL_RECORD_CONTACT_ADDED');
75
        // $select->group('added_on');
76
        // $select->order('added_on ASC');
5838 anderson 77
 
78
        //echo $select->getSqlString($this->adapter->platform); exit;
79
 
6288 anderson 80
        $select = $this->sql->select();
81
        $select->columns([
82
            'added_on',
83
            'user_id' => new Expression('COUNT(user_id)'),
84
        ]);
85
        $select->from(['dcl' => DiscoveryContactLogMapper::_TABLE]);
86
        $select->join(['u' => UserMapper::_TABLE], 'u.id = dcl.user_id', ['first_name', 'last_name', 'email']);
87
        $select->order('added_on ASC');
5838 anderson 88
 
6288 anderson 89
 
5838 anderson 90
        return $this->executeFetchAllArray($select);
91
    }
92
 
5836 anderson 93
    /**
94
     *
4235 efrain 95
     * @param int $id
96
     * @return DiscoveryContactLogMapper
97
     */
98
    public function fetchOne($id)
99
    {
5833 anderson 100
 
4235 efrain 101
        $select = $this->sql->select(self::_TABLE);
102
        $select->where->equalTo('id', $id);
5833 anderson 103
 
4235 efrain 104
        $prototype = new DiscoveryContactLog();
105
        return $this->executeFetchOneObject($select, $prototype);
106
    }
5833 anderson 107
 
4235 efrain 108
    /**
109
     *
110
     * @param string $uuid
111
     * @return DiscoveryContactLogMapper
112
     */
113
    public function fetchOneByUuid($uuid)
114
    {
5833 anderson 115
 
4235 efrain 116
        $select = $this->sql->select(self::_TABLE);
117
        $select->where->equalTo('uuid', $uuid);
5833 anderson 118
 
4235 efrain 119
        $prototype = new DiscoveryContactLog();
120
        return $this->executeFetchOneObject($select, $prototype);
121
    }
5833 anderson 122
 
4235 efrain 123
    /**
124
     *
125
     * @param int $company_id
126
     * @param int $contact_id
127
     * @param int $page
128
     * @param int $records_per_page
129
     * @return Paginator
130
     */
131
    public function fetchAllDataTableForCompanyIdAndContactId($company_id, $contact_id,  $page = 1, $records_per_page = 10)
132
    {
133
        $prototype = new DiscoveryContactLog();
134
        $select = $this->sql->select(self::_TABLE);
135
        $select->where->equalTo('company_id', $company_id);
136
        $select->where->equalTo('contact_id', $contact_id);
137
        $select->order('added_on DESC');
5833 anderson 138
 
4235 efrain 139
        $hydrator   = new ObjectPropertyHydrator();
140
        $resultset  = new HydratingResultSet($hydrator, $prototype);
5833 anderson 141
 
4235 efrain 142
        $adapter = new DbSelect($select, $this->sql, $resultset);
5833 anderson 143
        $paginator = new Paginator($adapter);
4235 efrain 144
        $paginator->setItemCountPerPage($records_per_page);
145
        $paginator->setCurrentPageNumber($page);
5833 anderson 146
 
147
 
4235 efrain 148
        return $paginator;
149
    }
5833 anderson 150
 
151
 
4235 efrain 152
    /**
153
     *
154
     * @param DiscoveryContactLog $record
155
     * @return boolean
156
     */
157
    public function insert($record)
158
    {
159
        $hydrator = new ObjectPropertyHydrator();
160
        $values = $hydrator->extract($record);
161
        $values = $this->removeEmpty($values);
5833 anderson 162
 
4235 efrain 163
        $insert = $this->sql->insert(self::_TABLE);
164
        $insert->values($values);
165
        $result = $this->executeInsert($insert);
5833 anderson 166
 
167
        if ($result) {
4235 efrain 168
            $record->id = $this->lastInsertId;
169
        }
5833 anderson 170
 
4235 efrain 171
        return $result;
172
    }
173
 
5833 anderson 174
 
175
 
176
 
177
 
178
 
4235 efrain 179
    /**
180
     *
181
     * @param DiscoveryContactLog $record
182
     * @return boolean
183
     */
184
    public function delete($record)
185
    {
186
        $delete = $this->sql->delete(self::_TABLE);
187
        $delete->where->equalTo('id', $record->id);
5833 anderson 188
 
4235 efrain 189
        return $this->executeDelete($delete);
190
    }
5833 anderson 191
}