2014-05-14 08:13:58 +00:00

76 lines
2.3 KiB
PHP

<?php
class Application_Controller_Plugin_Services extends Zend_Controller_Plugin_Abstract
{
/**
* Vérifie les autorisations
* Utilise _request et _response hérités et injectés par le FC
*
* @param Zend_Controller_Request_Abstract $request : non utilisé, mais demandé par l'héritage
*/
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$controller = $request->getControllerName();
$action = $request->getActionName();
if ( in_array($controller, array('service'))
|| ( $controller == 'user' && in_array($action, array('login', 'logout')) ) ) {
//Do nothing
} else {
$auth = Zend_Auth::getInstance();
if ( $auth->hasIdentity() ) {
$username = $auth->getIdentity()->username;
$idClient = $auth->getIdentity()->idClient;
$wsServices = array();
//Get all webservice client
$clients = include APPLICATION_PATH . '/../library/WsScore/Clients/ClientsConfig.php';
foreach( $clients as $section => $params ) {
if ( $params['actif']
&& (isset($params['idClient']) && in_array($idClient,$params['idClient'])) ) {
$params['name'] = $section;
$params['type'] = 'client';
if ( $idClient == 1 ) {
$params['name'] = 'Client - '.ucfirst($section);
}
$wsServices[$section] = $params;
}
}
//Standard service
if ( count($wsServices)==0 || $idClient==1 ) {
$services = include APPLICATION_PATH . '/../library/WsScore/ServicesConfig.php';
foreach( $services as $section => $params )
{
if ( $params['actif'] ) {
$params['name'] = ucfirst($section);
$params['type'] = 'sd';
if ( isset($params['idClient']) && in_array($idClient,$params['idClient']) ) {
if ( $idClient == 1 ) {
$params['name'] = 'SD - '.ucfirst($section);
}
$wsServices[$section] = $params;
}
elseif ( !isset($params['idClient']) ) {
if ( $idClient == 1 ) {
$params['name'] = 'SD - '.ucfirst($section);
}
$wsServices[$section] = $params;
}
}
}
}
$layout = Zend_Layout::getMVCInstance();
$view = $layout->getView();
$view->WsServices = $wsServices;
}
} // Zend_Auth::hasIdentity
}
}