Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Mapper;
6
 
7
use LeadersLinked\Model\UserNotificationSetting;
8
use LeadersLinked\Mapper\Common\MapperCommon;
9
use Laminas\Db\Adapter\AdapterInterface;
10
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
11
 
12
class UserNotificationSettingMapper extends MapperCommon
13
{
14
    const _TABLE = 'tbl_user_notification_settings';
15
 
16
    /**
17
     *
18
     * @var UserNotificationSettingMapper
19
     */
20
    private static $_instance;
21
 
22
    /**
23
     *
24
     * @param AdapterInterface $adapter
25
     */
26
    private function __construct($adapter)
27
    {
28
        parent::__construct($adapter);
29
    }
30
 
31
    /**
32
     *
33
     * @param AdapterInterface $adapter
34
     * @returnUserNotificationSettingMapper
35
     */
36
    public static function getInstance($adapter)
37
    {
38
        if(self::$_instance == null) {
39
            self::$_instance = new UserNotificationSettingMapper($adapter);
40
        }
41
        return self::$_instance;
42
    }
43
 
44
    /**
45
     *
46
     * @param int $user_id
47
     * @return UserNotificationSetting
48
     */
49
    public function fetchOne($user_id)
50
    {
51
        $select = $this->sql->select(self::_TABLE);
52
        $select->where->equalTo('user_id', $user_id);
53
 
54
        $prototype = new UserNotificationSetting();
55
        return $this->executeFetchOneObject($select, $prototype);
56
    }
57
 
58
 
59
    /**
60
     *
61
     * @param UserNotificationSetting $userNotificationSetting
62
     * @return boolean
63
     */
64
    public function insert($userNotificationSetting)
65
    {
66
        $hydrator = new ObjectPropertyHydrator();
67
        $values= $hydrator->extract($userNotificationSetting);
68
 
69
        $insert = $this->sql->insert(self::_TABLE);
70
        $insert->values($values);
71
 
72
        return $this->executeInsert($insert);
73
 
74
    }
75
 
76
    /**
77
     *
78
     * @param UserNotificationSetting $userNotificationSetting
79
     * @return boolean
80
     */
81
    public function update($userNotificationSetting)
82
    {
83
        $hydrator = new ObjectPropertyHydrator();
84
        $values = $hydrator->extract($userNotificationSetting);
85
 
86
        $update = $this->sql->update(self::_TABLE);
87
        $update->set($values);
88
        $update->where->equalTo('user_id', $userNotificationSetting->user_id);
89
 
90
        return $this->executeUpdate($update);
91
 
92
    }
93
 
94
 
95
    /**
96
     *
97
     * @return boolean
98
     */
99
    public function truncate()
100
    {
101
        $sql = sprintf('TRUNCATE TABLE `%s` ', self::_TABLE);
102
        return $this->executeSentenceWithParameters($sql);
103
    }
104
 
105
 
106
 
107
 
108
 
109
}