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