This repository has been archived by the owner on Jan 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
121 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
namespace Directus\Services; | ||
|
||
use Directus\Application\Container; | ||
use Directus\Database\RowGateway\BaseRowGateway; | ||
use Directus\Database\Schema\SchemaManager; | ||
use Directus\Database\TableGateway\DirectusActivityTableGateway; | ||
use Directus\Database\TableGateway\DirectusRolesTableGateway; | ||
use Directus\Util\ArrayUtils; | ||
use Directus\Util\DateTimeUtils; | ||
|
||
class ActivityService extends AbstractService | ||
{ | ||
/** | ||
* @var BaseRowGateway | ||
*/ | ||
protected $lastGroup = null; | ||
|
||
/** | ||
* @var DirectusRolesTableGateway | ||
*/ | ||
protected $tableGateway = null; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $collection; | ||
|
||
/** | ||
* @var ItemsService | ||
*/ | ||
protected $itemsService; | ||
|
||
public function __construct(Container $container) | ||
{ | ||
parent::__construct($container); | ||
$this->collection = SchemaManager::COLLECTION_ACTIVITY; | ||
$this->itemsService = new ItemsService($this->container); | ||
} | ||
|
||
public function createComment(array $data, array $params = []) | ||
{ | ||
$data = array_merge($data, [ | ||
'type' => DirectusActivityTableGateway::TYPE_COMMENT, | ||
'action' => DirectusActivityTableGateway::ACTION_ADD, | ||
'datetime' => DateTimeUtils::nowInUTC()->toString(), | ||
'ip' => get_request_ip(), | ||
'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '', | ||
'user' => $this->getAcl()->getUserId() | ||
]); | ||
|
||
$this->validatePayload($this->collection, null, $data, $params); | ||
$this->enforcePermissions($this->collection, $data, $params); | ||
|
||
$tableGateway = $this->getTableGateway(); | ||
|
||
// make sure to create new one instead of update | ||
unset($data[$tableGateway->primaryKeyFieldName]); | ||
$newComment = $tableGateway->updateRecord($data, $this->getCRUDParams($params)); | ||
|
||
return $tableGateway->wrapData( | ||
$newComment->toArray(), | ||
true, | ||
ArrayUtils::get($params, 'meta') | ||
); | ||
} | ||
|
||
/** | ||
* Finds a group by the given ID in the database | ||
* | ||
* @param int $id | ||
* @param array $params | ||
* | ||
* @return array | ||
*/ | ||
public function find($id, array $params = []) | ||
{ | ||
$tableGateway = $this->getTableGateway(); | ||
$params['id'] = $id; | ||
|
||
return $this->getItemsAndSetResponseCacheTags($tableGateway, $params); | ||
} | ||
|
||
public function findAll(array $params = []) | ||
{ | ||
$tableGateway = $this->getTableGateway(); | ||
|
||
return $this->getItemsAndSetResponseCacheTags($tableGateway, $params); | ||
} | ||
|
||
/** | ||
* @return DirectusActivityTableGateway | ||
*/ | ||
public function getTableGateway() | ||
{ | ||
if (!$this->tableGateway) { | ||
$acl = $this->container->get('acl'); | ||
$dbConnection = $this->container->get('database'); | ||
|
||
$this->tableGateway = new DirectusActivityTableGateway($dbConnection, $acl); | ||
} | ||
|
||
return $this->tableGateway; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters