Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2350 | Rev 5672 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 2350 Rev 5671
Línea 3... Línea 3...
3
declare(strict_types=1);
3
declare(strict_types=1);
Línea 4... Línea 4...
4
 
4
 
Línea 5... Línea 5...
5
namespace LeadersLinked\Mapper;
5
namespace LeadersLinked\Mapper;
6
 
6
 
7
use Laminas\Db\Adapter\AdapterInterface;
7
use Laminas\Db\Adapter\AdapterInterface;
8
Use LeadersLinked\Hydrator\ObjectPropertyHydrator;
8
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
Línea 9... Línea 9...
9
use LeadersLinked\Mapper\Common\MapperCommon;
9
use LeadersLinked\Mapper\Common\MapperCommon;
10
use LeadersLinked\Model\Conversation;
10
use LeadersLinked\Model\Conversation;
11
 
11
 
Línea 12... Línea 12...
12
class ConversationMapper extends MapperCommon
12
class ConversationMapper extends MapperCommon
13
{
13
{
14
    const _TABLE = 'tbl_conversations';
14
    const _TABLE = 'tbl_conversations';
15
 
15
 
16
    
16
 
17
    /**
17
    /**
18
     *
18
     *
19
     * @var ConversationMapper
19
     * @var ConversationMapper
20
     */
20
     */
21
    private static $_instance;
21
    private static $_instance;
22
    
22
 
23
    /**
23
    /**
24
     *
24
     *
25
     * @param AdapterInterface $adapter
25
     * @param AdapterInterface $adapter
26
     */
26
     */
27
    private function __construct($adapter)
27
    private function __construct($adapter)
28
    {
28
    {
29
        parent::__construct($adapter);
29
        parent::__construct($adapter);
30
    }
30
    }
31
    
31
 
32
    /**
32
    /**
33
     *
33
     *
34
     * @param AdapterInterface $adapter
34
     * @param AdapterInterface $adapter
35
     * @return ConversationMapper
35
     * @return ConversationMapper
36
     */
36
     */
37
    public static function getInstance($adapter)
37
    public static function getInstance($adapter)
38
    {
38
    {
39
        if(self::$_instance == null) {
39
        if (self::$_instance == null) {
Línea 40... Línea 40...
40
            self::$_instance = new ConversationMapper($adapter);
40
            self::$_instance = new ConversationMapper($adapter);
41
        }
41
        }
42
        return self::$_instance;
42
        return self::$_instance;
43
    }
43
    }
44
 
44
 
45
    
45
 
46
    /**
46
    /**
47
     *
47
     *
48
     * @param int $id
48
     * @param int $id
49
     * @return Conversation
49
     * @return Conversation
50
     */
50
     */
51
    public function fetchOne($id)
51
    public function fetchOne($id)
52
    {
52
    {
53
        $select = $this->sql->select(self::_TABLE);
53
        $select = $this->sql->select(self::_TABLE);
54
        $select->where->equalTo('id', $id);
54
        $select->where->equalTo('id', $id);
55
        
55
 
56
        $prototype = new Conversation();
56
        $prototype = new Conversation();
57
        return $this->executeFetchOneObject($select, $prototype);
57
        return $this->executeFetchOneObject($select, $prototype);
58
    }
58
    }
59
    
59
 
60
    
60
 
61
  
61
 
62
    
62
 
63
    /**
63
    /**
64
     * @param int $user1
64
     * @param int $user1
65
     * @param int $user2
65
     * @param int $user2
66
     * @return Conversation
66
     * @return Conversation
67
     */
67
     */
68
    public function fetchOneByUserId1AndUserId2($user1, $user2)
68
    public function fetchOneByUserId1AndUserId2($user1, $user2)
69
    {
69
    {
-
 
70
        $prototype = new Conversation();
70
        $prototype = new Conversation();
71
        $select = $this->sql->select(self::_TABLE);
-
 
72
        $select->where->and->nest()
71
        $select = $this->sql->select(self::_TABLE);
73
            ->nest()
72
        $select->where->and->nest()
74
            ->equalTo('sender_id', $user1)
73
        ->nest()
75
            ->and->equalTo('sender_status', Conversation::STATUS_NORMAL)
74
        ->equalTo('sender_id', $user1)
76
            ->and->equalTo('receiver_id', $user2)
75
        ->and->equalTo('receiver_id', $user2)
77
            ->and->equalTo('receiver_status', Conversation::STATUS_NORMAL)
76
        ->unnest()
78
            ->unnest()
77
        ->or->nest()
79
            ->or->nest()
78
        ->equalTo('receiver_id', $user1)
80
            ->equalTo('receiver_id', $user1)
79
        ->and->equalTo('sender_id', $user2)
81
            ->and->equalTo('sender_id', $user2)
Línea 91... Línea 93...
91
     * @return Conversation[]
93
     * @return Conversation[]
92
     */
94
     */
93
    public function fetchAllByUserId($user_id)
95
    public function fetchAllByUserId($user_id)
94
    {
96
    {
95
        $prototype = new Conversation();
97
        $prototype = new Conversation();
96
        
98
 
97
        $select = $this->sql->select(self::_TABLE);
99
        $select = $this->sql->select(self::_TABLE);
98
        $select->where->and->nest()
100
        $select->where->and->nest()
99
        ->nest()
101
            ->nest()
100
        ->equalTo('sender_id', $user_id)
102
            ->equalTo('sender_id', $user_id)
101
        ->and->equalTo('sender_status', Conversation::STATUS_NORMAL)
103
            ->and->equalTo('sender_status', Conversation::STATUS_NORMAL)
102
        ->unnest()
104
            ->unnest()
103
        ->or->nest()
105
            ->or->nest()
104
        ->equalTo('receiver_id', $user_id)
106
            ->equalTo('receiver_id', $user_id)
105
        ->and->equalTo('receiver_status', Conversation::STATUS_NORMAL)
107
            ->and->equalTo('receiver_status', Conversation::STATUS_NORMAL)
106
        ->unnest()
108
            ->unnest()
107
        ->unnest();
109
            ->unnest();
108
        
110
 
109
        return $this->executeFetchAllObject($select, $prototype);
111
        return $this->executeFetchAllObject($select, $prototype);
110
    }
112
    }
Línea 111... Línea 113...
111
 
113
 
112
 
114
 
113
    
115
 
114
    /**
116
    /**
115
     * 
117
     * 
116
     * @param Conversation $conversation
118
     * @param Conversation $conversation
117
     * @return boolean
119
     * @return boolean
118
     */
120
     */
119
    public function insert($conversation)
121
    public function insert($conversation)
120
    {
122
    {
121
        $hydrator = new ObjectPropertyHydrator();
123
        $hydrator = new ObjectPropertyHydrator();
122
        $values = $hydrator->extract($conversation);
124
        $values = $hydrator->extract($conversation);
123
        $values = $this->removeEmpty($values);
125
        $values = $this->removeEmpty($values);
124
        
126
 
125
        $insert = $this->sql->insert(self::_TABLE);
127
        $insert = $this->sql->insert(self::_TABLE);
126
        $insert->values($values);
128
        $insert->values($values);
127
        
129
 
128
        $response = $this->executeInsert($insert);
130
        $response = $this->executeInsert($insert);
129
        if($response) {
131
        if ($response) {
130
            $conversation->id = $this->lastInsertId;
132
            $conversation->id = $this->lastInsertId;
131
        }
133
        }
132
        
134
 
133
        return $response;
135
        return $response;
134
    }
136
    }
135
    
137
 
136
    
138
 
137
    /**
139
    /**
138
     *
140
     *
139
     * @param Conversation $conversation
141
     * @param Conversation $conversation
140
     * @return boolean
142
     * @return boolean
141
     */
143
     */
142
    public function update($conversation) 
144
    public function update($conversation)
143
    {
145
    {
144
        $hydrator = new ObjectPropertyHydrator();
146
        $hydrator = new ObjectPropertyHydrator();
145
        $values = $hydrator->extract($conversation);
147
        $values = $hydrator->extract($conversation);
146
        $values = $this->removeEmpty($values);
148
        $values = $this->removeEmpty($values);
147
        
149
 
148
        $update = $this->sql->update(self::_TABLE);
150
        $update = $this->sql->update(self::_TABLE);
149
        $update->set($values);
151
        $update->set($values);
150
        $update->where->equalTo('id', $conversation->id);
152
        $update->where->equalTo('id', $conversation->id);
151
        
153
 
152
        return $this->executeUpdate($update);
-
 
153
    }
-
 
154
    
-
 
155
 
-
 
156
    
154
        return $this->executeUpdate($update);
-
 
155
    }