extranet/application/controllers/WorldcheckController.php
Michael RICOIS 36146f5687 path
2013-09-19 10:31:29 +00:00

164 lines
5.3 KiB
PHP

<?php
class WorldcheckController extends Zend_Controller_Action
{
public function init()
{
require_once 'WorldCheck/WsWorldCheck.php';
require_once 'WorldCheck/SessionWorldcheck.php';
}
/**
*
*/
public function indexAction()
{
$request = $this->getRequest();
$param = new stdClass();
$dirNom = $request->getParam('dirNom');
$param->dirNom = ($dirNom)?$dirNom:$request->getParam('dirSociete');
$param->dirPrenom = $request->getParam('dirPrenom');
$param->dirType = $request->getParam('dirType');
$param->Siren = $request->getParam('siren');
$user = new Scores_Utilisateur();
$session = new SessionWorldcheck();
$wc = new WsWorldCheck();
$wcLocal = new Application_Model_Worldcheck();
//check worldcheck data correctness in the session
if (!$session->getName() || $session->getName()!=$param->dirNom || substr($session->getNameIdentifier(),0,3)!='so_' || $session->getNameType()!=$param->dirType)
{
$param->idClient = $user->getIdClient();
$param->login = $user->getLogin();
$localDBParams = $wcLocal->getScreenerId($param);
$param->matchCount = $localDBParams->matchCount;
$param->nameIdentifier = $localDBParams->nameIdentifier;
$session->setSession($param);
}
$nameIdentifier = $session->getNameIdentifier();
$matchCount = $session->getMatchCount();
if ($matchCount!==0)
{
$summary = new stdClass();
$summary->nameIdentifier = $nameIdentifier;
$summary->matchType = 'WATCHLIST';
//get results by lastName
$unfilteredWC = new stdClass();
$unfilteredWC = $wc->getSummariesArr($summary);
//end
//check if display all results (search by lastName), or filtered results (search by fullName)
$filtre = $request->getParam('filtre', 'tout');
$resultWC = $unfilteredWC;
if ($filtre=='filtered')
{
//get results by fullName (lastName and givenName)
$filteredWC = array();
foreach ($unfilteredWC as $entityId=>$shortData)
{
if (stripos($shortData->lastName, $param->dirNom)!==false || stripos($param->dirNom, $shortData->lastName)!==false) {
if (stripos($shortData->givenName, $param->dirPrenom)!==false || stripos($param->dirPrenom, $shortData->givenName)!==false) {
$filteredWC[$entityId] = $shortData;
}
}
}
//end
$resultWC = $filteredWC;
}
$filtres = array(
'tout' => array(
'txt'=>'Résultats par Nom',
'select'=>'',
'value' => 2,
),
'filtered' => array(
'txt'=>'Résultats précis',
'select'=>'',
'value' => 1,
)
);
$filtres[$filtre]['select'] = ' selected';
$this->view->assign('filtres', $filtres);
//end
$configWC = new Zend_Config_Ini(APPLICATION_PATH . '/../library/WorldCheck/applicationWC.ini');
$cacheConfig = $configWC->worldcheck->toArray();
/*$frontendOptions = array(
'lifetime' => $cacheConfig['cachedir']['lifetime'],
'automatic_serialization' => true
);
$backendOptions = array('cache_dir' => $cacheConfig['cachedir']['path'].$cacheConfig['cachedir']['name']);
$cache = Zend_Cache::factory('Output','File',$frontendOptions,$backendOptions);*/
//paginate results list
Zend_View_Helper_PaginationControl::setDefaultViewPartial('worldcheck/controls.phtml');
$paginator = Zend_Paginator::factory($resultWC);
$this->view->paginator = $paginator;
$itemCount = $cacheConfig['page']['items'];
$page = $this->_getParam('page', 1);
$ol_number = ($page-1)*$itemCount+1;
/*if(!($cache->load('page_'.$page))) {
$cache->save($paginator, 'page_'.$page);
}*/
$paginator->setCurrentPageNumber($page);
$paginator->setItemCountPerPage($itemCount);
$this->view->assign('ol_number', $ol_number);
$this->view->assign('itemCount', $itemCount);
//end
$this->view->assign('resultWC', $resultWC);
$this->view->assign('allMatches', $wc->getMatchesArrName($summary));
$this->view->assign('param', $param);
}
}
/**
* Affichage le quantite des occurences de la bdd en popup.
*/
public function occurenceAction()
{
$request = $this->getRequest();
if ( $request->isXmlHttpRequest() ) {
$this->_helper->layout()->disableLayout();
$data = new stdClass();
if ($request->getParam('dirType')) $data->Type = $request->getParam('dirType');
if ($request->getParam('dirNom')) $data->Nom = $request->getParam('dirNom');
if ($request->getParam('dirPrenom')) $data->Prenom = $request->getParam('dirPrenom');
if ($request->getParam('dirSociete')) $data->Societe = $request->getParam('dirSociete');
$wcLocal = new Application_Model_Worldcheck();
$this->view->assign('occurrence', $wcLocal->getCount($data));
}
}
/**
* Affichage le resultat de recherche en WorldCheck
*/
public function matchcontentAction()
{
$request = $this->getRequest();
$session = new SessionWorldcheck();
$param = new stdClass();
$param->matchIdentifier = $request->getParam('matchIdentifier');
$param->nameType = $session->getNameType();
$wc = new WsWorldCheck();
$content = $wc->getDetailsContent($param);
$this->view->assign('matchIdentifier', $param->matchIdentifier);
$this->view->assign('content', $content);
}
}