Пример #1
0
 public static function bdd($bdd, $method, $params = NULL)
 {
     switch ($method) {
         //--------------------------------------------------------
         case 'add':
             //traitement
             $elem = R::dispense($bdd);
             foreach ($params as $key => $value) {
                 $elem->{$key} = $value;
             }
             //default valeur pour les ajouts
             $elem->time_create = time();
             $elem->update = time();
             R::store($elem);
             return true;
             break;
             //--------------------------------------------------------
         //--------------------------------------------------------
         case 'del':
             if (isset($params['id'])) {
                 $obj = R::findOne($bdd, 'id=?', [$params['id']]);
                 R::trash($obj);
                 return true;
             }
             break;
             //--------------------------------------------------------
         //--------------------------------------------------------
         case 'upgrade':
             if (isset($params['id'])) {
                 $elem = R::load($bdd, $params['id']);
                 foreach ($params as $key => $value) {
                     $elem->{$key} = $value;
                 }
                 $elem->update = time();
                 R::store($elem);
                 return true;
             }
             break;
             //--------------------------------------------------------
         //--------------------------------------------------------
         case 'get':
             if (isset($params['id'])) {
                 return FoxFWbdd::convertRBtoObj(R::load($bdd, $params['id']));
             }
             break;
             //--------------------------------------------------------
         //--------------------------------------------------------
         case 'getAll':
             if (!isset($params['table'])) {
                 $params['table'] = '*';
             }
             return R::getAll('SELECT ' . $params['table'] . ' FROM ' . $bdd);
             break;
             //--------------------------------------------------------
         //--------------------------------------------------------
         case 'getAllLimit':
             if (isset($params['min'])) {
                 if (isset($params['max'])) {
                     if (!isset($params['table'])) {
                         $params['table'] = '*';
                     }
                     return R::getAll('SELECT ' . $params['table'] . ' FROM ' . $bdd . ' LIMIT ?,?', [$params['min'], $params['max']]);
                 }
             }
             break;
             //--------------------------------------------------------
         //--------------------------------------------------------
         case 'getListValTable':
             if (!isset($params['table'])) {
                 $params['table'] = '*';
             }
             $ret = [];
             $rep = R::getAll('SELECT ' . $params['table'] . ' FROM ' . $bdd);
             foreach ($rep as $key => $value) {
                 foreach ($value as $key2 => $value2) {
                     if (!isset($ret[$key2])) {
                         $ret[$key2] = array();
                     }
                     if ($value2 != '') {
                         if (array_search($value2, $ret[$key2]) === false) {
                             array_push($ret[$key2], $value2);
                         }
                     }
                 }
             }
             return $ret;
             break;
             //--------------------------------------------------------
         //--------------------------------------------------------
         case 'search':
             $prep = 'SELECT * FROM ' . $bdd . ' WHERE ';
             $search = $params['search'];
             $params['search'] = NULL;
             $tab = array();
             $compte = 0;
             foreach ($params as $key => $value) {
                 if ($compte != 0) {
                     $prep .= ' OR ';
                 }
                 $compte++;
                 $prep .= '( ' . $key . ' LIKE ?)';
                 array_push($tab, $search . '%');
             }
             return R::getAll($prep, $tab);
             break;
     }
     return false;
 }
Пример #2
0
    public function search()
    {
        $groupe = '';
        if (isset($_POST['groupe'])) {
            $groupe = 'AND groupe=\'' . $_POST['groupe'] . '\'';
        }
        $search = $_POST['search'];
        //préparation de la structure
        $list = FoxFWbdd::sql('SELECT * FROM contacts WHERE
		(( nom LIKE ?) OR ( prenom LIKE ?) OR ( telfixe LIKE ?) OR ( telportable LIKE ?) OR ( structure LIKE ?) OR ( email LIKE ?)) ' . $groupe, [$search . '%', $search . '%', $search . '%', $search . '%', $search . '%', $search . '%']);
        $list_groupe = FoxFWbdd::bdd('contacts', 'getListValTable', array('table' => 'groupe'));
        if (!isset($list_groupe['groupe'])) {
            $list_groupe['groupe'] = [];
        }
        return $GLOBALS['Twig']->render(FoxFWKernel::getView('contacts_liste'), array('list' => $list, 'groupe' => $list_groupe['groupe']));
    }