forked from thecodingmachine/database.tdbm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestUserDao.php
124 lines (113 loc) · 3.86 KB
/
TestUserDao.php
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
namespace Mouf\Database\TDBM\Dao;
use Mouf\Database\TDBM\Test\Dao\Generated\UserBaseDao;
use Mouf\Database\TDBM\UncheckedOrderBy;
/**
* The UserDao class will maintain the persistence of UserBean class into the users table.
*/
class TestUserDao extends UserBaseDao
{
/**
* Returns the list of users by alphabetical order.
*
* @return UserBean[]
*/
public function getUsersByAlphabeticalOrder()
{
// The third parameter will be used in the "ORDER BY" clause of the SQL query.
return $this->find(null, [], 'login ASC');
}
/**
* Returns the list of users by alphabetical order.
*
* @return UserBean[]
*/
public function getUsersFromSqlByAlphabeticalOrder()
{
// The third parameter will be used in the "ORDER BY" clause of the SQL query.
return $this->findFromSql('users', null, [], 'login ASC');
}
/**
* Returns the list of users by alphabetical order.
*
* @return UserBean[]
*/
public function getUsersByCountryOrder()
{
// The third parameter will be used in the "ORDER BY" clause of the SQL query.
return $this->find(null, [], 'country.label ASC', ['country']);
}
/**
* Returns the list of users by alphabetical order.
*
* @return UserBean[]
*/
public function getUsersFromSqlByCountryOrder()
{
// The third parameter will be used in the "ORDER BY" clause of the SQL query.
return $this->findFromSql('users JOIN country ON country.id = users.country_id', null, [], 'country.label ASC');
}
/**
* Returns the list of users whose login starts with $login.
*
* @param string $login
* @param string $mode
*
* @return \Mouf\Database\TDBM\ResultIterator|\Mouf\Database\TDBM\Test\Dao\Bean\UserBean[]|\Mouf\Database\TDBM\Test\Dao\ResultArray
*/
public function getUsersByLoginStartingWith($login = null, $mode = null)
{
return $this->find('login LIKE :login', ['login' => $login.'%'], null, [], $mode);
}
/**
* Returns the user whose login is $login.
*
* @param string $login
*
* @return \Mouf\Database\TDBM\Test\Dao\Bean\UserBean
*/
public function getUserByLogin($login)
{
return $this->findOne('login = :login', ['login' => $login]);
}
public function getUsersByManagerId($managerId)
{
return $this->find('contact.manager_id = :id!', ['id' => $managerId]);
}
/**
* Triggers an error because table "contacts" does not exist.
*
* @return \Mouf\Database\TDBM\ResultIterator|\Mouf\Database\TDBM\Test\Dao\Bean\UserBean[]|\Mouf\Database\TDBM\Test\Dao\Generated\ResultArray
*/
public function getUsersWrongTableName()
{
return $this->find('contacts.manager_id = 1');
}
/**
* Returns a list of users, sorted by a table on an external column.
*
* @return \Mouf\Database\TDBM\ResultIterator|\Mouf\Database\TDBM\Test\Dao\Bean\UserBean[]|\Mouf\Database\TDBM\Test\Dao\Generated\ResultArray
*/
public function getUsersByCountryName()
{
return $this->find(null, [], 'country.label DESC');
}
/**
* A test to sort by function.
*
* @return \Mouf\Database\TDBM\ResultIterator|\Mouf\Database\TDBM\Test\Dao\Bean\UserBean[]|\Mouf\Database\TDBM\Test\Dao\Generated\ResultArray
*/
public function getUsersByReversedCountryName()
{
return $this->find(null, [], new UncheckedOrderBy('REVERSE(country.label) ASC'));
}
/**
* A test to check exceptions when providing expressions in ORDER BY clause.
*
* @return \Mouf\Database\TDBM\ResultIterator|\Mouf\Database\TDBM\Test\Dao\Bean\UserBean[]|\Mouf\Database\TDBM\Test\Dao\Generated\ResultArray
*/
public function getUsersByInvalidOrderBy()
{
return $this->find(null, [], 'REVERSE(country.label) ASC');
}
}