extranet/application/models/Worldcheck.php

69 lines
1.9 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 string $idClient
* @param object $data
* @return object
*/
public function getScreenerId($idClient, $login, $data)
{
$result = new stdClass();
$sql = $this->select()
->where("idClient='".$idClient."' AND name='".$data->name."' AND nameType='".$data->nameType."' 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();
$result->nameIdentifier = $wc->getScreener($data);
$result->matchCount = $wc->getDetailsName($result->nameIdentifier)->unresolvedMatchCount;
$param = array(
'idClient' => $idClient,
'login' => $login,
'nameIdentifier' => $result->nameIdentifier,
'matchCount' => $result->matchCount,
'name' => $data->name,
'nameType' => $data->nameType,
'dateInsert' => date('Y-m-d')
);
$sql = $this->insert($param);
}
return $result;
}
/**
* Return array of names with matchCount
* @param object $data (Nom, Societe)
* @return array
*/
public function getCounts($data)
{
$allOccurences = array();
foreach ($data as $dir)
{
$nameType = (isset($dir->Societe) && $dir->Societe!='')?'ORGANISATION':'INDIVIDUAL';
$sql = $this->select()
->where("name='".$dir->Nom."' AND nameType='".$nameType."' AND LEFT(nameIdentifier, 3)='so_'")
->group('name');
$matchCount = NULL;
if ($this->fetchRow($sql))
{
$result=$this->fetchRow($sql);
$matchCount = $result->matchCount;
}
$allOccurences[$dir->Nom] = $matchCount;
}
return $allOccurences;
}
}