Skip to content

Commit

Permalink
Expands itnernal query API
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnathonKoster committed Nov 19, 2020
1 parent 5349a2d commit baebd92
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Addon
public const CODE_ADDON_NAME = 'meerkat';
public const ROUTE_PREFIX = 'meerkat';
public const ADDON_ID = 'stillat/meerkat';
public const VERSION = '2.1.10-beta2';
public const VERSION = '2.1.11-beta2';

/**
* Gets the addon API prefix.
Expand Down
16 changes: 16 additions & 0 deletions src/Core/Contracts/Storage/ThreadStorageManagerContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ public function getAllSystemComments();
*/
public function getAllSystemCommentsForCurrentUser();

/**
* Returns all comments across all threads, for the provided user.
*
* @param string $userId The user's identifier.
* @return CommentContract[]
*/
public function getAllCommentsForUserId($userId);

/**
* Queries all system comments using the provided query builder.
*
* @param callable $builderCallback The builder callback.
* @return CommentContract[]
*/
public function query($builderCallback);

/**
* Attempts to locate a thread by its identifier.
*
Expand Down
44 changes: 44 additions & 0 deletions src/Core/Storage/Drivers/Local/LocalThreadStorageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Stillat\Meerkat\Core\Contracts\Threads\ThreadContextContract;
use Stillat\Meerkat\Core\Contracts\Threads\ThreadContract;
use Stillat\Meerkat\Core\Contracts\Threads\ThreadMutationPipelineContract;
use Stillat\Meerkat\Core\Data\DataQuery;
use Stillat\Meerkat\Core\Data\DataQueryFactory;
use Stillat\Meerkat\Core\Data\RuntimeContext;
use Stillat\Meerkat\Core\Errors;
Expand Down Expand Up @@ -521,6 +522,49 @@ public function getAllSystemComments()
return $comments;
}

/**
* Returns all comments across all threads, for the provided user.
*
* @param string $userId The user's identifier.
* @return CommentContract[]
* @throws FilterException
*/
public function getAllCommentsForUserId($userId)
{
$builder = DataQueryFactory::newQuery();

if ($builder === null) {
return [];
}

$builder->withContext(new RuntimeContext());
$builder->where(AuthorContract::AUTHENTICATED_USER_ID, '=', $userId);

return $builder->get($this->getAllSystemComments())->flattenDataset();
}

/**
* Queries all system comments using the provided query builder.
*
* @param callable $builderCallback The builder callback.
* @return CommentContract[]
* @throws FilterException
*/
public function query($builderCallback)
{
$builder = DataQueryFactory::newQuery();

/** @var DataQuery $builder */
$tempBuilder = $builderCallback($builder);

if ($tempBuilder !== null && $tempBuilder instanceof DataQuery) {
$builder = $tempBuilder;
}

$builder->withContext(new RuntimeContext());
return $builder->get($this->getAllSystemComments())->flattenDataset();
}

/**
* Returns all comments across all threads, for the currently authenticated user.
*
Expand Down

0 comments on commit baebd92

Please sign in to comment.