Proyectos de Subversion LeadersLinked - Services

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 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 LeadersLinked\Model\PerformanceEvaluationTest;
152 efrain 10
use Laminas\Db\Sql\Expression;
1 efrain 11
 
12
 
13
 
14
class PerformanceEvaluationTestMapper extends MapperCommon
15
{
16
    const _TABLE = 'tbl_performance_evaluation_tests';
17
 
18
    /**
19
     *
20
     * @var PerformanceEvaluationTestMapper
21
     */
22
    private static $_instance;
23
 
24
    /**
25
     *
26
     * @param AdapterInterface $adapter
27
     */
28
    private function __construct($adapter)
29
    {
30
        parent::__construct($adapter);
31
    }
32
 
33
    /**
34
     *
35
     * @param AdapterInterface $adapter
36
     * @return PerformanceEvaluationTestMapper
37
     */
38
    public static function getInstance($adapter)
39
    {
40
        if(self::$_instance == null) {
41
            self::$_instance = new PerformanceEvaluationTestMapper($adapter);
42
        }
43
        return self::$_instance;
44
    }
45
 
46
    /**
47
     *
48
     * @param int $id
49
     * @return PerformanceEvaluationTest
50
     */
51
    public function fetchOne($id)
52
    {
53
        $prototype = new PerformanceEvaluationTest();
54
 
55
        $select = $this->sql->select(self::_TABLE);
56
        $select->where->equalTo('id', $id);
57
 
58
        return $this->executeFetchOneObject($select, $prototype);
59
    }
60
 
61
 
62
 
63
 
64
    /**
65
     *
66
     * @param int $uuid
67
     * @return PerformanceEvaluationTest
68
     */
69
    public function fetchOneByUuid($uuid)
70
    {
71
        $prototype = new PerformanceEvaluationTest();
72
        $select = $this->sql->select(self::_TABLE);
73
        $select->where->equalTo('uuid', $uuid);
74
 
75
        return $this->executeFetchOneObject($select, $prototype);
76
    }
77
 
78
 
79
 
80
    /**
81
     *
82
     * @param int $parent_id
83
     * @param string $type
84
     * @return PerformanceEvaluationTest
85
     */
86
    public function fetchOneByParentIdAndType($parent_id, $type)
87
    {
88
        $prototype = new PerformanceEvaluationTest();
89
 
90
        $select = $this->sql->select(self::_TABLE);
91
        $select->where->equalTo('parent_id', $parent_id);
92
        $select->where->equalTo('type', $type);
93
 
94
        return $this->executeFetchOneObject($select, $prototype);
95
    }
96
 
97
 
98
    /**
99
     *
100
     * @param PerformanceEvaluationTest $test
101
     * @return boolean
102
     */
103
    public function insert($test)
104
    {
105
        $hydrator = new ObjectPropertyHydrator();
106
        $values = $hydrator->extract($test);
107
        $values = $this->removeEmpty($values);
108
 
109
        $insert = $this->sql->insert(self::_TABLE);
110
        $insert->values($values);
111
 
112
        $result = $this->executeInsert($insert);
113
        if($result) {
114
            $test->id = $this->lastInsertId;
115
        }
116
        return $result;
117
    }
118
 
119
    /**
120
     *
121
     * @param PerformanceEvaluationTest $test
122
     * @return boolean
123
     */
124
    public function update($test)
125
    {
126
        $hydrator = new ObjectPropertyHydrator();
127
        $values = $hydrator->extract($test);
128
        $values = $this->removeEmpty($values);
129
 
130
        $update = $this->sql->update(self::_TABLE);
131
        $update->set($values);
132
        $update->where->equalTo('id', $test->id);
133
 
134
        return $this->executeUpdate($update);
135
    }
136
 
137
    /**
138
     *
139
     * @param PerformanceEvaluationTest $test
140
     * @return boolean
141
     */
142
    public function delete($test)
143
    {
144
        $delete = $this->sql->delete(self::_TABLE);
145
        $delete->where->equalTo('parent_id', $test->id);
146
 
147
        if($this->executeDelete($delete)) {
148
 
149
            $delete = $this->sql->delete(self::_TABLE);
150
            $delete->where->equalTo('id', $test->id);
151
            return $this->executeDelete($delete);
152
        } else {
153
            return false;
154
        }
155
 
156
 
157
    }
152 efrain 158
 
159
 
160
    /**
161
     *
162
     * @param int $company_id
163
     * @return int
164
     */
165
    public function fetchCountByCompanyId($company_id)
166
    {
167
 
168
 
169
        $select = $this->sql->select(self::_TABLE);
170
        $select->columns(['total' => new Expression('COUNT(*)')]);
171
        $select->where->equalTo('company_id', $company_id);
172
        $select->where->equalTo('status', PerformanceEvaluationTest::STATUS_PENDING);
173
        $select->where->greaterThanOrEqualTo('last_date', new Expression('date(now())'));
174
 
175
 
176
        $record = $this->executeFetchOneArray($select);
177
 
178
        return $record['total'];
179
    }
1 efrain 180
 
181
 
182
 
183
}