Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev Autor Línea Nro. Línea
324 www 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\HabitUserLogContent;
9
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
10
use Laminas\Db\Sql\Expression;
11
 
12
 
13
class HabitUserLogContentMapper extends MapperCommon
14
{
15
    const _TABLE = 'tbl_habits_user_logs_content';
16
 
17
    /**
18
     *
19
     * @var HabitUserLogContentMapper
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 HabitUserLogContentMapper
36
     */
37
    public static function getInstance($adapter)
38
    {
39
        if(self::$_instance == null) {
40
            self::$_instance = new HabitUserLogContentMapper($adapter);
41
        }
42
        return self::$_instance;
43
    }
44
 
45
    /**
46
     *
325 www 47
     * @param int $company_id
324 www 48
     * @param int $user_id
325 www 49
     * @return HabitUserLogContent
324 www 50
     */
325 www 51
    public function fetchOneMaxByCompanyIdAndUserId($company_id, $user_id)
324 www 52
    {
53
        $prototype = new HabitUserLogContent();
54
 
55
        $select = $this->sql->select(self::_TABLE);
325 www 56
        $select->where->equalTo('company_id', $company_id);
324 www 57
        $select->where->equalTo('user_id', $user_id);
325 www 58
        $select->order('id desc');
324 www 59
 
60
        return $this->executeFetchAllObject($select, $prototype);
61
    }
62
 
63
 
64
    /**
65
     *
66
     * @param int $user_id
67
     * @param int $content_id
68
     * @return HabitUserLogContent
69
     */
70
    public function fetchOneByUserIdAndContentId($user_id, $content_id)
71
    {
72
        $prototype = new HabitUserLogContent();
73
 
74
        $select = $this->sql->select(self::_TABLE);
75
        $select->where->equalTo('user_id', $user_id);
76
        $select->where->equalTo('content_id', $content_id);
77
 
78
        return $this->executeFetchOneObject($select, $prototype);
79
    }
80
 
81
 
82
    /**
83
     *
84
     * @param int $user_id
85
     * @param string $date
86
     * @return HabitUserLogContent
87
     */
88
    public function fetchOneByUserIdAndDate($user_id, $date)
89
    {
90
        $prototype = new HabitUserLogContent();
91
 
92
        $select = $this->sql->select(self::_TABLE);
93
        $select->where->equalTo('user_id', $user_id);
94
        $select->where->equalTo('date', $date);
95
 
96
        return $this->executeFetchOneObject($select, $prototype);
97
    }
98
 
99
 
100
    /**
101
     *
102
     * @param HabitUserLogContent $record
103
     * return boolean
104
     */
105
    public function insert($record)
106
    {
107
        $hydrator = new ObjectPropertyHydrator();
108
        $values = $hydrator->extract($record);
109
        $values = $this->removeEmpty($values);
110
 
111
        $insert = $this->sql->insert(self::_TABLE);
112
        $insert->values($values);
113
 
114
        $result = $this->executeInsert($insert);
115
        if($result) {
116
            $record->id = $this->lastInsertId;
117
        }
118
        return $result;
119
    }
120
 
121
 
122
    /**
123
     *
124
     * @param HabitUserLogContent $record
125
     * return boolean
126
     */
127
    public function update($record)
128
    {
129
        $hydrator = new ObjectPropertyHydrator();
130
        $values = $hydrator->extract($record);
131
        $values = $this->removeEmpty($values);
132
 
133
        $update = $this->sql->update(self::_TABLE);
134
        $update->set($values);
135
        $update->where->equalTo('id', $record->id);
136
 
137
        return $this->executeUpdate($update);
138
    }
139
 
140
 
141
}