Skip to content
Snippets Groups Projects
Commit 5bd78ef9 authored by adiouf's avatar adiouf
Browse files

dev #59639 Multimedia supprimer besoin Auth, refacti + Ajout service pour...

dev #59639 Multimedia supprimer besoin Auth, refacti + Ajout service pour prochaine reservation pour un poste
parent 7fd4fa4d
Branches
Tags
3 merge requests!2334Master,!2145Dev#59639 multimedia supprimer besoin auth pour question sur devices,!2143Dev#59639 multimedia supprimer besoin auth pour question sur devices
Pipeline #1298 passed with stage
in 12 minutes and 14 seconds
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_Multimedia_AbstractRequest {
/** @var boolean */
protected $_valid = false;
/** @var string */
protected $_error = '';
/** @var Class_Users */
protected $_user;
/** @var Class_Multimedia_Device */
protected $_device;
protected function _controleAuthRequest($request) {
if (!($login = $request->getParam('login'))
|| !($password = $request->getParam('password')))
return $this->_error('MissingParameter');
$auth = ZendAfi_Auth::getInstance();
if (!$auth->authenticateLoginPassword($login,
$password,
[$auth->newAuthSIGB(), $auth->newAuthDb()])) {
if (Class_Users::findFirstBy(['login' => $login]))
return $this->_error('PasswordIsWrong');
return $this->_error('UserNotFound');
}
$user = Class_Users::getIdentity();
$group = Class_UserGroup::findGroupUserMultimedia();
if (!$user->isAbonneInviteInGroupMultimedia() && !$user->isAbonnementValid())
return $this->_error('SubscriptionExpired');
$this->_user = $user;
}
protected function _controleAuthAndHoldRequest($request) {
if($this->_controleAuthRequest($request))
return $this;
if($this->_controleHoldRequest($request))
return $this;
}
protected function _controleHoldRequest($request) {
if (!($site = $request->getParam('site'))
|| !($poste = $request->getParam('poste')))
return $this->_error('MissingParameter');
if ($location = Class_Multimedia_Location::findByIdOrigine($site))
$this->_device = Class_Multimedia_Device::findByIdOrigineAndLocation($poste, $location);
if (!$this->_device)
return $this->_error('DeviceNotFound');
}
/** @return boolean */
public function isValid() {
return $this->_valid;
}
/** @return Class_Multimedia_AbstractRequest */
public function beValid() {
$this->_valid = true;
return $this;
}
/** @return string */
public function getError() {
return $this->_error;
}
/** @return Class_Users */
public function getUser() {
return $this->_user;
}
/**
* @param string $code
* @return Class_Multimedia_AbstractRequest
*/
protected function _error($code) {
$this->_error = $code;
return $this;
}
}
?>
\ No newline at end of file
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_Multimedia_HoldRequest extends Class_Multimedia_AbstractRequest{
/** @var Class_Multimedia_Device */
protected $_deviceHold;
/** @var boolean */
protected $_holdableDay = false;
/** @var boolean */
protected $_successHolding = false;
/**
* @param Zend_Controller_Request_Abstract
* @return Class_Multimedia_HoldRequest
*/
public static function getInstance() {
return new self();
}
/**
* @param Zend_Controller_Request_Abstract
* @return Class_Multimedia_HoldRequest
*/
public function closeHoldingDevice($request) {
if($this->_controleAuthAndHoldRequest($request))
return $this;
if(!$hold = $this->getCurrentHold())
return $this->_error('DeviceNotHeldByUser');
$start = $hold->getStart();
$duration = floor(($location->getTimeSource()->time() - $start) / 60);
$hold->delete();
$this->_device->createHoldWithStartTimeAndDuration($user, $start, $duration);
return $this->beValid();
}
/**
* @param Zend_Controller_Request_Abstract
* @return Class_Multimedia_HoldRequest
*/
public function isHoldableDay($request) {
if($this->_controleHoldRequest($request))
return $this;
$this->_holdableDay = $this->_device->isHoldableDayToDay();
return $this->beValid();
}
/**
* @param Zend_Controller_Request_Abstract
* @return Class_Multimedia_HoldRequest
*/
public function holdDevice($request) {
if($this->_controleAuthAndHoldRequest($request))
return $this;
$temps = $request->getParam('temps');
if(!$this->getCurrentHold($temps))
return $this->_error('DeviceNotHeldByUser');
$this->_successHolding = true;
return $this->beValid();
}
/**
* @return Class_Multimedia_DeviceHold
*/
public function getCurrentHold($temps=null) {
if (!isset($this->_current_hold) && isset($this->_device) && isset($this->_user))
$this->_current_hold = $this->_device->getCurrentHoldForUser($this->_user, $temps);
return $this->_current_hold;
}
/**
* @return string
*/
public function getCurrentHoldEnd() {
return $this->getCurrentHold()->getEnd();
}
/**
* @param Zend_Controller_Request_Abstract
* @return Class_Multimedia_HoldRequest
*/
public function getNextHoldDevice($request) {
if($this->_controleHoldRequest($request))
return $this;
if(! $this->_deviceHold = $this->_device->getNextHold())
return $this->_error('NotHaveHoldForDevice');
return $this->beValid();
}
public function getDeviceHold(){
return $this->_deviceHold;
}
public function canHoldingForToDay(){
return $this->_holdableDay;
}
public function isSuccessHolding(){
return $this->_successHolding;
}
}
?>
\ 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