Documents and Documentation (beta 1) (#23)
- Change to SQLite document store - Complete documentation on usage of Feed Reader Central - Update INSTALLING.md for new installation procedures Reviewed-on: #23
This commit was merged in pull request #23.
This commit is contained in:
58
src/lib/User.php
Normal file
58
src/lib/User.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace FeedReaderCentral;
|
||||
|
||||
use BitBadger\PDODocument\{Custom, Document, DocumentException, Field, Find, Parameters, Query};
|
||||
use BitBadger\PDODocument\Mapper\ExistsMapper;
|
||||
|
||||
/**
|
||||
* A user of Feed Reader Central
|
||||
*/
|
||||
class User
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $id The ID of the user
|
||||
* @param string $email The e-mail address for the user
|
||||
* @param string $password The password for the user
|
||||
*/
|
||||
public function __construct(public int $id = 0, public string $email = '', public string $password = '') { }
|
||||
|
||||
/**
|
||||
* Find a user by their e=mail address
|
||||
*
|
||||
* @param string $email The e-mail address of the user to retrieve
|
||||
* @return User|false The user information, or null if the user is not found
|
||||
* @throws DocumentException If any is encountered
|
||||
*/
|
||||
public static function findByEmail(string $email): User|false
|
||||
{
|
||||
return Find::firstByFields(Table::USER, [Field::EQ('email', $email)], User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a user
|
||||
*
|
||||
* @param string $email The e-mail address for the user
|
||||
* @param string $password The user's password
|
||||
* @throws DocumentException If any is encountered
|
||||
*/
|
||||
public static function add(string $email, string $password): void
|
||||
{
|
||||
Document::insert(Table::USER, new User(email: $email, password: $password));
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this user have any bookmarked items?
|
||||
*
|
||||
* @return bool True if the user has any bookmarked items, false if not
|
||||
* @throws DocumentException If any is encountered
|
||||
*/
|
||||
public static function hasBookmarks(): bool
|
||||
{
|
||||
$fields = [Data::userIdField(Table::FEED), Data::bookmarkField(true, Table::ITEM)];
|
||||
return Custom::scalar(Query\Exists::query(ItemWithFeed::FROM_WITH_JOIN, Query::whereByFields($fields)),
|
||||
Parameters::addFields($fields, []), new ExistsMapper());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user