This commit is contained in:
Nicolas Le Goff
2011-12-27 13:06:51 +01:00
300 changed files with 3436 additions and 3162 deletions

View File

@@ -22,214 +22,235 @@ require_once __DIR__ . '/../../classes/record/adapter.class.php';
*/
class BasketElement
{
/**
* @var integer $id
*/
private $id;
/**
* @var integer $record_id
*/
private $record_id;
/**
* @var integer $id
*/
private $id;
/**
* @var integer $sbas_id
*/
private $sbas_id;
/**
* @var integer $record_id
*/
private $record_id;
/**
* @var integer $ord
*/
private $ord;
/**
* @var integer $sbas_id
*/
private $sbas_id;
/**
* @var datetime $created
*/
private $created;
/**
* @var integer $ord
*/
private $ord;
/**
* @var datetime $updated
*/
private $updated;
/**
* @var datetime $created
*/
private $created;
/**
* @var Entities\Basket
*/
private $basket;
/**
* @var datetime $updated
*/
private $updated;
/**
* @var Entities\Basket
*/
private $basket;
/**
* Get id
*
* @return integer
*/
public function getId()
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set record_id
*
* @param integer $recordId
*/
public function setRecordId($recordId)
{
$this->record_id = $recordId;
}
/**
* Get record_id
*
* @return integer
*/
public function getRecordId()
{
return $this->record_id;
}
/**
* Set sbas_id
*
* @param integer $sbasId
*/
public function setSbasId($sbasId)
{
$this->sbas_id = $sbasId;
}
/**
* Get sbas_id
*
* @return integer
*/
public function getSbasId()
{
return $this->sbas_id;
}
/**
* Set ord
*
* @param integer $ord
*/
public function setOrd($ord)
{
$this->ord = $ord;
}
/**
* Get ord
*
* @return integer
*/
public function getOrd()
{
return $this->ord;
}
/**
* Set created
*
* @param datetime $created
*/
public function setCreated($created)
{
$this->created = $created;
}
/**
* Get created
*
* @return datetime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated
*
* @param datetime $updated
*/
public function setUpdated($updated)
{
$this->updated = $updated;
}
/**
* Get updated
*
* @return datetime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Set basket
*
* @param Entities\Basket $basket
*/
public function setBasket(\Entities\Basket $basket)
{
$this->basket = $basket;
}
/**
* Get basket
*
* @return Entities\Basket
*/
public function getBasket()
{
return $this->basket;
}
public function getRecord()
{
return new \record_adapter($this->getSbasId(), $this->getRecordId(), $this->getOrd());
}
public function setRecord(\record_adapter $record)
{
$this->setRecordId($record->get_record_id());
$this->setSbasId($record->get_sbas_id());
}
public function setLastInBasket()
{
$this->setOrd($this->getBasket()->getElements()->count() + 1);
}
/**
* @var Entities\ValidationData
*/
private $validation_datas;
public function __construct()
{
$this->validation_datas = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add validation_datas
*
* @param Entities\ValidationData $validationDatas
*/
public function addValidationData(\Entities\ValidationData $validationDatas)
{
$this->validation_datas[] = $validationDatas;
}
/**
* Get validation_datas
*
* @return Doctrine\Common\Collections\Collection
*/
public function getValidationDatas()
{
return $this->validation_datas;
}
/**
*
* @param \User_Adapter $user
* @return \Entities\ValidationData
*/
public function getUserValidationDatas(\User_Adapter $user)
{
foreach ($this->validation_datas as $validationData)
{
return $this->id;
/* @var $validationData \Entities\ValidationData */
if ($validationData->getParticipant()->getUser()->get_id() == $user->get_id())
{
return $validationData;
}
}
/**
* Set record_id
*
* @param integer $recordId
*/
public function setRecordId($recordId)
{
$this->record_id = $recordId;
}
throw new \Exception('There is no such participant');
}
/**
* Get record_id
*
* @return integer
*/
public function getRecordId()
{
return $this->record_id;
}
/**
* Set sbas_id
*
* @param integer $sbasId
*/
public function setSbasId($sbasId)
{
$this->sbas_id = $sbasId;
}
/**
* Get sbas_id
*
* @return integer
*/
public function getSbasId()
{
return $this->sbas_id;
}
/**
* Set ord
*
* @param integer $ord
*/
public function setOrd($ord)
{
$this->ord = $ord;
}
/**
* Get ord
*
* @return integer
*/
public function getOrd()
{
return $this->ord;
}
/**
* Set created
*
* @param datetime $created
*/
public function setCreated($created)
{
$this->created = $created;
}
/**
* Get created
*
* @return datetime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated
*
* @param datetime $updated
*/
public function setUpdated($updated)
{
$this->updated = $updated;
}
/**
* Get updated
*
* @return datetime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Set basket
*
* @param Entities\Basket $basket
*/
public function setBasket(\Entities\Basket $basket)
{
$this->basket = $basket;
}
/**
* Get basket
*
* @return Entities\Basket
*/
public function getBasket()
{
return $this->basket;
}
public function getRecord()
{
return new \record_adapter($this->getSbasId(), $this->getRecordId(), $this->getOrd());
}
public function setRecord(\record_adapter $record)
{
$this->setRecordId($record->get_record_id());
$this->setSbasId($record->get_sbas_id());
}
public function setLastInBasket()
{
$this->setOrd($this->getBasket()->getElements()->count() + 1);
}
/**
* @var Entities\ValidationData
*/
private $validation_datas;
public function __construct()
{
$this->validation_datas = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add validation_datas
*
* @param Entities\ValidationData $validationDatas
*/
public function addValidationData(\Entities\ValidationData $validationDatas)
{
$this->validation_datas[] = $validationDatas;
}
/**
* Get validation_datas
*
* @return Doctrine\Common\Collections\Collection
*/
public function getValidationDatas()
{
return $this->validation_datas;
}
}

View File

@@ -8,7 +8,9 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Entities;
/**
*
* @package
@@ -28,19 +30,44 @@ class ValidationParticipant
*/
private $usr_id;
/**
* @var Entities\ValidationData
*/
private $datases;
/**
* @var Entities\ValidationSession
*/
private $session;
/**
* @var datetime $reminded
*/
private $reminded = false;
/**
* @var Entities\ValidationData
*/
private $datas;
/**
* @var boolean $is_confirmed
*/
private $is_confirmed = false;
/**
* @var boolean $can_agree
*/
private $can_agree = false;
/**
* @var boolean $can_see_others
*/
private $can_see_others = false;
/**
* @var boolean $is_aware
*/
private $is_aware = false;
public function __construct()
{
$this->datases = new \Doctrine\Common\Collections\ArrayCollection();
$this->datas = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
@@ -76,21 +103,11 @@ class ValidationParticipant
/**
* Add datases
*
* @param Entities\ValidationData $datases
* @param Entities\ValidationData $datas
*/
public function addValidationData(\Entities\ValidationData $datases)
public function addValidationData(\Entities\ValidationData $datas)
{
$this->datases[] = $datases;
}
/**
* Get datases
*
* @return Doctrine\Common\Collections\Collection
*/
public function getDatases()
{
return $this->datases;
$this->datas[] = $datas;
}
/**
@@ -113,12 +130,6 @@ class ValidationParticipant
return $this->session;
}
/**
* @var boolean $is_aware
*/
private $is_aware = false;
/**
* Set is_aware
*
@@ -144,10 +155,125 @@ class ValidationParticipant
* @param \User_Adapter $user
* @return ValidationParticipant
*/
public function setParticipant(\User_Adapter $user)
public function setUser(\User_Adapter $user)
{
$this->usr_id = $user->get_id();
return $this;
}
public function getUser()
{
return \User_Adapter::getInstance($this->getUsrId(), appbox::get_instance());
}
/**
* Set reminded
*
* @param datetime $reminded
*/
public function setReminded($reminded)
{
$this->reminded = $reminded;
}
/**
* Get reminded
*
* @return datetime
*/
public function getReminded()
{
return $this->reminded;
}
/**
* Get datas
*
* @return Doctrine\Common\Collections\Collection
*/
public function getDatas()
{
return $this->datas;
}
/**
* Set is_confirmed
*
* @param boolean $isConfirmed
*/
public function setIsConfirmed($isConfirmed)
{
$this->is_confirmed = $isConfirmed;
}
/**
* Get is_confirmed
*
* @return boolean
*/
public function getIsConfirmed()
{
return $this->is_confirmed;
}
/**
* Set can_agree
*
* @param boolean $canAgree
*/
public function setCanAgree($canAgree)
{
$this->can_agree = $canAgree;
}
/**
* Get can_agree
*
* @return boolean
*/
public function getCanAgree()
{
return $this->can_agree;
}
/**
* Set can_see_others
*
* @param boolean $canSeeOthers
*/
public function setCanSeeOthers($canSeeOthers)
{
$this->can_see_others = $canSeeOthers;
}
/**
* Get can_see_others
*
* @return boolean
*/
public function getCanSeeOthers()
{
return $this->can_see_others;
}
public function isReleasable()
{
if ($this->getIsConfirmed())
{
return false;
}
foreach ($this->getDatas() as $validation_data)
{
/* @var $validation_data \Entities\ValidationData */
if ($validation_data->getAgreement() === null)
{
return false;
}
}
return true;
}
}

View File

@@ -265,6 +265,24 @@ class ValidationSession
return $this->participants;
}
/**
* Get a participant
*
* @return Entities\ValidationParticipant
*/
public function getParticipant(\User_Adapter $user)
{
foreach ($this->getParticipants() as $participant)
{
if ($participant->getUser()->get_id() == $user->get_id())
{
return $participant;
}
}
throw new \Exception_NotFound('Particpant not found');
}
/**
* @var integer $initiator
*/
@@ -295,6 +313,11 @@ class ValidationSession
return $this->initiator_id;
}
public function isInitiator(\User_Adapter $user)
{
return $this->getInitiatorId() == $user->get_id();
}
public function setInitiator(\User_Adapter $user)
{
$this->initiator_id = $user->get_id();
@@ -309,4 +332,55 @@ class ValidationSession
}
}
public function isFinished()
{
if (is_null($this->getExpires()))
{
return null;
}
$date_obj = new DateTime();
return $date_obj > $this->getExpires();
}
public function getValidationString(\User_Adapter $user)
{
if ($this->isInitiator($user))
{
if ($this->isFinished())
{
return sprintf(
_('Vous aviez envoye cette demande a %d utilisateurs')
, (count($this->getParticipants()) - 1)
);
}
else
{
return sprintf(
_('Vous avez envoye cette demande a %d utilisateurs')
, (count($this->getParticipants()) - 1)
);
}
}
else
{
if ($this->getParticipant($user)->getCanSeeOthers())
{
return sprintf(
_('Processus de validation recu de %s et concernant %d utilisateurs')
, $this->getInitiator()->get_display_name()
, (count($this->getParticipants()) - 1));
}
else
{
return sprintf(
_('Processus de validation recu de %s')
, $this->getInitiator()->get_display_name()
);
}
}
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace Repositories;
use Doctrine\ORM\EntityRepository;
/**
* BasketElementRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class BasketElementRepository extends EntityRepository
{
public function findUserElement($element_id, \User_Adapter $user)
{
$dql = 'SELECT e FROM Entities\BasketElement e
JOIN e.basket b
WHERE b.usr_id = :usr_id AND e.id = :element_id';
$params = array(
'usr_id' => $user->get_id(),
'element_id' => $element_id
);
$query = $this->_em->createQuery($dql);
$query->setParameters($params);
return $query->getOneOrNullResult();
}
public function findElementsByRecord(\record_adapter $record)
{
$dql = 'SELECT e FROM Entities\BasketElement e
WHERE e.record_id = :record_id AND e.sbas_id = :sbas_id';
$params = array(
'sbas_id' => $record->get_sbas_id(),
'record_id' => $record_id->get_record_id()
);
$query = $this->_em->createQuery($dql);
$query->setParameters($params);
return $query->getResult();
}
/**
*
* @param type $element_id
* @param \User_Adapter $user
* @return \Entities\BasketELement
*/
public function findUserElement($element_id, \User_Adapter $user)
{
$element = $this->find($element_id);
/* @var $element \Entities\BasketElement */
if (null === $element)
{
throw new \Exception_NotFound(_('Element is not found'));
}
if ($element->getBasket()->getowner()->get_id() != $user->get_id())
{
throw new \Exception_Forbidden(_('You have not access to this basket element'));
}
return $element;
}
}

View File

@@ -32,14 +32,13 @@ class BasketRepository extends EntityRepository
{
$dql = 'SELECT b FROM Entities\Basket b
WHERE b.usr_id = :usr_id AND b.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)
@@ -54,18 +53,27 @@ class BasketRepository extends EntityRepository
JOIN s.participants p
WHERE b.usr_id != ?1 AND p.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();
}
/**
* Find a basket specified by his basket_id and his owner
*
* @throws \Exception_NotFound
* @throws \Exception_Forbidden
* @param type $basket_id
* @param \User_Adapter $user
* @return \Entities\Basket
*/
public function findUserBasket($basket_id, \User_Adapter $user)
{
$basket = $this->find($basket_id);
/* @var $basket Entities\Basket */
/* @var $basket \Entities\Basket */
if (null === $basket)
{
throw new \Exception_NotFound(_('Basket is not found'));
@@ -79,4 +87,22 @@ class BasketRepository extends EntityRepository
return $basket;
}
public function findContainingRecord(\record_adapter $record)
{
$dql = 'SELECT b FROM Entities\Basket b
JOIN b.elements e
WHERE e.record_id = :record_id AND e.sbas_id = e.sbas_id';
$params = array(
'record_id' => $record->get_record_id(),
'sbas_id' => $record->get_sbas_id()
);
$query = $this->_em->createQuery($dql);
$query->setParameters($params);
return $query->getResult();
}
}