Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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