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