|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Repositories\AdminUserRepository |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Tim Wagner <[email protected]> |
|
15
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/techdivision/import |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Repositories; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Utils\MemberNames; |
|
24
|
|
|
use TechDivision\Import\Utils\SqlStatementKeys; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Repository implementation to load admin user data. |
|
28
|
|
|
* |
|
29
|
|
|
* @author Tim Wagner <[email protected]> |
|
30
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
|
31
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
32
|
|
|
* @link https://github.com/techdivision/import |
|
33
|
|
|
* @link http://www.techdivision.com |
|
34
|
|
|
*/ |
|
35
|
|
|
class AdminUserRepository extends AbstractRepository implements AdminUserRepositoryInterface |
|
36
|
|
|
{ |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* The prepared statement to load an user by it's username. |
|
40
|
|
|
* |
|
41
|
|
|
* @var \PDOStatement |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $adminUserByUsernameStmt; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Initializes the repository's prepared statements. |
|
47
|
|
|
* |
|
48
|
|
|
* @return void |
|
49
|
|
|
*/ |
|
50
|
|
|
public function init() |
|
51
|
|
|
{ |
|
52
|
|
|
|
|
53
|
|
|
// initialize the prepared statements |
|
54
|
|
|
$this->adminUsersStmt = |
|
|
|
|
|
|
55
|
|
|
$this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::ADMIN_USERS)); |
|
56
|
|
|
$this->adminUserByUsernameStmt = |
|
57
|
|
|
$this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::ADMIN_USER_BY_USERNAME)); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Return's an array with all available admin users. |
|
62
|
|
|
* |
|
63
|
|
|
* @return array The available admin users |
|
64
|
|
|
*/ |
|
65
|
|
|
public function findAll() |
|
66
|
|
|
{ |
|
67
|
|
|
// try to load the categories |
|
68
|
|
|
$this->adminUsersStmt->execute(); |
|
69
|
|
|
return $this->adminUsersStmt->fetchAll(\PDO::FETCH_ASSOC); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Load's and return's the admin user with the passed username. |
|
74
|
|
|
* |
|
75
|
|
|
* @param string $username The username of the admin user to return |
|
76
|
|
|
* |
|
77
|
|
|
* @return array|null The admin user with the passed username |
|
78
|
|
|
*/ |
|
79
|
|
|
public function findOneByUsername($username) |
|
80
|
|
|
{ |
|
81
|
|
|
|
|
82
|
|
|
// the parameters of the admin user to load |
|
83
|
|
|
$params = array(MemberNames::USERNAME => $username); |
|
84
|
|
|
|
|
85
|
|
|
// load and return the admin user with the passed parameters |
|
86
|
|
|
$this->adminUserByUsernameStmt->execute($params); |
|
87
|
|
|
return $this->adminUserByUsernameStmt->fetch(\PDO::FETCH_ASSOC); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: