Proyectos de Subversion LeadersLinked - Services

Rev

Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
307 www 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Mapper;
6
 
7
 
8
use Laminas\Db\Adapter\AdapterInterface;
9
 
10
 
11
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
12
 
13
use LeadersLinked\Model\HabitGoalSkill;
14
use LeadersLinked\Mapper\Common\MapperCommon;
15
 
16
 
17
class HabitGoalSkillMapper extends MapperCommon
18
{
19
    const _TABLE = 'tbl_habits_goal_skills';
20
 
21
    /**
22
     *
23
     * @var HabitGoalSkillMapper
24
     */
25
    private static $_instance;
26
 
27
    /**
28
     *
29
     * @param AdapterInterface $adapter
30
     */
31
    private function __construct($adapter)
32
    {
33
        parent::__construct($adapter);
34
    }
35
 
36
    /**
37
     *
38
     * @param AdapterInterface $adapter
39
     * @return HabitGoalSkillMapper
40
     */
41
    public static function getInstance($adapter)
42
    {
43
        if(self::$_instance == null) {
44
            self::$_instance = new HabitGoalSkillMapper($adapter);
45
        }
46
        return self::$_instance;
47
    }
48
 
49
    /**
50
     *
51
     * @param int $user_id
52
     * @param int $goal_id
53
     * @param int $skill_id
54
     * @return HabitGoalSkill
55
     */
56
    public function fetchOneByUserIdAndGoalIdAndSkillId($user_id, $goal_id, $skill_id)
57
    {
58
        $select = $this->sql->select(self::_TABLE);
59
        $select->where->equalTo('user_id', $user_id);
60
        $select->where->equalTo('goal_id', $goal_id);
61
        $select->where->equalTo('skill_id', $skill_id);
62
        $select->limit(1);
63
 
64
        $prototype = new HabitGoalSkill();
65
        return $this->executeFetchOneObject($select, $prototype);
66
    }
67
 
68
    /**
69
     *
70
     * @param int $user_id
71
     * @param int $goal_id
72
     * @return HabitGoalSkill
73
     */
74
    public function fetchAllByUserIdAndGoalId($user_id, $goal_id)
75
    {
76
        $select = $this->sql->select(self::_TABLE);
77
        $select->where->equalTo('user_id', $user_id);
78
        $select->where->equalTo('goal_id', $goal_id);
79
        $select->limit(1);
80
 
81
        $prototype = new HabitGoalSkill();
82
        return $this->executeFetchAllObject($select, $prototype);
83
    }
84
 
85
 
86
 
87
 
88
    /**
89
     *
90
     * @param HabitGoalSkill $habitGoalSkill
91
     * @return boolean
92
     */
93
    public function insert($habitGoalSkill)
94
    {
95
        $hydrator = new ObjectPropertyHydrator();
96
        $values = $hydrator->extract($habitGoalSkill);
97
        $values = $this->removeEmpty($values);
98
 
99
        $insert = $this->sql->insert(self::_TABLE);
100
        $insert->values($values);
101
 
102
 
103
        $result = $this->executeInsert($insert);
104
        if($result) {
105
            $habitGoalSkill->id = $this->lastInsertId;
106
        }
107
 
108
        return $result;
109
 
110
    }
111
 
112
    /**
113
     *
114
     * @param HabitGoalSkill $habitGoalSkill
115
     * @return boolean
116
     */
117
    public function delete($habitGoalSkill)
118
    {
119
        $delete = $this->sql->delete(self::_TABLE);
120
        $delete->where->equalTo('user_id', $habitGoalSkill->user_id);
121
        $delete->where->equalTo('goal_id', $habitGoalSkill->goal_id);
122
        $delete->where->equalTo('skill_id', $habitGoalSkill->skill_id);
123
 
124
        return $this->executeDelete($delete);
125
 
126
    }
127
 
128
 
129
    /**
130
     *
131
     * @param int $user_id
132
     * @param int $goal_id
133
     * @return boolean
134
     */
135
    public function deleteAllByUserIdAndGoalId($user_id, $goal_id)
136
    {
137
        $delete = $this->sql->delete(self::_TABLE);
138
        $delete->where->equalTo('user_id', $user_id);
139
        $delete->where->equalTo('goal_id', $goal_id);
140
 
141
        return $this->executeDelete($delete);
142
 
143
    }
144
 
145
 
146
}