Commit 4cb07a7d authored by sreg's avatar sreg

- Ajout de la classe anotea necessaire

parent 0f6c9f74
<?php
class Anotea
{
protected $db;
public function __construct($db)
{
$this->db=$db;
}
protected function prepareRequest($options)
{
$db=$this->db;
$request=array(1);
if(array_key_exists('ad_id',$options)) $request[]=$db->request('an.ad_id=%rd',$options['ad_id']);
if(array_key_exists('orga_id',$options)) $request[]=$db->request('an.orga_id=%rd',$options['orga_id']);
if(array_key_exists('idformintercarif',$options)) $request[]=$db->request('an.idformintercarif=%rs',$options['idformintercarif']);
if(array_key_exists('idorgaintercarif',$options)) $request[]=$db->request('an.idorgaintercarif=%rs',$options['idorgaintercarif']);
if(array_key_exists('domaine',$options)) $request[]=$db->request('SUBSTRING(an.formacode,1,3)=%rs',$options['domaine']);
$db->prepare("SELECT an.createdat,an.orga_id,an.ad_id,an.formacode,r.path,r.label,an.avisjson
FROM anotea an
INNER JOIN reference r ON r.type=3 AND r.status=1 AND r.extradata=SUBSTRING(an.formacode,1,3)
WHERE an.status='ACTIVE' AND %s
ORDER BY an.createdat DESC",
implode(' AND ',$request));
//if(ENV_DEV) echo Tools::Text2Html($db->getPrepare(),false);
return $db->assign('{createdat}','orga_id','ad_id','formacode','formapath','domaine','avisjson');
}
public function get($options)
{
return $this->prepareRequest($options)->queryFetchAll();
}
public function getByAnnonceId($id)
{
return $this->prepareRequest(array('ad_id'=>$id))->queryFetchAll();
}
public function getByDomaine($formacode,$orga_id)
{
return $this->prepareRequest(array('domaine'=>substr($formacode,0,3),'orga_id'=>$orga_id))->queryFetchAll();
}
public function getByIdFormIntercarif($idformintercarif)
{
return $this->prepareRequest(array('idformintercarif'=>$idformintercarif))->queryFetchAll();
}
public function getByOrgaId($id)
{
return $this->prepareRequest(array('orga_id'=>$id))->queryFetchAll();
}
public function getByIdOrgaIntercarif($idorgaintercarif)
{
return $this->prepareRequest(array('idorgaintercarif'=>$idorgaintercarif))->queryFetchAll();
}
public function getNbAvisDomaineOrga($orga_id)
{
$db=$this->db;
//$db->prepare("SELECT r.label,an.formacode,ROUND(AVG(an.noteglobale)) AS notemoyenne,COUNT(an.orga_id) AS nbavis
// FROM anotea an
// INNER JOIN reference r ON r.type=4 AND r.status=1 AND r.level=0 AND FUNC_EXTRADATA('fm',r.extradata,'')=SUBSTRING(an.formacode,1,3)
// WHERE an.status='ACTIVE' AND an.orga_id=%rd
// GROUP BY FUNC_EXTRADATA('fm',r.extradata,'')",
// $orga_id);
if(0)
$db->prepare("
SELECT r.label,r.labelslug,FUNC_EXTRADATA('fm',r.extradata,'') AS formacode,r.path AS formapath,ROUND(AVG(an.noteglobale)) AS notemoyenne,COUNT(DISTINCT an.id) AS nbavis,COUNT(DISTINCT s.ad_id,s.location) AS nbannonces
FROM reference r
INNER JOIN sphad s ON s.query=CONCAT('@formacode ',FUNC_EXTRADATA('fm',r.extradata,''),'*;mode=extended2;maxmatches=200000;limit=10000;filter=orgaid,%rd;')
LEFT OUTER JOIN anotea an ON SUBSTRING(an.formacode,1,3)=FUNC_EXTRADATA('fm',r.extradata,'') AND an.status='ACTIVE' AND an.orga_id=%rd
WHERE r.type=4 AND r.status=1 AND r.level=0
GROUP BY FUNC_EXTRADATA('fm',r.extradata,'')",
$orga_id,$orga_id);
if(0)
$db->prepare("
SELECT sql_no_cache r.label,r.labelslug,FUNC_EXTRADATA('fm',r.extradata,'') AS formacode,r.path AS formapath,ROUND(AVG(an.noteglobale)) AS notemoyenne,COUNT(DISTINCT an.id) AS nbavis,s._sph_count AS nbannonces
FROM reference r
INNER JOIN sphad s ON s.query=CONCAT('@formacode ',FUNC_EXTRADATA('fm',r.extradata,''),'*;mode=extended2;maxmatches=1;groupby=attr:groupbyanotea;limit=10000;filter=orgaid,2345;')
LEFT OUTER JOIN anotea an ON SUBSTRING(an.formacode,1,3)=FUNC_EXTRADATA('fm',r.extradata,'') AND an.status='ACTIVE' AND an.orga_id=2345
WHERE r.type=4 AND r.status=1 AND r.level=0
GROUP BY r.label,r.labelslug,FUNC_EXTRADATA('fm',r.extradata,'')
ORDER BY formacode
",$orga_id,$orga_id);
if(1)
$db->prepare("
SELECT SQL_NO_CACHE
r.label,
r.labelslug,
s.racineformacodeprincipal AS formacode,
r.path AS formapath,
ROUND(AVG(an.noteglobale)) AS notemoyenne,
COUNT(an.id) AS nbavis,
s.nbannonces
FROM
(
SELECT s.orgaid,s.racineformacodeprincipal,s._sph_count AS nbannonces
FROM sphad s
WHERE s.query=';mode=ext2;groupby=attr:racineformacodeprincipal;limit=10000;filter=orgaid,%rd'
) AS s
INNER JOIN reference r ON r.type=4 AND r.status=1 AND r.level=0 AND FUNC_EXTRADATA('fm',r.extradata,'')=s.racineformacodeprincipal
LEFT OUTER JOIN anotea an ON SUBSTRING(an.formacode,1,3)=s.racineformacodeprincipal AND an.status='ACTIVE' AND an.orga_id=s.orgaid
GROUP BY s.racineformacodeprincipal
ORDER BY r.label;",
$orga_id
);
//if(ENV_DEV) echo Tools::Text2Html($db->getPrepare(),false);
return $db->queryFetchAll();