osalabs / osafw-php

Business Applications Web Framework, PHP
MIT License
3 stars 3 forks source link

Make search and order working in lists for columns with dots in their names #29

Closed vladsavchuk closed 5 years ago

vladsavchuk commented 6 years ago

To test on a bare FW:

  1. Create a view

    CREATE VIEW demo_dicts_dots AS 
    SELECT *, iname AS 'ref1.iname', idesc AS 'ref2.idesc' FROM demo_dicts
  2. models/DemoDicts.php

 $this->table_name = 'demo_dicts_dots';
  1. controllers/AdminDemoDicts.php
    public $search_fields = 'ref1.iname ref2.idesc idesc';
    public $list_sortdef = 'ref1.iname asc';   //default sorting - req param name, asc|desc direction
    public $list_sortmap = array(                   //sorting map: req param name => sql field name(s) asc|desc direction
                        'id'            => 'id',
                        'iname'         => 'iname',
                        'add_time'      => 'add_time',
                        'status'        => 'status',
                        'ref1.iname'    => 'ref1.iname',
                        'ref2.idesc'    => 'ref2.idesc',
                        'ref.compound'  => 'ref1.iname asc, ref2.idesc desc'
                        );
  1. list_table.html
            <th class="sortable" data-sort="status">`Status`</th>
            <th class="sortable" data-sort="ref1.iname">Ref 1</th>
            <th class="sortable" data-sort="ref2.idesc">Ref 2</th>
            <th class="sortable" data-sort="ref.compound">Ref Compound</th>
            <td><~/common/sel/status.sel selvalue="status"></td>
            <td><~ref1.iname></td>
            <td><~ref2.idesc></td>
            <td><~ref1.iname>, <~ref2.idesc></td>
  1. Expected SQL-log
SELECT * FROM demo_dicts_dots WHERE  status<>127  ORDER BY `ref1.iname` ASC LIMIT 0, 25
SELECT * FROM demo_dicts_dots WHERE  status<>127  ORDER BY `ref1.iname` DESC LIMIT 0, 25
SELECT * FROM demo_dicts_dots WHERE  status<>127  ORDER BY `ref2.idesc` ASC LIMIT 0, 25
SELECT * FROM demo_dicts_dots WHERE  status<>127  ORDER BY `ref2.idesc` DESC LIMIT 0, 25
SELECT * FROM demo_dicts_dots WHERE  status<>127  ORDER BY `ref1.iname` ASC, `ref2.idesc` DESC LIMIT 0, 25
SELECT * FROM demo_dicts_dots WHERE  status<>127  ORDER BY `ref1.iname` DESC, `ref2.idesc` ASC LIMIT 0, 25
SELECT * FROM demo_dicts_dots WHERE  status<>127  and (`ref1.iname` LIKE '%t2%' or `ref2.idesc` LIKE '%t2%' or `idesc` LIKE '%t2%') ORDER BY `ref1.iname` DESC, `ref2.idesc` ASC LIMIT 0, 25
SELECT * FROM demo_dicts_dots WHERE  status<>127  and (`ref1.iname` LIKE '%t2%' or `ref2.idesc` LIKE '%t2%' or `idesc` LIKE '%t2%') ORDER BY `ref1.iname` ASC, `ref2.idesc` DESC LIMIT 0, 25