Skip to content
Snippets Groups Projects
Commit 933be922 authored by llaffont's avatar llaffont
Browse files

Refactoring Device/DeviceHold

parent ea25b36a
Branches
Tags
No related merge requests found
......@@ -183,22 +183,35 @@ class Class_Multimedia_Device extends Storm_Model_Abstract {
* @return boolean
*/
public function canCreateHoldGivenCurrentHoldAndUser($current_hold, $user) {
// pas de résa auto, on sort
if (!$this->isAutoholdEnabled())
return false;
// si une résa est en cours et n'est pas encore dans le délai d'annulation
if ((null !== $current_hold)
&& ($this->getCurrentTime() <= ($current_hold->getStart() + (60 * $this->getAuthDelay()))))
if ((null !== $current_hold) && !$this->isHoldCancelableNow($current_hold))
return false;
if (null == $next_hold = $this->getNextHold())
return true;
if (null == $next_hold = $this->getNextHold())
return true;
if ($user->getId() == $next_hold->getIdUser())
return true;
if ($next_hold->belongsToUser($user))
return true;
return ($this->getCurrentTime() < ($next_hold->getStart() - (60 * $this->getAutoholdMinTime())));
return $this->isThereEnoughTimeLeftBefore($next_hold->getStart());
}
/**
* @return bool
*/
public function isThereEnoughTimeLeftBefore($timestamp) {
return $this->getCurrentTime() < ($timestamp - (60 * $this->getAutoholdMinTime()));
}
/**
* @return bool
*/
public function isHoldCancelableNow($hold) {
return $this->getCurrentTime() > ($hold->getStart() + (60 * $this->getAuthDelay()));
}
......
......@@ -185,5 +185,10 @@ class Class_Multimedia_DeviceHold extends Storm_Model_Abstract {
public static function getLoader() {
return self::getLoaderFor(__CLASS__);
}
public function belongsToUser($user) {
return $user == $this->getUser();
}
}
?>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment