ullVentoryItemSearch - an implementation tutorial
This tutorial describes exemplary steps in the process of implementing search functionality using the ullSearch framework.
It's meant to be read in combination with the overview of the framework shown here.
Goal: Implement advanced search for the ullVentoryItem model.
Create ullVentoryItem search config
- Create new file: ullVentoryPlugin/lib/search/ullVentoryItemSearchConfig.php - copy from ullUserSearchConfig
- Adapt the file as needed: model name, default columns, ...
- Add unwanted columns to blacklist - e.g. for ullVentoryItem the 'id' column should not be searchable since we have a custom id called inventory number anyway.
Configure ullVentoryItem search config factory
ullVentoryPlugin/config/app.yml - create and/or insert:
all: ullVentoryItem: search_class: ullVentoryItemSearchConfig
Create ullVentorySearchGenerator
- Create new class, inherits from ullSearchGenerator
- Override
- protected function customColumnConfig($columnConfig)
- Implement as needed (e.g. custom item attribute handling code)
Create ullVentorySearch
- Create new class, inherits from ullSearch
- Override
- protected function modifyColumnName($columnName)
- protected function modifyAlias(Doctrine_Query $q, $alias, ullSearchCriterion $criterion)
- Again, implement as needed
Insert search action functions into BaseUllVentoryActions
ullVentoryPlugin/modules/ullVentory/lib/BaseUllVentoryActions.class.php: copy from existing module:
- executeSearch()
- breadcrumbForSearch()
Adapt the following in executeSearch():
- model names
- query urls
- class names for *generator, *search
Create searchSuccess template
ullVentoryPlugin/modules/ullVentory/templates/searchSuccess.php: copy from existing module
Adapt the following:
- form url
- title
Insert query modification into BaseUllVentoryActions - getFilterFromRequest()
ullVentoryPlugin/modules/ullVentory/lib/BaseUllVentoryActions.class.php:
Insert following if branch (e.g. from BaseUllTableToolActions) after existing filtering, before ordering:
if ($query = $this->getRequestParameter('query')) ... until closing bracket
Notes:
- Don't forget to adapt the name of the search variable when retrieving it from the session.
- Insert $this->ull_filter = new ullFilter(); if needed
- Depending on existing getFilterFromRequest code it might be necessary to manually merge some code here
Insert filter into listSuccess
ullVentoryPlugin/modules/ullVentory/templates/listSuccess.php: add the following (copy from ullTableTool)
<?php echo $ull_filter->getHtml(ESC_RAW) ?> <?php echo ull_form_tag(array('page' => '', 'filter' => array('search' => ''))) ?>
This displays 'Query: Custom' filter in list view, to provide a delete button
Insert new humanizations into ullHumanizer
ullCorePlugin/lib/ullHumanizer.class.php: insert entries for relation and column names humanization as needed.
Link to search from admin center and/or sidebar
Wherever needed, link to ullVentory/search.