Search among more than one sections

9 posts by 3 authors in: Forums > CMS Builder
Last Post: September 8, 2022   (RSS)

By andreasml - July 5, 2022

Hi

My CMSB contains a bunch of sections which share some common fields (eg. surname, name, id number etc). 

I wonder whether I could create a search tool for all different sections together (optimally, I could predefine which sections I would like to search into), instead of searching within each section as  the default search option of CMSB does.

Kind regards, 

Andreas Lazaris

By daniel - July 5, 2022

Hi Andreas,

Multi-table search is not natively supported in CMSB, but I can definitely see the potential use cases. It would be possible to create a plugin that does this, though the complexity of doing so would depend a bit on your needs.

CMSB has an experimental function called searchMultipleTables() that can be used to search through multiple tables as you want, but it was designed like a front-end view for listing records, so the list HTML is 100% custom, and it doesn't include the functionality built into the CMSB admin (view/modify/delete/etc.). If all you need to do is search the tables and list specific details this could work well. It's also pretty simple to create links to the edit page of any given record ("/cmsb/admin.php?menu=[insert table name here]&action=edit&num=[insert record num here]").

I've attached a file (multiSearch.php) that shows an example of how it can be used. The Sample Plugin (samplePlugin.php) could then be used as an example of how to add a page in CMSB to output the multi-search form/output.

If you need more of the built-in CMSB functionality, this is still possible but would require a more significant amount of custom programming. It would require either creating a plugin that replicates the default list and edit pages - but modified to support multiple tables - or a fully custom plugin built to your specific needs. As always, we're happy to provide an estimate for creating something like this if you're interested!

Let me know if you have any other questions.

Thanks!

Daniel
Technical Lead
interactivetools.com
Attachments:

multiSearch.php 4K

By andreasml - July 7, 2022

Hi Daniel

Thank you for your reply. For the beginning, this option seems acceptable. 

I created a web-page containing the multisearch.php file but it does not give anything 

Could you please give me a way to start?

Regards, 

Andreas

By daniel - July 7, 2022

Hi Andreas,

If the page is blank, it's likely having an issue loading the viewer library. By default it specifies the path manually:

require_once "../lib/viewer_functions.php";

You can either update this to point to the location of your viewer_functions.php file, or copy the "//load viewer library" section from the code generator, which would look something like this:

  // load viewer library
  $libraryPath = 'cmsb/lib/viewer_functions.php';
  $dirsToCheck = ['','../','../../','../../../','../../../../'];
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
  

Let me know if that helps!

Thanks,

Daniel
Technical Lead
interactivetools.com

By andreasml - July 9, 2022 - edited: July 9, 2022

Hi Daniel

Thank you for your reply. It seems that it starts to work. You can see it in this link: https://vascularregistry.gr/searchtest/ 

A few things with the search results that I cannot deal with are the following:

  1. On top of search results there appears some text which I cannot get rid of (see image 1)
  2. The results are correct but there is a bunch of information which I do not know how to modify them (see image 2). Also I do not know how I can modify Field1, field2, etc
  3. On the link for each one of the results records there appears a question-mark (see image 3) and when I click on this link a warning appears (see image 4) which does not allow me to open the record
  4. Also, the Next button does not seem to respond. Probably, due to the fact that there is a LIMIT of 10 in the SQL query. I cannot find where this SQL query is located. 

Thank you again for your assistance. 

Andreas

Attachments:

1.jpg 106K

2.jpg 84K

3.jpg 15K

4.jpg 38K

By daniel - July 11, 2022

Hi Andreas,

1. The sample multiSearch.php starts with the "debugSql" search option set to 1 - you can either change this to 0 or remove it entirely, which should remove that output.

2. This portion of the code is where you can change the returned values:

      $searchTables['news'] = array(
        'viewerUrl'       => 'newsPage.php',
        'titleField'      => 'title',
        'summaryField'    => 'summary',
        'searchFields'    =>  array('title','summary','content'),
      );

For example, you can change "title" and "summary" to the appropriate field names in your table. As well, you can use field1, field2, etc. to add up to 10 additional fields, like this:

      $searchTables['news'] = array(
        'viewerUrl'       => 'newsPage.php',
        'titleField'      => 'title',
        'summaryField'    => 'summary',
        'field1'          => 'content',
        'field2'          => 'category',
        'searchFields'    =>  array('title','summary','content'),
      );

3. The link-building portion of this function is currently incomplete - I would recommend constructing your own links in the page's output.

Regarding the warning: if you need this to open viewer/editor pages in the CMS it will need to be built into a plugin - I had forgotten that it's not possible to directly link to the admin from non-admin pages. Otherwise, if it'd work to view/edit on the front-end like you're doing with this test page, the simplest way would be to either use a regular details page from the Code Generator (view) or use the Form Generator with record editing enabled (edit).

4. You can change the number of records with the "perPage" search option.

Hopefully that all helps - let me know if you have any further questions!

Thanks,

Daniel
Technical Lead
interactivetools.com

By Tom - September 7, 2022 - edited: September 7, 2022

Hello Daniel,

As you said, "you can use field1, field2, etc. to add up to 10 additional fields"

Since 10 fields is not enough for my search page.

Is it possible to add more fields?

For example add up to 20 additional fields.

Thank You

By Tom - September 8, 2022

Thanks a lot Daniel !!