Merge branch '3.6' of github.com:alchemy-fr/Phraseanet into 3.6

This commit is contained in:
Romain Neutron
2011-12-15 20:37:59 +01:00
15 changed files with 650 additions and 33 deletions

View File

@@ -11,15 +11,16 @@
namespace Alchemy\Phrasea\Controller\Prod;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Silex\Application,
Silex\ControllerProviderInterface,
Silex\ControllerCollection;
use Symfony\Component\HttpFoundation\Request,
Symfony\Component\HttpFoundation\Response,
Symfony\Component\HttpFoundation\RedirectResponse,
Symfony\Component\HttpKernel\Exception\HttpException,
Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Alchemy\Phrasea\RouteProcessor\Basket as BasketRoute,
Alchemy\Phrasea\RequestHandler;
/**
*
@@ -34,27 +35,17 @@ class Basket implements ControllerProviderInterface
{
$controllers = new ControllerCollection();
$kernel = $app['Kernel'] ;
$controllers->post('/create/', function() use ($app)
$controllers->match('/', function(Application $app)
{
$requestHandler = new RequestHandler\Basket($app["kernel"]);
$processor = new BasketRoute\Root($requestHandler);
$em = $app['Kernel']->getEntityManager();
$Basket = new \Entities\Basket;
$Basket->setName($app['request']->get('name'));
$Basket->setUser($app['request']->get('desc'));
$Basket->setDescription($app['request']->get('desc'));
$em->persist($Basket);
$em->flush();
return new RedirectResponse(sprintf('/%d/', $Basket->getId()));
return $processor->getResponse();
});
$controllers->get('/{basket_id}/', function($basket_id) use ($app)
{
$em = $app['Kernel']->getEntityManager();
/* @var $entityManager \Doctrine\ORM\EntityManager */

View File

@@ -0,0 +1,49 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\Prod;
use Silex\Application,
Silex\ControllerProviderInterface,
Silex\ControllerCollection;
use Symfony\Component\HttpFoundation\Request,
Symfony\Component\HttpFoundation\Response,
Symfony\Component\HttpFoundation\RedirectResponse,
Symfony\Component\HttpKernel\Exception\HttpException,
Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Alchemy\Phrasea\RouteProcessor\WorkZone as RouteWorkZone,
Alchemy\Phrasea\RequestHandler;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Basket implements ControllerProviderInterface
{
public function connect(Application $app)
{
$controllers = new ControllerCollection();
$controllers->match('/', function(Application $app)
{
$requestHandler = new RequestHandler\WorkZone($app["kernel"]);
$processor = new RouteWorkZone\Root($requestHandler);
return $processor->getResponse();
});
return $controllers;
}
}

View File

@@ -91,6 +91,10 @@ class Kernel extends \Pimple
return $this['Request'];
}
/**
*
* @return \Registry
*/
public function getRegistry()
{
return $this['Registry'];
@@ -114,6 +118,29 @@ class Kernel extends \Pimple
return $this['Version'];
}
/**
*
* @return boolean
*/
public function isAuthenticated()
{
$session = \Session_Handler::getInstance(\appbox::get_instance());
return $session->is_authenticated();
}
/**
*
* @return \User_adapter
*/
public function getAuthenticatedUser()
{
$appbox = \appbox::get_instance();
$session = \Session_Handler::getInstance($appbox);
return \User_Adapter::getInstance($session->get_usr_id(), $appbox);
}
protected function verifyTimezone()
{
if ($this->getRegistry()->is_set('GV_timezone'))

View File

@@ -110,6 +110,12 @@ class Doctrine
);
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader(
'Repositories'
, realpath(__DIR__ . '/../../../../Doctrine')
);
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader(
'Proxies'
, realpath(__DIR__ . '/../../../../Doctrine')

View File

@@ -0,0 +1,25 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\RequestHandler;
use Alchemy\Phrasea\Kernel;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Basket extends RequestHandlerAbstract
{
}

View File

@@ -0,0 +1,40 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\RequestHandler;
use Alchemy\Phrasea\Kernel;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
abstract class RequestHandlerAbstract
{
private $kernel;
public function __construct(Kernel $kernel)
{
$this->kernel = $kernel;
return $this;
}
public function getKernel()
{
return $this->kernel;
}
}

View File

@@ -0,0 +1,53 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\RequestHandler;
use Alchemy\Phrasea\Kernel;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class WorkZone extends RequestHandlerAbstract
{
const BASKETS = 'baskets';
const STORIES = 'stories';
const VALIDATIONS = 'validations';
public function getContent()
{
$em = $this->kernel->getEntityManager();
$current_user = $this->kernel->getAuthenticatedUser();
/* @var $repo_baskets \Repositories\BasketRepository */
$repo_baskets = $em->getRepository('Entities\Baskets');
/* @var $repo_stories \Repositories\StoryWorkzoneRepository */
$repo_stories = $em->getRepository('Entities\StoryWorkZone');
$ret = new \Doctrine\Common\Collections\ArrayCollection();
$baskets = $repo_baskets->findActiveByUser($current_user);
$validations = $repo_baskets->findActiveValidationByUser($current_user);
$ret->set(self::BASKETS, $baskets);
$ret->set(self::VALIDATIONS, $validations);
$ret->set(self::STORIES, $repo_stories->findByUser($current_user));
return $ret;
}
}

View File

@@ -0,0 +1,51 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\RouteProcessor\Basket;
use Alchemy\Phrasea\RouteProcessor;
use Alchemy\Phrasea\RequestHandler;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Root extends RouteProcessor\RouteAbstract
{
public function __construct(RequestHandler\WorkZone $request)
{
parent::__construct($request);
}
public function getAllowedMethods()
{
return array('POST');
}
protected function post()
{
$em = $this->getEntityManager();
$Basket = new \Entities\Basket();
$Basket->setName($this->getRequest()->get('name'));
$Basket->setUser($this->getRequest()->get('desc'));
$Basket->setDescription($this->getRequest()->get('desc'));
$em->persist($Basket);
$em->flush();
return new RedirectResponse(sprintf('/%d/', $Basket->getId()));
}
}

View File

@@ -0,0 +1,205 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\RouteProcessor;
use Symfony\Component\HttpFoundation\Request,
Symfony\Component\HttpFoundation\Response;
use Doctrine\ORM\EntityManager;
use RequestHandler\RequestHandlerAbstract;
/**
*
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
abstract class RouteAbstract
{
const POST_OK = 201;
const GET_OK = 200;
const DELETE_OK = 204;
const PUT_OK = 200;
const OPTIONS_OK = 204;
const HEAD_OK = 200;
/**
*
* @var Phrasea\Kernel
*/
protected $requestHandler;
/**
* The response being rendered
* @var Response
*/
protected $response;
/**
* Return allowed methods for current controller
*/
abstract public function getAllowedMethods();
/**
* Constructor for a Statme Thread Module
* @param PDO $connection
*/
public function __construct(RequestHandlerAbstract $requestHandler)
{
$this->requestHandler = $requestHandler;
}
/**
*
* @return RequestHandlerAbstract
*/
public function getRequestHandler()
{
return $this->requestHandler;
}
/**
* Getter
* @return Phrasea\Kernel
*/
public function getKernel()
{
return $this->requestHandler->getKernel();
}
/**
* Getter
* @return Request
*/
public function getRequest()
{
return $this->getKernel()->getRequest();
}
/**
* Getter
* @return EntityManager
*/
public function getEntityManager()
{
return $this->getKernel()->getEntityManager();
}
/**
* Getter
* @return \registryInterface
*/
public function getRegistry()
{
return $this->getKernel()->getRegistry();
}
/**
* Getter
* @return Response
*/
public function getResponse()
{
if (null === $this->response)
{
$this->process();
}
return $this->response;
}
/**
*
* @return ControllerProcessorAbstract
*/
public function process()
{
$response = null;
switch (strtoupper($this->getRequest()->getMethod()))
{
case 'POST' :
$response = $this->post();
break;
case 'PUT' :
$response = $this->put();
break;
case 'DELETE' :
$response = $this->delete();
break;
case 'GET' :
$response = $this->get();
break;
case 'OPTIONS' :
$response = $this->options();
break;
case 'HEAD' :
$response = $this->head();
break;
default :
throw new Http\NotImplemented();
break;
}
$this->response = $response;
return $this;
}
/**
* Handle post action
*/
protected function post()
{
throw new Http\MethodNotAllowed($this->getAllowedMethods());
}
/**
* Handle delete action
*/
protected function delete()
{
throw new Http\MethodNotAllowed($this->getAllowedMethods());
}
/**
* Handle get action
*/
protected function get()
{
throw new Http\MethodNotAllowed($this->getAllowedMethods());
}
/**
* Handle put action
*/
protected function put()
{
throw new Http\MethodNotAllowed($this->getAllowedMethods());
}
/**
* Handle options action
*/
protected function options()
{
throw new Http\MethodNotAllowed($this->getAllowedMethods());
}
/**
* Handle head action
*/
protected function head()
{
throw new Http\MethodNotAllowed($this->getAllowedMethods());
}
}

View File

@@ -0,0 +1,40 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\RouteProcessor\WorkZone;
use Alchemy\Phrasea\RouteProcessor;
use Alchemy\Phrasea\RequestHandler;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Root extends RouteProcessor\RouteAbstract
{
public function __construct(RequestHandler\WorkZone $workzone)
{
parent::__construct($workzone);
}
public function getAllowedMethods()
{
return array('GET');
}
protected function get()
{
$content = $this->getRequestHandler()->getContent();
}
}

View File

@@ -0,0 +1,64 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Repositories;
use Doctrine\ORM\EntityRepository;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class BasketRepository extends EntityRepository
{
/**
* Returns all basket for a given user that are not marked as archived
*
* @param \User_Adapter $user
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function findActiveByUser(\User_Adapter $user)
{
$dql = 'SELECT b FROM Entities\Basket b
WHERE b.usr_id = :usr_id AND archived = false';
$query = $this->_em->createQuery($dql);
$query->setParameters(array(':usr_id' => $user->get_id()));
return $query->getResult();
}
/**
* Returns all baskets that are in validation session not expired and
* where a specified user is participant (not owner)
*
* @param \User_Adapter $user
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function findActiveValidationByUser(\User_Adapter $user)
{
$dql = 'SELECT b FROM Entities\Basket b
JOIN b.Entities\ValidationSession s
JOIN s.Entities\ValidationParticipant
WHERE b.usr_id != ?1 AND s.usr_id = ?2
AND s.expires > CURRENT_TIMESTAMP()';
$query = $this->_em->createQuery($dql);
$query->setParameters(array(1 => $user->get_id(), 2 => $user->get_id()));
return $query->getResult();
}
}

View File

@@ -0,0 +1,38 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Repositories;
use Doctrine\ORM\EntityRepository;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class StoryWorkzoneRepository extends EntityRepository
{
/**
* Returns all StoryWorkZone currently attached to a user
*
* @param \User_Adapter $user
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function findByUser(\User_Adapter $user)
{
return $this->findBy(array('usr_id'=>$user->get_id()));
}
}

View File

@@ -0,0 +1,26 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Repositories;
use Doctrine\ORM\EntityRepository;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ValidationParticipantRepository extends EntityRepository
{
}

View File

@@ -1,5 +1,6 @@
Entities\Basket:
type: entity
repositoryClass: Repositories\BasketRepository
table: Baskets
id:
id:

View File

@@ -1,5 +1,6 @@
Entities\ValidationParticipant:
type: entity
repositoryClass: Repositories\ValidationParticipantRepository
table: ValidationParticipants
id:
id: