Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

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