Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
4113 efrain 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Mapper;
5
 
6
 
7
use LeadersLinked\Mapper\Common\MapperCommon;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use LeadersLinked\Model\CalendarEvent;
10
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
11
 
12
 
13
class CalendarEventMapper extends MapperCommon
14
{
4141 efrain 15
    const _TABLE = 'tbl_calendar_events';
4113 efrain 16
 
17
    /**
18
     *
19
     * @var CalendarEventMapper
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 CalendarEventMapper
36
     */
37
    public static function getInstance($adapter)
38
    {
39
        if(self::$_instance == null) {
40
            self::$_instance = new CalendarEventMapper($adapter);
41
        }
42
        return self::$_instance;
43
    }
44
 
45
    /**
46
     *
47
     * @param int $id
48
     * @return CalendarEvent
49
     */
50
    public function fetchOne($id)
51
    {
52
 
53
        $select = $this->sql->select(self::_TABLE);
54
        $select->where->equalTo('id', $id);
55
 
56
        $prototype = new CalendarEvent();
57
        return $this->executeFetchOneObject($select, $prototype);
58
    }
59
 
60
    /**
61
     *
62
     * @param string $uuid
63
     * @return CalendarEvent
64
     */
65
    public function fetchOneByUuid($uuid)
66
    {
67
 
68
        $select = $this->sql->select(self::_TABLE);
69
        $select->where->equalTo('uuid', $uuid);
70
 
71
        $prototype = new CalendarEvent();
72
        return $this->executeFetchOneObject($select, $prototype);
73
    }
74
 
75
    /**
76
     *
77
     * @param CalendarEvent $calendarEvent
78
     * @return boolean
79
     */
80
    public function insert($calendarEvent)
81
    {
82
        $hydrator = new ObjectPropertyHydrator();
83
        $values = $hydrator->extract($calendarEvent);
84
        $values = $this->removeEmpty($values);
85
 
86
        $insert = $this->sql->insert(self::_TABLE);
87
        $insert->values($values);
88
 
89
 
90
        $result = $this->executeInsert($insert);
91
        if($result) {
92
            $calendarEvent->id = $this->lastInsertId;
93
        }
94
 
95
        return $result;
96
 
97
    }
98
 
99
    /**
100
     *
101
     * @param CalendarEvent $calendarEvent
102
     * @return boolean
103
     */
104
    public function update($calendarEvent)
105
    {
106
        $hydrator = new ObjectPropertyHydrator();
107
        $values = $hydrator->extract($calendarEvent);
108
        $values = $this->removeEmpty($values);
109
 
110
        $update = $this->sql->update(self::_TABLE);
111
        $update->set($values);
112
        $update->where->equalTo('id', $calendarEvent->id);
113
 
114
        return $this->executeUpdate($update);
115
    }
116
 
117
    /**
118
     *
119
     * @param CalendarEvent $calendarEvent
120
     * @return boolean
121
     */
122
    public function delete($calendarEvent)
123
    {
124
        $delete = $this->sql->delete(self::_TABLE);
125
        $delete->where->equalTo('id', $calendarEvent->id);
126
 
127
        return $this->executeDelete($delete);
128
 
129
 
130
    }
131
 
132
 
133
    /**
134
     *
4141 efrain 135
     * @param int $user_id
136
     * @param string $startTime
137
     * @param string $endTime
4113 efrain 138
     * @return CalendarEvent[]
139
     */
4141 efrain 140
    public function fetchAllByUserIdAndStartTimeAndEndTime($user_id, $startTime, $endTime)
4113 efrain 141
    {
4141 efrain 142
 
4113 efrain 143
        $select = $this->sql->select(self::_TABLE);
144
        $select->where->equalTo('user_id', $user_id);
145
        $select->where->between('start_time', $startTime, $endTime);
146
 
4141 efrain 147
        //echo $select->getSqlString($this->adapter->platform); exit;
148
 
4113 efrain 149
        $prototype = new CalendarEvent();
150
        return $this->executeFetchAllObject($select, $prototype);
151
    }
152
 
153
}