mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-11 20:13:28 +00:00
67 lines
1.5 KiB
PHP
67 lines
1.5 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Phraseanet
|
|
*
|
|
* (c) 2005-2014 Alchemy
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Alchemy\Phrasea\Model\Manipulator;
|
|
|
|
use Alchemy\Phrasea\ControllerProvider\Api\V1;
|
|
use Alchemy\Phrasea\Model\Entities\ApiAccount;
|
|
use Alchemy\Phrasea\Model\Entities\ApiApplication;
|
|
use Alchemy\Phrasea\Model\Entities\User;
|
|
use Doctrine\Common\Persistence\ObjectManager;
|
|
|
|
class ApiAccountManipulator implements ManipulatorInterface
|
|
{
|
|
private $om;
|
|
|
|
public function __construct(ObjectManager $om)
|
|
{
|
|
$this->om = $om;
|
|
}
|
|
|
|
public function create(ApiApplication $application, User $user)
|
|
{
|
|
$account = new ApiAccount();
|
|
$account->setUser($user);
|
|
$account->setApplication($application);
|
|
$account->setApiVersion(V1::VERSION);
|
|
|
|
$this->update($account);
|
|
|
|
return $account;
|
|
}
|
|
|
|
public function delete(ApiAccount $account)
|
|
{
|
|
$this->om->remove($account);
|
|
$this->om->flush();
|
|
}
|
|
|
|
public function update(ApiAccount $account)
|
|
{
|
|
$this->om->persist($account);
|
|
$this->om->flush();
|
|
}
|
|
|
|
public function authorizeAccess(ApiAccount $account)
|
|
{
|
|
$account->setRevoked(false);
|
|
|
|
$this->update($account);
|
|
}
|
|
|
|
public function revokeAccess(ApiAccount $account)
|
|
{
|
|
$account->setRevoked(true);
|
|
|
|
$this->update($account);
|
|
}
|
|
}
|