-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserModel.php
More file actions
100 lines (87 loc) · 1.81 KB
/
Copy pathUserModel.php
File metadata and controls
100 lines (87 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace Models;
use MongoDB\MongoDBModel;
/**
* User model
*
* @package Models
* @author leandro <leandro_mnc@yahoo.com.br>
*/
class UserModel extends MongoDBModel
{
/**
* Database name
*
* @var string
*/
protected $database = 'test';
/**
* Collection name
*
* @var string
*/
private $collection = 'user';
/**
* Insert new user
*
* @return void
*/
public function insertUser()
{
$data['name'] = 'John';
$data['age'] = 30;
$data['phones'] = [
[
//'_id' => $this->getObjectId(),
'area' => 11,
'number' => 983055557,
'type' => 'mobile'
],
[
//'_id' => $this->getObjectId(),
'area' => 11,
'number' => 50722540,
'type' => 'home'
],
];
$this->insert($this->collection, $data);
}
/**
* Update user
*
* @return void
*/
public function updateUser()
{
$data = $this->findOne($this->collection, ['idade' => 30]);
$data->phones[1] = [
'area' => 11,
'number' => 12345678,
'type' => 'home'
];
$filter = ['_id' => $data->_id];
$this->update($this->collection, $filter, $data);
}
/**
* Get all users
*
* @return type
*/
public function getAllUsers()
{
return $this->find($this->collection);
}
/**
* Remove all users
*
* @return void
*/
public function removeAll()
{
$lista = $this->getAllUsers();
foreach ($lista as $doc) {
$data['_id'] = $doc->_id;
$this->delete($this->collection, $data);
}
}
}