|
|
| $dbh |
| |
|
| $creditUnion |
| |
|
| $logger |
| |
Definition at line 2 of file UserRepo.php.
◆ __construct()
| UserRepo::__construct |
( |
|
$dbh, |
|
|
|
$logger, |
|
|
String |
$creditUnion |
|
) |
| |
- Parameters
-
| resource | $dbh | Database handle |
| object | $logger | Logger to log |
| String | $creditUnion | |
Definition at line 17 of file UserRepo.php.
19 $this->logger = $logger;
20 $this->creditUnion = $creditUnion;
◆ BuildInsertColumns()
| UserRepo::BuildInsertColumns |
( |
|
$data, |
|
|
|
$meta |
|
) |
| |
|
private |
Simple helper to collect the column & value strings for inserts
- Parameters
-
| array | $data | Array of columns and values |
| array | $meta | Meta information about the table structure |
- Returns
- array
Definition at line 168 of file UserRepo.php.
173 foreach ($data as $column => $value) {
174 if (!array_key_exists($column, $meta)) {
175 $this->logger->debug(
"Tried to insert invalid column: $column, into table " . static::TABLE_NAME);
178 $type = $meta[$column][
'type'];
179 $columns[] = $column;
180 $place[] =
"\$$count";
185 implode(
',', $columns),
186 implode(
',', $place),
ColumnByType($value, $type)
◆ BuildSetColumns()
| UserRepo::BuildSetColumns |
( |
|
$data, |
|
|
|
$meta |
|
) |
| |
|
private |
Simple helper to collect the set values for update
- Parameters
-
| array | $data | Array of columns and values |
| array | $meta | Meta information about the table structure |
- Returns
- array
Definition at line 148 of file UserRepo.php.
152 foreach ($data as $column => $value) {
153 $type = $meta[$column][
'type'];
154 $result .=
"$column = \$$index,\n";
158 return [rtrim($result,
",\n"), $values];
ColumnByType($value, $type)
◆ ColumnByType()
| UserRepo::ColumnByType |
( |
|
$value, |
|
|
|
$type |
|
) |
| |
|
private |
Simple helper to create a database value based on type
- Parameters
-
| string | $value | Column value |
| string | $type | Column type |
- Returns
- string
Definition at line 198 of file UserRepo.php.
200 case strpos($type,
'int') !==
false:
201 return intval($value);
203 case strpos($type,
'double') !==
false:
204 case 'numeric' === $type:
205 return floatval($value);
207 case strpos($type,
'char') !==
false:
208 case 'text' === $type:
211 case strpos($type,
'timestamp') !==
false:
212 case 'date' === $type:
215 case strpos($type,
'bool') !==
false:
216 return $value ?
'true' :
'false';
◆ Create()
| UserRepo::Create |
( |
|
$data | ) |
|
Create
- Parameters
-
| array | $data | Array of data to be inserted [ 'column_name' => 'my new value', ] An empty array or no valid columns will return a False |
- Returns
- bool
- Exceptions
-
Definition at line 82 of file UserRepo.php.
◆ Delete()
| UserRepo::Delete |
( |
|
$keys | ) |
|
Delete feature gate
- Parameters
-
- Returns
- bool|int
- Exceptions
-
Definition at line 138 of file UserRepo.php.
◆ Read()
| UserRepo::Read |
( |
|
$username | ) |
|
Return user.
- Parameters
-
| string | $username | User to retrieve |
- Returns
- array|bool
Definition at line 33 of file UserRepo.php.
34 $sql =
"SELECT user_id, 35 TRIM(user_name) AS user_name, 36 TRIM(passwd) AS passwd, 37 forcechange AS fchange, 38 COALESCE(forceremain, 0) AS fremain, 41 LOWER(TRIM(email)) AS email, 42 TRIM(confidence) As confidence, 43 group_id AS cuuser_group_id, 44 TRIM(lastlogin) AS llog, 45 TRIM(failedlogin) AS flog, 46 COALESCE(msg_tx, 0) AS msg_tx, 48 COALESCE(challenge_quest_id, 0) AS savecqid, 50 TRIM(primary_account) As primary_account 52 WHERE LOWER(user_name) = '" . strtolower(prep_save($username)) .
"'";
54 $sql = sprintf($sql, $this->TableName($this->creditUnion));
56 $query = db_query($sql, $this->dbh);
59 $error = db_last_error();
60 $this->logger->error(
'Could not read table ' . $this->TableName($this->creditUnion) .
". Error: $error");
63 $rows = db_fetch_all($query);
◆ Update()
| UserRepo::Update |
( |
|
$identifiers, |
|
|
|
$data |
|
) |
| |
Update
- Parameters
-
| array | $identifiers | User identifiers |
| array | $data | Array of data to be updated [ 'column_name' => 'my new value', ] An empty array or no valid columns will return a False |
- Returns
- bool
- Exceptions
-
Definition at line 96 of file UserRepo.php.
97 if (empty($identifiers)) {
98 throw new Exception(static::class .
': Did not pass an identifier to update');
101 throw new Exception(static::class .
': Did not pass any valid columns to update in table ' . $this->TableName($this->creditUnion));
103 $meta = db_meta_data($this->dbh, $this->TableName($this->creditUnion));
106 throw new Exception(static::class .
': Did not pass any valid columns to update in table ' . $this->TableName($this->creditUnion) );
109 $index = count($values) + 1;
110 foreach ($identifiers as $value) {
114 $key = rtrim($key,
',');
118 WHERE user_name IN ($key);
120 $sql = sprintf($sql, $this->TableName($this->creditUnion) );
121 $query = db_query_params($sql, array_merge($values, $identifiers), $this->dbh);
123 $error = db_last_error();
124 $this->logger->error(
'Failed updating identifier [' . implode(
',', $identifiers) .
": $error");
BuildSetColumns($data, $meta)
◆ TABLE_NAME
| const UserRepo::TABLE_NAME = '%suser' |
The documentation for this class was generated from the following file: