view->headLink()->appendStylesheet('/themes/default/styles/dashboard.css', 'all'); $this->view->headScript()->appendFile('/themes/default/scripts/dashboard.js', 'text/javascript'); } public function indexAction() { $auth = Zend_Auth::getInstance(); $user = $auth->getIdentity(); $criteresM = new Application_Model_Criteres(); $sql = $criteresM->select() ->from($criteresM, array('id', 'reference', 'dateAjout')) ->where("idClient = ?", $user->idClient) ->where("login = ?", $user->username) ->order('dateAjout DESC') ->limit(5); $rows = $criteresM->fetchAll($sql); // $results = array(); $comptagesM = new Application_Model_Comptages(); foreach($rows->toArray() as $item) { $info = array( 'id' => $item['id'], 'reference' => $item['reference'], 'dateCriteres' => $item['dateAjout'], ); //Recherche des comptages $sql = $comptagesM->select() ->from($comptagesM, array('resultat', 'uniteInsee', "DATE_FORMAT(dateAjout, '%Y/%m/%d %H:%i:%s') as dateAjout")) ->where('idDefinition = ?', $item['id']) ->order('dateAjout DESC')->limit(1); $comptage = $comptagesM->fetchAll($sql)->toArray(); if (count($comptage)>0){ $info['resultat'] = $comptage[0]['resultat']; $info['uniteInsee'] = $comptage[0]['uniteInsee']; $info['dateComptage'] = $comptage[0]['dateAjout']; } $results[] = $info; } $this->view->comptages = $results; // $enrichissements = new Application_Model_EnrichissementIdentifiants(); $sql = $enrichissements->select() ->setIntegrityCheck(false) ->from( array('i' => 'enrichissement_identifiants'), array('id', 'reference', 'fichier', 'nbLigneTotales', 'nbLigneTraites', 'error', 'dateAdded', 'dateStart', 'dateStop') ) ->join( array('c' => 'ciblage_criteres'), 'i.idCriteres = c.id', array('') ) ->where('c.idClient = ?', $user->idClient) ->where('c.login = ?', $user->username) ->order('i.dateAdded DESC'); $this->view->enrichissements = $enrichissements->fetchAll($sql); } public function ciblagesAction() { $request = $this->getRequest(); $page = $request->getParam('page', 1); $offset = 20; //Liste des ciblages par paquet de n $auth = Zend_Auth::getInstance(); $user = $auth->getIdentity(); $criteresM = new Application_Model_Criteres(); //Compter le nombre de page $sql = $criteresM->select() ->from($criteresM, array('nb' => 'COUNT(*)')) ->where("idClient = ?", $user->idClient) ->where("login = ?", $user->username); $count = $criteresM->fetchRow($sql); $nbCiblage = $count->nb; //Récupérer les informations $position = ($page-1)*$offset+1; $sql = $criteresM->select() ->from($criteresM, array('id', 'reference', 'dateAjout')) ->where("idClient = ?", $user->idClient) ->where("login = ?", $user->username) ->order('dateAjout DESC') ->limitPage($position, $offset); $rows = $criteresM->fetchAll($sql); $results = array(); $comptagesM = new Application_Model_Comptages(); foreach($rows->toArray() as $item) { $info = array( 'id' => $item['id'], 'reference' => $item['reference'], 'dateCriteres' => $item['dateAjout'], ); //Recherche des comptages $sql = $comptagesM->select() ->from($comptagesM, array('resultat', 'uniteInsee', "DATE_FORMAT(dateAjout, '%d/%m/%Y %H:%i:%s') as dateAjout")) ->where('idDefinition = ?', $item['id']) ->order('dateAjout DESC')->limit(1); $comptage = $comptagesM->fetchAll($sql)->toArray(); if (count($comptage)>0){ $info['resultat'] = $comptage[0]['resultat']; $info['uniteInsee'] = $comptage[0]['uniteInsee']; $info['dateComptage'] = $comptage[0]['dateAjout']; } $results[] = $info; } $this->view->ciblages = $results; $this->view->nbCiblage = $nbCiblage; } public function ciblageAction() { $request = $this->getRequest(); $auth = Zend_Auth::getInstance(); $user = $auth->getIdentity(); $comptageId = $request->getParam('id'); $fields = new Scores_Fields(); //Lecture des paramètres du ciblage $criteresM = new Application_Model_Criteres(); $sql = $criteresM->select() ->where('idClient = ?', $user->idClient) ->where('login = ?', $user->username) ->where('id = ?', $comptageId); $criteres = $criteresM->fetchRow($sql)->toArray(); $infosCriteres = array(); if ($criteres != null) { $comptageRef = $criteres['reference']; $decodeCriteres = json_decode($criteres['criteres'], true); //Construction affichage des critères foreach ( $decodeCriteres as $key => $item ) { $inValue = $fields->getValueLabel($key, $item['in']); $exValue = $fields->getValueLabel($key, $item['ex']); //Add label to struct for display $infosCriteres[] = array( 'label' => $fields->getLabel($key), 'in' => $inValue, 'ex' => $exValue, ); } //Lecture des comptages $comptageM = new Application_Model_Comptages(); $sql = $comptageM->select() ->where('idDefinition = ?', $comptageId) ->order('dateAjout DESC'); $comptages = $comptageM->fetchAll($sql)->toArray(); //Lecture enrichissement existe $enrichissementsM = new Application_Model_EnrichissementIdentifiants(); $sql = $enrichissementsM->select() ->where('idCriteres = ?', $comptageId); $enrichissements = $enrichissementsM->fetchAll($sql); //Affichage $this->view->comptageId = $comptageId; $this->view->comptageRef = $comptageRef; $this->view->criteres = $infosCriteres; $this->view->comptages = $comptages; $this->view->enrichissements = $enrichissements; } } public function rcomptageAction() { $this->_helper->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $request = $this->getRequest(); $q = $request->getParam('q'); $auth = Zend_Auth::getInstance(); $user = $auth->getIdentity(); $criteresM = new Application_Model_Criteres(); $sql = $criteresM->select() ->from($criteresM, array('id', 'reference', "DATE_FORMAT(dateAjout, '%d/%m/%Y') as date")) ->where("idClient = ?", $user->idClient) ->where("login = ?", $user->username) ->where("reference LIKE ?", $q.'%'); $rows = $criteresM->fetchAll($sql); if (count($rows)>0){ $separator = " , "; foreach ($rows as $item) { $output[] = array( 'label' => $item->reference . $separator . $item->date, 'value' => $item->reference, 'url' => $this->view->url(array('controller'=>'dashboard', 'action'=>'ciblage', 'id'=>$item->id)), ); } } echo json_encode($output); } /** * Liste des enrichissements */ public function enrichissementsAction() { $auth = Zend_Auth::getInstance(); $user = $auth->getIdentity(); //Criteres => Comptages (last) => enrichissement_identifiants => enrichissement_commandes $enrichissementsM = new Application_Model_EnrichissementIdentifiants(); // Pending $sql = $enrichissementsM->select() ->setIntegrityCheck(false) ->from( array('i' => 'enrichissement_identifiants'), array('id', 'reference', 'fichier', 'nbLigneTotales', 'nbLigneTraites', 'error', 'dateAdded', 'dateStart', 'dateStop') ) ->join( array('c' => 'ciblage_comptages'), 'i.idComptage = c.id', array('') ) ->join( array('criteres' => 'ciblage_criteres'), 'i.idCriteres = criteres.id', array('') ); $sql->where('i.dateStop = ?', 0) ->where('criteres.idClient = ?', $user->idClient) ->where('criteres.login = ?', $user->username); $encours = $enrichissementsM->fetchAll($sql); $this->view->encours = $encours; // Impossible de copie la varible issu d'un select car sinon elle conserve les meme propriété que sont parent // donc les selects... donc obliger de faire deux requetes pour le moment. $sql = $enrichissementsM->select() ->setIntegrityCheck(false) ->from( array('i' => 'enrichissement_identifiants'), array('id', 'reference', 'fichier', 'nbLigneTotales', 'nbLigneTraites', 'error', 'dateAdded', 'dateStart', 'dateStop') ) ->join( array('c' => 'ciblage_comptages'), 'i.idComptage = c.id', array('') ) ->join( array('criteres' => 'ciblage_criteres'), 'i.idCriteres = criteres.id', array('') ); $sql->where('criteres.idClient = ?', $user->idClient) ->where('criteres.login = ?', $user->username) ->where('i.dateStart != ?', '0000-00-00 00:00:00'); $fini = $enrichissementsM->fetchAll($sql)->toArray(); $this->view->fini = $fini; $this->view->pathfile = $config->path->data; } /** * Détail d'un enrichissment */ public function enrichissementAction() { } /** * Display information about user's profil */ public function configurationAction() { //User's params $auth = Zend_Auth::getInstance(); $user = $auth->getIdentity(); if (array_key_exists('filter', $user->preferences) && count($user->preferences['filter'])>0) { $liste = $user->preferences['filter']; foreach ( $liste as $name => $value ){ $this->view->assign('prefFilter'.ucfirst($name), $value); } } if (array_key_exists('interface', $user->preferences) && count($user->preferences['interface'])>0) { $liste = $user->preferences['interface']; foreach ( $liste as $name => $value ){ $this->view->assign('prefInterface'.ucfirst($name), $value); } } $timestamp = strtotime( $user->dateContrat ); $dateBegin = date( 'd/m/Y', $timestamp ); $timestamp = mktime(0,0,0,substr($dateBegin,3,2)+$user->periodContrat,substr($dateBegin,0,2), substr($dateBegin,6,4)); $dateEnd = date( 'd/m/Y', $timestamp ); $this->view->assign('dateBegin', $dateBegin); $this->view->assign('dateEnd', $dateEnd); //Customer params have an option on the RNCS filter $this->view->assign('filterRNCS', $user->filterRNCS); $this->view->assign('licenceINSEE', $user->licenceINSEE); $this->view->assign('immediatExtract', $user->immediatExtract); $tarifText = ''; //Tarifs if ($user->forfait!=0) { //Forfait de $tarifText = 'Forfait de '.$user->forfait.' euros'; } else { $tarifText = 'Tarif unitaire à la ligne de '.$user->priceLine.' euros'; } //Paramètres if ( $user->limitFiles!=0 && $user->limitLines!=0 ) { $tarifText.= ' limité à '.$user->limitFiles.' fichiers et à '.$user->limitLines.' lignes par fichier.'; } elseif ( $user->limitFiles!=0 && $user->limitLines==0 ) { $tarifText.= ' limité à '.$user->limitFiles.' fichiers'; } elseif ( $user->limitFiles==0 && $user->limitLines!=à ) { $tarifText.= ' limité à '.$user->limitLines.' lignes par fichier.'; } $this->view->assign('tarifText', $tarifText); //List of data to extract $profilsM = new Application_Model_EnrichissementProfils(); $sql = $profilsM->select() ->where('login = ?', $user->username) ->where('idClient = ?', $user->idClient); $result = $profilsM->fetchRow($sql); if ($result) { $criteres = json_decode($result['criteres'], true); require_once 'Scores/Enrichissement.php'; $enrichissement = new Enrichissement(); $data = $enrichissement->getFields(); $profilLabels = array(); foreach ( $data as $key => $item ) { if (in_array($key, $criteres)) { $profilLabels[] = $item['label']; } } $profil = new stdClass(); $profil->labels = $profilLabels; $profil->reference = $result['reference']; $this->view->assign('profil', $profil); } } /** * Set preferences */ public function prefAction() { $this->_helper->layout()->disableLayout(); $auth = Zend_Auth::getInstance(); $user = $auth->getIdentity(); //Read prefs table to load actual config $prefsM = new Application_Model_Prefs(); $userPrefs = $prefsM->find($user->username); if ($userPrefs) { $data = json_decode($userPrefs->current()->json, true); } else { $data = array('interface'=>array(),'filter'=>array()); $prefsM->insert(array('login'=>$user->username, 'json'=>json_encode($data))); } $request = $this->getRequest(); $sendParam = $request->getParams(); $prefsFilter = array('rncs'); $prefsInterface = array('insee'); $filter = array(); foreach ( $prefsFilter as $item ) { if (array_key_exists($item, $sendParam)) { $filter = array($item => $sendParam[$item]); } } if (array_key_exists('filter', $data)) { $filter = array_merge($data['filter'], $filter); } $data['filter'] = $filter; $interface = array(); foreach ( $prefsInterface as $item ) { if (array_key_exists($item, $sendParam)) { $interface = array($item => $sendParam[$item]); } } if (array_key_exists('interface', $data)) { $interface = array_merge($data['interface'], $interface); } $data['interface'] = $interface; $newjson = json_encode($data); $nbRow = $prefsM->update(array('json'=>$newjson), "login='".$user->username."'"); //Don't forget to save new preferences in session $this->view->assign('nbRow', $nbRow); } }