extranet/application/modules/default/controllers/WorldcheckController.php
2017-02-13 12:06:18 +01:00

342 lines
10 KiB
PHP

<?php
class WorldcheckController extends Zend_Controller_Action
{
protected $theme;
protected $wcConfig;
/**
* Logger
* @var \Monolog\Logger
*/
protected $logger;
public function init()
{
if (Zend_Registry::isRegistered('logger')) {
$this->logger = Zend_Registry::get('logger');
}
// --- Theme
$this->theme = Zend_Registry::get('theme');
require_once 'WorldCheck/WsWorldCheck.php';
require_once 'Scores/Cache.php';
$configWC = new Zend_Config_Ini(APPLICATION_PATH . '/../library/WorldCheck/applicationWC.ini');
$this->wcConfig = $configWC->worldcheck->toArray();
}
/**
* Get nameIdentifier and set all data into the session
*/
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');
$entityId = $request->getParam('entityId', null);
$user = new Scores_Utilisateur();
$wc = new WsWorldCheck();
$wcLocal = new Application_Model_Worldcheck();
$param->idClient = $user->getIdClient();
$param->login = $user->getLogin();
$localDBParams = $wcLocal->getScreenerId($param);
$param->matchCount = $localDBParams->matchCount;
$param->nameIdentifier = $localDBParams->nameIdentifier;
if ($entityId===null) {
//$this->_redirect('/worldcheck/list');
$params = array(
'nameIdentifier' => $param->nameIdentifier,
'matchCount' => $param->matchCount
);
$this->forward('list', null, null, $params);
} else {
$id = $request->getParam('id', null);
$data = new stdClass();
$data->nameIdentifier = $param->nameIdentifier;
$data->matchType = 'WATCHLIST';
$matchArr = $wc->getMatchesArrName($data);
$paramAssoc = new stdClass();
$paramAssoc->matchIdentifier = $matchArr[$entityId];
$paramAssoc->nameType = $param->dirType;
$nodeParam = $wc->getAssociates($paramAssoc);
$wcLocal->setTree($nodeParam);
$this->redirect('/worldcheck/orgchildren/entityid/'.$entityId.'/id/'.$id);
}
}
/**
* List results of WorldCheck search
*/
public function listAction()
{
$request = $this->getRequest();
$wc = new WsWorldCheck();
$param = new stdClass();
$nameIdentifier = $request->getParam('nameIdentifier');
$matchCount = $request->getParam('matchCount');
$dirNom = $request->getParam('dirNom');
$param->dirNom = ($dirNom)?$dirNom:$request->getParam('dirSociete');
$param->dirPrenom = $request->getParam('dirPrenom');
$param->dirType = $request->getParam('dirType');
print_r($param);
if ($matchCount!==0)
{
$summary = new stdClass();
$summary->nameIdentifier = $nameIdentifier;
$summary->matchType = 'WATCHLIST';
$cache = new Cache();
$unfilteredWC = $cache->wcCache($this->wcConfig['cachedir'], $wc, "getSummariesArr", $summary, $nameIdentifier);
//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
//paginate results list
Zend_View_Helper_PaginationControl::setDefaultViewPartial('worldcheck/controls.phtml');
$paginator = Zend_Paginator::factory($resultWC);
$this->view->paginator = $paginator;
$itemCount = $this->wcConfig['page']['items'];
$page = $this->_getParam('page', 1);
$ol_number = ($page-1)*$itemCount+1;
$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');
$data->Soc = new stdClass();
if ($request->getParam('dirSocNom2')) $data->Soc->Nom2 = $request->getParam('dirSocNom2');
if ($request->getParam('dirSocNomLong')) $data->Soc->NomLong = $request->getParam('dirSocNomLong');
if ($request->getParam('dirSocCommercial')) $data->Soc->NomCommercial = $request->getParam('dirSocCommercial');
if ($request->getParam('dirSocSigle')) $data->Soc->Sigle = $request->getParam('dirSocSigle');
if ($request->getParam('dirSocSigleLong')) $data->Soc->SigleLong = $request->getParam('dirSocSigleLong');
if ($request->getParam('dirSocEnseigne')) $data->Soc->Enseigne = $request->getParam('dirSocEnseigne');
if ($request->getParam('dirSocEnseigneLong')) $data->Soc->EnseigneLong = $request->getParam('dirSocEnseigneLong');
$wcLocal = new Application_Model_Worldcheck();
$this->view->assign('occurrence', $wcLocal->getCount($data));
$this->view->assign('data', $data);
}
}
/**
* Affichage le resultat de recherche en WorldCheck
*/
public function matchcontentAction()
{
$request = $this->getRequest();
$param = new stdClass();
$param->matchIdentifier = $request->getParam('matchIdentifier');
$param->nameType = $request->getParam('nameType');
$wc = new WsWorldCheck();
$nodeParam = $wc->getAssociates($param);
$db = new Application_Model_Worldcheck();
$db->setTree($nodeParam);
$cache = new Cache();
$content = $cache->wcCache($this->wcConfig['cachedir'], $wc, "getDetailsContent", $param, $param->matchIdentifier);
$this->view->assign('content', $content[0]);
$this->view->assign('nameType', $param->nameType);
$this->view->assign('exportObjet', $content[0]);
}
/**
* le Parent de l'organigramme des associés
*/
public function organigrammeAction()
{
$this->_helper->layout()->disableLayout();
$wc = new WsWorldCheck();
$request = $this->getRequest();
$entityId = $request->getParam('entityid', null);
$wcLocal = new Application_Model_Worldcheck();
$currentBranch = $wcLocal->getTree($entityId);
$primary = $currentBranch['primary'];
$parent = array();
$data = new stdClass();
$data->title = $primary['fullName'];
$data->icon = "/themes/default/images/worldcheck/".strtolower($primary['nameType']).".png";
$attr = new stdClass();
$attr->id = uniqid('wc_');
$attr->entityId = $primary['entityId'];
$attr->nameType = $primary['nameType'];
$attr->lastName = $primary['lastName'];
$attr->givenName = $primary['givenName'];
$parent[] = array(
"data" => $data,
"attr" => $attr,
"state" => "closed",
"parent" => "#"
);
$jData = json_encode($parent);
$this->view->assign('data', $jData);
}
/**
* les associés du parent de l'organigramme
*/
public function orgchildrenAction()
{
$this->_helper->layout()->disableLayout();
$wc = new WsWorldCheck();
$request = $this->getRequest();
$entityId = $request->getParam('entityid', null);
$id = $request->getParam('id', null);
$wcLocal = new Application_Model_Worldcheck();
$currentBranch = $wcLocal->getTree($entityId);
$associates = $currentBranch['associates'];
$children = array();
foreach ($associates as $associate) {
$data = new stdClass();
$data->title = $associate['fullName'];
$data->icon = "/themes/default/images/worldcheck/".strtolower($associate['nameType']).".png";
$attr = new stdClass();
$attr->id = uniqid('wc_');
$attr->entityId = $associate['entityId'];
$attr->nameType = $associate['nameType'];
$attr->lastName = $associate['lastName'];
$attr->givenName = $associate['givenName'];
$children[] = array(
"data" => $data,
"attr" => $attr,
"state" => "closed",
"parent" => $id,
);
}
$jData = json_encode($children);
$this->view->assign('data', $jData);
}
/**
* Affichage de l'information courte de chaque node dans le popup
*/
public function popupAction()
{
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
$entityId = $request->getParam('entityId', null);
$entityIdP = $request->getParam('entityIdP', null);
$wc = new WsWorldCheck();
$user = new Scores_Utilisateur();
$paramP = new stdClass();
$paramP->idClient = $user->getIdClient();
$paramP->dirNom = $request->getParam('dirNomP');
$paramP->dirPrenom = $request->getParam('dirPrenomP');
$paramP->dirType = $request->getParam('dirTypeP');
$wcLocal = new Application_Model_Worldcheck();
$result = $wcLocal->getScreenerId($paramP);
$data = new stdClass();
$data->nameIdentifier = $result->nameIdentifier;
$data->matchType = "WATCHLIST";
$matches = $wc->getMatchesArrName($data);
$param = new stdClass();
$param->matchIdentifier = $matches[$entityIdP];
$param->nameType = $paramP->dirType;
$associates = $wc->getAssociates($param);
foreach($associates['associates'] as $assoc)
{
if ($assoc['entityId']==$entityId)
break;
}
$this->view->assign('data', $assoc);
}
}