|
Building a Custom Search in CiviCRM
Design your search.
<joomla root>/administrator/components/com_civicrm/civicrm/CRM/Contact/Form/Search/Custom
Register your custom search component
* You will need to insert a record in civicrm_option_value to register your new search. The registration record includes an integer "value" - which is the invoke ID for the search component, the class path (defined in previous step), and the file name.
In my database, the highest "value" row was 5. So I'll use 6 as the `value` for our new search. Remember this value as we will use it in the URL to view the search form later. The class path is the `label`. The file path and name is the `name`. So, for our Employee Listing example - the insert query is: Modify functions in the new custom search file to meet your design.Define result set columns.
Create search form fields.
* If you want defaults for any form values - create a setDefaultValues() function and define them there. Define SELECT clause and DEFAULT SORT in the all() function.
Define a default sort - we'll use sort_name asc. If you want to modify the value returned in a cell...
Define FROM clause.
Define WHERE clause.
Define HAVING clause.
Decide on page layout.You can stick with the standard sample template to layout your search form and results (CRM/Contact/Form/Search/Custom/Sample.tpl), or create your own. The sample template simply loops through the list of fields you've defined in the 'elements' array above, and arranges them in a table - one field per row. If you want to lay out the form differently, and/or add styling, custom javascript etc. - create and modify a copy of that file. Then update the templateFile() function in your .php file to point to your new template. Test your search.
If you're not getting expected results, you can print out the SQL query being issued from the search form by adding these lines just before the return statement at the end of the all() function: If your search returns too many rows check that function all has a LIMIT statement appended to the sql: |
Custom Search Components
Skip to end of metadata
Go to start of metadata
Labels:
