Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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