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;
1399 eleazar 13
use LeadersLinked\Model\SurveyIndustry;
1363 eleazar 14
 
15
 
16
class SurveyIndustryMapper extends MapperCommon
17
{
18
    const _TABLE = 'tbl_survey_industry';
19
 
20
    /**
21
     *
22
     * @var SurveyMapper
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
1385 eleazar 38
     * @return SurveyIndustryMapper
1363 eleazar 39
     */
40
    public static function getInstance($adapter)
41
    {
42
        if(self::$_instance == null) {
1385 eleazar 43
            self::$_instance = new SurveyIndustryMapper($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
    {
1525 eleazar 55
        $prototype = new SurveyIndustry();
1363 eleazar 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 $survey_id
67
     * @return Survey
68
     */
69
    public function fetchAllBySurveyId($survey_id)
70
    {
1525 eleazar 71
        $prototype = new SurveyIndustry();
1363 eleazar 72
 
73
        $select = $this->sql->select(self::_TABLE);
74
        $select->where->equalTo('survey_id', $survey_id);
75
        $select->order('id');
76
 
77
        return $this->executeFetchAllObject($select, $prototype);
78
    }
79
 
80
 
81
    /**
82
     *
1388 eleazar 83
     * @param $record
1363 eleazar 84
     * @return boolean
85
     */
1388 eleazar 86
    public function insert($record)
1363 eleazar 87
    {
1388 eleazar 88
        $hydrator = new ObjectPropertyHydrator();
1398 eleazar 89
        $values = $hydrator->extract($record);
1388 eleazar 90
        $values = $this->removeEmpty($values);
1363 eleazar 91
 
92
        $insert = $this->sql->insert(self::_TABLE);
93
        $insert->values($values);
94
 
1388 eleazar 95
        //echo $insert->getSqlString($this->adapter->platform); exit;
96
 
97
        $result = $this->executeInsert($insert);
1363 eleazar 98
        if($result) {
1398 eleazar 99
            $record->id = $this->lastInsertId;
1363 eleazar 100
        }
101
        return $result;
102
    }
103
 
104
    /**
105
     *
106
     * @param SurveyForm $form
107
     * @return boolean
108
     */
109
    public function update($form)
110
    {
111
        $hydrator = new ObjectPropertyHydrator();
112
        $values = $hydrator->extract($form);
113
        $values = $this->removeEmpty($values);
114
 
115
        $update = $this->sql->update(self::_TABLE);
116
        $update->set($values);
117
        $update->where->equalTo('id', $form->id);
118
 
119
        return $this->executeUpdate($update);
120
    }
121
 
122
    /**
123
     *
124
     * @param int $form_id
125
     * @return boolean
126
     */
1527 eleazar 127
    public function deleteBySurevy($survey_id)
1363 eleazar 128
    {
129
        $delete = $this->sql->delete(self::_TABLE);
1527 eleazar 130
        $delete->where->equalTo('survey_id', $survey_id);
1363 eleazar 131
 
132
        return $this->executeDelete($delete);
133
    }
134
 
135
 
136
 
137
 
138
 
139
}