Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

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