Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
121 lines (103 sloc) 3.16 KB
<?php
namespace deasilworks\Collector\CEF\Data\Manager;
use Cassandra\Uuid;
use deasilworks\API\Annotation\ApiAction;
use deasilworks\API\Annotation\ApiController;
use deasilworks\CEF\EntityDataManager;
use deasilworks\CEF\Statement\Simple;
use deasilworks\CEF\StatementBuilder\Select;
use deasilworks\Collector\CEF\Data\Collection\LogDataCollection;
use deasilworks\Collector\CEF\Data\Model\LogDataModel;
/**
* Class LogDataManager.
*
* Responsible for providing CRUD operations
* on LogDataModels and providing LogDataCollections.
*
* @ApiController()
*/
class LogDataManager extends EntityDataManager
{
/**
* Overwritten to customize Collection Class.
*
* @var string
*/
protected $collectionClass = LogDataCollection::class;
/**
* Create or Update a log entry.
*
* @param LogDataModel $logDataModel
*
* @return true
*/
public function setLog(LogDataModel $logDataModel)
{
$logDataModel
->setEntityManager($this)
->save();
return true;
}
/**
* Get Log Entries By Day
*
* @ApiAction()
*
* @param string $client
* @param string $type
* @param int $day
*
* @return LogDataCollection
*/
public function getLogEntriesByDay($client, $type, $day)
{
// get a Simple Statement Manager
$stmtMgr = $this->getStatementManager(Simple::class);
// get a Select Statement Builder
/** @var Select $stmtBuilder */
$stmtBuilder = $stmtMgr->getStatementBuilder(Select::class);
// create a statement
$stmt = $stmtBuilder->setWhere(['client = :client', 'type = :type', 'day = :day']);
// give statement and argument to the Statement Manager and execute the query expecting
// a LogDataCollection in return.
/** @var LogDataCollection $logCollection */
$logCollection = $stmtMgr
->setStatement($stmt)
->setArguments([
'client' => (string)$client,
'type' => (string)$type,
'day' => (int)$day
])
->execute();
return $logCollection;
}
/**
* Get Log Entries Event Uuid
*
* @ApiAction()
*
* @param string $eventUuid
*
* @return LogDataCollection
*/
public function getLogEntriesByEventUuid($eventUuid)
{
// get a Simple Statement Manager
$stmtMgr = $this->getStatementManager(Simple::class);
// get a Select Statement Builder
/** @var Select $stmtBuilder */
$stmtBuilder = $stmtMgr->getStatementBuilder(Select::class);
// create a statement
$stmt = $stmtBuilder->setWhere(['event_uuid = :event_uuid']);
// give statement and argument to the Statement Manager and execute the query expecting
// a LogDataCollection in return.
/** @var LogDataCollection $logCollection */
$logCollection = $stmtMgr
->setStatement($stmt->setFrom('mv_log_by_event_uuid'))
->setArguments([
'event_uuid' => new Uuid($eventUuid),
])
->execute();
return $logCollection;
}
}
You can’t perform that action at this time.