extranet/application/models/Worldcheck.php
Aram HARUTYUNYAN 9399f19ada Issue #0001653:
2013-10-04 10:59:12 +00:00

74 lines
2.0 KiB
PHP

<?php
class Application_Model_Worldcheck extends Zend_Db_Table_Abstract
{
protected $_name = 'worldcheck';
/**
* 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;
}
}