112 lines
2.8 KiB
PHP
112 lines
2.8 KiB
PHP
<?php
|
|
class Scores_Ws_Trigger
|
|
{
|
|
protected $userInfos;
|
|
protected $event;
|
|
protected $events = null;
|
|
|
|
public function __construct($event, $userInfos)
|
|
{
|
|
$this->event = $event;
|
|
$this->userInfos = $userInfos;
|
|
}
|
|
|
|
/**
|
|
* Check if we have a trigger to execute
|
|
* @return number
|
|
*/
|
|
protected function hasTrigger()
|
|
{
|
|
if ( $this->userInfos['Service'] === null ) {
|
|
$service = 'default';
|
|
}
|
|
|
|
$model = new Application_Model_Sdv1ClientsServicesTrigger();
|
|
$sql = $model->select()
|
|
->where('event=?', $this->event)
|
|
->where('idClient=?', $this->userInfos['idClient'])
|
|
->where('service=?', $service)
|
|
->where('login=? OR login=""', $login);
|
|
$result = $model->fetchAll($sql);
|
|
if ( count($result)>0 ) {
|
|
foreach ( $result as $item ) {
|
|
$tmp->action = $item->action;
|
|
$tmp->params = json_decode($item->actionParams, true);
|
|
}
|
|
}
|
|
|
|
return count($result);
|
|
}
|
|
|
|
/**
|
|
* Execute all triggers after hasTrigger
|
|
* @param array $args
|
|
* @return boolean
|
|
*/
|
|
protected function executeAllTrigger($args)
|
|
{
|
|
if ( count($this->events)>0 ) {
|
|
foreach ( $this->events as $action ) {
|
|
$args = array_merge($args, $action->params);
|
|
switch ( $action->action ) {
|
|
case 'surveillance':
|
|
return $this->surveillance($args);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Mise en surveillance automatique
|
|
* @param array $args
|
|
* source, siren, ...
|
|
* @return boolean
|
|
*/
|
|
protected function surveillance($args)
|
|
{
|
|
if ( !array_key_exists('source', $args) ) {
|
|
return false;
|
|
}
|
|
|
|
if ( !array_key_exists('siren', $args) ) {
|
|
return false;
|
|
}
|
|
|
|
if ( !array_key_exists('nic', $args) ) {
|
|
return false;
|
|
}
|
|
|
|
if ( empty(trim($this->userInfos['email'])) ) {
|
|
return false;
|
|
}
|
|
|
|
if ( array_key_exists('ref', $args)) {
|
|
$ref = $args['ref'];
|
|
}
|
|
|
|
try {
|
|
$model = new Application_Model_JoSurveillancesSite();
|
|
$data = array(
|
|
'source' => $args['source'],
|
|
'login' => $this->userInfos['login'],
|
|
'email' => $this->userInfos['email'],
|
|
'siren' => $args['siren'],
|
|
'nic' => $args['nic'],
|
|
'ref' => $ref,
|
|
'encoursClient' => 0,
|
|
'rs' => $args['Nom'],
|
|
'cp' => $args['CP'],
|
|
'ville' => $args['Ville'],
|
|
'dateAjout' => date('Y-m-d'),
|
|
'dateSuppr' => 0,
|
|
);
|
|
$model->insert($data);
|
|
return true;
|
|
} catch (Zend_Db_Exception $e) {
|
|
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} |