2013-09-16 15:41:31 +00:00
|
|
|
<?php
|
|
|
|
class Application_Model_Worldcheck extends Zend_Db_Table_Abstract
|
|
|
|
{
|
|
|
|
protected $_name = 'worldcheck';
|
2014-02-13 14:41:39 +00:00
|
|
|
protected $tbList = 'worldcheck_list';
|
|
|
|
protected $tbAssoc = 'worldcheck_a';
|
2013-09-16 15:41:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return nameIdentifier and matchCount from local DB if found.
|
|
|
|
* Otherwise get nameIdentifier and matchCount from WorldCheck
|
|
|
|
* @param object $param
|
|
|
|
* @return object
|
|
|
|
*/
|
|
|
|
public function getScreenerId($param)
|
|
|
|
{
|
|
|
|
$result = new stdClass();
|
|
|
|
$sql = $this->select()
|
|
|
|
->where("idClient='".$param->idClient."' AND name='".$param->dirNom."' AND nameType='".$param->dirType."' AND LEFT(nameIdentifier, 3)='so_'")
|
|
|
|
->order('dateInsert DESC');
|
|
|
|
if ($this->fetchRow($sql))
|
|
|
|
{
|
|
|
|
$result->nameIdentifier = $this->fetchRow($sql)->nameIdentifier;
|
|
|
|
$result->matchCount = $this->fetchRow($sql)->matchCount;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$wc = new WsWorldCheck();
|
|
|
|
$data = new stdClass();
|
|
|
|
$data->name = $param->dirNom;
|
|
|
|
$data->nameType = $param->dirType;
|
|
|
|
$result->nameIdentifier = $wc->getScreener($data);
|
|
|
|
$result->matchCount = $wc->getDetailsName($result->nameIdentifier)->unresolvedMatchCount;
|
|
|
|
$params = array(
|
|
|
|
'idClient' => $param->idClient,
|
|
|
|
'login' => $param->login,
|
|
|
|
'nameIdentifier' => $result->nameIdentifier,
|
|
|
|
'matchCount' => $result->matchCount,
|
|
|
|
'name' => $param->dirNom,
|
|
|
|
'siren' => $param->Siren,
|
|
|
|
'nameType' => $param->dirType,
|
|
|
|
'dateInsert' => date('Y-m-d')
|
|
|
|
);
|
|
|
|
$sql = $this->insert($params);
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return matchCount of name
|
|
|
|
* @param object $data (Nom, Prenom, Societe, Type)
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getCount($data)
|
|
|
|
{
|
|
|
|
if (isset($data->Societe) && $data->Societe!='')
|
|
|
|
{
|
|
|
|
$nameType = 'ORGANISATION';
|
|
|
|
$name = $data->Societe;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$nameType = 'INDIVIDUAL';
|
|
|
|
$name = $data->Nom;
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = $this->select()
|
|
|
|
->where("name='".$name."' AND nameType='".$nameType."' AND LEFT(nameIdentifier, 3)='so_'")
|
|
|
|
->group('name');
|
|
|
|
|
|
|
|
if ($this->fetchRow($sql))
|
|
|
|
{
|
|
|
|
$result=$this->fetchRow($sql);
|
|
|
|
return $result->matchCount;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-13 14:41:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set WorldCheck associates tree data into DB
|
|
|
|
* @param array $nodeParams
|
|
|
|
* @param string $nodeType, value must be 'p'[parent] or 'a'[associate]
|
|
|
|
*/
|
|
|
|
public function setTree($nodeParams)
|
|
|
|
{
|
|
|
|
$primary = array(
|
|
|
|
'entityId'=>'',
|
|
|
|
'nameType'=>'',
|
|
|
|
'fullName'=>'',
|
|
|
|
'givenName'=>'',
|
|
|
|
'lastName'=>'');
|
|
|
|
|
|
|
|
$assoc = array(
|
|
|
|
'entityIdP'=>'',
|
|
|
|
'entityId'=>'',
|
|
|
|
'nameType'=>'',
|
|
|
|
'fullName'=>'',
|
|
|
|
'givenName'=>'',
|
|
|
|
'lastName'=>'');
|
|
|
|
|
|
|
|
$primary = array_intersect_key($nodeParams['primary'], $primary);
|
|
|
|
|
|
|
|
$sql = $this->getAdapter()->select()
|
|
|
|
->from($this->tbList, 'entityId')
|
|
|
|
->where('entityId=?', $primary['entityId']);
|
|
|
|
if (!$this->getAdapter()->fetchRow($sql)) {
|
|
|
|
$this->getAdapter()->insert($this->tbList, $primary);
|
|
|
|
}
|
|
|
|
|
|
|
|
$associates = $nodeParams['associates'];
|
|
|
|
|
|
|
|
foreach($associates as $associate) {
|
|
|
|
$associate = array_intersect_key($associate, $assoc);
|
|
|
|
$associate['entityIdP'] = $primary['entityId'];
|
|
|
|
|
|
|
|
$sql = $this->getAdapter()->select()
|
|
|
|
->from($this->tbAssoc, array('entityId', 'entityIdP'))
|
|
|
|
->where('entityId=?', $associate['entityId'])
|
|
|
|
->where('entityIdP=?', $primary['entityId']);
|
|
|
|
if (!$this->getAdapter()->fetchRow($sql)) {
|
|
|
|
$this->getAdapter()->insert($this->tbAssoc, $associate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get WorldCheck associates tree data from DB
|
|
|
|
* @param string $entityId
|
|
|
|
* @return Ambigous <multitype:, multitype:mixed Ambigous <string, boolean, mixed> >
|
|
|
|
*/
|
|
|
|
public function getTree($entityId)
|
|
|
|
{
|
|
|
|
$sql = $this->getAdapter()->select()
|
|
|
|
->from(array('a' => $this->tbAssoc), array('a.entityId', 'a.fullName', 'a.givenName', 'a.lastName', 'a.nameType'))
|
|
|
|
->join(array('l' => $this->tbList), 'a.entityIdP = l.entityId', array())
|
|
|
|
->where('a.entityIdP=?', $entityId);
|
|
|
|
$associates = $this->getAdapter()->fetchAll($sql);
|
|
|
|
|
|
|
|
$sql = $this->getAdapter()->select()
|
|
|
|
->from(array('l' => $this->tbList), array('l.entityId', 'l.fullName', 'l.givenName', 'l.lastName', 'l.nameType'))
|
|
|
|
->where('l.entityId=?', $entityId);
|
|
|
|
$primary = $this->getAdapter()->fetchRow($sql);
|
|
|
|
|
|
|
|
$output = array('primary' => $primary, 'associates' => $associates);
|
|
|
|
return $output;
|
|
|
|
}
|
2013-09-16 15:41:31 +00:00
|
|
|
}
|