Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Mapper;
6
 
7
 
8
use Laminas\Db\Adapter\AdapterInterface;
9
use Laminas\Db\ResultSet\HydratingResultSet;
10
use Laminas\Paginator\Adapter\DbSelect;
11
use Laminas\Paginator\Paginator;
12
use Laminas\Log\LoggerInterface;
13
use Laminas\Hydrator\ArraySerializableHydrator;
14
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
15
 
16
use LeadersLinked\Model\CompanyRole;
17
use LeadersLinked\Mapper\Common\MapperCommon;
18
 
19
 
20
class CompanyRoleMapper extends MapperCommon
21
{
22
    const _TABLE = 'tbl_company_roles';
23
 
24
 
25
    /**
26
     *
27
     * @var CompanyRoleMapper
28
     */
29
    private static $_instance;
30
 
31
    /**
32
     *
33
     * @param AdapterInterface $adapter
34
     */
35
    private function __construct($adapter)
36
    {
37
        parent::__construct($adapter);
38
    }
39
 
40
    /**
41
     *
42
     * @param AdapterInterface $adapter
43
     * @return CompanyRoleMapper
44
     */
45
    public static function getInstance($adapter)
46
    {
47
        if(self::$_instance == null) {
48
            self::$_instance = new CompanyRoleMapper($adapter);
49
        }
50
        return self::$_instance;
51
    }
52
 
53
    /**
54
     *
55
     * @param int $id
56
     * @return CompanyRole
57
     */
58
    public function fetchOne($id)
59
    {
60
        $select = $this->sql->select(self::_TABLE);
61
        $select->where->equalTo('id', $id);
62
        $select->limit(1);
63
 
64
        $prototype = new CompanyRole();
65
        return $this->executeFetchOneObject($select, $prototype);
66
    }
67
 
68
    /**
69
     *
70
     * @param int $company_id
71
     * @param int $role_id
72
     * @return CompanyRole
73
     */
74
    public function fetchOneByCompanyIdAndRoleId($company_id, $role_id)
75
    {
76
        $select = $this->sql->select(self::_TABLE);
77
        $select->where->equalTo('company_id', $company_id);
78
        $select->where->equalTo('role_id', $role_id);
79
        $select->limit(1);
80
 
81
        $prototype = new CompanyRole();
82
        return $this->executeFetchOneObject($select, $prototype);
83
    }
84
 
85
 
86
    /**
87
     *
88
     * @param int $company_id
89
     * @return CompanyRole[]
90
     */
91
    public function fetchAllByCompanyId($company_id)
92
    {
93
        $prototype = new CompanyRole();
94
        $select = $this->sql->select(self::_TABLE);
95
        $select->where->equalTo('company_id', $company_id);
96
 
97
        return $this->executeFetchAllObject($select, $prototype);
98
    }
99
 
100
    /**
101
     *
102
     * @param CompanyRole $companyRole
103
     * @return boolean
104
     */
105
    public function insert($companyRole)
106
    {
107
        $hydrator = new ObjectPropertyHydrator();
108
        $values = $hydrator->extract($companyRole);
109
        $values = $this->removeEmpty($values);
110
 
111
        $insert = $this->sql->insert(self::_TABLE);
112
        $insert->values($values);
113
 
114
 
115
        $result = $this->executeInsert($insert);
116
        if($result) {
117
            $companyRole->id = $this->lastInsertId;
118
        }
119
 
120
        return $result;
121
 
122
    }
123
 
124
 
125
 
126
    /**
127
     *
128
     * @param int $id
129
     * @return boolean
130
     */
131
    public function delete($id)
132
    {
133
        $delete = $this->sql->delete(self::_TABLE);
134
        $delete->where->equalTo('id', $id);
135
 
136
        return $this->executeDelete($delete);
137
 
138
    }
139
 
140
    /**
141
     *
142
     * @param int $company_id
143
     * @param int $role_id
144
     * @return boolean
145
     */
146
    public function deleteByCompanyIdAndRoleId($company_id, $role_id)
147
    {
148
        $delete = $this->sql->delete(self::_TABLE);
149
        $delete->where->equalTo('company_id', $company_id);
150
        $delete->where->equalTo('role_id', $company_id);
151
 
152
        return $this->executeDelete($delete);
153
 
154
    }
155
 
156
}