67 lines
2.7 KiB
PHP

<?php
class Application_Controller_Plugin_Histo extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$module = $request->getModuleName();
$controller = $request->getControllerName();
$action = $request->getActionName();
if ($module == 'default' && $controller == 'index' && $action = 'index') {
return;
}
Zend_Registry::get('firebug')->info('PLUGIN HISTO - START');
$siret = $request->getParam('siret');
$layout = Zend_Layout::getMVCInstance();
if ( $layout->isEnabled() ) {
$user = new Scores_Utilisateur();
if ( $user->isLog() ) {
// --- Detecter les changements d'entité pour ne recharger la liste qu'au changement
$session = new Zend_Session_Namespace('histo');
$getLogs = true;
if (count($session->UserHisto) > 0) {
Zend_Registry::get('firebug')->info($session->UserHisto);
$lastHisto = $session->UserHisto[0];
if ($lastHisto->CompanyId == $siret) {
$getLogs = false;
}
if ($siret === null) {
$getLogs = false;
}
}
// --- Get Log
$view = $layout->getView();
if ($getLogs) {
$view->UserHisto = array();
$ws = new Scores_Ws_Client('gestion', '0.4');
try {
$result = $ws->getUserHistory();
if ($result !== false) {
if (count($result->item) > 0) {
foreach ($result->item as $i) {
$struct = new stdClass();
$struct->CompanyName = $i->CompanyName;
$struct->CompanyId = $i->CompanyId;
$date = new Zend_Date($i->Date);
$struct->Date = $date->toString('dd/MM/yyyy HH:mm:ss');
$view->UserHisto[] = $struct;
}
}
}
Zend_Registry::get('firebug')->info('PLUGIN HISTO - MAJ');
$session->UserHisto = $view->UserHisto;
} catch (Exception $e) {
Zend_Registry::get('firebug')->info($e->getMessage());
}
} else {
$view->UserHisto = $session->UserHisto;
}
}
}
Zend_Registry::get('firebug')->info('PLUGIN HISTO - END');
}
}