Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| MySqlUserLoader | |
0.00% |
0 / 13 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
| exists | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| fetch | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| fetchAll | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| generateActivationToken | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace UserFrosting; |
| 4 | |
| 5 | /* This class is responsible for retrieving User object(s) from the database, checking for existence, etc. */ |
| 6 | |
| 7 | class MySqlUserLoader extends MySqlObjectLoader implements UserLoaderInterface { |
| 8 | |
| 9 | protected static $_table; // The table whose rows this class represents. Must be set in the child concrete class. |
| 10 | |
| 11 | /* Determine if a user exists based on the value of a given column. Returns true if a match is found, false otherwise. |
| 12 | * @param value $value The value to find. |
| 13 | * @param string $name The name of the column to match (defaults to id) |
| 14 | * @return bool |
| 15 | */ |
| 16 | public static function exists($value, $name = "id"){ |
| 17 | return parent::fetch($value, $name); |
| 18 | } |
| 19 | |
| 20 | /* Fetch a single user based on the value of a given column. For non-unique columns, it will return the first entry found. Returns false if no match is found. |
| 21 | * @param value $value The value to find. |
| 22 | * @param string $name The name of the column to match (defaults to id) |
| 23 | * @return User |
| 24 | */ |
| 25 | public static function fetch($value, $name = "id"){ |
| 26 | $results = parent::fetch($value, $name); |
| 27 | |
| 28 | if ($results) |
| 29 | return new User($results, $results['id']); |
| 30 | else |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | /* Fetch a list of users based on the value of a given column. Returns empty array if no match is found. |
| 35 | * @param value $value The value to find. (defaults to null, which means return all records in the table) |
| 36 | * @param string $name The name of the column to match (defaults to null) |
| 37 | * @return array An array of User objects |
| 38 | */ |
| 39 | public static function fetchAll($value = null, $name = null){ |
| 40 | $resultArr = parent::fetchAll($value, $name); |
| 41 | |
| 42 | $results = []; |
| 43 | foreach ($resultArr as $id => $user) |
| 44 | $results[$id] = new User($user, $id); |
| 45 | |
| 46 | return $results; |
| 47 | } |
| 48 | |
| 49 | //Generate an activation key for a user |
| 50 | public static function generateActivationToken($gen = null) { |
| 51 | do { |
| 52 | $gen = md5(uniqid(mt_rand(), false)); |
| 53 | } while(static::exists($gen, 'activation_token')); |
| 54 | return $gen; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | ?> |