Overview
Comment:Ajout option de tri et de limite dans la recherche avancée
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: 4dbda990afc98d92a67df5e851a402465bc2b157
User & Date: bohwaz on 2018-09-04 00:25:29
Other Links: branch diff | manifest | tags
Context
2018-09-04
23:22
Corriger divers détails sur la recherche avancée check-in: 20568ca832 user: bohwaz tags: dev
00:25
Ajout option de tri et de limite dans la recherche avancée check-in: 4dbda990af user: bohwaz tags: dev
00:05
Recherche avancée fonctionnelle check-in: 3ef9a80ec7 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Membres.php from [d83688a88c] to [da2dddadc6].

397
398
399
400
401
402
403






404









405
406
407
408
409
410
411
412
413
414
415
416
                $query_group_conditions[] = $query;
            }

            $query_groups[] = implode(' ' . $group['operator'] . ' ', $query_group_conditions);
        }

        $colonnes = array_unique($colonnes);






        array_walk($colonnes, [$db, 'quoteIdentifier']);










        $sql_query = sprintf('SELECT id, %s FROM membres WHERE %s ORDER BY %s %s LIMIT 0,%d;',
            implode(', ', $colonnes),
            '(' . implode(') AND (', $query_groups) . ')',
            $db->quoteIdentifier($order),
            $desc ? 'DESC' : 'ASC',
            (int) $limit);

        return $sql_query;
    }

    public function getSearchHeaderFields(array $result)







>
>
>
>
>
>

>
>
>
>
>
>
>
>
>




|







397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
                $query_group_conditions[] = $query;
            }

            $query_groups[] = implode(' ' . $group['operator'] . ' ', $query_group_conditions);
        }

        $colonnes = array_unique($colonnes);

        if (!in_array($config->get('champ_identite'), $colonnes))
        {
            array_unshift($colonnes, $config->get('champ_identite'));
        }

        array_walk($colonnes, [$db, 'quoteIdentifier']);

        if ($champs->isText($order))
        {
            $order = sprintf('transliterate_to_ascii(%s)', $db->quoteIdentifier($order));
        }
        else
        {
            $order = $db->quoteIdentifier($order);
        }

        $sql_query = sprintf('SELECT id, %s FROM membres WHERE %s ORDER BY %s %s LIMIT 0,%d;',
            implode(', ', $colonnes),
            '(' . implode(') AND (', $query_groups) . ')',
            $order,
            $desc ? 'DESC' : 'ASC',
            (int) $limit);

        return $sql_query;
    }

    public function getSearchHeaderFields(array $result)

Modified src/templates/admin/membres/recherche.tpl from [df74ceb0fe] to [deac15b972].

8
9
10
11
12
13
14











15
16
17
18
19

20
21
22
23
24
25
26
</ul>
{/if}

<form method="post" action="{$admin_url}membres/recherche.php" id="queryBuilderForm">
	<fieldset>
		<legend>Rechercher un membre</legend>
		<div class="queryBuilder" id="queryBuilder"></div>











		<p class="submit">
			<input type="submit" value="Chercher &rarr;" id="send" />
			<input type="hidden" name="q" id="jsonQuery" />
		</p>
	</fieldset>

</form>

<script type="text/javascript">
var colonnes = {$colonnes|escape:'json'};

{literal}
var traductions = {







>
>
>
>
>
>
>
>
>
>
>





>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
</ul>
{/if}

<form method="post" action="{$admin_url}membres/recherche.php" id="queryBuilderForm">
	<fieldset>
		<legend>Rechercher un membre</legend>
		<div class="queryBuilder" id="queryBuilder"></div>
		<p class="actions">
			<label>Trier par 
				<select name="order">
					{foreach from=$colonnes key="colonne" item="config"}
					<option value="{$colonne}"{form_field name="order" selected=$colonne}>{$config.label}</option>
					{/foreach}
				</select>
			</label>
			<label><input type="checkbox" name="desc" value="1" {form_field name="desc" checked=1 default=$desc} /> Tri inversé</label>
			<label>Limiter à <input type="number" value="{$limit}" name="limit" size="5" /> résultats</label>
		</p>
		<p class="submit">
			<input type="submit" value="Chercher &rarr;" id="send" />
			<input type="hidden" name="q" id="jsonQuery" />
		</p>
	</fieldset>
	<p class="help">{$sql_query}</p>
</form>

<script type="text/javascript">
var colonnes = {$colonnes|escape:'json'};

{literal}
var traductions = {

Modified src/www/admin/membres/recherche.php from [6952bd8048] to [218ac5f508].

2
3
4
5
6
7
8




9
10
11
12
13
14
15
..
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
..
66
67
68
69
70
71
72

73



74
75
76
77
78
79
80
namespace Garradin;

require_once __DIR__ . '/_inc.php';

$champs = $config->get('champs_membres');
$text_query = trim(qg('qt'));
$query = null;





// Recherche simple
if ($text_query !== '')
{
    $operator = 'LIKE %?%';

    if (is_numeric(trim($text_query)))
................................................................................
elseif (f('q') !== null)
{
    $query = json_decode(f('q'), true);
}

if ($query)
{
    $sql_query = $membres->buildSQLSearchQuery($query, 'id', false, 100);
    $result = $membres->searchSQL($sql_query);

    if (count($result) == 1 && $text_query !== '')
    {
        Utils::redirect(ADMIN_URL . 'membres/fiche.php?id=' . (int)$result[0]->id);
    }

................................................................................
            ],
        ],
    ]];
    $result = null;
}

$tpl->assign('query', $query);

$tpl->assign('result', $result);




$colonnes = [];

foreach ($champs->getList() as $champ => $config)
{
    $colonne = [
        'label' => $config->title,







>
>
>
>







 







|







 







>

>
>
>







2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
..
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
..
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
namespace Garradin;

require_once __DIR__ . '/_inc.php';

$champs = $config->get('champs_membres');
$text_query = trim(qg('qt'));
$query = null;
$limit = f('limit') ?: 100;
$order = f('order');
$desc = (bool) f('desc');
$sql_query = null;

// Recherche simple
if ($text_query !== '')
{
    $operator = 'LIKE %?%';

    if (is_numeric(trim($text_query)))
................................................................................
elseif (f('q') !== null)
{
    $query = json_decode(f('q'), true);
}

if ($query)
{
    $sql_query = $membres->buildSQLSearchQuery($query, $order, $desc, $limit);
    $result = $membres->searchSQL($sql_query);

    if (count($result) == 1 && $text_query !== '')
    {
        Utils::redirect(ADMIN_URL . 'membres/fiche.php?id=' . (int)$result[0]->id);
    }

................................................................................
            ],
        ],
    ]];
    $result = null;
}

$tpl->assign('query', $query);
$tpl->assign('sql_query', $sql_query);
$tpl->assign('result', $result);
$tpl->assign('order', $order);
$tpl->assign('desc', $desc);
$tpl->assign('limit', $limit);

$colonnes = [];

foreach ($champs->getList() as $champ => $config)
{
    $colonne = [
        'label' => $config->title,