Proyectos de Subversion LeadersLinked - Services

Rev

Rev 307 | | Comparar con el anterior | 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 $goal_id
71
     * @return HabitGoalSkill
72
     */
308 www 73
    public function fetchAllByGoalId($goal_id)
307 www 74
    {
75
        $select = $this->sql->select(self::_TABLE);
76
        $select->where->equalTo('goal_id', $goal_id);
308 www 77
 
307 www 78
 
79
        $prototype = new HabitGoalSkill();
80
        return $this->executeFetchAllObject($select, $prototype);
81
    }
82
 
83
 
84
 
85
 
86
    /**
87
     *
88
     * @param HabitGoalSkill $habitGoalSkill
89
     * @return boolean
90
     */
91
    public function insert($habitGoalSkill)
92
    {
93
        $hydrator = new ObjectPropertyHydrator();
94
        $values = $hydrator->extract($habitGoalSkill);
95
        $values = $this->removeEmpty($values);
96
 
97
        $insert = $this->sql->insert(self::_TABLE);
98
        $insert->values($values);
99
 
100
 
101
        $result = $this->executeInsert($insert);
102
        if($result) {
103
            $habitGoalSkill->id = $this->lastInsertId;
104
        }
105
 
106
        return $result;
107
 
108
    }
109
 
110
    /**
111
     *
112
     * @param HabitGoalSkill $habitGoalSkill
113
     * @return boolean
114
     */
115
    public function delete($habitGoalSkill)
116
    {
117
        $delete = $this->sql->delete(self::_TABLE);
118
        $delete->where->equalTo('user_id', $habitGoalSkill->user_id);
119
        $delete->where->equalTo('goal_id', $habitGoalSkill->goal_id);
120
        $delete->where->equalTo('skill_id', $habitGoalSkill->skill_id);
121
 
122
        return $this->executeDelete($delete);
123
 
124
    }
125
 
126
 
127
    /**
128
     *
129
     * @param int $goal_id
130
     * @return boolean
131
     */
308 www 132
    public function deleteAllByGoalId($goal_id)
307 www 133
    {
134
        $delete = $this->sql->delete(self::_TABLE);
135
        $delete->where->equalTo('goal_id', $goal_id);
136
 
137
        return $this->executeDelete($delete);
138
 
139
    }
140
 
141
 
142
}