Files
Phraseanet/lib/Alchemy/Phrasea/Model/Entities/ValidationSession.php
Nicolas Le Goff 26bd977d5f Delete references to usr.usr_id field in entities
Conflicts:
	lib/Alchemy/Phrasea/Controller/Prod/Push.php
	lib/Alchemy/Phrasea/Controller/Prod/UsrLists.php
	lib/conf.d/migrations.yml

Conflicts:
	lib/Alchemy/Phrasea/ACL/BasketACL.php
	lib/Alchemy/Phrasea/Authentication/Authenticator.php
	lib/Alchemy/Phrasea/Controller/Prod/Order.php
	lib/Alchemy/Phrasea/Controller/Prod/UsrLists.php
	lib/Alchemy/Phrasea/Controller/Root/RSSFeeds.php
	lib/Alchemy/Phrasea/Controller/Root/Session.php
	lib/Alchemy/Phrasea/Model/Entities/Basket.php
	lib/Alchemy/Phrasea/Model/Entities/BasketElement.php
	lib/Alchemy/Phrasea/Model/Entities/Feed.php
	lib/Alchemy/Phrasea/Model/Entities/FeedEntry.php
	lib/Alchemy/Phrasea/Model/Entities/FtpExport.php
	lib/Alchemy/Phrasea/Model/Entities/Session.php
	lib/Alchemy/Phrasea/Model/Entities/StoryWZ.php
	lib/Alchemy/Phrasea/Model/Entities/UsrList.php
	lib/Alchemy/Phrasea/Model/Entities/UsrListEntry.php
	lib/Alchemy/Phrasea/Model/Entities/UsrListOwner.php
	lib/Alchemy/Phrasea/Model/Entities/ValidationParticipant.php
	lib/Alchemy/Phrasea/Model/Entities/ValidationSession.php
	lib/Alchemy/Phrasea/Model/Repositories/StoryWZRepository.php
	lib/classes/API/V1/adapter.php
	templates/mobile/lightbox/sc_note.html.twig
	templates/web/admin/connected-users.html.twig
	templates/web/admin/publications/fiche.html.twig
	templates/web/lightbox/IE6/agreement_box.html.twig
	templates/web/lightbox/agreement_box.html.twig
	templates/web/lightbox/basket_content_report.html.twig
	templates/web/lightbox/sc_note.html.twig
	templates/web/prod/WorkZone/Browser/Basket.html.twig
	templates/web/prod/WorkZone/Browser/Results.html.twig
	templates/web/prod/WorkZone/Macros.html.twig
	templates/web/prod/actions/Feedback/List-Share.html.twig
	templates/web/prod/actions/Feedback/ListsMacros.html.twig
	templates/web/prod/orders/order_box.html.twig
	templates/web/prod/orders/order_item.html.twig
	templates/web/prod/upload/lazaret.html.twig
	tests/Alchemy/Tests/Phrasea/Controller/Root/SessionTest.php
2014-02-19 17:29:25 +01:00

295 lines
6.2 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\Entities;
use Alchemy\Phrasea\Application;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* @ORM\Table(name="ValidationSessions")
* @ORM\Entity
*/
class ValidationSession
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue
*/
private $id;
/**
* @ORM\Column(type="integer")
*/
private $initiator_id;
/**
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
private $created;
/**
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
*/
private $updated;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $expires;
/**
* @ORM\OneToOne(targetEntity="Basket", inversedBy="validation", cascade={"persist"})
* @ORM\JoinColumn(name="basket_id", referencedColumnName="id")
*/
private $basket;
/**
* @ORM\OneToMany(targetEntity="ValidationParticipant", mappedBy="session", cascade={"all"})
*/
private $participants;
/**
* Constructor
*/
public function __construct()
{
$this->participants = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set initiator_id
*
* @param integer $initiatorId
* @return ValidationSession
*/
public function setInitiatorId($initiatorId)
{
$this->initiator_id = $initiatorId;
return $this;
}
/**
* Get initiator_id
*
* @return integer
*/
public function getInitiatorId()
{
return $this->initiator_id;
}
public function isInitiator(\User_Adapter $user)
{
return $this->getInitiatorId() == $user->getId();
}
public function setInitiator(\User_Adapter $user)
{
$this->initiator_id = $user->getId();
return;
}
public function getInitiator(Application $app)
{
if ($this->initiator_id) {
return \User_Adapter::getInstance($this->initiator_id, $app);
}
}
/**
* Set created
*
* @param \DateTime $created
* @return ValidationSession
*/
public function setCreated(\DateTime $created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* @return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated
*
* @param \DateTime $updated
* @return ValidationSession
*/
public function setUpdated(\DateTime $updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated
*
* @return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Set expires
*
* @param \DateTime $expires
* @return ValidationSession
*/
public function setExpires($expires)
{
$this->expires = $expires;
return $this;
}
/**
* Get expires
*
* @return \DateTime
*/
public function getExpires()
{
return $this->expires;
}
/**
* Set basket
*
* @param Basket $basket
* @return ValidationSession
*/
public function setBasket(Basket $basket = null)
{
$this->basket = $basket;
return $this;
}
/**
* Get basket
*
* @return Basket
*/
public function getBasket()
{
return $this->basket;
}
/**
* Add participants
*
* @param ValidationParticipant $participants
* @return ValidationSession
*/
public function addParticipant(ValidationParticipant $participants)
{
$this->participants[] = $participants;
return $this;
}
/**
* Remove participants
*
* @param ValidationParticipant $participants
*/
public function removeParticipant(ValidationParticipant $participants)
{
$this->participants->removeElement($participants);
}
/**
* Get participants
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getParticipants()
{
return $this->participants;
}
public function isFinished()
{
if (is_null($this->getExpires())) {
return null;
}
$date_obj = new \DateTime();
return $date_obj > $this->getExpires();
}
public function getValidationString(Application $app, \User_Adapter $user)
{
if ($this->isInitiator($user)) {
if ($this->isFinished()) {
return $app->trans('Vous aviez envoye cette demande a %n% utilisateurs', ['%n%' => count($this->getParticipants()) - 1]);
} else {
return $app->trans('Vous avez envoye cette demande a %n% utilisateurs', ['%n%' => count($this->getParticipants()) - 1]);
}
} else {
if ($this->getParticipant($user, $app)->getCanSeeOthers()) {
return $app->trans('Processus de validation recu de %user% et concernant %n% utilisateurs', ['%user%' => $this->getInitiator($app)->getDisplayName(), '%n%' => count($this->getParticipants()) - 1]);
} else {
return $app->trans('Processus de validation recu de %user%', ['%user%' => $this->getInitiator($app)->getDisplayName()]);
}
}
}
/**
* Get a participant
*
* @return ValidationParticipant
*/
public function getParticipant(\User_Adapter $user, Application $app)
{
foreach ($this->getParticipants() as $participant) {
if ($participant->getUser()->getId() == $user->getId()) {
return $participant;
}
}
throw new NotFoundHttpException('Participant not found' . $user->get_email());
}
}