Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 7244 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
7244 efrain 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;
9
use LeadersLinked\Model\SurveyCampaignSkill;
7328 efrain 10
use Laminas\Db\Sql\Expression;
7244 efrain 11
 
12
 
13
class SurveyCampaignSkillMapper extends MapperCommon
14
{
15
    const _TABLE = 'tbl_survey_campaign_skills';
16
 
17
    /**
18
     *
19
     * @var SurveyCampaignSkillMapper
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 SurveyCampaignSkillMapper
36
     */
37
    public static function getInstance($adapter)
38
    {
39
        if(self::$_instance == null) {
40
            self::$_instance = new SurveyCampaignSkillMapper($adapter);
41
        }
42
        return self::$_instance;
43
    }
44
 
45
    /**
46
     *
47
     * @param int $id
48
     * @return SurveyCampaignSkill
49
     */
50
    public function fetchOne($id)
51
    {
52
        $prototype = new SurveyCampaignSkill();
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
     * @param int $survey_id
63
     * @return SurveyCampaignSkill[]
64
     */
65
    public function fetchAllByCampaignId($campaign_id)
66
    {
67
        $prototype = new  SurveyCampaignSkill();
68
 
69
        $select = $this->sql->select(self::_TABLE);
70
        $select->where->equalTo('campaign_id', $campaign_id);
71
        $select->order('id');
72
 
73
        return $this->executeFetchAllObject($select, $prototype);
74
    }
75
 
7328 efrain 76
    /**
77
     *
78
     * @param int $company_id
79
     * @param int $campaign_id
80
     * @return int[]
81
     */
82
    public function fetchAllUserIdsByCompanyIdAndCampaignId($company_id, $campaign_id)
83
    {
84
        $select2 = $this->sql->select(self::_TABLE);
85
        $select2->columns(['skill_id']);
86
        $select2->where->equalTo('campaign_id', $campaign_id);
87
 
88
 
89
        $select = $this->sql->select();
90
        $select->columns(['user_id' => new Expression('DISTINCT(tb1.user_id)')]);
91
        $select->from(['tb1' => CompanyUserMapper::_TABLE]);
92
        $select->join(['tb2' => UserSkillMapper::_TABLE], 'tb1.user_id = tb2.user_id', []);
93
        $select->where->in('tb2.skill_id', $select2);
94
        $select->where->equalTo('tb1.company_id', $company_id);
95
 
96
        $ids = [];
97
        $records = $this->executeFetchAllArray($select);
98
        foreach($records as $record)
99
        {
100
            array_push($ids, $record['user_id']);
101
        }
102
 
103
        return $ids;
104
    }
7244 efrain 105
 
7328 efrain 106
 
7244 efrain 107
    /**
108
     *
109
     * @param SurveyCampaignSkill $record
110
     * @return boolean
111
     */
112
    public function insert($record)
113
    {
114
        $hydrator = new ObjectPropertyHydrator();
115
        $values = $hydrator->extract($record);
116
        $values = $this->removeEmpty($values);
117
 
118
        $insert = $this->sql->insert(self::_TABLE);
119
        $insert->values($values);
120
 
121
        //echo $insert->getSqlString($this->adapter->platform); exit;
122
 
123
        $result = $this->executeInsert($insert);
124
        if($result) {
125
            $record->id = $this->lastInsertId;
126
        }
127
        return $result;
128
    }
129
 
130
    /**
131
     *
132
     * @param  SurveyCampaignSkill $record
133
     * @return boolean
134
     */
135
    public function update($record)
136
    {
137
        $hydrator = new ObjectPropertyHydrator();
138
        $values = $hydrator->extract($record);
139
        $values = $this->removeEmpty($values);
140
 
141
        $update = $this->sql->update(self::_TABLE);
142
        $update->set($values);
143
        $update->where->equalTo('id', $record->id);
144
 
145
        return $this->executeUpdate($update);
146
    }
147
 
148
    /**
149
     *
150
     * @param int $campaign_id
151
     * @return boolean
152
     */
153
    public function deleteAllByCampaignId($campaign_id)
154
    {
155
        $delete = $this->sql->delete(self::_TABLE);
156
        $delete->where->equalTo('campaign_id', $campaign_id);
157
 
158
        return $this->executeDelete($delete);
159
    }
160
}