Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
547 geraldo 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\Model\CompanyPerformanceEvaluationForm;
9
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
10
use Laminas\Paginator\Paginator;
11
use Laminas\Db\ResultSet\HydratingResultSet;
12
use Laminas\Paginator\Adapter\DbSelect;
13
 
14
 
15
class CompanyPerformanceEvaluationFormMapper extends MapperCommon
16
{
548 geraldo 17
    const _TABLE = 'tbl_company_performance_evaluation_forms';
547 geraldo 18
 
19
    /**
20
     *
21
     * @var CompanyPerformanceEvaluationFormMapper
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 CompanyPerformanceEvaluationFormMapper
38
     */
39
    public static function getInstance($adapter)
40
    {
41
        if(self::$_instance == null) {
42
            self::$_instance = new CompanyPerformanceEvaluationFormMapper($adapter);
43
        }
44
        return self::$_instance;
45
    }
46
 
47
    /**
48
     *
49
     * @param int $id
50
     * @return CompanyPerformanceEvaluationForm
51
     */
52
    public function fetchOne($id)
53
    {
54
        $prototype = new CompanyPerformanceEvaluationForm();
55
 
56
        $select = $this->sql->select(self::_TABLE);
57
        $select->where->equalTo('id', $id);
58
 
59
        return $this->executeFetchOneObject($select, $prototype);
60
    }
61
 
62
 
63
    /**
64
     *
65
     * @param int $uuid
66
     * @return CompanyPerformanceEvaluationForm
67
     */
68
    public function fetchOneByUuid($uuid)
69
    {
70
        $prototype = new CompanyPerformanceEvaluationForm();
71
        $select = $this->sql->select(self::_TABLE);
72
        $select->where->equalTo('uuid', $uuid);
73
 
74
        return $this->executeFetchOneObject($select, $prototype);
75
    }
76
 
77
 
78
    /**
79
     *
80
     * @param int $company_id
81
     * @return CompanyPerformanceEvaluationForm
82
     */
83
    public function fetchAllByCompanyId($company_id)
84
    {
85
        $prototype = new CompanyPerformanceEvaluationForm();
86
 
87
        $select = $this->sql->select(self::_TABLE);
88
        $select->where->equalTo('company_id', $company_id);
2089 eleazar 89
        $select->where->equalTo('status', CompanyPerformanceEvaluationForm::STATUS_ACTIVE);
547 geraldo 90
        $select->order('name');
91
 
92
        return $this->executeFetchAllObject($select, $prototype);
93
    }
94
 
95
 
96
    /**
97
     *
98
     * @param CompanyPerformanceEvaluationForm $form
99
     * @return boolean
100
     */
101
    public function insert($form)
102
    {
103
        $hydrator = new ObjectPropertyHydrator();
104
        $values = $hydrator->extract($form);
105
        $values = $this->removeEmpty($values);
106
 
107
        $insert = $this->sql->insert(self::_TABLE);
108
        $insert->values($values);
109
 
110
        $result = $this->executeInsert($insert);
111
        if($result) {
112
            $form->id = $this->lastInsertId;
113
        }
552 geraldo 114
        return $result;
547 geraldo 115
    }
116
 
117
    /**
118
     *
119
     * @param CompanyPerformanceEvaluationForm $form
120
     * @return boolean
121
     */
122
    public function update($form)
123
    {
124
        $hydrator = new ObjectPropertyHydrator();
125
        $values = $hydrator->extract($form);
126
        $values = $this->removeEmpty($values);
127
 
128
        $update = $this->sql->update(self::_TABLE);
129
        $update->set($values);
130
        $update->where->equalTo('id', $form->id);
131
 
132
        return $this->executeUpdate($update);
133
    }
134
 
135
    /**
136
     *
137
     * @param int $form_id
138
     * @return boolean
139
     */
140
    public function delete($form_id)
141
    {
142
        $delete = $this->sql->delete(self::_TABLE);
143
        $delete->where->equalTo('id', $form_id);
144
 
145
        return $this->executeDelete($delete);
146
    }
147
 
148
 
149
    /**
150
     *
151
     * @param int $companyId
152
     * @param string $search
153
     * @param int $page
154
     * @param int $records_per_page
155
     * @param string $order_field
156
     * @param string $order_direction
157
     * @return Paginator
158
     */
159
    public function fetchAllDataTableByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
160
    {
161
        $prototype = new CompanyPerformanceEvaluationForm();
162
        $select = $this->sql->select(self::_TABLE);
163
        $select->where->equalTo('company_id', $companyId);
164
 
165
        if($search) {
166
            $select->where->like('name', '%' . $search . '%');
167
        }
168
        $select->order($order_field . ' ' . $order_direction);
169
 
170
        //echo $select->getSqlString($this->adapter->platform); exit;
171
 
172
        $hydrator   = new ObjectPropertyHydrator();
173
        $resultset  = new HydratingResultSet($hydrator, $prototype);
174
 
175
        $adapter = new DbSelect($select, $this->sql, $resultset);
176
        $paginator = new Paginator($adapter);
177
        $paginator->setItemCountPerPage($records_per_page);
178
        $paginator->setCurrentPageNumber($page);
179
 
180
 
181
        return $paginator;
182
    }
183
 
184
 
185
}