コード例 #1
0
 public function executeCreateOkFilter(sfWebRequest $request)
 {
     $this->forward404Unless($request->isMethod('post'));
     // On récupère les informations dont on a besoin dans le formulaire
     $params = array('mode' => 'create', 'filter_id' => $request->getPostParameter('id'), 'filter_name' => $request->getPostParameter('form[name]'), 'filter_description' => $request->getPostParameter('form[description]'), 'private_blacklist_content' => $request->getPostParameter('form[PBlist]'), 'globale_blacklist_content' => $request->getPostParameter('form[GBlist]'), 'private_whitelist_content' => $request->getPostParameter('form[PWlist]'), 'globale_whitelist_content' => $request->getPostParameter('form[GWlist]'));
     // Si le champ 'name' est vide, on arrête le traitement
     if ($params['filter_name'] == null) {
         //return $params;
     }
     // création du filtre s'il n'existe pas
     if ($params['filter_id'] == null) {
         $this->menu = $this->getMenu('createFilter');
         // On créé un nouveau filtre
         $filter = new Filter();
         $filter->name = $params['filter_name'];
         $filter->description = $params['filter_description'];
         $filter->save();
         // On récupère son ID
         $params['filter_id'] = $filter->id;
         // Lien avec liste globales white
         $lfwg = new ListsFilter();
         $lfwg->filter_id = $params['filter_id'];
         $lfwg->list_id = 1;
         $lfwg->ordre = 0;
         $lfwg->save();
         // Lien avec liste global black
         $lfbg = new ListsFilter();
         $lfbg->filter_id = $params['filter_id'];
         $lfbg->list_id = 2;
         $lfbg->ordre = 1;
         $lfbg->save();
         // Création liste SI White du filtre
         $lists = new Lists();
         $lists->name = "PW" . $params['filter_id'];
         $lists->type = "W";
         $lists->origin = "SI";
         $lists->static = 0;
         $lists->save();
         $lfwp = new ListsFilter();
         $lfwp->filter_id = $params['filter_id'];
         $lfwp->list_id = $lists->id;
         $lfwp->ordre = 2;
         $lfwp->save();
         // Création liste SI Black du filtre
         $lists = new Lists();
         $lists->name = "PB" . $params['filter_id'];
         $lists->type = "B";
         $lists->origin = "SI";
         $lists->static = 0;
         $lists->save();
         $lfbp = new ListsFilter();
         $lfbp->filter_id = $params['filter_id'];
         $lfbp->list_id = $lists->id;
         $lfbp->ordre = 3;
         $lfbp->save();
     } else {
         $this->menu = $this->getMenu('index');
         $sql = "UPDATE filter SET name = '{$params['filter_name']}', description = '{$params['filter_description']}' WHERE id = '{$params['filter_id']}';";
         $dq = new Doctrine_Query();
         $conn = $dq->getConnection();
         $conn->execute($sql);
     }
     // On remet à jour les listes SI
     $private_blacklist_content_details = explode("\n", $params['private_blacklist_content']);
     $globale_blacklist_content_details = explode("\n", $params['globale_blacklist_content']);
     $private_whitelist_content_details = explode("\n", $params['private_whitelist_content']);
     $globale_whitelist_content_details = explode("\n", $params['globale_whitelist_content']);
     // Mise à jour White liste Globale
     $listGlobale_whitelist = Doctrine_Query::create()->delete()->from('ListsDetail')->where('lists_id = ?', 1)->execute();
     for ($i = 0; $i < count($globale_whitelist_content_details); $i++) {
         if (trim($globale_whitelist_content_details[$i]) != "") {
             $insert = new ListsDetail();
             $insert->domain = trim($globale_whitelist_content_details[$i]);
             $insert->lists_id = 1;
             $insert->save();
         }
     }
     // Mise à jour Black liste Globale
     $listGlobale_blacklist = Doctrine_Query::create()->delete()->from('ListsDetail')->where('lists_id = ?', 2)->execute();
     for ($i = 0; $i < count($globale_blacklist_content_details); $i++) {
         if (trim($globale_blacklist_content_details[$i]) != "") {
             $insert = new ListsDetail();
             $insert->domain = trim($globale_blacklist_content_details[$i]);
             $insert->lists_id = 2;
             $insert->save();
         }
     }
     // Mise à jour White liste Locale
     // Recherche de l'id de la liste
     $lists_query = Doctrine_Query::create()->select('id')->from('Lists')->where('name = ?', 'PW' . $params['filter_id']);
     $lists_res = $lists_query->fetchOne();
     $id_PW = $lists_res['id'];
     // Suppression des détails
     $listLocale_whitelist = Doctrine_Query::create()->delete()->from('ListsDetail')->where('lists_id = ?', $id_PW)->execute();
     for ($i = 0; $i < count($private_whitelist_content_details); $i++) {
         if (trim($private_whitelist_content_details[$i]) != "") {
             $insert = new ListsDetail();
             $insert->domain = trim($private_whitelist_content_details[$i]);
             $insert->lists_id = $id_PW;
             $insert->save();
         }
     }
     // Mise à jour Black liste Locale
     // Recherche de l'id de la liste
     $lists_query = Doctrine_Query::create()->select('id')->from('Lists')->where('name = ?', 'PB' . $params['filter_id']);
     $lists_res = $lists_query->fetchOne();
     $id_PB = $lists_res['id'];
     // Suppression des détails
     $listLocale_blacklist = Doctrine_Query::create()->delete()->from('ListsDetail')->where('lists_id = ?', $id_PB)->execute();
     for ($i = 0; $i < count($private_blacklist_content_details); $i++) {
         if (trim($private_blacklist_content_details[$i]) != "") {
             $insert = new ListsDetail();
             $insert->domain = trim($private_blacklist_content_details[$i]);
             $insert->lists_id = $id_PB;
             $insert->save();
         }
     }
     // Traitement des listes externes (Toulouse)
     // Ajout des liens
     $lists_query = Doctrine_Query::create()->select('id')->from('Lists')->where('origin != ?', 'SI');
     $lists_res = $lists_query->fetchArray();
     $dq = new Doctrine_Query();
     $conn = $dq->getConnection();
     foreach ($lists_res as $list) {
         // Suppression de l'ancien lien s'il existe
         $sql = " delete from lists_filter";
         $sql .= " where list_id = {$list['id']}";
         $sql .= " and filter_id = {$params['filter_id']}";
         $conn->execute($sql);
         // Ajout du lien s'il est coché
         if ($request->getPostParameter('chBox_' . $list['id']) != null) {
             $insert = new ListsFilter();
             $insert->list_id = $list['id'];
             $insert->filter_id = $params['filter_id'];
             $insert->ordre = 4;
             $insert->save();
         }
     }
 }
コード例 #2
0
    public function executeCreateOkFilter(sfWebRequest $request)
    {
        $this->menu = $this->getMenu('index');
        $this->forward404Unless($request->isMethod('post'));
        // On récupère les informations dont on a besoin dans le formulaire
        $params = array('mode' => 'create', 'filter_id' => $request->getPostParameter('id'), 'filter_name' => $request->getPostParameter('form[name]'), 'filter_description' => $request->getPostParameter('form[description]'), 'private_blacklist_content' => $request->getPostParameter('form[PBlist]'), 'globale_blacklist_content' => $request->getPostParameter('form[GBlist]'), 'private_whitelist_content' => $request->getPostParameter('form[PWlist]'), 'globale_whitelist_content' => $request->getPostParameter('form[GWlist]'));
        // Si le champ 'name' est vide, on arrête le traitement
        if ($params['filter_name'] == null) {
            //return $params;
        }
        if ($params['filter_id'] == null) {
            // On créé un nouveau filtre
            $filter = new Filter();
            $filter->name = $params['filter_name'];
            $filter->description = $params['filter_description'];
            $filter->save();
            // On récupère son ID
            $params['filter_id'] = $filter->id;
        } else {
            $params['mode'] = 'update';
            $sql = <<<SQL
\t\t\t\tSELECT ld.id, ld.lists_id
\t\t\t\tFROM lists_detail ld
\t\t\t\t\tLEFT JOIN lists li ON ld.lists_id = li.id
\t\t\t\t\tLEFT JOIN lists_filter lf ON li.id = lf.list_id
\t\t\t\tWHERE lf.filter_id = '{$params['filter_id']}'
\t\t\t\t\tAND li.origin = 'SI'
\t\t\t\tORDER BY ld.lists_id
SQL;
            $dq = new Doctrine_Query();
            $conn = $dq->getConnection();
            $lists = $conn->fetchAll($sql);
            foreach ($lists as $list) {
                $sql = <<<SQL
\t\t\t\t\tDELETE FROM lists_detail WHERE id = '{$list['id']}';
SQL;
                $dq = new Doctrine_Query();
                $conn = $dq->getConnection();
                $conn->execute($sql);
                if ($list['lists_id'] != $ancVal) {
                    $ancVal = $list['lists_id'];
                    $sql = <<<SQL
\t\t\t\t\t\tDELETE FROM lists WHERE id = '{$ancVal}';
SQL;
                    $dq = new Doctrine_Query();
                    $conn = $dq->getConnection();
                    $conn->execute($sql);
                }
            }
            $sql = "UPDATE filter SET name = '{$params['filter_name']}', description = '{$params['filter_description']}' WHERE id = '{$params['filter_id']}';";
            $dq = new Doctrine_Query();
            $conn = $dq->getConnection();
            $conn->execute($sql);
            $deleteAllListFilter = Doctrine_Query::create()->delete()->from('ListsFilter')->where('filter_id = ?', $params['filter_id'])->execute();
        }
        // On remet à jour les listes globales
        $private_blacklist_content_details = explode("\n", $params['private_blacklist_content']);
        $globale_blacklist_content_details = explode("\n", $params['globale_blacklist_content']);
        $private_whitelist_content_details = explode("\n", $params['private_whitelist_content']);
        $globale_whitelist_content_details = explode("\n", $params['globale_whitelist_content']);
        $listGlobale_whitelist = Doctrine_Query::create()->delete()->from('ListsDetail')->where('lists_id = ?', 0)->execute();
        for ($i = 0; $i < count($globale_whitelist_content_details); $i++) {
            if ($globale_whitelist_content_details[$i] != null) {
                $insert = new ListsDetail();
                $insert->domain = $globale_whitelist_content_details[$i];
                $insert->lists_id = 0;
                $insert->save();
            }
        }
        $listGlobale_blacklist = Doctrine_Query::create()->delete()->from('ListsDetail')->where('lists_id = ?', 1)->execute();
        for ($i = 0; $i < count($globale_blacklist_content_details); $i++) {
            if ($globale_blacklist_content_details[$i] != null) {
                $insert = new ListsDetail();
                $insert->domain = $globale_blacklist_content_details[$i];
                $insert->lists_id = 1;
                $insert->save();
            }
        }
        // On les attachent au filtre que l'on a créé
        $attach_global_whitelist = new ListsFilter();
        $attach_global_whitelist->list_id = 0;
        $attach_global_whitelist->filter_id = $params['filter_id'];
        $attach_global_whitelist->ordre = 0;
        $attach_global_whitelist->save();
        $attach_global_blacklist = new ListsFilter();
        $attach_global_blacklist->list_id = 1;
        $attach_global_blacklist->filter_id = $params['filter_id'];
        $attach_global_blacklist->ordre = 1;
        $attach_global_blacklist->save();
        // On créé une nouvelle liste (whitelist)
        if ($params['private_whitelist_content'] != null) {
            $whitelist = new Lists();
            $whitelist->name = 'PW' . $params['filter_id'];
            $whitelist->type = 'W';
            $whitelist->origin = 'SI';
            $whitelist->static = '1';
            $whitelist->save();
            $id = $whitelist->id;
            for ($i = 0; $i < count($private_whitelist_content_details); $i++) {
                if ($private_whitelist_content_details[$i] != null) {
                    $insert = new ListsDetail();
                    $insert->domain = $private_whitelist_content_details[$i];
                    $insert->lists_id = $whitelist->id;
                    $insert->save();
                }
            }
            $attach_whitelist = new ListsFilter();
            $attach_whitelist->list_id = $whitelist->id;
            $attach_whitelist->filter_id = $params['filter_id'];
            $attach_whitelist->ordre = 2;
            $attach_whitelist->save();
        }
        // On créé une nouvelle liste (blacklist)
        if ($params['private_blacklist_content'] != null) {
            $blacklist = new Lists();
            $blacklist->name = 'PB' . $params['filter_id'];
            $blacklist->type = 'B';
            $blacklist->origin = 'SI';
            $blacklist->static = '1';
            $blacklist->save();
            $id = $blacklist->id;
            for ($i = 0; $i < count($private_blacklist_content_details); $i++) {
                if ($private_blacklist_content_details[$i] != null) {
                    $insert = new ListsDetail();
                    $insert->domain = $private_blacklist_content_details[$i];
                    $insert->lists_id = $blacklist->id;
                    $insert->save();
                }
            }
            $attach_blacklist = new ListsFilter();
            $attach_blacklist->list_id = $blacklist->id;
            $attach_blacklist->filter_id = $params['filter_id'];
            $attach_blacklist->ordre = 3;
            $attach_blacklist->save();
        }
        // On récupère les listes provenant de Toulouse
        $lists_query = Doctrine_Query::create()->select('id')->from('Lists')->where('origin != ?', 'SI');
        $lists_res = $lists_query->fetchArray();
        foreach ($lists_res as $list) {
            if ($request->getPostParameter('chBox_' . $list['id']) != null) {
                $insert = new ListsFilter();
                $insert->list_id = $list['id'];
                $insert->filter_id = $params['filter_id'];
                $insert->ordre = 4;
                $insert->save();
            }
        }
    }