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\SelfEvaluationTest;
13
 
14
 
15
class SelfEvaluationTestMapper extends MapperCommon
16
{
17
    const _TABLE = 'tbl_self_evaluation_tests';
18
 
19
    /**
20
     *
21
     * @var SelfEvaluationTestMapper
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 SelfEvaluationTestMapper
38
     */
39
    public static function getInstance($adapter)
40
    {
41
        if(self::$_instance == null) {
42
            self::$_instance = new SelfEvaluationTestMapper($adapter);
43
        }
44
        return self::$_instance;
45
    }
46
 
47
    /**
48
     *
49
     * @param int $id
50
     * @return SelfEvaluationTest
51
     */
52
    public function fetchOne($id)
53
    {
54
        $prototype = new SelfEvaluationTest();
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 $form_id
66
     * @param int $user_id
67
     * @return SelfEvaluationTest
68
     */
69
    public function fetchOneBy($form_id, $user_id)
70
    {
71
        $prototype = new SelfEvaluationTest();
72
 
73
        $select = $this->sql->select(self::_TABLE);
74
        $select->where->equalTo('form_id', $form_id);
75
        $select->where->equalTo('user_id', $user_id);
76
 
77
        return $this->executeFetchOneObject($select, $prototype);
78
    }
79
 
80
 
81
    /**
82
     *
83
     * @param int $uuid
84
     * @return SelfEvaluationTest
85
     */
86
    public function fetchOneByUuid($uuid)
87
    {
88
        $prototype = new SelfEvaluationTest();
89
        $select = $this->sql->select(self::_TABLE);
90
        $select->where->equalTo('uuid', $uuid);
91
 
92
        return $this->executeFetchOneObject($select, $prototype);
93
    }
94
 
95
 
96
    /**
97
     *
98
     * @param SelfEvaluationTest $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
        }
114
        return $result;
115
    }
116
 
117
    /**
118
     *
119
     * @param SelfEvaluationTest $form
120
     * @param int $id
121
     * @return boolean
122
     */
123
    public function update($form, $id)
124
    {
125
        $hydrator = new ObjectPropertyHydrator();
126
        $values = $hydrator->extract($form);
127
        $values = $this->removeEmpty($values);
128
 
129
        $update = $this->sql->update(self::_TABLE);
130
        $update->set($values);
131
        $update->where->equalTo('id', $id);
132
 
133
        return $this->executeUpdate($update);
134
    }
135
 
136
    /**
137
     *
138
     * @param SelfEvaluationTest $form
139
     * @return boolean
140
     */
141
    public function delete($form)
142
    {
143
        $delete = $this->sql->delete(self::_TABLE);
144
        $delete->where->equalTo('id', $form->id);
145
 
146
        return $this->executeDelete($delete);
147
    }
148
 
149
 
150
 
151
 
152
 
153
 
154
}