Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

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